-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_native.py
More file actions
110 lines (98 loc) · 2.89 KB
/
setup_native.py
File metadata and controls
110 lines (98 loc) · 2.89 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
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
#!/usr/bin/env python3
"""
NexaDB Native C++ Extensions Setup
===================================
Build high-performance C++ extensions for vector operations
Installation:
python3 setup_native.py build_ext --inplace
Requirements:
- C++17 compatible compiler (gcc 7+, clang 5+, MSVC 2017+)
- pybind11
Features:
- SIMD optimizations (AVX2/AVX-512)
- Multi-threaded batch operations
- 50-100x faster than pure Python
"""
import sys
import platform
from pathlib import Path
from pybind11.setup_helpers import Pybind11Extension, build_ext
from setuptools import setup
# Determine compiler flags based on platform
def get_compile_args():
"""Get platform-specific compiler flags"""
system = platform.system()
if system == "Darwin": # macOS
return [
'-std=c++17',
'-O3', # Maximum optimization
'-march=native', # Use CPU-specific instructions
'-ffast-math', # Fast math optimizations
'-DNDEBUG', # Disable debug assertions
]
elif system == "Linux":
return [
'-std=c++17',
'-O3',
'-march=native',
'-ffast-math',
'-DNDEBUG',
'-fopenmp', # OpenMP for multi-threading
]
elif system == "Windows":
return [
'/std:c++17',
'/O2', # Maximum optimization
'/arch:AVX2', # Enable AVX2 instructions
'/DNDEBUG',
]
else:
return ['-std=c++17', '-O3']
def get_link_args():
"""Get platform-specific linker flags"""
system = platform.system()
if system == "Linux":
return ['-fopenmp']
else:
return []
# Define the C++ extension
ext_modules = [
Pybind11Extension(
"nexadb_native",
["nexadb/native/bindings.cpp"],
include_dirs=[
"nexadb/native",
],
extra_compile_args=get_compile_args(),
extra_link_args=get_link_args(),
cxx_std=17,
language='c++',
),
]
setup(
name="nexadb_native",
version="2.2.0",
author="NexaDB Team",
description="High-performance C++ vector operations for NexaDB",
long_description=__doc__,
ext_modules=ext_modules,
cmdclass={"build_ext": build_ext},
zip_safe=False,
python_requires=">=3.8",
)
if __name__ == "__main__":
print("=" * 80)
print("Building NexaDB Native C++ Extensions")
print("=" * 80)
print()
print(f"Platform: {platform.system()} {platform.machine()}")
print(f"Python: {sys.version.split()[0]}")
print(f"Compiler: {get_compile_args()}")
print()
print("Features:")
print(" ✓ SIMD optimizations (AVX2/AVX-512)")
print(" ✓ Multi-threaded batch operations")
print(" ✓ 50-100x faster than pure Python")
print()
print("=" * 80)
print()