MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / get_extensions

Function get_extensions

setup.py:84–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

82
83
84def get_extensions():
85 this_dir = os.path.dirname(os.path.abspath(__file__))
86 ext_dir = os.path.join(this_dir, "monai", "csrc")
87 include_dirs = [ext_dir]
88
89 source_cpu = glob.glob(os.path.join(ext_dir, "**", "*.cpp"), recursive=True)
90 source_cuda = glob.glob(os.path.join(ext_dir, "**", "*.cu"), recursive=True)
91
92 extension = None
93 define_macros = [(f"{torch_parallel_backend()}", 1), ("MONAI_TORCH_VERSION", TORCH_VERSION)]
94 extra_compile_args = {}
95 extra_link_args = []
96 sources = source_cpu
97 if BUILD_CPP:
98 extension = CppExtension
99 extra_compile_args.setdefault("cxx", [])
100 if torch_parallel_backend() == "AT_PARALLEL_OPENMP":
101 extra_compile_args["cxx"] += omp_flags()
102 extra_link_args = omp_flags()
103 if BUILD_CUDA:
104 extension = CUDAExtension
105 sources += source_cuda
106 define_macros += [("WITH_CUDA", None)]
107 # Embed the maximum compute capability from TORCH_CUDA_ARCH_LIST
108 _torch_cuda_arch_list = os.environ.get("TORCH_CUDA_ARCH_LIST", "")
109 _max_cc = 0
110 if _torch_cuda_arch_list:
111 for _maj, _min in re.findall(r"([0-9]+)\.([0-9]+)", _torch_cuda_arch_list):
112 try:
113 _cc = int(_maj) * 100 + int(_min)
114 if _cc > _max_cc:
115 _max_cc = _cc
116 except ValueError:
117 pass
118 if _max_cc > 0:
119 define_macros += [("MONAI_MAX_COMPUTE_CAPABILITY", _max_cc)]
120 extra_compile_args = {"cxx": [], "nvcc": []}
121 if torch_parallel_backend() == "AT_PARALLEL_OPENMP":
122 extra_compile_args["cxx"] += omp_flags()
123 if extension is None or not sources:
124 return [] # compile nothing
125
126 ext_modules = [
127 extension(
128 name="monai._C",
129 sources=sources,
130 include_dirs=include_dirs,
131 define_macros=define_macros,
132 extra_compile_args=extra_compile_args,
133 extra_link_args=extra_link_args,
134 )
135 ]
136 return ext_modules
137
138
139def get_cmds():

Callers 1

setup.pyFile · 0.85

Calls 3

torch_parallel_backendFunction · 0.85
omp_flagsFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…