CUDA: re-enable automatic CC detection on Jetson#17805
CUDA: re-enable automatic CC detection on Jetson#17805opencv-pushbot merged 1 commit intoopencv:3.4from
Conversation
|
I followed same behavior of #17745, but I can switch this PR on 3.4 branch, as usual procedure. |
alalek
left a comment
There was a problem hiding this comment.
Lets try to switch on C++ compiler.
If it works, lets re-target this PR to 3.4 branch.
| if(OPENCV_CUDA_DETECTION_NVCC_FLAGS MATCHES "-ccbin") | ||
| # already specified by user | ||
| elseif(CUDA_HOST_COMPILER AND EXISTS "${CUDA_HOST_COMPILER}") | ||
| LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}") |
There was a problem hiding this comment.
elseif(CUDA_HOST_COMPILER AND EXISTS "${CUDA_HOST_COMPILER}")
- LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}")
+ get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
+ # C compiler doesn't work with --run option, forcing C++ compiler instead
+ if(CUDA_HOST_COMPILER STREQUAL c_compiler_realpath)
+ if(DEFINED CMAKE_CXX_COMPILER)
+ get_filename_component(cxx_compiler_realpath "${CMAKE_CXX_COMPILER}" REALPATH)
+ LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${cxx_compiler_realpath}")
+ else()
+ message(STATUS "CUDA: CMAKE_CXX_COMPILER is not available. You may need to specify CUDA_HOST_COMPILER.")
+ endif()
+ else()
+ LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}")
+ endif()
elseif(...)There was a problem hiding this comment.
I had to remove
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
This line will lead comparing /usr/bin/cc with /usr/bin/aarch64-linux-gnu-gcc-7
(CMAKE_C_COMPILER is /usr/bin/cc but get_filename_component retruns /usr/bin/aarch64-linux-gnu-gcc-7)
Thus, I had to remove get_filename_component and use CMAKE_CXX_COMPILER directly
There was a problem hiding this comment.
Looks strange.
It is aligned with this part of code:
Lines 467 to 472 in ff99218
Otherwise STREQUAL check may fail.
Could you find similar part from system CMake on Jetson?
Perhaps we can adapt check to:
if(CUDA_HOST_COMPILER STREQUAL c_compiler_realpath OR CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER)
There was a problem hiding this comment.
The system CMake on Jetson is as following.
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC")
else()
if(APPLE
AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang"
AND "${CMAKE_C_COMPILER}" MATCHES "/cc$")
# Using cc which is symlink to clang may let NVCC think it is GCC and issue
# unhandled -dumpspecs option to clang. Also in case neither
# CMAKE_C_COMPILER is defined (project does not use C language) nor
# CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let
# nvcc use its own default C compiler.
# Only care about this on APPLE with clang to avoid
# following symlinks to things like ccache
if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER)
get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH)
# if the real path does not end up being clang then
# go back to using CMAKE_C_COMPILER
if(NOT "${c_compiler_realpath}" MATCHES "/clang$")
set(c_compiler_realpath "${CMAKE_C_COMPILER}")
endif()
else()
set(c_compiler_realpath "")
endif()
set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC")
else()
set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}"
CACHE FILEPATH "Host side compiler used by NVCC")
endif()
endif()
So basically, this line gets executed
set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}"
CACHE FILEPATH "Host side compiler used by NVCC")
Let's take the OR plan
508a091 to
e97e8ce
Compare
|
Now switched to 3.4 |
cmake/OpenCVDetectCUDA.cmake
Outdated
| LIST(APPEND OPENCV_CUDA_DETECTION_NVCC_FLAGS -ccbin "${CUDA_HOST_COMPILER}") | ||
| get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH) | ||
| # C compiler doesn't work with --run option, forcing C++ compiler instead | ||
| if(CUDA_HOST_COMPILER STREQUAL ${c_compiler_realpath} OR CUDA_HOST_COMPILER STREQUAL ${CMAKE_C_COMPILER}) |
There was a problem hiding this comment.
${c_compiler_realpath}
${CMAKE_C_COMPILER}
Why just c_compiler_realpath doesn't work for you?
Expanding without quotes breaks on paths with spaces (most observed problem on Windows).
Variable expanding in not required with modern CMake (2.8.12.2):
if(<variable|string> STREQUAL <variable|string>)
There was a problem hiding this comment.
Understood what you mean.
I just forgot to quote, and I didn't knew that I can avoid expanding.
Pushed without expanding.
* treat both CMAKE_C_COMPILER and c_compiler_realpath as candidate
e97e8ce to
269b810
Compare
resolves #17804
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.