Kernel.__init__: Deal with being passed bare _Programs.
[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         Option("CL_PRETEND_VERSION", None, "Dotted CL version (e.g. 1.2) which you'd like to use."),
47
48         IncludeDir("CL", []),
49         LibraryDir("CL", []),
50         Libraries("CL", default_libs),
51
52         StringListOption("CXXFLAGS", default_cxxflags, 
53             help="Any extra C++ compiler options to include"),
54         StringListOption("LDFLAGS", default_ldflags, 
55             help="Any extra linker options to include"),
56         ])
57
58
59
60
61 def main():
62     import glob
63     from aksetup_helper import (hack_distutils, get_config, setup,
64             NumpyExtension, set_up_shipped_boost_if_requested,
65             check_git_submodules)
66
67     check_git_submodules()
68
69     hack_distutils()
70     conf = get_config(get_config_schema(),
71             warn_about_no_config=False)
72     EXTRA_OBJECTS, EXTRA_DEFINES = set_up_shipped_boost_if_requested("pyopencl", conf)
73
74     LIBRARY_DIRS = conf["BOOST_LIB_DIR"]
75     LIBRARIES = conf["BOOST_PYTHON_LIBNAME"]
76
77     EXTRA_INCLUDE_DIRS = []
78
79     EXTRA_DEFINES["PYGPU_PACKAGE"] = "pyopencl"
80     EXTRA_DEFINES["PYGPU_PYOPENCL"] = "1"
81
82     if conf["CL_TRACE"]:
83         EXTRA_DEFINES["PYOPENCL_TRACE"] = 1
84
85     INCLUDE_DIRS = conf["BOOST_INC_DIR"] + conf["CL_INC_DIR"]
86
87     if conf["CL_ENABLE_GL"]:
88         EXTRA_DEFINES["HAVE_GL"] = 1
89
90     if conf["CL_ENABLE_DEVICE_FISSION"]:
91         EXTRA_DEFINES["PYOPENCL_USE_DEVICE_FISSION"] = 1
92     if conf["CL_PRETEND_VERSION"]:
93         try:
94             major, minor = [int(x) for x in conf["CL_PRETEND_VERSION"].split(".")]
95             EXTRA_DEFINES["PYOPENCL_PRETEND_CL_VERSION"] = 0x1000*major + 0x10 * minor
96         except:
97             print("CL_PRETEND_VERSION must be of the form M.N, with two integers M and N")
98             raise
99
100     ver_dic = {}
101     version_file = open("pyopencl/version.py")
102     try:
103         version_file_contents = version_file.read()
104     finally:
105         version_file.close()
106
107     exec(compile(version_file_contents, "pyopencl/version.py", 'exec'), ver_dic)
108
109     try:
110         from distutils.command.build_py import build_py_2to3 as build_py
111     except ImportError:
112         # 2.x
113         from distutils.command.build_py import build_py
114
115     try:
116         import mako
117     except ImportError:
118         print("-------------------------------------------------------------------------")
119         print("Mako is not installed.")
120         print("-------------------------------------------------------------------------")
121         print("That is not a problem, as most of PyOpenCL will be just fine without it.")
122         print("Some higher-level parts of pyopencl (such as pyopencl.reduction)")
123         print("will not function without the templating engine Mako [1] being installed.")
124         print("If you would like this functionality to work, you might want to install")
125         print("Mako after you finish installing PyOpenCL.")
126         print("")
127         print("[1] http://www.makotemplates.org/")
128         print("-------------------------------------------------------------------------")
129         print("Hit Ctrl-C now if you'd like to think about the situation.")
130         print("-------------------------------------------------------------------------")
131
132         from aksetup_helper import count_down_delay
133         count_down_delay(delay=5)
134
135     might_be_cuda = False
136     for inc_dir in conf["CL_INC_DIR"]:
137         inc_dir = inc_dir.lower()
138         if "nv" in inc_dir or "cuda" in inc_dir:
139             might_be_cuda = True
140
141     if might_be_cuda and conf["CL_ENABLE_DEVICE_FISSION"]:
142         print("-------------------------------------------------------------------------")
143         print("You might be compiling against Nvidia CUDA with device fission enabled.")
144         print("-------------------------------------------------------------------------")
145         print("That is not a problem on CUDA 4.0 and newer. If you are using CUDA 3.2,")
146         print("your build will break, because Nvidia shipped a broken CL header in")
147         print("in your version. The fix is to set CL_ENABLE_DEVICE_FISSION to False")
148         print("in your PyOpenCL configuration.")
149         print("-------------------------------------------------------------------------")
150         print("Hit Ctrl-C now if you'd like to think about the situation.")
151         print("-------------------------------------------------------------------------")
152
153         from aksetup_helper import count_down_delay
154         count_down_delay(delay=5)
155
156     import sys
157     if sys.version_info >= (3,):
158         pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
159     else:
160         pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
161
162     setup(name="pyopencl",
163             # metadata
164             version=ver_dic["VERSION_TEXT"],
165             description="Python wrapper for OpenCL",
166             long_description=open("README.rst", "rt").read(),
167             author="Andreas Kloeckner",
168             author_email="inform@tiker.net",
169             license = "MIT",
170             url="http://mathema.tician.de/software/pyopencl",
171             classifiers=[
172               'Environment :: Console',
173               'Development Status :: 5 - Production/Stable',
174               'Intended Audience :: Developers',
175               'Intended Audience :: Other Audience',
176               'Intended Audience :: Science/Research',
177               'License :: OSI Approved :: MIT License',
178               'Natural Language :: English',
179               'Programming Language :: C++',
180               'Programming Language :: Python',
181               'Programming Language :: Python :: 2',
182               'Programming Language :: Python :: 2.4',
183               'Programming Language :: Python :: 2.5',
184               'Programming Language :: Python :: 2.6',
185               'Programming Language :: Python :: 2.7',
186               'Programming Language :: Python :: 3',
187               'Programming Language :: Python :: 3.2',
188               'Programming Language :: Python :: 3.3',
189               'Topic :: Scientific/Engineering',
190               'Topic :: Scientific/Engineering :: Mathematics',
191               'Topic :: Scientific/Engineering :: Physics',
192               ],
193
194             # build info
195             packages=["pyopencl", "pyopencl.characterize", "pyopencl.compyte"],
196
197             install_requires=[
198                 "pytools>=2011.2",
199                 "pytest>=2",
200                 "decorator>=3.2.0",
201                 # "Mako>=0.3.6",
202                 ],
203
204             ext_package="pyopencl",
205             ext_modules=[
206                 NumpyExtension("_cl", 
207                     [
208                         "src/wrapper/wrap_cl.cpp", 
209                         "src/wrapper/wrap_cl_part_1.cpp", 
210                         "src/wrapper/wrap_cl_part_2.cpp", 
211                         "src/wrapper/wrap_constants.cpp", 
212                         "src/wrapper/wrap_mempool.cpp", 
213                         "src/wrapper/bitlog.cpp", 
214                         ]+EXTRA_OBJECTS, 
215                     include_dirs=INCLUDE_DIRS + EXTRA_INCLUDE_DIRS,
216                     library_dirs=LIBRARY_DIRS + conf["CL_LIB_DIR"],
217                     libraries=LIBRARIES + conf["CL_LIBNAME"],
218                     define_macros=list(EXTRA_DEFINES.items()),
219                     extra_compile_args=conf["CXXFLAGS"],
220                     extra_link_args=conf["LDFLAGS"],
221                     ),
222                 NumpyExtension("_pvt_struct",
223                     [pvt_struct_source],
224                     extra_compile_args=conf["CXXFLAGS"],
225                     extra_link_args=conf["LDFLAGS"],
226                     ),
227                 ],
228
229             include_package_data=True,
230             package_data={
231                     "pyopencl": [
232                         "cl/*.cl",
233                         "cl/*.h",
234                         ]
235                     },
236
237             # 2to3 invocation
238             cmdclass={'build_py': build_py},
239             zip_safe=False)
240
241
242
243
244 if __name__ == '__main__':
245     main()