Skip to content

Commit

Permalink
fix build system
Browse files Browse the repository at this point in the history
  • Loading branch information
JBlaschke committed Dec 23, 2020
1 parent f3e5753 commit 73ed4b9
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 104 deletions.
2 changes: 1 addition & 1 deletion PyNVTX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

major_version = 0;
minor_version = 2;
release_version = 2;
release_version = 3;

NVTX_IDENTIFIER = "NVTX"
REGISTRY = Registry()
Expand Down
196 changes: 93 additions & 103 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import os
import sys
import pybind11
import setuptools

Expand Down Expand Up @@ -93,7 +94,6 @@ def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
postargs = extra_postargs['nvcc']
else:
postargs = extra_postargs['gcc']
return # do no compile the .cpp (as we're in nvcc mode)

super(obj, src, ext, cc_args, postargs, pp_opts)
# Reset the default compiler_so, which we might have changed for cuda
Expand All @@ -104,110 +104,100 @@ def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):



def customize_compiler_for_gcc(self):

# Tell the compiler it can processes .cu
self.src_extensions.append('.cu')

# Save references to the default compiler_so and _comple methods
super = self._compile

# Now redefine the _compile method. This gets executed for each
# object but distutils doesn't have the ability to change compilers
# based on source extension: we add it.
def _compile(obj, src, ext, cc_args, extra_postargs, pp_opts):
if os.path.splitext(src)[1] == '.cu':
return

super(obj, src, ext, cc_args, postargs, pp_opts)
# Run the customize_compiler
class custom_build_ext(build_ext):
def build_extensions(self):
customize_compiler_for_nvcc(self.compiler)
build_ext.build_extensions(self)

# Inject our redefined _compile method into the class
self._compile = _compile


if __name__ == "__main__":

CUDA = locate_cuda()

# Run the customize_compiler
class custom_build_ext(build_ext):
def build_extensions(self):
if CUDA == None:
customize_compiler_for_gcc(self.compiler)
build_ext.build_extensions(self)
else:
customize_compiler_for_nvcc(self.compiler)
build_ext.build_extensions(self)



CUDA = locate_cuda()

if CUDA == None:
ext_modules = [
Extension(
"PyNVTX_backend",
sorted(glob(join("PyNVTX", "*.cpp")))
+ sorted(glob(join("PyNVTX", "*.cu"))),
# this syntax is specific to this build system we're only going to
# use certain compiler args with nvcc and not with gcc the
# implementation of this trick is in customize_compiler() below
extra_compile_args={"gcc": [],},
include_dirs=["PyNVTX"]
+ [pybind11.get_include(True ),
pybind11.get_include(False)]
)
]
else:
ext_modules = [
Extension(
"PyNVTX_backend",
sorted(glob(join("PyNVTX", "*.cpp")))
+ sorted(glob(join("PyNVTX", "*.cu"))),
library_dirs=[CUDA["lib64"]],
libraries=["cudart", "nvToolsExt"],
runtime_library_dirs=[CUDA["lib64"]],
# this syntax is specific to this build system we're only going to
# use certain compiler args with nvcc and not with gcc the
# implementation of this trick is in customize_compiler() below
# extra_compile_args={"gcc": [],
# "nvcc": ["-arch=sm_20", "--ptxas-options=-v",
# "-c", "--compiler-options", "'-fPIC'"]},
extra_compile_args={"gcc": [],
"nvcc": ["-std=c++11", "-O3", "-shared",
"--compiler-options", "-fPIC",
"-lnvToolsExt",]},
include_dirs=[CUDA["include"], "PyNVTX"]
+ [pybind11.get_include(True ),
pybind11.get_include(False)]
)
]



with open("README.md", "r") as fh:
long_description = fh.read()



setup(
name="PyNVTX",
version="0.2.2",
author="Johannes Blaschke",
author_email="[email protected]",
description="A thin python wrapper for the nvToolsExt (NVTX) library, using pybind11",
ext_modules=ext_modules,
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/JBlaschke/PyNVTX",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
install_requires=[
'pybind11',
],
# inject our custom trigger
cmdclass={'build_ext': custom_build_ext},
)
if CUDA == None:
ext_modules = [
Extension(
"PyNVTX_backend",
sorted(glob(join("PyNVTX", "*.cpp"))),
# this syntax is specific to this build system we're only going
# to use certain compiler args with nvcc and not with gcc the
# implementation of this trick is in customize_compiler() below
extra_compile_args={"gcc": [],},
include_dirs=["PyNVTX"]
+ [pybind11.get_include(True ),
pybind11.get_include(False)]
)
]
else:
ext_modules = [
Extension(
"PyNVTX_backend",
sorted(glob(join("PyNVTX", "*.cu"))),
library_dirs=[CUDA["lib64"]],
libraries=["cudart", "nvToolsExt"],
runtime_library_dirs=[CUDA["lib64"]],
# this syntax is specific to this build system we're only going
# to use certain compiler args with nvcc and not with gcc the
# implementation of this trick is in customize_compiler() below
# extra_compile_args={"gcc": [],
# "nvcc": ["-arch=sm_20", "--ptxas-options=-v",
# "-c", "--compiler-options", "'-fPIC'"]},
extra_compile_args={"gcc": [],
"nvcc": ["-std=c++11", "-O3", "-shared",
"--compiler-options", "-fPIC",
"-lnvToolsExt",]},
include_dirs=[CUDA["include"], "PyNVTX"]
+ [pybind11.get_include(True ),
pybind11.get_include(False)]
)
]


# We're in sdist mode => overwite extension module to include ALL sources
if "sdist" in sys.argv:
print(" *** ATTENTION: Running in sdist mode -- both CUDA and non-CUDA sources packaged to dist/")
ext_modules = [
Extension(
"PyNVTX_backend",
sorted(glob(join("PyNVTX", "*.cpp")))
+ sorted(glob(join("PyNVTX", "*.cu"))),
# this syntax is specific to this build system we're only going
# to use certain compiler args with nvcc and not with gcc the
# implementation of this trick is in customize_compiler() below
extra_compile_args={"gcc": [],},
include_dirs=["PyNVTX"]
+ [pybind11.get_include(True ),
pybind11.get_include(False)]
)
]


with open("README.md", "r") as fh:
long_description = fh.read()


setup(
name="PyNVTX",
version="0.2.3",
author="Johannes Blaschke",
author_email="[email protected]",
description="A thin python wrapper for the nvToolsExt (NVTX) library, using pybind11 ... with some bells and whistles thrown in for good measure.",
ext_modules=ext_modules,
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/JBlaschke/PyNVTX",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
python_requires='>=3.6',
install_requires=[
'pybind11',
],
# inject our custom trigger
cmdclass={'build_ext': custom_build_ext},
)

0 comments on commit 73ed4b9

Please sign in to comment.