Cuda 如何在cmake';我们试试跑吧?
我试图在cmake阶段通过编译和运行简单测试来设置Cuda 如何在cmake';我们试试跑吧?,cuda,cmake,nvcc,Cuda,Cmake,Nvcc,我试图在cmake阶段通过编译和运行简单测试来设置nvcc的计算能力标志: #include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> int main(int argc, char **argv){ cudaDeviceProp dP; if(cudaSuccess != cudaGetDeviceProperties(&dP, 0)) return 0; p
nvcc
的计算能力标志:
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
int main(int argc, char **argv){
cudaDeviceProp dP;
if(cudaSuccess != cudaGetDeviceProperties(&dP, 0)) return 0;
printf("-arch=sm_%d%d\n", dP.major, dP.minor);
return 0;
}
#包括
#包括
#包括
int main(int argc,字符**argv){
cudaDeviceProp dP;
if(cudaSuccess!=cudaGetDeviceProperties(&dP,0))返回0;
printf(“-arch=sm\ud%d\n”,dP.major,dP.minor);
返回0;
}
我读过如何做到这一点,但是try\u run
让我只通过gcc编译目标。如果我添加cuda\u compile
,我也不会得到二进制文件
如何在
cmake
阶段编译.cu
-文件,并通过execute\u process
运行它以设置正确的编译标志?嗯,我不知道如何正确地执行,所以我做得很简单。
在我找到的CUDA_
部分的开头,我添加了:
if(CUDA_FOUND)
set(TEST ${CMAKE_BINARY_DIR}/test)
set(TESTSRC ${CMAKE_CURRENT_SOURCE_DIR}/test/capability.cu)
execute_process(COMMAND nvcc -lcuda ${TESTSRC} -o ${TEST})
execute_process(COMMAND ${TEST} OUTPUT_VARIABLE CUDA_ARCH)
message("Cuda architecture: ${CUDA_ARCH}")
list(APPEND CUDA_NVCC_FLAGS --use_fast_math ${CUDA_ARCH})
这只是编译我的测试源代码并在fillingCUDA\u ARCH
变量中运行