Fix GPUArray.get{,_async}() docs. Fixes #58
[pycuda.git] / setup.py
1 #!/usr/bin/env python
2 # -*- coding: latin-1 -*-
3 from os.path import dirname, join, normpath
4
5
6 def search_on_path(filenames):
7     """Find file on system path."""
8     # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52224
9
10     from os.path import exists, abspath
11     from os import pathsep, environ
12
13     search_path = environ["PATH"]
14
15     paths = search_path.split(pathsep)
16     for path in paths:
17         for filename in filenames:
18             if exists(join(path, filename)):
19                 return abspath(join(path, filename))
20
21
22 def get_config_schema():
23     from aksetup_helper import ConfigSchema, Option, \
24             IncludeDir, LibraryDir, Libraries, BoostLibraries, \
25             Switch, StringListOption, make_boost_base_options
26
27     nvcc_path = search_on_path(["nvcc", "nvcc.exe"])
28     if nvcc_path is None:
29         print("***************************************************************")
30         print("*** WARNING: nvcc not in path.")
31         print("*** May need to set CUDA_INC_DIR for installation to succeed.")
32         print("***************************************************************")
33         cuda_root_default = None
34     else:
35         cuda_root_default = normpath(join(dirname(nvcc_path), ".."))
36
37     return ConfigSchema(make_boost_base_options() + [
38         Switch("USE_SHIPPED_BOOST", True, "Use included Boost library"),
39
40         BoostLibraries("python"),
41         BoostLibraries("thread"),
42
43         Switch("CUDA_TRACE", False, "Enable CUDA API tracing"),
44         Option("CUDA_ROOT", default=cuda_root_default,
45             help="Path to the CUDA toolkit"),
46         Option("CUDA_PRETEND_VERSION",
47             help="Assumed CUDA version, in the form 3010 for 3.1."),
48         IncludeDir("CUDA", None),
49
50         Switch("CUDA_ENABLE_GL", False, "Enable CUDA GL interoperability"),
51         Switch("CUDA_ENABLE_CURAND", True, "Enable CURAND library"),
52
53         LibraryDir("CUDADRV", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
54         Libraries("CUDADRV", ["cuda"]),
55
56         LibraryDir("CUDART", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
57         Libraries("CUDART", ["cudart"]),
58
59         LibraryDir("CURAND", ["${CUDA_ROOT}/lib", "${CUDA_ROOT}/lib64"]),
60         Libraries("CURAND", ["curand"]),
61
62         StringListOption("CXXFLAGS", [],
63             help="Any extra C++ compiler options to include"),
64         StringListOption("LDFLAGS", [],
65             help="Any extra linker options to include"),
66         ])
67
68
69 def main():
70     import sys
71
72     from aksetup_helper import (hack_distutils, get_config, setup,
73             NumpyExtension, set_up_shipped_boost_if_requested,
74             check_git_submodules)
75
76     check_git_submodules()
77
78     hack_distutils()
79     conf = get_config(get_config_schema())
80
81     EXTRA_SOURCES, EXTRA_DEFINES = set_up_shipped_boost_if_requested("pycuda", conf)
82
83     EXTRA_DEFINES["PYGPU_PACKAGE"] = "pycuda"
84     EXTRA_DEFINES["PYGPU_PYCUDA"] = "1"
85
86     LIBRARY_DIRS = conf["BOOST_LIB_DIR"] + conf["CUDADRV_LIB_DIR"]
87     LIBRARIES = (conf["BOOST_PYTHON_LIBNAME"] + conf["BOOST_THREAD_LIBNAME"]
88             + conf["CUDADRV_LIBNAME"])
89
90     if not conf["CUDA_INC_DIR"] and conf["CUDA_ROOT"]:
91         conf["CUDA_INC_DIR"] = [join(conf["CUDA_ROOT"], "include")]
92
93     if conf["CUDA_TRACE"]:
94         EXTRA_DEFINES["CUDAPP_TRACE_CUDA"] = 1
95
96     if conf["CUDA_PRETEND_VERSION"]:
97         EXTRA_DEFINES["CUDAPP_PRETEND_CUDA_VERSION"] = conf["CUDA_PRETEND_VERSION"]
98
99     INCLUDE_DIRS = ['src/cpp'] + conf["BOOST_INC_DIR"]
100     if conf["CUDA_INC_DIR"]:
101         INCLUDE_DIRS += conf["CUDA_INC_DIR"]
102
103     conf["USE_CUDA"] = True
104
105     if 'darwin' in sys.platform and sys.maxsize == 2147483647:
106         # The Python interpreter is running in 32 bit mode on OS X
107         if "-arch" not in conf["CXXFLAGS"]:
108             conf["CXXFLAGS"].extend(['-arch', 'i386', '-m32'])
109         if "-arch" not in conf["LDFLAGS"]:
110             conf["LDFLAGS"].extend(['-arch', 'i386', '-m32'])
111
112     if 'darwin' in sys.platform:
113         # set path to Cuda dynamic libraries,
114         # as a safe substitute for DYLD_LIBRARY_PATH
115         for lib_dir in conf["CUDADRV_LIB_DIR"]:
116             conf["LDFLAGS"].extend(["-Xlinker", "-rpath", "-Xlinker", lib_dir])
117
118     if conf["CUDA_ENABLE_GL"]:
119         EXTRA_SOURCES.append("src/wrapper/wrap_cudagl.cpp")
120         EXTRA_DEFINES["HAVE_GL"] = 1
121
122     if conf["CUDA_ENABLE_CURAND"]:
123         EXTRA_DEFINES["HAVE_CURAND"] = 1
124         EXTRA_SOURCES.extend([
125             "src/wrapper/wrap_curand.cpp"
126             ])
127         LIBRARIES.extend(conf["CURAND_LIBNAME"])
128         LIBRARY_DIRS.extend(conf["CURAND_LIB_DIR"])
129
130     ver_dic = {}
131     exec(compile(open("pycuda/__init__.py").read(), "pycuda/__init__.py", 'exec'),
132             ver_dic)
133
134     try:
135         from distutils.command.build_py import build_py_2to3 as build_py
136     except ImportError:
137         # 2.x
138         from distutils.command.build_py import build_py
139
140     import sys
141     if sys.version_info >= (3,):
142         pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
143     else:
144         pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
145
146     setup(name="pycuda",
147             # metadata
148             version=ver_dic["VERSION_TEXT"],
149             description="Python wrapper for Nvidia CUDA",
150             long_description=open("README.rst", "rt").read(),
151             author="Andreas Kloeckner",
152             author_email="inform@tiker.net",
153             license="MIT",
154             url="http://mathema.tician.de/software/pycuda",
155             classifiers=[
156                 'Environment :: Console',
157                 'Development Status :: 5 - Production/Stable',
158                 'Intended Audience :: Developers',
159                 'Intended Audience :: Other Audience',
160                 'Intended Audience :: Science/Research',
161                 'License :: OSI Approved :: MIT License',
162                 'Natural Language :: English',
163                 'Programming Language :: C++',
164                 'Programming Language :: Python',
165                 'Programming Language :: Python :: 3',
166                 'Programming Language :: Python :: 2.6',
167                 'Programming Language :: Python :: 2.7',
168                 'Programming Language :: Python :: 3.3',
169                 'Programming Language :: Python :: 3.4',
170                 'Topic :: Scientific/Engineering',
171                 'Topic :: Scientific/Engineering :: Mathematics',
172                 'Topic :: Scientific/Engineering :: Physics',
173                 'Topic :: Scientific/Engineering :: Visualization',
174                 ],
175
176             # build info
177             packages=["pycuda", "pycuda.gl", "pycuda.sparse", "pycuda.compyte"],
178
179             install_requires=[
180                 "pytools>=2011.2",
181                 "pytest>=2",
182                 "decorator>=3.2.0"
183                 ],
184
185             ext_package="pycuda",
186             ext_modules=[
187                 NumpyExtension("_driver",
188                     [
189                         "src/cpp/cuda.cpp",
190                         "src/cpp/bitlog.cpp",
191                         "src/wrapper/wrap_cudadrv.cpp",
192                         "src/wrapper/mempool.cpp",
193                         ]+EXTRA_SOURCES,
194                     include_dirs=INCLUDE_DIRS,
195                     library_dirs=LIBRARY_DIRS,
196                     libraries=LIBRARIES,
197                     define_macros=list(EXTRA_DEFINES.items()),
198                     extra_compile_args=conf["CXXFLAGS"],
199                     extra_link_args=conf["LDFLAGS"],
200                     ),
201                 NumpyExtension("_pvt_struct",
202                     [pvt_struct_source],
203                     extra_compile_args=conf["CXXFLAGS"],
204                     extra_link_args=conf["LDFLAGS"],
205                     ),
206                 ],
207
208             include_package_data=True,
209             package_data={
210                     "pycuda": [
211                         "cuda/*.hpp",
212                         ]
213                     },
214
215             zip_safe=False,
216
217             # 2to3 invocation
218             cmdclass={'build_py': build_py})
219
220
221 if __name__ == '__main__':
222     main()