Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
IP
elsa
Commits
6ad66e61
Commit
6ad66e61
authored
Feb 12, 2020
by
Jens Petit
Committed by
Tobias Lasser
Feb 12, 2020
Browse files
CUDA compute capability detection stand-alone
parent
fa4ecd06
Pipeline
#216659
passed with stages
in 41 minutes and 38 seconds
Changes
2
Pipelines
10
Hide whitespace changes
Inline
Side-by-side
cmake/ComputeCapabilityCUDA.cmake
0 → 100644
View file @
6ad66e61
cmake_minimum_required
(
VERSION 3.10
)
################################################################################################
# Automatic GPU detection is not included with every CMake release (e.g. it is unavailable in
# the CMake version installed with the default Ubuntu package manager)
#
# Taken from the official CMake repository, with minor modifications:
# https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindCUDA/select_compute_arch.cmake
#
# A function for automatic detection of GPUs installed (if autodetection is enabled)
# Usage:
# CUDA_DETECT_INSTALLED_GPUS(OUT_VARIABLE)
#
function
(
CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE
)
set
(
file
"
${
PROJECT_BINARY_DIR
}
/detect_cuda_compute_capabilities.cu"
)
file
(
WRITE
${
file
}
""
"#include <cuda_runtime.h>
\n
"
"#include <cstdio>
\n
"
"int main()
\n
"
"{
\n
"
" int count = 0;
\n
"
" if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;
\n
"
" if (count == 0) return -1;
\n
"
" for (int device = 0; device < count; ++device)
\n
"
" {
\n
"
" cudaDeviceProp prop;
\n
"
" if (cudaSuccess == cudaGetDeviceProperties(&prop, device))
\n
"
" std::printf(
\"
%d.%d
\"
, prop.major, prop.minor);
\n
"
" }
\n
"
" return 0;
\n
"
"}
\n
"
)
try_run
(
run_result compile_result
${
PROJECT_BINARY_DIR
}
${
file
}
RUN_OUTPUT_VARIABLE compute_capabilities
)
# Filter unrelated content out of the output.
string
(
REGEX MATCHALL
"[0-9]+
\\
.[0-9]+"
compute_capabilities
"
${
compute_capabilities
}
"
)
if
(
run_result EQUAL 0
)
string
(
REPLACE
"2.1"
"2.1(2.0)"
compute_capabilities
"
${
compute_capabilities
}
"
)
set
(
CUDA_GPU_DETECT_OUTPUT
${
compute_capabilities
}
CACHE INTERNAL
"Returned GPU architectures from detect_gpus tool"
FORCE
)
endif
()
if
(
NOT CUDA_GPU_DETECT_OUTPUT
)
message
(
WARNING
"Automatic GPU detection failed. Defaulting to 3.0. You can also set CUDA_ARCH_TYPES manually."
)
set
(
${
OUT_VARIABLE
}
"3.0"
PARENT_SCOPE
)
separate_arguments
(
OUT_VARIABLE
)
else
()
# Filter based on CUDA version supported archs
message
(
STATUS
"Automatically detected GPU architectures:
${
CUDA_GPU_DETECT_OUTPUT
}
"
)
separate_arguments
(
CUDA_GPU_DETECT_OUTPUT
)
set
(
${
OUT_VARIABLE
}
${
CUDA_GPU_DETECT_OUTPUT
}
PARENT_SCOPE
)
endif
()
list
(
REMOVE_DUPLICATES OUT_VARIABLE
)
list
(
SORT OUT_VARIABLE
)
endfunction
()
elsa/projectors_cuda/projector_kernels/CMakeLists.txt
View file @
6ad66e61
cmake_minimum_required
(
VERSION 3.10
)
################################################################################################
# Automatic GPU detection is not included with every CMake release (e.g. it is unavailable in
# the CMake version installed with the default Ubuntu package manager)
#
# Taken from the official CMake repository, with minor modifications:
# https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindCUDA/select_compute_arch.cmake
#
# A function for automatic detection of GPUs installed (if autodetection is enabled)
# Usage:
# CUDA_DETECT_INSTALLED_GPUS(OUT_VARIABLE)
#
function
(
CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE
)
set
(
file
"
${
PROJECT_BINARY_DIR
}
/detect_cuda_compute_capabilities.cu"
)
file
(
WRITE
${
file
}
""
"#include <cuda_runtime.h>
\n
"
"#include <cstdio>
\n
"
"int main()
\n
"
"{
\n
"
" int count = 0;
\n
"
" if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;
\n
"
" if (count == 0) return -1;
\n
"
" for (int device = 0; device < count; ++device)
\n
"
" {
\n
"
" cudaDeviceProp prop;
\n
"
" if (cudaSuccess == cudaGetDeviceProperties(&prop, device))
\n
"
" std::printf(
\"
%d.%d
\"
, prop.major, prop.minor);
\n
"
" }
\n
"
" return 0;
\n
"
"}
\n
"
)
try_run
(
run_result compile_result
${
PROJECT_BINARY_DIR
}
${
file
}
RUN_OUTPUT_VARIABLE compute_capabilities
)
# Filter unrelated content out of the output.
string
(
REGEX MATCHALL
"[0-9]+
\\
.[0-9]+"
compute_capabilities
"
${
compute_capabilities
}
"
)
if
(
run_result EQUAL 0
)
string
(
REPLACE
"2.1"
"2.1(2.0)"
compute_capabilities
"
${
compute_capabilities
}
"
)
set
(
CUDA_GPU_DETECT_OUTPUT
${
compute_capabilities
}
CACHE INTERNAL
"Returned GPU architectures from detect_gpus tool"
FORCE
)
endif
()
if
(
NOT CUDA_GPU_DETECT_OUTPUT
)
message
(
WARNING
"Automatic GPU detection failed. Defaulting to 3.0. You can also set CUDA_ARCH_TYPES manually."
)
set
(
${
OUT_VARIABLE
}
"3.0"
PARENT_SCOPE
)
separate_arguments
(
OUT_VARIABLE
)
else
()
# Filter based on CUDA version supported archs
message
(
STATUS
"Automatically detected GPU architectures:
${
CUDA_GPU_DETECT_OUTPUT
}
"
)
separate_arguments
(
CUDA_GPU_DETECT_OUTPUT
)
set
(
${
OUT_VARIABLE
}
${
CUDA_GPU_DETECT_OUTPUT
}
PARENT_SCOPE
)
endif
()
list
(
REMOVE_DUPLICATES OUT_VARIABLE
)
list
(
SORT OUT_VARIABLE
)
endfunction
()
include
(
ComputeCapabilityCUDA
)
# make sure host compiler used by NVCC is the one used for the rest of the project
set
(
CMAKE_CUDA_HOST_COMPILER
"
${
CMAKE_CXX_COMPILER
}
"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment