运行系统及版本:
Jetson TK1
cmake version 2.8.12.2
Cuda compilation tools, release 6.0, V6.0.1
直接上代码
CmakeLists.txt
1 cmake_minimum_required(VERSION 2.8)
2
3 project(vectorAdd)
4
5 FIND_PACKAGE(CUDA REQUIRED)
6
7 # set source files
8 set(PROJECT_SRC vectorAdd.cu)
9
10 # build options
11 set(GENCODE -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute _35,code=compute_35)
12 set(GENCODE ${GENCODE} -gencode=arch=compute_20,code=sm_20)
13 #set(GENCODE ${GENCODE} -gencode=arch=compute_10,code=sm_10)
14
15 # debug options
16 set(CUDA_NVCC_FLAGS_DEBUG "-g -G")
17 set(CMAKE_CXX_FLAGS_DEBUG "-g")
18
19 # release options
20 set(CUDA_NVCC_FLAGS_RELEASE "-O2")
21 set(CMAKE_CXX_FLAGS_RELEASE "-O2")
22 #cuda_add_executable(vectorAdd vectorAdd.cu)
23 cuda_add_executable(vectorAdd ${PROJECT_SRC} OPTIONS ${GENCODE})
运行效果:
ubuntu@tegra-ubuntu:~/work/learn_cuda/vector_add/build$ cmake ..
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found CUDA: /usr/local/cuda (found version "6.0")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/work/learn_cuda/vector_add/build
ubuntu@tegra-ubuntu:~/work/learn_cuda/vector_add/build$ make
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/work/learn_cuda/vector_add/build
make[2]: Warning: File `../vectorAdd.cu' has modification time 4.7e+08 s in the future
[100%] Building NVCC (Device) object CMakeFiles/vectorAdd.dir//./vectorAdd_generated_vectorAdd.cu.o
Scanning dependencies of target vectorAdd
make[2]: warning: Clock skew detected. Your build may be incomplete.
make[2]: Warning: File `../vectorAdd.cu' has modification time 4.7e+08 s in the future
[100%] Building NVCC (Device) object CMakeFiles/vectorAdd.dir//./vectorAdd_generated_vectorAdd.cu.o
Linking CXX executable vectorAdd
make[2]: warning: Clock skew detected. Your build may be incomplete.
[100%] Built target vectorAdd
ubuntu@tegra-ubuntu:~/work/learn_cuda/vector_add/build$ ls
CMakeCache.txt CMakeFiles cmake_install.cmake Makefile vectorAdd
ubuntu@tegra-ubuntu:~/work/learn_cuda/vector_add/build$ ./vectorAdd
[Vector addition of 50000 elements]
Copy input data from the host memory to the CUDA device
CUDA kernel launch with 196 blocks of 256 threads
Copy output data from the CUDA device to the host memory
Test PASSED
Done
ubuntu@tegra-ubuntu:~/work/learn_cuda/vector_add/build$