fix: cmake set_gpu_env() and windows build (#520)

This commit is contained in:
yshekel
2024-05-20 13:05:45 +03:00
committed by GitHub
parent 1e343f17a3
commit 19a9b76d64
10 changed files with 67 additions and 36 deletions

View File

@@ -16,7 +16,10 @@ cpp:
- icicle/**/*.c
- icicle/**/*.h
- icicle/CMakeLists.txt
- .github/workflows/cpp_cuda.yml
- .github/workflows/cpp_cuda.yml
- icicle/cmake/Common.cmake
- icicle/cmake/CurvesCommon.cmake
- icicle/cmake/FieldsCommon.cmake
examples:
- examples/**/*
- .github/workflows/examples.yml

View File

@@ -100,5 +100,6 @@ jobs:
if: needs.check-changed-files.outputs.rust == 'true' || needs.check-changed-files.outputs.cpp_cuda == 'true'
env:
CUDA_PATH: ${{ steps.cuda-toolkit.outputs.CUDA_PATH }}
CUDA_ARCH: 50 # Using CUDA_ARCH=50 env variable since the CI machines have no GPUs
# Building from the root workspace will build all members of the workspace by default
run: cargo build --release --verbose

View File

@@ -21,46 +21,35 @@ function(set_gpu_env)
else()
find_program(_nvidia_smi "nvidia-smi")
if(_nvidia_smi)
set(DETECT_GPU_COUNT_NVIDIA_SMI 0)
if(_nvidia_smi)
execute_process(
COMMAND ${_nvidia_smi} --query-gpu=compute_cap --format=csv,noheader
OUTPUT_VARIABLE GPU_COMPUTE_CAPABILITIES
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Process the output to form the CUDA architectures string
string(REPLACE "\n" ";" GPU_COMPUTE_CAPABILITIES_LIST "${GPU_COMPUTE_CAPABILITIES}")
# execute nvidia-smi -L to get a short list of GPUs available
exec_program(${_nvidia_smi_path} ARGS -L
OUTPUT_VARIABLE _nvidia_smi_out
RETURN_VALUE _nvidia_smi_ret)
set(CUDA_ARCHITECTURES "")
foreach(CAPABILITY ${GPU_COMPUTE_CAPABILITIES_LIST})
# Remove the dot in compute capability to match CMake format
string(REPLACE "." "" CAPABILITY "${CAPABILITY}")
if(CUDA_ARCHITECTURES)
set(CUDA_ARCHITECTURES "${CUDA_ARCHITECTURES};${CAPABILITY}")
else()
set(CUDA_ARCHITECTURES "${CAPABILITY}")
endif()
endforeach()
# process the stdout of nvidia-smi
if(_nvidia_smi_ret EQUAL 0)
# convert string with newlines to list of strings
string(REGEX REPLACE "\n" ";" _nvidia_smi_out "${_nvidia_smi_out}")
foreach(_line ${_nvidia_smi_out})
if(_line MATCHES "^GPU [0-9]+:")
math(EXPR DETECT_GPU_COUNT_NVIDIA_SMI "${DETECT_GPU_COUNT_NVIDIA_SMI}+1")
# the UUID is not very useful for the user, remove it
string(REGEX REPLACE " \\(UUID:.*\\)" "" _gpu_info "${_line}")
if(NOT _gpu_info STREQUAL "")
list(APPEND DETECT_GPU_INFO "${_gpu_info}")
endif()
endif()
endforeach()
check_num_gpu_info(${DETECT_GPU_COUNT_NVIDIA_SMI} DETECT_GPU_INFO)
set(DETECT_GPU_COUNT ${DETECT_GPU_COUNT_NVIDIA_SMI})
message("Setting CMAKE_CUDA_ARCHITECTURES to: ${CUDA_ARCHITECTURES}")
set(CMAKE_CUDA_ARCHITECTURES "${CUDA_ARCHITECTURES}" PARENT_SCOPE)
else()
# no GPUs found, like on Github CI runners
message("Setting CMAKE_CUDA_ARCHITECTURES to: 50")
set(CMAKE_CUDA_ARCHITECTURES 50 PARENT_SCOPE) # some safe value
endif()
endif()
# ##
if(DETECT_GPU_COUNT GREATER 0)
set(CMAKE_CUDA_ARCHITECTURES native PARENT_SCOPE) # do native
else()
# no GPUs found, like on Github CI runners
set(CMAKE_CUDA_ARCHITECTURES 50 PARENT_SCOPE) # some safe value
endif()
endif()
# Check CUDA version and, if possible, enable multi-threaded compilation
if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "12.2")
message(STATUS "Using multi-threaded CUDA compilation.")

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -21,6 +22,10 @@ fn main() {
#[cfg(feature = "devmode")]
config.define("DEVMODE", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_curve")
@@ -48,6 +53,9 @@ fn main() {
#[cfg(feature = "devmode")]
config.define("DEVMODE", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_curve")

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -20,6 +21,10 @@ fn main() {
#[cfg(feature = "devmode")]
config.define("DEVMODE", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_curve")

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -20,6 +21,10 @@ fn main() {
#[cfg(feature = "devmode")]
config.define("DEVMODE", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_curve")

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -12,6 +13,10 @@ fn main() {
#[cfg(feature = "devmode")]
config.define("DEVMODE", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
let out_dir = config
.build_target("icicle_curve")
.build();

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -11,6 +12,10 @@ fn main() {
.define("CMAKE_BUILD_TYPE", "Release")
.define("EXT_FIELD", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_field")

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -11,6 +12,10 @@ fn main() {
.define("CMAKE_BUILD_TYPE", "Release")
.define("EXT_FIELD", "OFF");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_field")

View File

@@ -1,4 +1,5 @@
use cmake::Config;
use std::env;
fn main() {
println!("cargo:rerun-if-env-changed=CXXFLAGS");
@@ -9,6 +10,10 @@ fn main() {
config.define("CMAKE_BUILD_TYPE", "Release");
config.define("BUILD_HASH", "ON");
if let Ok(cuda_arch) = env::var("CUDA_ARCH") {
config.define("CUDA_ARCH", &cuda_arch);
}
// Build
let out_dir = config
.build_target("icicle_hash")