Fix Bessel include. Don't flood terminal in case of scan error.
[pyopencl.git] / setup.py
1 #!/usr/bin/env python
2 # -*- coding: latin-1 -*-
3
4
5
6 def get_config_schema():
7     from aksetup_helper import ConfigSchema, Option, \
8             IncludeDir, LibraryDir, Libraries, BoostLibraries, \
9             Switch, StringListOption, make_boost_base_options
10
11     import sys
12     if 'darwin' in sys.platform:
13         import platform
14         osx_ver, _, _ = platform.mac_ver()
15         osx_ver = '.'.join(osx_ver.split('.')[:2])
16
17         sysroot_paths = [
18                 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX%s.sdk" % osx_ver,
19                 "/Developer/SDKs/MacOSX%s.sdk" % osx_ver
20                 ]
21
22         default_libs = []
23         default_cxxflags = ['-arch', 'i386', '-arch', 'x86_64']
24
25         from os.path import isdir
26         for srp in sysroot_paths:
27             if isdir(srp):
28                 default_cxxflags.extend(['-isysroot', srp])
29                 break
30
31         default_ldflags = default_cxxflags[:] + ["-Wl,-framework,OpenCL"]
32
33     else:
34         default_libs = ["OpenCL"]
35         default_cxxflags = []
36         default_ldflags = []
37
38     return ConfigSchema(make_boost_base_options() + [
39         BoostLibraries("python"),
40
41         Switch("USE_SHIPPED_BOOST", True, "Use included Boost library"),
42
43         Switch("CL_TRACE", False, "Enable OpenCL API tracing"),
44         Switch("CL_ENABLE_GL", False, "Enable OpenCL<->OpenGL interoperability"),
45         Switch("CL_ENABLE_DEVICE_FISSION", True, "Enable device fission extension, if present"),
46
47         IncludeDir("CL", []),
48         LibraryDir("CL", []),
49         Libraries("CL", default_libs),
50
51         StringListOption("CXXFLAGS", default_cxxflags, 
52             help="Any extra C++ compiler options to include"),
53         StringListOption("LDFLAGS", default_ldflags, 
54             help="Any extra linker options to include"),
55         ])
56
57
58
59
60 def main():
61     import glob
62     from aksetup_helper import (hack_distutils, get_config, setup,
63             NumpyExtension, set_up_shipped_boost_if_requested,
64             check_git_submodules)
65
66     check_git_submodules()
67
68     hack_distutils()
69     conf = get_config(get_config_schema(),
70             warn_about_no_config=False)
71     EXTRA_OBJECTS, EXTRA_DEFINES = set_up_shipped_boost_if_requested("pyopencl", conf)
72
73     LIBRARY_DIRS = conf["BOOST_LIB_DIR"]
74     LIBRARIES = conf["BOOST_PYTHON_LIBNAME"]
75
76     from os.path import dirname, join, normpath
77
78     EXTRA_INCLUDE_DIRS = []
79     EXTRA_LIBRARY_DIRS = []
80     EXTRA_LIBRARIES = []
81
82     EXTRA_DEFINES["PYGPU_PACKAGE"] = "pyopencl"
83     EXTRA_DEFINES["PYGPU_PYOPENCL"] = "1"
84
85     if conf["CL_TRACE"]:
86         EXTRA_DEFINES["PYOPENCL_TRACE"] = 1
87
88     INCLUDE_DIRS = conf["BOOST_INC_DIR"] + conf["CL_INC_DIR"]
89
90     ext_kwargs = dict()
91
92     if conf["CL_ENABLE_GL"]:
93         EXTRA_DEFINES["HAVE_GL"] = 1
94
95     if conf["CL_ENABLE_DEVICE_FISSION"]:
96         EXTRA_DEFINES["PYOPENCL_USE_DEVICE_FISSION"] = 1
97
98     ver_dic = {}
99     version_file = open("pyopencl/version.py")
100     try:
101         version_file_contents = version_file.read()
102     finally:
103         version_file.close()
104
105     exec(compile(version_file_contents, "pyopencl/version.py", 'exec'), ver_dic)
106
107     try:
108         from distutils.command.build_py import build_py_2to3 as build_py
109     except ImportError:
110         # 2.x
111         from distutils.command.build_py import build_py
112
113     try:
114         import mako
115     except ImportError:
116         print("-------------------------------------------------------------------------")
117         print("Mako is not installed.")
118         print("-------------------------------------------------------------------------")
119         print("That is not a problem, as most of PyOpenCL will be just fine without it.")
120         print("Some higher-level parts of pyopencl (such as pyopencl.reduction)")
121         print("will not function without the templating engine Mako [1] being installed.")
122         print("If you would like this functionality to work, you might want to install")
123         print("Mako after you finish installing PyOpenCL.")
124         print("")
125         print("[1] http://www.makotemplates.org/")
126         print("-------------------------------------------------------------------------")
127         print("Hit Ctrl-C now if you'd like to think about the situation.")
128         print("-------------------------------------------------------------------------")
129
130         from aksetup_helper import count_down_delay
131         count_down_delay(delay=5)
132
133     might_be_cuda = False
134     for inc_dir in conf["CL_INC_DIR"]:
135         inc_dir = inc_dir.lower()
136         if "nv" in inc_dir or "cuda" in inc_dir:
137             might_be_cuda = True
138
139     if might_be_cuda and conf["CL_ENABLE_DEVICE_FISSION"]:
140         print("-------------------------------------------------------------------------")
141         print("You might be compiling against Nvidia CUDA with device fission enabled.")
142         print("-------------------------------------------------------------------------")
143         print("That is not a problem on CUDA 4.0 and newer. If you are using CUDA 3.2,")
144         print("your build will break, because Nvidia shipped a broken CL header in")
145         print("in your version. The fix is to set CL_ENABLE_DEVICE_FISSION to False")
146         print("in your PyOpenCL configuration.")
147         print("-------------------------------------------------------------------------")
148         print("Hit Ctrl-C now if you'd like to think about the situation.")
149         print("-------------------------------------------------------------------------")
150
151         from aksetup_helper import count_down_delay
152         count_down_delay(delay=5)
153
154     import sys
155     if sys.version_info >= (3,):
156         pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
157     else:
158         pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
159
160     setup(name="pyopencl",
161             # metadata
162             version=ver_dic["VERSION_TEXT"],
163             description="Python wrapper for OpenCL",
164             long_description="""
165             PyOpenCL lets you access GPUs and other massively parallel compute
166             devices from Python. It tries to offer computing goodness in the
167             spirit of its sister project `PyCUDA <http://mathema.tician.de/software/pycuda>`_:
168
169             * Object cleanup tied to lifetime of objects. This idiom, often
170               called
171               `RAII <http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization>`_
172               in C++, makes it much easier to write correct, leak- and
173               crash-free code.
174
175             * Completeness. PyOpenCL puts the full power of OpenCL's API at
176               your disposal, if you wish.  Every obscure `get_info()` query and 
177               all CL calls are accessible.
178
179             * Automatic Error Checking. All CL errors are automatically
180               translated into Python exceptions.
181
182             * Speed. PyOpenCL's base layer is written in C++, so all the niceties
183               above are virtually free.
184
185             * Helpful and complete `Documentation <http://documen.tician.de/pyopencl>`_
186               as well as a `Wiki <http://wiki.tiker.net/PyOpenCL>`_.
187
188             * Liberal license. PyOpenCL is open-source under the 
189               `MIT license <http://en.wikipedia.org/wiki/MIT_License>`_
190               and free for commercial, academic, and private use.
191
192             * Broad support. PyOpenCL was tested and works with Apple's, AMD's, and Nvidia's 
193               CL implementations.
194
195             Like PyOpenCL? (And perhaps use it for `bitcoin
196             <http://bitcoin.org>`_ mining?) Leave a (bitcoin) tip:
197             1HGPQitv27CdENBcH1bstu5B3zeqXRDwtY
198             """,
199             author="Andreas Kloeckner",
200             author_email="inform@tiker.net",
201             license = "MIT",
202             url="http://mathema.tician.de/software/pyopencl",
203             classifiers=[
204               'Environment :: Console',
205               'Development Status :: 5 - Production/Stable',
206               'Intended Audience :: Developers',
207               'Intended Audience :: Other Audience',
208               'Intended Audience :: Science/Research',
209               'License :: OSI Approved :: MIT License',
210               'Natural Language :: English',
211               'Programming Language :: C++',
212               'Programming Language :: Python',
213             'Programming Language :: Python :: 3',
214               'Topic :: Scientific/Engineering',
215               'Topic :: Scientific/Engineering :: Mathematics',
216               'Topic :: Scientific/Engineering :: Physics',
217               ],
218
219             # build info
220             packages=["pyopencl", "pyopencl.characterize", "pyopencl.compyte"],
221
222             install_requires=[
223                 "pytools>=2011.2",
224                 "pytest>=2",
225                 "decorator>=3.2.0",
226                 # "Mako>=0.3.6",
227                 ],
228
229             ext_package="pyopencl",
230             ext_modules=[
231                 NumpyExtension("_cl", 
232                     [
233                         "src/wrapper/wrap_cl.cpp", 
234                         "src/wrapper/wrap_cl_part_1.cpp", 
235                         "src/wrapper/wrap_cl_part_2.cpp", 
236                         "src/wrapper/wrap_constants.cpp", 
237                         "src/wrapper/wrap_mempool.cpp", 
238                         "src/wrapper/bitlog.cpp", 
239                         ]+EXTRA_OBJECTS, 
240                     include_dirs=INCLUDE_DIRS + EXTRA_INCLUDE_DIRS,
241                     library_dirs=LIBRARY_DIRS + conf["CL_LIB_DIR"],
242                     libraries=LIBRARIES + conf["CL_LIBNAME"],
243                     define_macros=list(EXTRA_DEFINES.items()),
244                     extra_compile_args=conf["CXXFLAGS"],
245                     extra_link_args=conf["LDFLAGS"],
246                     ),
247                 NumpyExtension("_pvt_struct",
248                     [pvt_struct_source],
249                     extra_compile_args=conf["CXXFLAGS"],
250                     extra_link_args=conf["LDFLAGS"],
251                     ),
252                 ],
253
254             data_files=[
255                 ("include/pyopencl",
256                     glob.glob("src/cl/*.cl") + glob.glob("src/cl/*.h"))
257                 ],
258
259             # 2to3 invocation
260             cmdclass={'build_py': build_py})
261
262
263
264
265 if __name__ == '__main__':
266     main()