CUDA가 설치되면 다음의 테스트 파일을 컴파일 해보자. 소스코드의 파일명은 test_cuda.cu이다.
#include <stdio.h>
#include <cuda_runtime.h>
__global__ void kernel(void) {
printf("Hello, CUDA!\n");
}
int main(void) {
kernel<<<1,1>>>();
cudaError_t err = cudaDeviceSynchronize();
if (err != cudaSuccess) {
printf("CUDA Error: %s\n", cudaGetErrorString(err));
return -1;
}
return 0;
내가 쓰는 비루한 Quadro P2200의 아키텍처는 Pascal 아키텍쳐라고 하며, compute capability는 6.1이라고 한다. 그러면 아래와 같이 CUDA컴파일 할때 아키텍쳐 옵션은 -arch=sm_61로 지정하면 된다.
nvcc -arch=sm_61 -o test_cuda test_cuda.cu
여기서 옵션 -o은 nvcc --help로 살펴보면 다음과 같이 실행화일명을 지정하는 옵션이다. 옵션이 드럽게 많다.
--output-file <file> (-o)
Specify name and location of the output file. Only a single input file is
allowed when this option is present in nvcc non-linking/archiving mode.
컴파일을 하면 test_cuda라는 실행화일이 생기며 실행해 보면 다음과 같다.
$ nvcc -arch=sm_61 -o test_cuda test_cuda.cu
$ ls
05_CFDDEM_Example cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb intel real-essi vtkPVESSIReader.cxx
a.out gmsh-4.12.2-Linux64 LIGGGHTS test_cuda
CFDEM IMSI Linux test_cuda.cu
$ ./test_cuda
Hello, CUDA!
'CUDA' 카테고리의 다른 글
CUDPP and MPS (0) | 2024.12.25 |
---|---|
CUDA Driver와 CUDA Toolkit의 호환 테이블 (1) | 2024.11.28 |