-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
74 lines (59 loc) · 1.67 KB
/
Copy pathsetup.py
File metadata and controls
74 lines (59 loc) · 1.67 KB
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
from __future__ import annotations
import sys
from setuptools import setup
# pybind11 provides build helpers that correctly set up include paths and
# compiler flags for Python extension modules.
from pybind11.setup_helpers import Pybind11Extension, build_ext
# Single source of truth for the version. Passed to C++ via the VERSION_INFO
# macro and stringified there (see pybind_module.cpp).
VERSION = "0.1.0"
def compile_args():
"""Return compiler args for high-performance builds.
Requirement mapping:
- C++17
- -O3
- -mavx2 for SIMD
Note (Windows/MSVC):
- MSVC doesn't understand -O3/-mavx2, so we translate to /O2 and /arch:AVX2.
"""
if sys.platform.startswith("win"):
# MSVC flags
return ["/O2", "/arch:AVX2", "/openmp"]
# GCC/Clang flags
return [
"-O3",
"-mavx2",
"-mfma",
"-fopenmp",
]
def link_args():
if sys.platform.startswith("win"):
return []
return ["-fopenmp"]
ext_modules = [
Pybind11Extension(
"vectorcore", # module name: import vectorcore
[
"src/pybind_module.cpp",
"src/bruteforce_index.cpp",
"src/distance.cpp",
"src/hnsw_index.cpp",
"src/pq_index.cpp",
],
include_dirs=[
"include",
],
cxx_std=17,
define_macros=[("VERSION_INFO", VERSION)],
extra_compile_args=compile_args(),
extra_link_args=link_args(),
)
]
setup(
name="vectorcore",
version=VERSION,
description="VectorCore (prototype) - pybind11 extension",
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
zip_safe=False,
)