The AI chip trade cracked this week, and the hunt for what replaces it has begun
Back to Tutorials
techTutorialintermediate

The AI chip trade cracked this week, and the hunt for what replaces it has begun

July 3, 202620 views3 min read

Learn to set up a GPU-enabled development environment with NVIDIA CUDA toolkit, essential for AI and machine learning applications in today's evolving chip market.

Introduction

In the wake of the recent AI chip market volatility described in the TNW article, it's crucial for developers and engineers to understand how to work with GPU-accelerated computing systems. This tutorial will guide you through setting up a GPU-enabled development environment using NVIDIA's CUDA toolkit, which is essential for building and deploying AI applications that leverage GPU parallelism. Understanding GPU computing is key to staying competitive in the rapidly evolving AI landscape.

Prerequisites

  • NVIDIA GPU with CUDA support (Compute Capability 3.5 or higher)
  • Ubuntu 20.04 or later Linux distribution
  • Basic understanding of Python programming
  • Internet connection for package installation
  • Root or sudo access to your system

Step-by-step instructions

Step 1: Verify GPU Compatibility

Before installing any software, we must confirm that your system has a compatible NVIDIA GPU. Run the following command to check your hardware:

lspci | grep -i nvidia

This command lists all NVIDIA devices in your system. Look for a device with a name like "GeForce RTX 3080" or "Tesla V100". If no NVIDIA device appears, you'll need to install a compatible GPU first.

Step 2: Install NVIDIA Driver

First, we need to install the appropriate NVIDIA driver for your GPU. Update your system packages:

sudo apt update
sudo apt upgrade -y

Then install the driver:

sudo apt install nvidia-driver-535

Why this step? The NVIDIA driver is essential for hardware communication with CUDA. Version 535 is chosen as it provides good compatibility with most modern GPUs and CUDA versions.

Step 3: Install CUDA Toolkit

Download and install the CUDA toolkit, which provides the development environment for GPU computing:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get install cuda-toolkit-12-4

Why this step? The CUDA toolkit contains everything needed to compile and run GPU-accelerated applications, including the CUDA runtime, libraries, and development tools.

Step 4: Verify Installation

After installation, verify that CUDA is properly installed:

nvidia-smi

This command should display your GPU information and CUDA version. You should also run:

nvcc --version

This confirms that the CUDA compiler is working correctly.

Step 5: Set Up Python Environment

Install Python packages needed for GPU-accelerated computing:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
pip install tensorflow-gpu
pip install cupy-cuda12x

Why this step? These packages provide high-level interfaces to GPU computing. PyTorch and TensorFlow are essential for machine learning, while CuPy provides NumPy-like operations on GPU.

Step 6: Create a Simple GPU Test Program

Create a Python script to verify GPU access:

import torch
import tensorflow as tf
import cupy as cp

print("PyTorch CUDA available:", torch.cuda.is_available())
print("PyTorch CUDA version:", torch.version.cuda)
print("TensorFlow GPU available:", tf.config.list_physical_devices('GPU'))

# Test CuPy
x = cp.array([1, 2, 3])
y = cp.array([4, 5, 6])
print("CuPy result:", cp.add(x, y))

Save this as gpu_test.py and run:

python gpu_test.py

Why this step? This comprehensive test ensures all GPU components are working together properly, which is crucial before developing larger applications.

Step 7: Configure Environment Variables

Set up environment variables for consistent CUDA access:

echo 'export CUDA_HOME=/usr/local/cuda' >> ~/.bashrc
echo 'export PATH=$PATH:$CUDA_HOME/bin' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDA_HOME/lib64' >> ~/.bashrc
source ~/.bashrc

Why this step? Proper environment configuration ensures that all tools can locate and use CUDA libraries without issues.

Summary

In this tutorial, you've set up a complete GPU-accelerated development environment using NVIDIA's CUDA toolkit. You've verified hardware compatibility, installed necessary drivers and libraries, and confirmed everything works correctly with a test program. This foundation is essential for any developer working in AI, machine learning, or high-performance computing. As the AI chip market continues to evolve, having a solid understanding of GPU computing infrastructure will be increasingly valuable for building competitive applications.

Source: TNW Neural

Related Articles