From a9ef372e6b88f2ae97c89703241f212ab8d9a388 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 29 Nov 2023 15:10:09 -0500 Subject: [PATCH 1/4] Set pybind11_INCLUDE_DIRS correctly for CUDA --- pybind_interface/cuda/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pybind_interface/cuda/CMakeLists.txt b/pybind_interface/cuda/CMakeLists.txt index e5644d4e..d1d4b3f2 100644 --- a/pybind_interface/cuda/CMakeLists.txt +++ b/pybind_interface/cuda/CMakeLists.txt @@ -18,7 +18,12 @@ INCLUDE(../GetPybind11.cmake) find_package(PythonLibs 3.7 REQUIRED) find_package(CUDA REQUIRED) -include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) +include_directories(${PYTHON_INCLUDE_DIRS}) +if(pybind11_FOUND) + include_directories(${pybind11_INCLUDE_DIRS}) +else() # means pybind11 has been fetched in GetPybind11.cmake + include_directories(${pybind11_SOURCE_DIR}/include) +endif() cuda_add_library(qsim_cuda MODULE pybind_main_cuda.cpp) set_target_properties(qsim_cuda PROPERTIES From 11523c5d1359187684735a31cd0d384efe6d29f2 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 29 Nov 2023 15:07:28 -0500 Subject: [PATCH 2/4] Set CUDA_ARCHITECTURES to use CUDAARCHS (cmake-policy CMP0104) --- pybind_interface/cuda/CMakeLists.txt | 7 ++++--- pybind_interface/custatevec/CMakeLists.txt | 4 ++-- pybind_interface/decide/CMakeLists.txt | 11 ++++++----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pybind_interface/cuda/CMakeLists.txt b/pybind_interface/cuda/CMakeLists.txt index d1d4b3f2..81a5e16e 100644 --- a/pybind_interface/cuda/CMakeLists.txt +++ b/pybind_interface/cuda/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.18) project(qsim LANGUAGES CXX CUDA) if(WIN32) @@ -27,8 +27,9 @@ endif() cuda_add_library(qsim_cuda MODULE pybind_main_cuda.cpp) set_target_properties(qsim_cuda PROPERTIES - PREFIX "${PYTHON_MODULE_PREFIX}" - SUFFIX "${PYTHON_MODULE_EXTENSION}" + CUDA_ARCHITECTURES "$ENV{CUDAARCHS}" + PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}" ) set_source_files_properties(pybind_main_cuda.cpp PROPERTIES LANGUAGE CUDA) diff --git a/pybind_interface/custatevec/CMakeLists.txt b/pybind_interface/custatevec/CMakeLists.txt index 8c1d3871..acc4347d 100644 --- a/pybind_interface/custatevec/CMakeLists.txt +++ b/pybind_interface/custatevec/CMakeLists.txt @@ -40,8 +40,8 @@ cuda_add_library(qsim_custatevec MODULE pybind_main_custatevec.cpp) target_link_libraries(qsim_custatevec -lcustatevec -lcublas) set_target_properties(qsim_custatevec PROPERTIES - PREFIX "${PYTHON_MODULE_PREFIX}" - SUFFIX "${PYTHON_MODULE_EXTENSION}" + PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}" ) set_source_files_properties(pybind_main_custatevec.cpp PROPERTIES LANGUAGE CUDA) diff --git a/pybind_interface/decide/CMakeLists.txt b/pybind_interface/decide/CMakeLists.txt index 6b36282c..4303ea5f 100644 --- a/pybind_interface/decide/CMakeLists.txt +++ b/pybind_interface/decide/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.18) if(WIN32) set(CMAKE_CXX_FLAGS "/O2 /openmp") @@ -26,8 +26,9 @@ if(has_nvcc) find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development) include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) set_target_properties(qsim_decide PROPERTIES - PREFIX "${PYTHON_MODULE_PREFIX}" - SUFFIX "${PYTHON_MODULE_EXTENSION}" + CUDA_ARCHITECTURES "$ENV{CUDAARCHS}" + PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}" ) set_source_files_properties(decide.cpp PROPERTIES LANGUAGE CUDA) target_link_libraries(qsim_decide OpenMP::OpenMP_CXX) @@ -39,8 +40,8 @@ elseif(has_hipcc) find_package(Python3 3.7 REQUIRED COMPONENTS Interpreter Development) include_directories(${PYTHON_INCLUDE_DIRS} ${pybind11_SOURCE_DIR}/include) set_target_properties(qsim_decide PROPERTIES - PREFIX "${PYTHON_MODULE_PREFIX}" - SUFFIX "${PYTHON_MODULE_EXTENSION}" + PREFIX "${PYTHON_MODULE_PREFIX}" + SUFFIX "${PYTHON_MODULE_EXTENSION}" ) target_link_libraries(qsim_decide PUBLIC OpenMP::OpenMP_CXX) else() From 5ea50be970eb21e3efdeb738962efd1d27946f5f Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Fri, 8 Dec 2023 23:17:54 -0800 Subject: [PATCH 3/4] Add support for additional CMake arguments --- setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.py b/setup.py index 0ccdb084..c8b7efcc 100644 --- a/setup.py +++ b/setup.py @@ -48,6 +48,10 @@ def build_extension(self, ext): "-DPYTHON_INCLUDE_DIR=" + python_include_dir, ] + additional_cmake_args = os.environ.get("CMAKE_ARGS", "") + if additional_cmake_args: + cmake_args += additional_cmake_args.split() + cfg = "Debug" if self.debug else "Release" build_args = ["--config", cfg] From cad966217130af0ce9b0aea8947c991d52c83233 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 29 Nov 2023 10:16:09 -0800 Subject: [PATCH 4/4] Fix 'no instance of constructor "qsim::StateSpaceCUDA::Parameter::Parameter [with FP=float]" matches the argument list' Full error: ./pybind_interface/cuda/pybind_main_cuda.cpp(30): error: no instance of constructor "qsim::StateSpaceCUDA::Parameter::Parameter [with FP=float]" matches the argument list --- pybind_interface/cuda/pybind_main_cuda.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pybind_interface/cuda/pybind_main_cuda.cpp b/pybind_interface/cuda/pybind_main_cuda.cpp index 57b0ba84..74801408 100644 --- a/pybind_interface/cuda/pybind_main_cuda.cpp +++ b/pybind_interface/cuda/pybind_main_cuda.cpp @@ -27,8 +27,10 @@ namespace qsim { unsigned num_sim_threads, unsigned num_state_threads, unsigned num_dblocks - ) : ss_params{num_state_threads, num_dblocks} {} - + ) { + ss_params.num_threads = num_state_threads; + ss_params.num_dblocks = num_dblocks; + } StateSpace CreateStateSpace() const { return StateSpace(ss_params); }