forked from IntelPython/dpctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
226 lines (192 loc) · 6.12 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
##===---------- setup.py - dpctl.ocldrv interface -----*- Python -*-----===##
##
## Data Parallel Control Library (dpCtl)
##
## Copyright 2020 Intel Corporation
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##===----------------------------------------------------------------------===##
###
### \file
### This file builds the dpctl and dpctl.ocldrv extension modules.
##===----------------------------------------------------------------------===##
import os
import os.path
import sys
import versioneer
import subprocess
import setuptools.command.install as orig_install
import setuptools.command.develop as orig_develop
from setuptools import setup, Extension, find_packages
from Cython.Build import cythonize
import numpy as np
requirements = [
"cython",
]
IS_WIN = False
IS_MAC = False
IS_LIN = False
if "linux" in sys.platform:
IS_LIN = True
elif sys.platform == "darwin":
IS_MAC = True
elif sys.platform in ["win32", "cygwin"]:
IS_WIN = True
else:
assert False, sys.platform + " not supported"
if IS_LIN:
DPCPP_ROOT = os.environ["ONEAPI_ROOT"] + "/compiler/latest/linux"
os.environ["CC"] = DPCPP_ROOT + "/bin/clang"
os.environ["CXX"] = DPCPP_ROOT + "/bin/clang++"
os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl"
os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl/include"
os.environ["CFLAGS"] = "-fPIC"
elif IS_WIN:
os.environ["CC"] = "clang-cl.exe"
os.environ["CXX"] = "dpcpp.exe"
os.environ["DPPL_SYCL_INTERFACE_LIBDIR"] = "dpctl"
os.environ["DPPL_SYCL_INTERFACE_INCLDIR"] = "dpctl\include"
dppl_sycl_interface_lib = os.environ["DPPL_SYCL_INTERFACE_LIBDIR"]
dppl_sycl_interface_include = os.environ["DPPL_SYCL_INTERFACE_INCLDIR"]
sycl_lib = os.environ["ONEAPI_ROOT"] + "\compiler\latest\windows\lib"
def get_sdl_cflags():
if IS_LIN or IS_MAC:
return [
"-fstack-protector",
"-fPIC",
"-D_FORTIFY_SOURCE=2",
"-Wformat",
"-Wformat-security",
]
elif IS_WIN:
return []
def get_sdl_ldflags():
if IS_LIN:
return [
"-Wl,-z,noexecstack,-z,relro,-z,now",
]
elif IS_MAC:
return []
elif IS_WIN:
return ["/NXCompat", "/DynamicBase"]
def get_other_cxxflags():
if IS_LIN:
return ["-O3", "-fsycl", "-std=c++17"]
elif IS_MAC:
return []
elif IS_WIN:
# FIXME: These are specific to MSVC and we should first make sure
# what compiler we are using.
return ["/Ox", "/std:c++17"]
def get_suppressed_warning_flags():
if IS_LIN:
# PEP 590 renamed "tp_print" to "tp_vectorcall" and this causes a flood
# of deprecation warnings in the Cython generated module. This flag
# temporarily suppresses the warnings. The flag should not be needed
# once we move to Python 3.9 and/or Cython 0.30.
return ["-Wno-deprecated-declarations"]
elif IS_WIN:
return []
def build_backend():
build_script = os.path.join(os.getcwd(), "scripts", "build_backend.py")
subprocess.check_call([sys.executable, build_script])
def extensions():
# Security flags
eca = get_sdl_cflags()
ela = get_sdl_ldflags()
libs = []
librarys = []
if IS_LIN:
libs += ["rt", "DPPLSyclInterface"]
elif IS_MAC:
pass
elif IS_WIN:
libs += ["DPPLSyclInterface", "sycl"]
if IS_LIN:
librarys = [dppl_sycl_interface_lib]
elif IS_WIN:
librarys = [dppl_sycl_interface_lib, sycl_lib]
elif IS_MAC:
librarys = [dppl_sycl_interface_lib]
if IS_LIN or IS_MAC:
runtime_library_dirs = ["$ORIGIN"]
elif IS_WIN:
runtime_library_dirs = []
extension_args = {
"depends": [
dppl_sycl_interface_include,
],
"include_dirs": [np.get_include(), dppl_sycl_interface_include],
"extra_compile_args": eca
+ get_other_cxxflags()
+ get_suppressed_warning_flags(),
"extra_link_args": ela,
"libraries": libs,
"library_dirs": librarys,
"runtime_library_dirs": runtime_library_dirs,
"language": "c++",
}
extensions = [
Extension(
"dpctl._sycl_core",
[
os.path.join("dpctl", "_sycl_core.pyx"),
],
**extension_args
),
Extension(
"dpctl.memory._memory",
[
os.path.join("dpctl", "memory", "_memory.pyx"),
],
**extension_args
),
]
exts = cythonize(extensions)
return exts
class install(orig_install.install):
def run(self):
build_backend()
return super().run()
class develop(orig_develop.develop):
def run(self):
build_backend()
return super().run()
def _get_cmdclass():
cmdclass = versioneer.get_cmdclass()
cmdclass["install"] = install
cmdclass["develop"] = develop
return cmdclass
print("packages:", find_packages(include=["*"]))
setup(
name="dpctl",
version=versioneer.get_version(),
cmdclass=_get_cmdclass(),
description="A lightweight Python wrapper for a subset of OpenCL and SYCL.",
license="Apache 2.0",
author="Intel Corporation",
url="https://github.com/IntelPython/dpCtl",
packages=find_packages(include=["*"]),
include_package_data=True,
ext_modules=extensions(),
setup_requires=requirements,
install_requires=requirements,
keywords="dpctl",
classifiers=[
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)