Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
111 lines (95 loc) · 3.6 KB
/
Copy pathsetup.py
File metadata and controls
111 lines (95 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
from __future__ import annotations
import importlib.util
import os
import re
import sys
import sysconfig
from pathlib import Path
from setuptools import setup
ROOT = Path(__file__).resolve().parent
_TRUE_VALUES = {"1", "true", "yes", "on"}
_FALSE_VALUES = {"0", "false", "no", "off"}
def _development_version(version):
from packaging.version import Version
from setuptools_scm.version import release_branch_semver_version
inferred = release_branch_semver_version(version)
branch = (version.branch or "").rsplit("/", 1)[-1]
if version.exact or re.fullmatch(r"[0-9]+\.[0-9]+\.x", branch):
return inferred
minimum = version.format_with("0.3.0.dev{distance}")
return str(max(Version(inferred), Version(minimum)))
def _load_build_helpers(component):
module_path = ROOT / "src" / "cuphoton" / component / "setup_package.py"
spec = importlib.util.spec_from_file_location(
f"_cuphoton_{component}_setup_package", module_path
)
if spec is None or spec.loader is None:
raise RuntimeError(
f"Cannot load {component} build helpers: {module_path}"
)
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
def _build_enabled(variable, *, default=False):
mode = os.environ.get(variable, "1" if default else "0").strip().lower()
if mode in _FALSE_VALUES:
return False
if mode not in _TRUE_VALUES:
raise RuntimeError(
f"{variable} must be one of: "
+ ", ".join(sorted(_FALSE_VALUES | _TRUE_VALUES))
)
return True
extensions = []
commands = {}
if _build_enabled("CUPHOTON_XDR_BUILD_EXT"):
extensions.extend(_load_build_helpers("xdr").get_extensions())
if _build_enabled("CUPHOTON_XRAY_BUILD_EXT"):
extensions.extend(_load_build_helpers("xray").get_extensions())
build_xfit = _build_enabled("CUPHOTON_XFIT_BUILD_EXT")
build_imaging = _build_enabled(
"CUPHOTON_IMAGING_BUILD_EXT", default=build_xfit
)
if build_xfit or build_imaging:
xfit = _load_build_helpers("xfit")
commands["build_ext"] = xfit.CUDABuildExt
if build_xfit:
extensions.extend(xfit.get_extensions())
if build_imaging:
# Use the same selected SDK, architectures and licensed CCCL headers
# for the independent imaging extension.
imaging = xfit.get_extensions(require_cufft=True)[0]
source = Path("src/cuphoton/core/src")
imaging.name = "cuphoton.core._imaging_ext"
imaging.sources = [str(source / "imaging_ext.cpp")]
imaging.cuda_source_directory = source
imaging.include_dirs.append(sysconfig.get_path("include"))
imaging.libraries.append(":libcufft.so.12")
units = (
"imaging_copy",
"imaging_selection",
"imaging_reproject",
"imaging_xpois",
"imaging_spatial_xpois",
"imaging_fits",
)
imaging.depends = [
str(source / "imaging_api.h"),
*(str(source / f"{unit}.cu") for unit in units),
]
highest = int(imaging.architectures[-1].removesuffix("a"))
portable_ptx = tuple(sorted({75, highest}))
imaging.cuda_units = tuple(
(unit, False, False, imaging.architectures, portable_ptx)
for unit in units
)
extensions.append(imaging)
setup(
use_scm_version={"version_scheme": _development_version},
ext_modules=extensions,
cmdclass=commands,
)