Notice
Recent Posts
Recent Comments
Link
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Archives
Today
Total
관리 메뉴

제니 블로그

CUDA on Linux (22.04 Ubuntu) 본문

카테고리 없음

CUDA on Linux (22.04 Ubuntu)

jennystar 2023. 8. 30. 15:45

CUDA (Compute Unified Device Architecture) is a parallel computing platform and application programming interface (API) model created by NVIDIA. IT enables CUDA-enabled graphics processing unit for general-purpose preprocessing. It extended the capabilities of the GPU to handle computational workloads beyond graphic.

Key Features:

  1. Parallel Computing: CUDA enables running thousands of threads concurrently, making it beneficial for highly parallel tasks.
  2. Heterogeneous Computing: It allows for the integration of both CPU and GPU computation in a unified programming model. This means you can offload computationally intensive tasks to the GPU while the CPU handles other tasks.
  3. High-Performance Computing: CUDA offers significant speedup for certain computational tasks compared to traditional CPU-only computation, especially in fields like machine learning, scientific simulations, and financial modeling.
  4. Rich Ecosystem: There are many libraries, tools, and frameworks that support CUDA, including but not limited to cuBLAS, cuFFT, and cuDNN for tasks like linear algebra, Fourier transforms, and deep learning respectively.
  5. C/C++ Based: CUDA extends C/C++ with keywords to allow for parallel execution on the GPU.
  6. Cross-Platform: CUDA is available for Windows, Linux, and macOS, although the full feature set is best supported on Linux.
  7. Versioning: CUDA has been through several versions, each bringing performance improvements and additional features.

How Does It Work?

  1. Kernel Launch: A function running on the CPU (known as the "host") launches a function to be run on the GPU (known as the "device"). This function is called a "kernel."
  2. Thread Hierarchy: Each kernel is executed by multiple threads on the GPU. Threads are organized into blocks, and blocks are organized into a grid.
  3. Memory Management: CUDA provides various types of memory (global, shared, constant, etc.) optimized for different use-cases.
  4. Synchronization: CUDA provides mechanisms to synchronize threads and manage resources.
  5. Data Transfer: Data is often transferred from the CPU memory to the GPU memory before computation and back after computation.
  6. CUDA is particularly popular in fields that require heavy computational power, such as deep learning, scientific research, and real-time systems.

Installing Nvidia-driver + CUDA v12.0 

You need to download the CUDA from the NVIDIA CUDA Downloads page to download the appropriate version of the CUDA toolkit for the system. 

$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
$ sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ wget https://developer.download.nvidia.com/compute/cuda/12.0.0/local_installers/cuda-repo-ubuntu2204-12-0-local_12.0.0-525.60.13-1_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu2204-12-0-local_12.0.0-525.60.13-1_amd64.deb
$ sudo cp /var/cuda-repo-ubuntu2204-12-0-local/cuda-*-keyring.gpg /usr/share/keyrings/
$ sudo apt-get update
$ sudo apt-get -y install cuda

After the installation, you need to set the path for CUDA in bashrc to locate the program. 

$ vi ~/.bashrc

export PATH="$PATH:/usr/local/cuda-12.2/bin:/usr/local/go/bin"
export LD_LIBRARY_PATH="/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PATH"
export CUDA_HOME="/usr/local/cuda"

$ source ~/.bashrc

If installed successfully and set up , then running the command nvcc --version will give a result below.

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Fri_Jan__6_16:45:21_PST_2023
Cuda compilation tools, release 12.0, V12.0.140
Build cuda_12.0.r12.0/compiler.32267302_0

CUDA is used for many purposes, but the one that I mainly work with currently is for GPU computing for Lotus, the software program for Filecoin.

 

Filecoin is built on blockchain and as a storage provider, we currently store data on the blockchain network, sealing the data in process which involves having a powerful GPU (ex : GeForceRTX 3080 or above) using the CUDA architecture.