Skip to main content

Compiling CUDA Files

Learn how to use the Compiler Explorer to compile your CUDA code and generate assembly output.

Basic Workflow

1

Select a File

Click the file selector in the Compiler Explorer header to choose a .cu file from your workspace.
2

Configure Settings

The compiler auto-detects your nvcc version and GPU architecture. You can override these if needed.
3

Compile

Click Compile to generate PTX and SASS output. Results appear in the tabbed view below.

File Selection

From the File Picker

Click the folder icon or File button to open a file dialog. Navigate to and select your .cu file.

From an Open Editor

If you have a .cu file open in VS Code, the Compiler Explorer can detect and use it automatically.

Configuration Options

Compiler Version

The nvcc version is auto-detected from your local installation. The detected version shows with “(detected)” suffix. You can manually select a different version if needed—for example, if you want to see how code compiles with a different CUDA version.
VersionNotes
Auto-detectedUses your local nvcc installation
Manual selectionChoose from available CUDA versions

GPU Architecture

The target architecture is auto-detected from your local GPU. The detected architecture shows with “(detected)” suffix. Common architectures:
ArchitectureGPU Examples
sm_100NVIDIA B200
sm_90NVIDIA H100, H200
sm_89NVIDIA L40S
sm_80NVIDIA A100
sm_75NVIDIA T4
The architecture affects SASS output. PTX is architecture-independent, but SASS is specific to each GPU generation.

Live Compilation

When a file is selected, live compilation is automatically enabled. This means:
  • The file is recompiled whenever you save it
  • Results update automatically without clicking Compile
  • You can iterate quickly on optimizations
The live compile checkbox shows this status (always enabled when a file is selected).

Compilation Process

When you compile, Wafer:
  1. Runs nvcc with your file and settings
  2. Generates PTX from the CUDA source
  3. Generates SASS using nvdisasm (if available)
  4. Displays results in the tabbed interface

What Happens Behind the Scenes

# PTX generation
nvcc -ptx -arch=sm_90 your_file.cu -o output.ptx

# SASS generation (requires nvdisasm)
nvcc -cubin -arch=sm_90 your_file.cu -o output.cubin
nvdisasm output.cubin

Handling Errors

Compilation Errors

If your code has errors, they appear in the Compilation Output panel at the bottom:
  • Syntax errors
  • Type mismatches
  • Missing headers
  • Undefined symbols
The error output includes line numbers and descriptions to help you fix issues.

NVCC Not Found

If nvcc isn’t installed or not in your PATH:
NVCC (CUDA Compiler) Not Found
Solution: Install the CUDA Toolkit and ensure nvcc is in your PATH.
sudo apt-get install nvidia-cuda-toolkit
After installing, restart VS Code for the changes to take effect.

Tips for Better Compilation

For best results, compile files that contain complete kernels. Files with only device functions may not produce meaningful output.
Make sure your .cu file includes all required headers. The compiler runs with your file in isolation.
Compile for your target deployment GPU, not just your development machine. This ensures you see the actual instructions that will run.

View Modes

After compilation, you can view results in different modes:

Single Panel Mode

View one output type at a time using the tabs:
  • Source — Your original CUDA code
  • PTX — Generated PTX assembly
  • SASS — Generated SASS machine code

Side-by-Side Mode

Click the side-by-side button to view two panels at once. Compare:
  • Source vs. PTX
  • Source vs. SASS
  • PTX vs. SASS

Understanding Output

Learn how to read and interpret PTX and SASS →