Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cuda 如何在cmake';我们试试跑吧?_Cuda_Cmake_Nvcc - Fatal编程技术网

Cuda 如何在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

我试图在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;
    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})
这只是编译我的测试源代码并在filling
CUDA\u ARCH
变量中运行