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