Skip to content
Snippets Groups Projects
setup.py 9.41 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/usr/bin/env python
    # -*- coding: latin-1 -*-
    
    
    def get_config_schema():
        from aksetup_helper import ConfigSchema, Option, \
    
    Marko Bencun's avatar
    Marko Bencun committed
                IncludeDir, LibraryDir, Libraries, \
                Switch, StringListOption
    
        import sys
        if 'darwin' in sys.platform:
    
            import platform
            osx_ver, _, _ = platform.mac_ver()
    
            osx_ver = '.'.join(osx_ver.split('.')[:2])
    
            sysroot_paths = [
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                    "/Applications/Xcode.app/Contents/Developer/Platforms/"
                    "MacOSX.platform/Developer/SDKs/MacOSX%s.sdk" % osx_ver,
    
                    "/Developer/SDKs/MacOSX%s.sdk" % osx_ver
                    ]
    
            default_cxxflags = ['-arch', 'i386', '-arch', 'x86_64']
    
            from os.path import isdir
            for srp in sysroot_paths:
                if isdir(srp):
                    default_cxxflags.extend(['-isysroot', srp])
                    break
    
    
            default_ldflags = default_cxxflags[:] + ["-Wl,-framework,OpenCL"]
    
        else:
            default_libs = ["OpenCL"]
            default_cxxflags = []
            default_ldflags = []
    
    
    Marko Bencun's avatar
    Marko Bencun committed
        return ConfigSchema([
    
            Switch("CL_TRACE", False, "Enable OpenCL API tracing"),
    
            Switch("CL_ENABLE_GL", False, "Enable OpenCL<->OpenGL interoperability"),
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            Switch("CL_ENABLE_DEVICE_FISSION", True,
                "Enable device fission extension, if present"),
            Option("CL_PRETEND_VERSION", None,
                "Dotted CL version (e.g. 1.2) which you'd like to use."),
    
    
            IncludeDir("CL", []),
            LibraryDir("CL", []),
    
            Libraries("CL", default_libs),
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            StringListOption("CXXFLAGS", default_cxxflags,
    
                help="Any extra C++ compiler options to include"),
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            StringListOption("LDFLAGS", default_ldflags,
    
                help="Any extra linker options to include"),
            ])
    
    
    def main():
    
        import os
        os.environ['PYOPENCL_SETUP'] = '1'
        
    
        from aksetup_helper import (hack_distutils, get_config, setup,
    
    Marko Bencun's avatar
    Marko Bencun committed
                NumpyExtension, 
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                check_git_submodules)
    
        check_git_submodules()
    
    
        hack_distutils()
    
        conf = get_config(get_config_schema(),
                warn_about_no_config=False)
    
    Marko Bencun's avatar
    Marko Bencun committed
        EXTRA_DEFINES = {}
    
        EXTRA_DEFINES["PYGPU_PACKAGE"] = "pyopencl"
    
        EXTRA_DEFINES["PYGPU_PYOPENCL"] = "1"
    
        if conf["CL_TRACE"]:
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            EXTRA_DEFINES["PYOPENCL_TRACE"] = 1
    
        if conf["CL_ENABLE_GL"]:
            EXTRA_DEFINES["HAVE_GL"] = 1
    
    
        if conf["CL_ENABLE_DEVICE_FISSION"]:
            EXTRA_DEFINES["PYOPENCL_USE_DEVICE_FISSION"] = 1
    
        if conf["CL_PRETEND_VERSION"]:
            try:
                major, minor = [int(x) for x in conf["CL_PRETEND_VERSION"].split(".")]
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                EXTRA_DEFINES["PYOPENCL_PRETEND_CL_VERSION"] = \
                        0x1000*major + 0x10 * minor
    
            except:
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                print("CL_PRETEND_VERSION must be of the form M.N, "
                        "with two integers M and N")
    
                raise
    
        version_file = open("pyopencl/version.py")
        try:
            version_file_contents = version_file.read()
        finally:
            version_file.close()
    
        exec(compile(version_file_contents, "pyopencl/version.py", 'exec'), ver_dic)
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
        SEPARATOR = "-"*75
    
        try:
            from distutils.command.build_py import build_py_2to3 as build_py
        except ImportError:
            # 2.x
            from distutils.command.build_py import build_py
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            import mako  # noqa
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
    
            print("Mako is not installed.")
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
            print("That is not a problem, as most of PyOpenCL will be just fine ")
            print("without it.Some higher-level parts of pyopencl (such as ")
            print("pyopencl.reduction) will not function without the templating engine ")
            print("Mako [1] being installed. If you would like this functionality to ")
            print("work, you might want to install Mako after you finish ")
            print("installing PyOpenCL.")
    
            print("")
            print("[1] http://www.makotemplates.org/")
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print("Hit Ctrl-C now if you'd like to think about the situation.")
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
    
            from aksetup_helper import count_down_delay
            count_down_delay(delay=5)
    
        might_be_cuda = False
        for inc_dir in conf["CL_INC_DIR"]:
            inc_dir = inc_dir.lower()
            if "nv" in inc_dir or "cuda" in inc_dir:
                might_be_cuda = True
    
        if might_be_cuda and conf["CL_ENABLE_DEVICE_FISSION"]:
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
            print("You might be compiling against Nvidia CUDA with device "
                    "fission enabled.")
            print(SEPARATOR)
            print("That is not a problem on CUDA 4.0 and newer. If you are "
                    "using CUDA 3.2,")
    
            print("your build will break, because Nvidia shipped a broken CL header in")
            print("in your version. The fix is to set CL_ENABLE_DEVICE_FISSION to False")
            print("in your PyOpenCL configuration.")
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print("Hit Ctrl-C now if you'd like to think about the situation.")
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
            print(SEPARATOR)
    
    
            from aksetup_helper import count_down_delay
            count_down_delay(delay=5)
    
        import sys
        if sys.version_info >= (3,):
            pvt_struct_source = "src/wrapper/_pvt_struct_v3.cpp"
        else:
            pvt_struct_source = "src/wrapper/_pvt_struct_v2.cpp"
    
    
    Marko Bencun's avatar
    Marko Bencun committed
        # wrap_cl_core.h needs to be available in pyopencl/
        # the cffi verifier depends on it.
        import shutil
        shutil.copyfile("src/c_wrapper/wrap_cl_core.h", "pyopencl/wrap_cl_core.h")
        
    
        # from pyopencl._cffi import _get_verifier
        # import os.path
        # current_directory = os.path.dirname(__file__)
    
        # # for development: clean cache such that the extension is rebuilt
        # shutil.rmtree(os.path.join(current_directory, 'pyopencl', '__pycache__/'), ignore_errors=True)
    
        setup(name="pyopencl",
                # metadata
    
                version=ver_dic["VERSION_TEXT"],
    
                description="Python wrapper for OpenCL",
    
                long_description=open("README.rst", "rt").read(),
    
                author="Andreas Kloeckner",
    
                author_email="inform@tiker.net",
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                license="MIT",
    
                url="http://mathema.tician.de/software/pyopencl",
                classifiers=[
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                    'Environment :: Console',
                    'Development Status :: 5 - Production/Stable',
                    'Intended Audience :: Developers',
                    'Intended Audience :: Other Audience',
                    'Intended Audience :: Science/Research',
                    'License :: OSI Approved :: MIT License',
                    'Natural Language :: English',
                    'Programming Language :: C++',
                    'Programming Language :: Python',
                    'Programming Language :: Python :: 2',
                    'Programming Language :: Python :: 2.4',
                    'Programming Language :: Python :: 2.5',
                    'Programming Language :: Python :: 2.6',
                    'Programming Language :: Python :: 2.7',
                    'Programming Language :: Python :: 3',
                    'Programming Language :: Python :: 3.2',
                    'Programming Language :: Python :: 3.3',
                    'Topic :: Scientific/Engineering',
                    'Topic :: Scientific/Engineering :: Mathematics',
                    'Topic :: Scientific/Engineering :: Physics',
                    ],
    
    
                # build info
    
                packages=["pyopencl", "pyopencl.characterize", "pyopencl.compyte"],
    
    
                install_requires=[
    
                    "pytools>=2013.5.2",
    
                    "decorator>=3.2.0",
    
    Marko Bencun's avatar
    Marko Bencun committed
                    "cffi>=0.7.2",
    
                    # "Mako>=0.3.6",
    
                ext_package="pyopencl",
                ext_modules=[
    
                    # _get_verifier(
                    #     sources=[
                    #         "src/c_wrapper/wrap_cl.cpp",
                    #         "src/c_wrapper/wrap_constants.cpp",
                    #         #"src/c_wrapper/wrap_mempool.cpp",
                    #         "src/c_wrapper/bitlog.cpp",
                    #     ],
                    #     include_dirs=conf["CL_INC_DIR"] + ["src/c_wrapper/"],
                    #     library_dirs=conf["CL_LIB_DIR"],
                    #     libraries=conf["CL_LIBNAME"],
                    #     define_macros=list(EXTRA_DEFINES.items()),
                    #     extra_compile_args=conf["CXXFLAGS"],
                    #     extra_link_args=conf["LDFLAGS"],
                    # ).get_extension()
                    NumpyExtension("_wrapcl",
                                   ["src/c_wrapper/wrap_cl.cpp",
                                    "src/c_wrapper/wrap_constants.cpp",
                                    #"src/c_wrapper/wrap_mempool.cpp",
                                    "src/c_wrapper/bitlog.cpp",],
                                   include_dirs=conf["CL_INC_DIR"] + ["src/c_wrapper/"],
                                   library_dirs=conf["CL_LIB_DIR"],
                                   libraries=conf["CL_LIBNAME"],
                                   define_macros=list(EXTRA_DEFINES.items()),
                                   extra_compile_args=conf["CXXFLAGS"],
                                   extra_link_args=conf["LDFLAGS"])
    
                include_package_data=True,
                package_data={
                        "pyopencl": [
                            "cl/*.cl",
                            "cl/*.h",
    
    Marko Bencun's avatar
    Marko Bencun committed
                            "wrap_cl_core.h",
    
                # 2to3 invocation
    
    Andreas Klöckner's avatar
    Andreas Klöckner committed
                cmdclass={'build_py': build_py},
                zip_safe=False)
    
    
    
    if __name__ == '__main__':
        main()