-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,322 additions
and
1,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
BasedOnStyle: Google | ||
|
||
ColumnLimit: 120 | ||
IndentWidth: 4 | ||
Standard: Cpp11 | ||
AccessModifierOffset: -4 | ||
IndentCaseLabels: false | ||
|
||
AlignAfterOpenBracket: Align | ||
AlignConsecutiveAssignments: false | ||
AlignTrailingComments: true | ||
AlignOperands: true | ||
AllowAllParametersOfDeclarationOnNextLine: false | ||
AllowAllConstructorInitializersOnNextLine: false | ||
AllowShortBlocksOnASingleLine: false | ||
AllowShortFunctionsOnASingleLine: false | ||
BinPackArguments: true | ||
BreakConstructorInitializers: BeforeColon | ||
BreakConstructorInitializersBeforeComma: true | ||
Cpp11BracedListStyle: false | ||
ConstructorInitializerAllOnOneLineOrOnePerLine: false | ||
DerivePointerAlignment: false | ||
MaxEmptyLinesToKeep: 1 | ||
PointerAlignment: Right | ||
ReflowComments: false | ||
SortIncludes: false | ||
|
||
UseTab: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import platform | ||
|
||
from setuptools import setup | ||
from setuptools.errors import CCompilerError, PackageDiscoveryError | ||
from torch.utils.cpp_extension import BuildExtension | ||
|
||
|
||
class MyBuildExtension(BuildExtension): | ||
def run(self): | ||
try: | ||
super(MyBuildExtension, self).run() | ||
except FileNotFoundError: | ||
raise Exception("File not found. Could not compile C extension") | ||
|
||
def build_extension(self, ext): | ||
# common settings | ||
for e in self.extensions: | ||
pass | ||
|
||
# OS specific settings | ||
if platform.system() == "Darwin": | ||
for e in self.extensions: | ||
e.extra_compile_args.extend([ | ||
"-Xpreprocessor", | ||
"-fopenmp", | ||
"-mmacosx-version-min=10.15", | ||
]) | ||
e.extra_link_args.extend([ | ||
"-lomp", | ||
]) | ||
|
||
elif platform.system() == "Linux": | ||
for e in self.extensions: | ||
e.extra_compile_args.extend([ | ||
"-fopenmp", | ||
]) | ||
e.extra_link_args.extend([ | ||
"-fopenmp", | ||
]) | ||
|
||
# compiler specific settings | ||
if self.compiler.compiler_type == "unix": | ||
for e in self.extensions: | ||
e.extra_compile_args.extend([ | ||
"-std=c++17", | ||
"-pthread", | ||
]) | ||
|
||
elif self.compiler.compiler_type == "msvc": | ||
for e in self.extensions: | ||
e.extra_compile_args.extend(["/utf-8", "/std:c++17", "/openmp"]) | ||
e.define_macros.extend([ | ||
("_CRT_SECURE_NO_WARNINGS", 1), | ||
("_SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING", 1), | ||
]) | ||
|
||
# building | ||
try: | ||
super(MyBuildExtension, self).build_extension(ext) | ||
except (CCompilerError, PackageDiscoveryError, ValueError): | ||
raise Exception("Could not compile C extension") | ||
|
||
|
||
def build(setup_kwargs): | ||
from torch.utils.cpp_extension import CUDAExtension | ||
|
||
try: | ||
setup_kwargs.update({ | ||
"ext_modules": [ | ||
CUDAExtension( | ||
'torchmcubes_module', | ||
[ | ||
'cxx/pscan.cu', | ||
'cxx/mcubes.cpp', | ||
'cxx/mcubes_cpu.cpp', | ||
'cxx/mcubes_cuda.cu', | ||
'cxx/grid_interp_cpu.cpp', | ||
'cxx/grid_interp_cuda.cu', | ||
], | ||
extra_compile_args=['-DWITH_CUDA'], | ||
) | ||
], | ||
"cmdclass": { | ||
"build_ext": BuildExtension | ||
} | ||
}) | ||
except: | ||
from torch.utils.cpp_extension import CppExtension | ||
|
||
print('CUDA environment was not successfully loaded!') | ||
print('Build only CPU module!') | ||
|
||
setup_kwargs.update({ | ||
'ext_modules': [ | ||
CppExtension('torchmcubes_module', [ | ||
'cxx/mcubes.cpp', | ||
'cxx/mcubes_cpu.cpp', | ||
'cxx/grid_interp_cpu.cpp', | ||
]) | ||
], | ||
'cmdclass': { | ||
'build_ext': MyBuildExtension | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.