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"),
46 Option("CL_PRETEND_VERSION", None, "Dotted CL version (e.g. 1.2) which you'd like to use."),
50 Libraries("CL", default_libs),
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"),
63 from aksetup_helper import (hack_distutils, get_config, setup,
64 NumpyExtension, set_up_shipped_boost_if_requested,
67 check_git_submodules()
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)
74 LIBRARY_DIRS = conf["BOOST_LIB_DIR"]
75 LIBRARIES = conf["BOOST_PYTHON_LIBNAME"]
77 EXTRA_INCLUDE_DIRS = []
79 EXTRA_DEFINES["PYGPU_PACKAGE"] = "pyopencl"
80 EXTRA_DEFINES["PYGPU_PYOPENCL"] = "1"
83 EXTRA_DEFINES["PYOPENCL_TRACE"] = 1
85 INCLUDE_DIRS = conf["BOOST_INC_DIR"] + conf["CL_INC_DIR"]
87 if conf["CL_ENABLE_GL"]:
88 EXTRA_DEFINES["HAVE_GL"] = 1
90 if conf["CL_ENABLE_DEVICE_FISSION"]:
91 EXTRA_DEFINES["PYOPENCL_USE_DEVICE_FISSION"] = 1
92 if conf["CL_PRETEND_VERSION"]:
94 major, minor = [int(x) for x in conf["CL_PRETEND_VERSION"].split(".")]
95 EXTRA_DEFINES["PYOPENCL_PRETEND_CL_VERSION"] = 0x1000*major + 0x10 * minor
97 print("CL_PRETEND_VERSION must be of the form M.N, with two integers M and N")
101 version_file = open("pyopencl/version.py")
103 version_file_contents = version_file.read()
107 exec(compile(version_file_contents, "pyopencl/version.py", 'exec'), ver_dic)
110 from distutils.command.build_py import build_py_2to3 as build_py
113 from distutils.command.build_py import build_py
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.")
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("-------------------------------------------------------------------------")
132 from aksetup_helper import count_down_delay
133 count_down_delay(delay=5)
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:
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("-------------------------------------------------------------------------")
153 from aksetup_helper import count_down_delay
154 count_down_delay(delay=5)
157 if sys.version_info >= (3,):
158 pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
160 pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
162 setup(name="pyopencl",
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",
170 url="http://mathema.tician.de/software/pyopencl",
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',
195 packages=["pyopencl", "pyopencl.characterize", "pyopencl.compyte"],
204 ext_package="pyopencl",
206 NumpyExtension("_cl",
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",
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"],
222 NumpyExtension("_pvt_struct",
224 extra_compile_args=conf["CXXFLAGS"],
225 extra_link_args=conf["LDFLAGS"],
229 include_package_data=True,
238 cmdclass={'build_py': build_py},
244 if __name__ == '__main__':