From b4b0c723f58e6cf53e9aedaea63ed842805b6b83 Mon Sep 17 00:00:00 2001 From: "junam.song" Date: Wed, 22 Apr 2026 16:15:46 +0900 Subject: [PATCH 1/3] build: add torch to build-system.requires scikit-build-core's isolated build env runs CMakeLists.txt which calls find_package(Torch CONFIG REQUIRED). The Torch CMake package ships inside the installed PyTorch Python package (torch/share/cmake/Torch/ TorchConfig.cmake), so torch must be importable in the build env. Without listing torch in [build-system].requires, any clean `pip install git+https://github.com/tatsy/torchmcubes.git` fails with CMake Error at CMakeLists.txt:43 (find_package): Could not find a package configuration file provided by "Torch" Adding torch here makes the install work in isolated build environments without requiring --no-build-isolation or manually pre-installing torch. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4a80e71..11e0694 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ license-files = ["LICENSE"] exclude = ["**/.mypy_cache/**", "**/build/**", "**/.vscode/**"] [build-system] -requires = ["scikit-build-core>=0.10", "pybind11>=2.10", "cmake", "ninja"] +requires = ["scikit-build-core>=0.10", "pybind11>=2.10", "cmake", "ninja", "torch"] build-backend = "scikit_build_core.build" [tool.isort] From 59c175d7343a57ddec7e805c4741d21ab40d8977 Mon Sep 17 00:00:00 2001 From: Junam Song Date: Thu, 10 Sep 2026 15:16:44 +0900 Subject: [PATCH 2/3] build: C++20, which torch >= 2.6 headers require torch/all.h and ATen.h #error on anything below C++20, so the wheel build fails against current torch (seen with 2.11: std::strong_ordering, string_view::starts_with, requires-clauses all missing under gnu++17). CPU sources verified to compile under -std=gnu++20 against torch 2.11.0+cpu. Co-Authored-By: Claude Fable 5 --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3433480..e2a762c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ if(CMAKE_CUDA_COMPILER) add_definitions(-DWITH_CUDA) find_package(CUDAToolkit REQUIRED) - set(CMAKE_CUDA_STANDARD 17) + set(CMAKE_CUDA_STANDARD 20) set(CMAKE_CUDA_STANDARD_REQUIRED ON) message(STATUS "INSTALLING EXTENSIONS WITH CUDA!") @@ -25,7 +25,8 @@ else() message(WARNING "NO CUDA INSTALLATION FOUND, TRYING TO INSTALL CPU VERSION ONLY!") endif() -set(CMAKE_CXX_STANDARD 17) +# torch >= 2.6 headers #error without C++20 (torch/all.h, ATen.h). +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) From aa49f65962e67e814a8fc0a7556a4f8319ad6384 Mon Sep 17 00:00:00 2001 From: Junam Song Date: Thu, 10 Sep 2026 20:08:32 +0900 Subject: [PATCH 3/3] build: locate Torch through torch itself find_package(Torch CONFIG) only worked where the environment's single site-packages happened to land on the search path; on RHEL-family platforms pip splits the build env into lib/ and lib64/ and the config is never found. Ask torch for torch.utils.cmake_prefix_path (the pattern PyTorch documents) and append it to CMAKE_PREFIX_PATH, with backend autoload disabled so a device extension does not have to load to answer a path query. A failed probe changes nothing. Co-Authored-By: Claude Fable 5 --- CMakeLists.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2a762c..d8dfc00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,22 @@ find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) find_package(pybind11 CONFIG REQUIRED) find_package(OpenMP) +# Ask torch itself where its CMake config lives: on RHEL-family platforms the +# build env splits site-packages into lib/ and lib64/, and a bare find_package +# never looks inside either. +# AUTOLOAD=0: a torch backend extension (e.g. torch-rbln) must not have to +# load just to answer a path query. +execute_process( + COMMAND "${CMAKE_COMMAND}" -E env TORCH_DEVICE_BACKEND_AUTOLOAD=0 + "${Python_EXECUTABLE}" -c "import torch; print(torch.utils.cmake_prefix_path)" + OUTPUT_VARIABLE TORCH_CMAKE_PREFIX_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE TORCH_QUERY_RESULT +) +if(TORCH_QUERY_RESULT EQUAL 0) + list(APPEND CMAKE_PREFIX_PATH "${TORCH_CMAKE_PREFIX_PATH}") +endif() + find_package(Torch CONFIG REQUIRED) find_library(TORCH_PYTHON_LIBRARY torch_python PATH "${TORCH_INSTALL_PREFIX}/lib") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")