Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
4e59d6fd
Commit
4e59d6fd
authored
Aug 16, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12224 from cv3d:improvments/CUDA_detection
parents
94758c18
e136c11c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
7 deletions
+26
-7
OpenCVDetectCUDA.cmake
cmake/OpenCVDetectCUDA.cmake
+10
-2
OpenCVDetectCudaArch.cu
cmake/checks/OpenCVDetectCudaArch.cu
+16
-5
No files found.
cmake/OpenCVDetectCUDA.cmake
View file @
4e59d6fd
...
...
@@ -70,6 +70,12 @@ if(CUDA_FOUND)
unset
(
CUDA_ARCH_PTX CACHE
)
endif
()
SET
(
DETECT_ARCHS_COMMAND
"
${
CUDA_NVCC_EXECUTABLE
}
"
${
CUDA_NVCC_FLAGS
}
"
${
OpenCV_SOURCE_DIR
}
/cmake/checks/OpenCVDetectCudaArch.cu"
"--run"
)
if
(
WIN32 AND CMAKE_LINKER
)
#Workaround for VS cl.exe not being in the env. path
get_filename_component
(
host_compiler_bindir
${
CMAKE_LINKER
}
DIRECTORY
)
SET
(
DETECT_ARCHS_COMMAND
${
DETECT_ARCHS_COMMAND
}
"-ccbin"
"
${
host_compiler_bindir
}
"
)
endif
()
set
(
__cuda_arch_ptx
""
)
if
(
CUDA_GENERATION STREQUAL
"Fermi"
)
set
(
__cuda_arch_bin
"2.0"
)
...
...
@@ -82,10 +88,11 @@ if(CUDA_FOUND)
elseif
(
CUDA_GENERATION STREQUAL
"Volta"
)
set
(
__cuda_arch_bin
"7.0"
)
elseif
(
CUDA_GENERATION STREQUAL
"Auto"
)
execute_process
(
COMMAND
"
${
CUDA_NVCC_EXECUTABLE
}
"
${
CUDA_NVCC_FLAGS
}
"
${
OpenCV_SOURCE_DIR
}
/cmake/checks/OpenCVDetectCudaArch.cu"
"--run"
execute_process
(
COMMAND
${
DETECT_ARCHS_COMMAND
}
WORKING_DIRECTORY
"
${
CMAKE_BINARY_DIR
}${
CMAKE_FILES_DIRECTORY
}
/CMakeTmp/"
RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
string
(
REGEX REPLACE
".*
\n
"
""
_nvcc_out
"
${
_nvcc_out
}
"
)
#Strip leading warning messages, if any
if
(
NOT _nvcc_res EQUAL 0
)
message
(
STATUS
"Automatic detection of CUDA generation failed. Going to build for all known architectures."
)
else
()
...
...
@@ -99,10 +106,11 @@ if(CUDA_FOUND)
set
(
__cuda_arch_bin
"3.2"
)
set
(
__cuda_arch_ptx
""
)
elseif
(
AARCH64
)
execute_process
(
COMMAND
"
${
CUDA_NVCC_EXECUTABLE
}
"
${
CUDA_NVCC_FLAGS
}
"
${
OpenCV_SOURCE_DIR
}
/cmake/checks/OpenCVDetectCudaArch.cu"
"--run"
execute_process
(
COMMAND
${
DETECT_ARCHS_COMMAND
}
WORKING_DIRECTORY
"
${
CMAKE_BINARY_DIR
}${
CMAKE_FILES_DIRECTORY
}
/CMakeTmp/"
RESULT_VARIABLE _nvcc_res OUTPUT_VARIABLE _nvcc_out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
string
(
REGEX REPLACE
".*
\n
"
""
_nvcc_out
"
${
_nvcc_out
}
"
)
#Strip leading warning messages, if any
if
(
NOT _nvcc_res EQUAL 0
)
message
(
STATUS
"Automatic detection of CUDA generation failed. Going to build for all known architectures."
)
set
(
__cuda_arch_bin
"5.3 6.2 7.0"
)
...
...
cmake/checks/OpenCVDetectCudaArch.cu
View file @
4e59d6fd
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <list>
int main()
{
std::ostringstream arch;
std::list<std::string> archs;
int count = 0;
if (cudaSuccess != cudaGetDeviceCount(&count)){
return -1;
}
if (count == 0) {
return -1;
}
if (cudaSuccess != cudaGetDeviceCount(&count)){
return -1;
}
if (count == 0) {
return -1;
}
for (int device = 0; device < count; ++device)
{
cudaDeviceProp prop;
if (cudaSuccess != cudaGetDeviceProperties(&prop, device)){ continue;}
printf("%d.%d ", prop.major, prop.minor);
if (cudaSuccess != cudaGetDeviceProperties(&prop, device)){ continue; }
arch << prop.major << "." << prop.minor;
archs.push_back(arch.str());
arch.str("");
}
archs.unique(); #Some devices might have the same arch
for (std::list<std::string>::iterator it=archs.begin(); it!=archs.end(); ++it)
std::cout << *it << " ";
return 0;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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