-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetup.py
129 lines (100 loc) · 4.08 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# SPDX-FileCopyrightText: © 2024 Tenstorrent AI ULC
# SPDX-License-Identifier: Apache-2.0
import os
import re
import sys
import sysconfig
import platform
import subprocess
__requires__ = ["pip >= 24.0"]
from setuptools import setup, Extension, find_packages
from setuptools.command.build_ext import build_ext
forge_files = {"test": {"path": "forge/test", "files": ["conftest.py", "__init__.py", "utils.py", "test_user.py"]}}
class TTExtension(Extension):
def __init__(self, name):
Extension.__init__(self, name, sources=[])
class MyBuild(build_ext):
def run(self):
for ext in self.extensions:
fullname = self.get_ext_fullname(ext.name)
filename = self.get_ext_filename(fullname)
build_lib = self.build_lib
if not os.path.exists(build_lib):
continue # editable install?
# Build using our make flow, and then copy the file over
# Pass the required variables for building Wormhole or Grayskull
if "BACKEND_ARCH_NAME" not in os.environ:
print("Please provide environment variable `BACKEND_ARCH_NAME` to the build process.")
sys.exit(1)
additional_env_variables = {
"BACKEND_ARCH_NAME": os.environ.get("BACKEND_ARCH_NAME"),
}
env = os.environ.copy()
env.update(additional_env_variables)
nproc = os.cpu_count()
subprocess.check_call(
["make", f"-j{nproc}", "forge", r"DEVICE_VERSIM_INSTALL_ROOT=\$$ORIGIN/../.."], env=env
)
src = "build/lib/libforge_csrc.so"
self.copy_file(src, os.path.join(build_lib, filename))
self._copy_forge(build_lib)
def _copy_forge(self, target_path):
for t, d in forge_files.items():
path = target_path + "/" + d["path"]
os.makedirs(path, exist_ok=True)
src_path = d["path"]
if d["files"] == "*":
self.copy_tree(src_path, path)
else:
for f in d["files"]:
self.copy_file(src_path + "/" + f, path + "/" + f)
with open("README.md", "r") as f:
long_description = f.read()
# Read the requirements from the core list that is shared between
# dev and test.
with open("python_env/core_requirements.txt", "r") as f:
requirements = f.read().splitlines()
# Add specific requirements for distribution
# due to how we use the requirements file we can not use include requirements files
with open("python_env/dist_requirements.txt", "r") as f:
requirements += [r for r in f.read().splitlines() if not r.startswith("-r")]
# forge._C
forge_c = TTExtension("forge._C")
ext_modules = [forge_c]
packages = [p for p in find_packages("forge") if not p.startswith("test")]
short_hash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("ascii").strip()
date = (
subprocess.check_output(["git", "show", "-s", "--format=%cd", "--date=format:%y%m%d", "HEAD"])
.decode("ascii")
.strip()
)
arch_codes = {"wormhole_b0": "wh_b0", "grayskull": "gs", "blackhole": "bh"}
arch_code = arch_codes[os.environ["BACKEND_ARCH_NAME"]]
version = "0.1." + date + "+dev." + arch_code + "." + short_hash
setup(
name="forge",
version=version,
author="Tenstorrent",
url="http://www.tenstorrent.com",
author_email="info@tenstorrent.com",
description="AI/ML framework for Tenstorrent devices",
python_requires=">=3.8",
packages=packages,
package_data={"forge": ["tti/runtime_param_yamls/*.yaml"]},
package_dir={"forge": "forge/forge"},
long_description=long_description,
long_description_content_type="text/markdown",
ext_modules=ext_modules,
cmdclass=dict(build_ext=MyBuild),
zip_safe=False,
install_requires=requirements,
license="TBD",
keywords="forge machine learning tenstorrent",
# PyPI
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
)