반응형

1. 환경구성

  • 운영체제 : Windows 10 pro 22H2
  • 하드웨어
    - 현재 구성으로 GPU1은 디스플레이용, GPU2는 컴퓨팅용
CPU 라이젠7 3700X
GPU1 라데온 RX570
GPU2 NVIDIA Geforce T400 4GB
  • 설치할 CUDA toolkit 버전 : CUDA toolkit 12.3 update 2

 

2. NVIDIA 그래픽카드 드라이버 설치

  • CUDA 프로그래밍을 하기 위해 NVIDIA사 그래픽카드를 사용하여야 한다.

1) NVIDIA 그래픽카드 드라이버 다운로드
- https://www.nvidia.co.kr/Download/index.aspx?lang=kr

 

Download the latest official NVIDIA drivers

Download the latest official NVIDIA drivers

www.nvidia.com

 

2) 그래픽카드 선택 및 검색

 

3) 다운로드 후 설치(설치과정생략)
- 설치는 기본옵션으로 설치함


3. CUDA toolkit 버전 지원 확인

 

CUDA - Wikipedia

From Wikipedia, the free encyclopedia Parallel computing platform and programming model Compute Unified Device Architecture (CUDA) is a parallel computing platform and application programming interface (API) that allows software to use certain types of gra

en.wikipedia.org

  • 아래 그림은 GPU 아키텍처별 지원가능한 CUDA toolkit 버전을 표시하고 있다.
    예) NVIDIA Geforce T400 4GB 그래픽카드인 경우 GPU 아키텍처는 "Turing" 이므로 CUDA toolkit 버전은 10.0 ~ 10.2을 볼 수 있다.
  • 연두색 블럭CUDA toolkit버전마다 지원가능한 GPU아키텍처를 표시된다. 현재 Turing GPU 아키텍처는 CUDA toolkit 12.4까지 지원이 가능하는 것을 볼 수 있다.


4. CUDA toolkit 설치

1) CUDA toolkit 다운로드 홈페이지 접속 후 해당 버전 선택하기
- https://developer.nvidia.com/cuda-toolkit-archive 

 

CUDA Toolkit Archive

Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production

developer.nvidia.com

 

2) 타겟 플랫폼 선택 후 다운로드

 

3) 설치하기(설치과정생략)
- 설치 오류 시 아래 링크 클릭

2024.04.19 - [C++/CUDA] - [C++/CUDA] NVIDIA installer failed, CUDA 설치 오류(VisualStudio)

 

[C++/CUDA] NVIDIA installer failed, CUDA 설치 오류(VisualStudio)

1. 증상 아래와 같이 설치 실패가 되는 경우가 있다. 2. 해결방법 CUDA 체크트리에서 Nsight VSE (visual studio edition) 체크하지 않음 3. NSight Visual Studio Edition 설치하기 (1/2) 체크되지않은 설치목록은 NVIDIA

manbedded.tistory.com

 

4) 설치완료 및 버전확인


5. 예제소스 실행 1

1) NVIDIA에서 제공하는 CUDA예제소스 다운로드
- https://github.com/NVIDIA/cuda-samples 

 

GitHub - NVIDIA/cuda-samples: Samples for CUDA Developers which demonstrates features in CUDA Toolkit

Samples for CUDA Developers which demonstrates features in CUDA Toolkit - NVIDIA/cuda-samples

github.com

 

2) 다운받은 CUDA예제소스 압축파일 풀기

3) 예제소스 실행
- cuda-samples-master → Samples → 1_Utilities → deviceQuery
- 설치된 Visual Studio 버전에 맞게 .sln 실행하기

 

4) 실행결과
- GPU 장치확인, CUDA toolkit 버전, CUDA코어 개수 확인


6. 예제소스 실행 2

1) 예제소스

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <iostream>

#define N 1024*1024*1024

__global__ void vector_add_gpu(float *out, float *a, float *b, int n) {
    for(int i = 0; i < n; i++){
        out[i] = a[i] + b[i];
    }
}


__host__ void vector_add_cpu(float *out, float *a, float *b, int n) {
    for(int i = 0; i < n; i++){
        out[i] = a[i] + b[i];
    }
}

int main(){
    float *a, *b, *out; 

    // Allocate memory
    a   = (float*)malloc(sizeof(float) * N);
    b   = (float*)malloc(sizeof(float) * N);
    out = (float*)malloc(sizeof(float) * N);

    for(int i = 0; i < N; i++){
        if(i==0){
            a[i] = 2.0001f;
            b[i] = 2.0001f;
        }else{
            b[i] = 2.0001f;
            a[i] = 2.0002f + a[i-1];
        }
    }

    time_t start, end;
    start = clock();
    vector_add_cpu(out, a, b, N);
    end = clock();
    printf("CPU elapsed time:%d, result:%f\n", (int)(end-start), a[N-1]);


    // Main function
    start = clock();
    vector_add_gpu<<<1,1>>>(out, a, b, N);
    end = clock();
    printf("GPU elapsed time:%d, result:%f\n", (int)(end-start), a[N-1]);

    free(a  );
    free(b  );
    free(out);

    return 1;
}

 

2) 결과
- CPU 경과시간 : 884ms
- GPU 경과시간 : 116ms


감사합니다.

잘못된 정보나 오타 및 수정사항이 있을 경우 댓글로 달아주시면 감사하겠습니다. 


 

반응형

+ Recent posts