forked from ashvardanian/SimSIMD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
204 lines (176 loc) · 7.48 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import os
import sys
from os.path import dirname
from setuptools import setup, Extension
from pathlib import Path
__lib_name__ = "simsimd"
__version__ = open("VERSION", "r").read().strip()
compile_args = []
link_args = []
macros_args = [
("SIMSIMD_NATIVE_F16", "0"),
("SIMSIMD_NATIVE_BF16", "0"),
("SIMSIMD_DYNAMIC_DISPATCH", "1"),
]
def is_editable_install():
"""Check if the package is installed in editable mode."""
if "develop" in sys.argv or "install" in sys.argv and "-e" in sys.argv:
return True
# Get the path to the site-packages or dist-packages
for path in sys.path:
egg_link = Path(path) / f"{__lib_name__}.egg-link"
if egg_link.exists():
return True
return False
# Check if the installation is in editable mode:
# In that case, we can't include type annotations, as it will lead to name resolution issues.
setup_kwargs = (
{
"packages": ["simsimd"],
"package_dir": {"simsimd": "python/annotations"},
"package_data": {"simsimd": ["__init__.pyi", "py.typed"]},
}
if not is_editable_install()
else {}
)
if is_editable_install():
print("You are installing in editable mode. Skipping type annotations installation.")
def get_bool_env(name: str, preference: bool) -> bool:
return os.environ.get(name, "1" if preference else "0") == "1"
def get_bool_env_w_name(name: str, preference: bool) -> tuple:
return name, "1" if get_bool_env(name, preference) else "0"
if sys.platform == "linux":
compile_args.append("-std=c11")
compile_args.append("-O3")
compile_args.append("-ffast-math")
compile_args.append("-fdiagnostics-color=always")
compile_args.append("-fvisibility=default")
compile_args.append("-fPIC")
link_args.append("-shared")
# Disable warnings
compile_args.append("-w")
# Enable OpenMP for Linux
compile_args.append("-fopenmp")
link_args.append("-fopenmp")
# Add vectorized `logf` implementation from the `glibc`
link_args.append("-lm")
# SIMD all the way on Linux!
macros_args.extend(
[
get_bool_env_w_name("SIMSIMD_TARGET_NEON", True),
get_bool_env_w_name("SIMSIMD_TARGET_NEON_F16", True),
get_bool_env_w_name("SIMSIMD_TARGET_NEON_BF16", True),
get_bool_env_w_name("SIMSIMD_TARGET_SVE", True),
get_bool_env_w_name("SIMSIMD_TARGET_SVE_F16", True),
get_bool_env_w_name("SIMSIMD_TARGET_SVE_BF16", True),
get_bool_env_w_name("SIMSIMD_TARGET_SVE2", True),
get_bool_env_w_name("SIMSIMD_TARGET_HASWELL", True),
get_bool_env_w_name("SIMSIMD_TARGET_SKYLAKE", True),
get_bool_env_w_name("SIMSIMD_TARGET_ICE", True),
get_bool_env_w_name("SIMSIMD_TARGET_GENOA", True),
get_bool_env_w_name("SIMSIMD_TARGET_SAPPHIRE", True),
get_bool_env_w_name("SIMSIMD_TARGET_TURIN", True),
get_bool_env_w_name("SIMSIMD_TARGET_SIERRA", False), # TODO: Add target spec to GCC & Clang
]
)
if sys.platform == "darwin":
compile_args.append("-std=c11")
compile_args.append("-O3")
compile_args.append("-ffast-math")
# Disable warnings
compile_args.append("-w")
# We can't SIMD all the way on MacOS :(
macros_args.extend(
[
get_bool_env_w_name("SIMSIMD_TARGET_NEON", True),
get_bool_env_w_name("SIMSIMD_TARGET_NEON_F16", True), # Supported on Apple M1 and newer
get_bool_env_w_name("SIMSIMD_TARGET_NEON_BF16", True), # Supported on Apple M2 and newer
get_bool_env_w_name("SIMSIMD_TARGET_SVE", False),
get_bool_env_w_name("SIMSIMD_TARGET_SVE2", False),
get_bool_env_w_name("SIMSIMD_TARGET_HASWELL", True),
get_bool_env_w_name("SIMSIMD_TARGET_SKYLAKE", False),
get_bool_env_w_name("SIMSIMD_TARGET_ICE", False),
get_bool_env_w_name("SIMSIMD_TARGET_GENOA", False),
get_bool_env_w_name("SIMSIMD_TARGET_SAPPHIRE", False),
get_bool_env_w_name("SIMSIMD_TARGET_TURIN", False),
get_bool_env_w_name("SIMSIMD_TARGET_SIERRA", False),
]
)
if sys.platform == "win32":
compile_args.append("/std:c11")
compile_args.append("/O2")
compile_args.append("/fp:fast")
compile_args.append("/EXPORT:*")
# Dealing with MinGW linking errors
# https://cibuildwheel.readthedocs.io/en/stable/faq/#windows-importerror-dll-load-failed-the-specific-module-could-not-be-found
compile_args.append("/d2FH4-")
# We can't SIMD all the way on Windows :(
# Even NEON `f16` fails: https://github.com/ashvardanian/SimSIMD/actions/runs/11419164624/job/31773473319?pr=214
macros_args.extend(
[
get_bool_env_w_name("SIMSIMD_TARGET_NEON", True),
get_bool_env_w_name("SIMSIMD_TARGET_NEON_F16", False),
get_bool_env_w_name("SIMSIMD_TARGET_NEON_BF16", False),
get_bool_env_w_name("SIMSIMD_TARGET_SVE", False),
get_bool_env_w_name("SIMSIMD_TARGET_SVE2", False),
get_bool_env_w_name("SIMSIMD_TARGET_HASWELL", True),
get_bool_env_w_name("SIMSIMD_TARGET_SKYLAKE", True),
get_bool_env_w_name("SIMSIMD_TARGET_ICE", True),
get_bool_env_w_name("SIMSIMD_TARGET_GENOA", False),
get_bool_env_w_name("SIMSIMD_TARGET_SAPPHIRE", False),
get_bool_env_w_name("SIMSIMD_TARGET_TURIN", False),
get_bool_env_w_name("SIMSIMD_TARGET_SIERRA", False),
]
)
ext_modules = [
Extension(
"simsimd",
sources=["python/lib.c", "c/lib.c"],
include_dirs=["include"],
extra_compile_args=compile_args,
extra_link_args=link_args,
define_macros=macros_args,
),
]
this_directory = os.path.abspath(dirname(__file__))
with open(os.path.join(this_directory, "README.md"), "r", encoding="utf8") as f:
long_description = f.read()
setup(
name=__lib_name__,
version=__version__,
author="Ash Vardanian",
author_email="[email protected]",
url="https://github.com/ashvardanian/simsimd",
description="Portable mixed-precision BLAS-like vector math library for x86 and ARM",
long_description=long_description,
long_description_content_type="text/markdown",
license="Apache-2.0",
classifiers=[
"License :: OSI Approved :: Apache Software License",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Development Status :: 5 - Production/Stable",
"Natural Language :: English",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Programming Language :: C",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Information Analysis",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Scientific/Engineering :: Chemistry",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
ext_modules=ext_modules,
zip_safe=False,
include_package_data=True,
**setup_kwargs,
)