Background
Vector addition is the hello world of CUDA. So I learned the basics, wrote my first kernel, compiled it, and boom. The simplest example didn’t work out of the box.
nvcc -o main_err main.cu./main_errmain.cu:33: CUDA err: the provided PTX was compiled with an unsupported toolchain.After quick searching, the fix is not that complicated, just blindly (for now) add a compiler flag and the code runs.
nvcc -arch=native -o main_ok main.cu./main_ok0.0 2.0 4.0 6.0 8.0 10.0 12.0 14.0 16.0 ...Full main.cu code for context
#include <stdio.h>#include <stdlib.h>
#define CUDA_CHECK(call) \ do { \ cudaError_t err = call; \ if (err != cudaSuccess) { \ fprintf(stderr, "%s:%d: CUDA err: %s\n", __FILE__, __LINE__, cudaGetErrorString(err)); \ exit(EXIT_FAILURE); \ } \ } while (false)
__global__ void vec_add_kernel(float* a, float* b, float* out, int n) { int i = blockIdx.x * blockDim.x + threadIdx.x; if (i < n) { out[i] = a[i] + b[i]; }}
void vec_add(float* a, float* b, float* out, int n) { float* ad; float* bd; float* outd; int nbytes = n * sizeof(float); cudaMalloc((void**)&ad, nbytes); cudaMalloc((void**)&bd, nbytes); cudaMalloc((void**)&outd, nbytes); cudaMemcpy(ad, a, nbytes, cudaMemcpyHostToDevice); cudaMemcpy(bd, b, nbytes, cudaMemcpyHostToDevice); int threads_per_block = 64; int blocks_per_grid = (n + threads_per_block - 1) / threads_per_block; vec_add_kernel<<<blocks_per_grid, threads_per_block>>>(ad, bd, outd, n); CUDA_CHECK(cudaGetLastError()); cudaMemcpy(out, outd, nbytes, cudaMemcpyDeviceToHost); cudaFree(ad); cudaFree(bd); cudaFree(outd);}
int main() { int n = 100; float* a = (float*)malloc(sizeof(float) * n); float* b = (float*)malloc(sizeof(float) * n); float* out = (float*)malloc(sizeof(float) * n); for (int i = 0; i < n; ++i) { a[i] = i; b[i] = i; } vec_add(a, b, out, n); for (int i = 0; i < n; ++i) { printf("%0.1f ", out[i]); } printf("\n"); return 0;}FYI, this is my setup as I’m writing this blog:
- RTX 3060 GPU
- Max supported CUDA version by the driver is
13.0(fromnvidia-smi) - nvcc version (including all the toolkit) is
13.2(fromnvcc --version)
Did I just happen to make the rookie mistake of not installing the same version of CUDA driver and CUDA toolkit? Probably. But then the nvcc -arch=native ... is doing just fine. What gives?
In this post, we will try to understand CUDA versioning so that when the same or similar problems happen, at least we know what the cause is. We will also explore compute capabilities, PTX, and other relevant CUDA jargon.
Hardware and compute capability
There are a lot of NVIDIA GPUs. Right now, what we care about is the compute capability. Compute capability (CC) defines the hardware features and supported instructions for each NVIDIA GPU architecture.1 That means your GPU sets the ceiling of what’s possible, and it is literally burned in the silicon!
But what about the architecture name? We’ve heard a lot of names like: Blackwell, Ampere, Turing, etc. The architecture name is not always mapped one-to-one with specific compute capability. For example both RTX 3060 and A100 are Ampere, but their CC are 8.6 and 8.0, respectively.
The compute capability directly corresponds to the version number of the SM. For example, the SMs within a GPU of CC 12.0 have SM version sm_120. This version is used to label binaries.2 CC format is major.minor, so 8.6 means CC major 8 and CC minor 6.
CUDA compilation pipeline
main_err does not work, but main_ok works. That must mean they are compiled differently. To inspect the executables, we use cuobjdump. First, on the broken one:
nvcc -o main_err main.cucuobjdump main_errFatbin elf code:================arch = sm_75code version = [1,8]host = linuxcompile_size = 64bit
Fatbin elf code:================arch = sm_75code version = [1,8]host = linuxcompile_size = 64bit
Fatbin ptx code:================arch = sm_75code version = [9,2]host = linuxcompile_size = 64bitcompressedptxasOptions =And then, on the working one:
nvcc -arch=native -o main_ok main.cucuobjdump main_okFatbin elf code:================arch = sm_86code version = [1,8]host = linuxcompile_size = 64bit
Fatbin elf code:================arch = sm_86code version = [1,8]host = linuxcompile_size = 64bit
Some CUDA jargon in a very simplified manner:
- ELF (Executable and Linkable Format): Linux/Unix executable or shared object format.
- Fatbin: container that can hold many cubins and PTXs, hence called fat.
cuobjdumpis actually listing all the fatbin contents itself. An executable can have more than 1 fatbin (resulting in seemingly duplicate entries). - cubin (CUDA binary): binary that will run on real GPU. This is container of SASS. Fatbin entries with the
Fatbin elf code:heading are cubins. - PTX (Parallel Thread Execution): NVIDIA virtual ISA (Instruction Set Architecture). This is a bytecode for virtual GPU. Similar in spirit to Java bytecode. Fatbin entries with the
Fatbin ptx code:heading are PTX. - SASS (Streaming Assembler): NVIDIA real ISA, the actual machine code that will be run by the GPU. Think assembly language.
- ptxas (PTX Assembler): PTX to SASS compiler.
What you really need to pay attention to on the fatbin entries:
- In SASS, one thing to look for:
arch. Arch is the real target GPU to run.Fatbin elf code:================arch = sm_75 <---- SASS targeting sm_75 GPUcode version = [1,8]host = linuxcompile_size = 64bit - In PTX, two things to look for:
archandcode version. PTX’ arch however, means virtual instruction the PTX targets.Fatbin ptx code:================arch = sm_75 <---- PTX contains compute_75 instructionscode version = [9,2] <---- PTX ISA versionhost = linuxcompile_size = 64bitcompressedptxasOptions =
The main idea of executable creation is: Source code -> PTX -> SASS. We can see this in more detail below.


