2 # -*- coding: latin-1 -*-
3 from os.path import dirname, join, normpath
6 def search_on_path(filenames):
7 """Find file on system path."""
8 # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52224
10 from os.path import exists, abspath
11 from os import pathsep, environ
13 search_path = environ["PATH"]
15 paths = search_path.split(pathsep)
17 for filename in filenames:
18 if exists(join(path, filename)):
19 return abspath(join(path, filename))
21 def get_config_schema():
22 from aksetup_helper import ConfigSchema, Option, \
23 IncludeDir, LibraryDir, Libraries, BoostLibraries, \
24 Switch, StringListOption, make_boost_base_options
26 nvcc_path = search_on_path(["nvcc", "nvcc.exe"])
28 print("*** WARNING: nvcc not in path.")
29 cuda_root_default = None
31 cuda_root_default = normpath(join(dirname(nvcc_path), ".."))
33 return ConfigSchema(make_boost_base_options() + [
34 Switch("USE_SHIPPED_BOOST", True, "Use included Boost library"),
36 BoostLibraries("python"),
37 BoostLibraries("thread"),
39 Switch("CUDA_TRACE", False, "Enable CUDA API tracing"),
40 Option("CUDA_ROOT", default=cuda_root_default, help="Path to the CUDA toolkit"),
41 Option("CUDA_PRETEND_VERSION", help="Assumed CUDA version, in the form 3010 for 3.1."),
42 IncludeDir("CUDA", None),
44 Switch("CUDA_ENABLE_GL", False, "Enable CUDA GL interoperability"),
45 Switch("CUDA_ENABLE_CURAND", True, "Enable CURAND library"),
47 LibraryDir("CUDADRV", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
48 Libraries("CUDADRV", ["cuda"]),
50 LibraryDir("CUDART", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
51 Libraries("CUDART", ["cudart"]),
53 LibraryDir("CURAND", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
54 Libraries("CURAND", ["curand"]),
56 StringListOption("CXXFLAGS", [],
57 help="Any extra C++ compiler options to include"),
58 StringListOption("LDFLAGS", [],
59 help="Any extra linker options to include"),
70 from aksetup_helper import (hack_distutils, get_config, setup, \
71 NumpyExtension, set_up_shipped_boost_if_requested,
74 check_git_submodules()
77 conf = get_config(get_config_schema())
79 EXTRA_SOURCES, EXTRA_DEFINES = set_up_shipped_boost_if_requested("pycuda", conf)
81 EXTRA_DEFINES["PYGPU_PACKAGE"] = "pycuda"
82 EXTRA_DEFINES["PYGPU_PYCUDA"] = "1"
84 LIBRARY_DIRS = conf["BOOST_LIB_DIR"] + conf["CUDADRV_LIB_DIR"]
85 LIBRARIES = (conf["BOOST_PYTHON_LIBNAME"] + conf["BOOST_THREAD_LIBNAME"]
86 + conf["CUDADRV_LIBNAME"])
88 if not conf["CUDA_INC_DIR"]:
89 conf["CUDA_INC_DIR"] = [join(conf["CUDA_ROOT"], "include")]
91 if conf["CUDA_TRACE"]:
92 EXTRA_DEFINES["CUDAPP_TRACE_CUDA"] = 1
94 if conf["CUDA_PRETEND_VERSION"]:
95 EXTRA_DEFINES["CUDAPP_PRETEND_CUDA_VERSION"] = conf["CUDA_PRETEND_VERSION"]
97 INCLUDE_DIRS = ['src/cpp'] + conf["BOOST_INC_DIR"] + conf["CUDA_INC_DIR"]
98 conf["USE_CUDA"] = True
100 if 'darwin' in sys.platform and sys.maxsize == 2147483647:
101 # The Python interpreter is running in 32 bit mode on OS X
102 if "-arch" not in conf["CXXFLAGS"]:
103 conf["CXXFLAGS"].extend(['-arch', 'i386', '-m32'])
104 if "-arch" not in conf["LDFLAGS"]:
105 conf["LDFLAGS"].extend(['-arch', 'i386', '-m32'])
107 if 'darwin' in sys.platform:
108 # set path to Cuda dynamic libraries,
109 # as a safe substitute for DYLD_LIBRARY_PATH
110 for lib_dir in conf["CUDADRV_LIB_DIR"]:
111 conf["LDFLAGS"].extend(["-Xlinker", "-rpath", "-Xlinker", lib_dir])
113 if conf["CUDA_ENABLE_GL"]:
114 EXTRA_SOURCES.append("src/wrapper/wrap_cudagl.cpp")
115 EXTRA_DEFINES["HAVE_GL"] = 1
117 if conf["CUDA_ENABLE_CURAND"]:
118 EXTRA_DEFINES["HAVE_CURAND"] = 1
119 EXTRA_SOURCES.extend([
120 "src/wrapper/wrap_curand.cpp"
122 LIBRARIES.extend(conf["CURAND_LIBNAME"])
123 LIBRARY_DIRS.extend(conf["CURAND_LIB_DIR"])
126 exec(compile(open("pycuda/__init__.py").read(), "pycuda/__init__.py", 'exec'), ver_dic)
129 from distutils.command.build_py import build_py_2to3 as build_py
132 from distutils.command.build_py import build_py
135 if sys.version_info >= (3,):
136 pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
138 pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
142 version=ver_dic["VERSION_TEXT"],
143 description="Python wrapper for Nvidia CUDA",
144 long_description=open("README.rst", "rt").read(),
145 author="Andreas Kloeckner",
146 author_email="inform@tiker.net",
148 url="http://mathema.tician.de/software/pycuda",
150 'Environment :: Console',
151 'Development Status :: 5 - Production/Stable',
152 'Intended Audience :: Developers',
153 'Intended Audience :: Other Audience',
154 'Intended Audience :: Science/Research',
155 'License :: OSI Approved :: MIT License',
156 'Natural Language :: English',
157 'Programming Language :: C++',
158 'Programming Language :: Python',
159 'Programming Language :: Python :: 3',
160 'Programming Language :: Python :: 2.4',
161 'Programming Language :: Python :: 2.5',
162 'Programming Language :: Python :: 2.6',
163 'Programming Language :: Python :: 2.7',
164 'Programming Language :: Python :: 3.2',
165 'Programming Language :: Python :: 3.3',
166 'Topic :: Scientific/Engineering',
167 'Topic :: Scientific/Engineering :: Mathematics',
168 'Topic :: Scientific/Engineering :: Physics',
169 'Topic :: Scientific/Engineering :: Visualization',
173 packages=["pycuda", "pycuda.gl", "pycuda.sparse", "pycuda.compyte"],
181 ext_package="pycuda",
183 NumpyExtension("_driver",
186 "src/cpp/bitlog.cpp",
187 "src/wrapper/wrap_cudadrv.cpp",
188 "src/wrapper/mempool.cpp",
190 include_dirs=INCLUDE_DIRS,
191 library_dirs=LIBRARY_DIRS,
193 define_macros=list(EXTRA_DEFINES.items()),
194 extra_compile_args=conf["CXXFLAGS"],
195 extra_link_args=conf["LDFLAGS"],
197 NumpyExtension("_pvt_struct",
199 extra_compile_args=conf["CXXFLAGS"],
200 extra_link_args=conf["LDFLAGS"],
204 include_package_data=True,
214 cmdclass={'build_py': build_py})
217 if __name__ == '__main__':