Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/tools/test_generate_cmake_presets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json

from tools.generate_cmake_presets import generate_presets


def test_generate_presets_accepts_explicit_cuda_compiler(tmp_path):
output = tmp_path / "CMakeUserPresets.json"

generate_presets(
output_path=str(output),
force_overwrite=True,
cuda_compiler="/opt/maca/bin/cucc",
)

data = json.loads(output.read_text(encoding="utf-8"))
cache = data["configurePresets"][0]["cacheVariables"]
assert cache["CMAKE_CUDA_COMPILER"] == "/opt/maca/bin/cucc"
32 changes: 28 additions & 4 deletions tools/generate_cmake_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ def get_cpu_cores():
return multiprocessing.cpu_count()


def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False):
def generate_presets(
output_path="CMakeUserPresets.json",
force_overwrite=False,
cuda_compiler=None,
):
"""Generates the CMakeUserPresets.json file."""

print("Attempting to detect your system configuration...")

# Detect NVCC
nvcc_path = None
if CUDA_HOME:
nvcc_path = cuda_compiler
if nvcc_path:
print(f"Using CUDA-compatible compiler from argument: {nvcc_path}")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If the cuda_compiler argument is provided as a relative path or as a command name, it is written directly to CMakeUserPresets.json without resolution. Since CMake configure presets are executed with the working directory set to the build directory (e.g., ${sourceDir}/cmake-build-release), any relative path will be resolved relative to the build directory rather than the project root, leading to configuration failures. Resolving the compiler path to an absolute path (similar to how python_executable is handled) ensures robust behavior.

    nvcc_path = cuda_compiler
    if nvcc_path:
        if not os.path.isabs(nvcc_path) and which(nvcc_path):
            nvcc_path = os.path.abspath(which(nvcc_path))
        elif not os.path.isabs(nvcc_path):
            nvcc_path = os.path.abspath(nvcc_path)
        print(f"Using CUDA-compatible compiler from argument: {nvcc_path}")


if not nvcc_path and CUDA_HOME:
prospective_path = os.path.join(CUDA_HOME, "bin", "nvcc")
if os.path.exists(prospective_path):
nvcc_path = prospective_path
Expand Down Expand Up @@ -176,6 +183,23 @@ def generate_presets(output_path="CMakeUserPresets.json", force_overwrite=False)
action="store_true",
help="Force overwrite existing CMakeUserPresets.json without prompting",
)
parser.add_argument(
"--output",
default="CMakeUserPresets.json",
help="Output path for the generated presets file",
)
parser.add_argument(
"--cuda-compiler",
help=(
"Path to the CUDA-compatible compiler. Use this in non-interactive "
"MACA containers when the compiler is exposed as cucc/mxcc rather "
"than nvcc."
),
)

args = parser.parse_args()
generate_presets(force_overwrite=args.force_overwrite)
generate_presets(
output_path=args.output,
force_overwrite=args.force_overwrite,
cuda_compiler=args.cuda_compiler,
)