The above image where we stuff many PTXs and cubins into the same executable can be achieved with the command below. arch= means generate what PTX, code= means what to put into the final binary.
nvcc \ -gencode arch=compute_80,code=[compute_80,sm_80,sm_86] \ -gencode arch=compute_90,code=[compute_90,sm_90] \ -o example example.cuTry cuobjdump-ing on the example binary, it will show 8 entries instead of 5. This is because there are 2 fatbins and the fatbin we care about is the one holding 5 entries.
Perspective from the driver
The NVIDIA Driver can be thought of as the operating system of the GPU.3 The main job of the driver is to talk with the actual GPU hardware.
When someone launches an executable (like ./main_ok above), this is what the driver does:
Rules for SASS:
- SASS arch major == GPU major
- SASS arch minor <= GPU minor
- Example:
- SASS
sm_86andsm_80are runnable onsm_86GPU - SASS
sm_86andsm_75are not runnable onsm_80GPU
- SASS
Rules for PTX:
- PTX ISA version <= driver PTX ISA version
- PTX can be JIT compiled to any higher or equal SASS
- Example4:
- CUDA driver
13.2with PTX ISA9.2can JIT compile PTX ISA9.2,9.0,8.8or anything lower than or equal to9.2 - CUDA driver
12.0with PTX ISA8.0cannot JIT compile PTX ISA9.2,9.0
- CUDA driver
So, why did main_err fail? Why did nvcc produce sm_75 by default? This is because when no flags are supplied to nvcc, it compiles to the lowest supported version. Lowest is chosen so that the final executable can support the widest range of GPUs (thanks to PTX JIT compilation).
We can query the supported PTX and SM using nvcc --list-gpu-arch and nvcc --list-gpu-code, respectively. Below is the output of my nvcc (CUDA 13.2):
nvcc --list-gpu-codesm_75sm_80sm_86sm_87sm_88sm_89sm_90sm_100sm_110sm_103sm_120sm_121Let’s look back on the main_err case above. Here are the important bits:
- SASS is targeting
sm_75, which RTX 3060sm_86can’t run. - PTX ISA version
9.2, which is not parsable by driver with max supported CUDA13.0having PTX ISA ver9.0. - The above point is important, even though the PTX is forward compatible, i.e.
compute_XYcan be compiled intosm_ABSASS as long asXY<=AB, the unparsable PTX ISA is the blocker here.
main_ok is fine because -arch=native is the same as -gencode arch=compute_86,code=sm_86. There is no PTX tho, and the driver loads the SASS successfully.
Takeaways
- Update your driver to the highest CUDA version supported on your GPU.
- Read the different error logs and refer to the driver flow diagram above to diagnose where the issues are.
- For smoother operations, make sure the max supported CUDA version by the driver is higher than or equal to the CUDA toolkit.
- One useful trick: use
pixias the CUDA toolkit version manager.pixiis a bettercondaIMO, it uses conda-forge as well. Relevant Jeremy Howard’s tweet.
Further reading
-
https://docs.nvidia.com/cuda/cuda-programming-guide/01-introduction/cuda-platform.html#compute-capability-and-streaming-multiprocessor-versions ↩
-
https://docs.nvidia.com/cuda/cuda-programming-guide/01-introduction/cuda-platform.html#cuda-toolkit-and-nvidia-driver ↩
-
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#release-notes ↩