2 # -*- coding: latin-1 -*-
6 def get_config_schema():
7 from aksetup_helper import ConfigSchema, Option, \
8 IncludeDir, LibraryDir, Libraries, BoostLibraries, \
9 Switch, StringListOption, make_boost_base_options
12 if 'darwin' in sys.platform:
14 osx_ver, _, _ = platform.mac_ver()
15 osx_ver = '.'.join(osx_ver.split('.')[:2])
18 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX%s.sdk" % osx_ver,
19 "/Developer/SDKs/MacOSX%s.sdk" % osx_ver
23 default_cxxflags = ['-arch', 'i386', '-arch', 'x86_64']
25 from os.path import isdir
26 for srp in sysroot_paths:
28 default_cxxflags.extend(['-isysroot', srp])
31 default_ldflags = default_cxxflags[:] + ["-Wl,-framework,OpenCL"]
34 default_libs = ["OpenCL"]
38 return ConfigSchema(make_boost_base_options() + [
39 BoostLibraries("python"),
41 Switch("USE_SHIPPED_BOOST", True, "Use included Boost library"),
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"),
49 Libraries("CL", default_libs),
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"),
62 from aksetup_helper import (hack_distutils, get_config, setup,
63 NumpyExtension, set_up_shipped_boost_if_requested,
66 check_git_submodules()
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)
73 LIBRARY_DIRS = conf["BOOST_LIB_DIR"]
74 LIBRARIES = conf["BOOST_PYTHON_LIBNAME"]
76 from os.path import dirname, join, normpath
78 EXTRA_INCLUDE_DIRS = []
79 EXTRA_LIBRARY_DIRS = []
82 EXTRA_DEFINES["PYGPU_PACKAGE"] = "pyopencl"
83 EXTRA_DEFINES["PYGPU_PYOPENCL"] = "1"
86 EXTRA_DEFINES["PYOPENCL_TRACE"] = 1
88 INCLUDE_DIRS = conf["BOOST_INC_DIR"] + conf["CL_INC_DIR"]
92 if conf["CL_ENABLE_GL"]:
93 EXTRA_DEFINES["HAVE_GL"] = 1
95 if conf["CL_ENABLE_DEVICE_FISSION"]:
96 EXTRA_DEFINES["PYOPENCL_USE_DEVICE_FISSION"] = 1
99 version_file = open("pyopencl/version.py")
101 version_file_contents = version_file.read()
105 exec(compile(version_file_contents, "pyopencl/version.py", 'exec'), ver_dic)
108 from distutils.command.build_py import build_py_2to3 as build_py
111 from distutils.command.build_py import build_py
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.")
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("-------------------------------------------------------------------------")
130 from aksetup_helper import count_down_delay
131 count_down_delay(delay=5)
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:
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("-------------------------------------------------------------------------")
151 from aksetup_helper import count_down_delay
152 count_down_delay(delay=5)
155 if sys.version_info >= (3,):
156 pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
158 pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
160 setup(name="pyopencl",
162 version=ver_dic["VERSION_TEXT"],
163 description="Python wrapper for OpenCL",
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>`_:
169 * Object cleanup tied to lifetime of objects. This idiom, often
171 `RAII <http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization>`_
172 in C++, makes it much easier to write correct, leak- and
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.
179 * Automatic Error Checking. All CL errors are automatically
180 translated into Python exceptions.
182 * Speed. PyOpenCL's base layer is written in C++, so all the niceties
183 above are virtually free.
185 * Helpful and complete `Documentation <http://documen.tician.de/pyopencl>`_
186 as well as a `Wiki <http://wiki.tiker.net/PyOpenCL>`_.
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.
192 * Broad support. PyOpenCL was tested and works with Apple's, AMD's, and Nvidia's
195 Like PyOpenCL? (And perhaps use it for `bitcoin
196 <http://bitcoin.org>`_ mining?) Leave a (bitcoin) tip:
197 1HGPQitv27CdENBcH1bstu5B3zeqXRDwtY
199 author="Andreas Kloeckner",
200 author_email="inform@tiker.net",
202 url="http://mathema.tician.de/software/pyopencl",
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',
220 packages=["pyopencl", "pyopencl.characterize", "pyopencl.compyte"],
229 ext_package="pyopencl",
231 NumpyExtension("_cl",
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",
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"],
247 NumpyExtension("_pvt_struct",
249 extra_compile_args=conf["CXXFLAGS"],
250 extra_link_args=conf["LDFLAGS"],
256 glob.glob("src/cl/*.cl") + glob.glob("src/cl/*.h"))
260 cmdclass={'build_py': build_py})
265 if __name__ == '__main__':