Home Knowledge Base Tensor Core Programming

Tensor Core Programming is the utilization of specialized matrix multiplication hardware on NVIDIA GPUs to achieve 10-20× higher throughput than CUDA cores — where Tensor Cores perform mixed-precision matrix operations (FP16/BF16 input, FP32 accumulation) at 312 TFLOPS on A100 and 989 TFLOPS on H100 compared to 19.5 TFLOPS and 67 TFLOPS for CUDA cores, accessed through WMMA (Warp Matrix Multiply-Accumulate) API or cuBLAS/cuDNN libraries that automatically utilize Tensor Cores, requiring specific matrix dimensions (multiples of 8 for FP16, 16 for INT8) and memory layouts (row-major or column-major with proper alignment) to achieve peak performance, enabling 5-15× faster training of large language models and 10-30× faster inference through INT8 quantization, making Tensor Core programming essential for AI workloads where matrix multiplication dominates (60-90% of compute) and proper utilization can reduce training time from weeks to days.

Tensor Core Capabilities:

<svg viewBox="0 0 760 470" xmlns="http://www.w3.org/2000/svg" font-family="-apple-system,Segoe UI,Roboto,sans-serif">
  <rect x="0" y="0" width="760" height="470" fill="#0d1117"/>
  <text x="380" y="28" fill="#e6edf3" font-size="21" font-weight="700" text-anchor="middle">Tensor Cores — Matrix Multiply Accelerators</text>
  <text x="380" y="48" fill="#8b98a5" font-size="12" text-anchor="middle">hardware units that compute D = A×B + C in one cycle for 4×4 or 16×16 matrix tiles</text>

  <!-- Core operation -->
  <rect x="30" y="65" width="700" height="155" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="380" y="84" fill="#e6edf3" font-size="11" font-weight="600" text-anchor="middle">Tensor Core Operation: D = A × B + C (one warp, one cycle)</text>

  <!-- Matrix A -->
  <rect x="70" y="105" width="60" height="60" rx="3" fill="#1e3a5f" stroke="#60a5fa" stroke-width="1"/>
  <text x="100" y="125" fill="#93c5fd" font-size="9" text-anchor="middle">A</text>
  <text x="100" y="140" fill="#60a5fa" font-size="7" text-anchor="middle">16×16</text>
  <text x="100" y="155" fill="#6b7684" font-size="6.5" text-anchor="middle">FP16/BF16/FP8</text>

  <text x="145" y="138" fill="#e6edf3" font-size="14" text-anchor="middle">×</text>

  <!-- Matrix B -->
  <rect x="162" y="105" width="60" height="60" rx="3" fill="#14261f" stroke="#34d399" stroke-width="1"/>
  <text x="192" y="125" fill="#6ee7b7" font-size="9" text-anchor="middle">B</text>
  <text x="192" y="140" fill="#34d399" font-size="7" text-anchor="middle">16×16</text>
  <text x="192" y="155" fill="#6b7684" font-size="6.5" text-anchor="middle">FP16/BF16/FP8</text>

  <text x="237" y="138" fill="#e6edf3" font-size="14" text-anchor="middle">+</text>

  <!-- Matrix C -->
  <rect x="254" y="105" width="60" height="60" rx="3" fill="#1c1633" stroke="#a78bfa" stroke-width="1"/>
  <text x="284" y="125" fill="#c4b5fd" font-size="9" text-anchor="middle">C</text>
  <text x="284" y="140" fill="#a78bfa" font-size="7" text-anchor="middle">16×16</text>
  <text x="284" y="155" fill="#6b7684" font-size="6.5" text-anchor="middle">FP32 (accum)</text>

  <text x="332" y="138" fill="#e6edf3" font-size="14" text-anchor="middle">=</text>

  <!-- Matrix D -->
  <rect x="349" y="105" width="60" height="60" rx="3" fill="#2a1a0a" stroke="#f59e0b" stroke-width="1.2"/>
  <text x="379" y="125" fill="#fbbf24" font-size="9" text-anchor="middle">D</text>
  <text x="379" y="140" fill="#f59e0b" font-size="7" text-anchor="middle">16×16</text>
  <text x="379" y="155" fill="#6b7684" font-size="6.5" text-anchor="middle">FP32 result</text>

  <!-- Throughput numbers -->
  <rect x="440" y="100" width="270" height="100" rx="4" fill="#0d1117" stroke="#334155" stroke-width="0.5"/>
  <text x="575" y="118" fill="#e6edf3" font-size="9" font-weight="600" text-anchor="middle">H100 Tensor Core TFLOPS</text>
  <text x="460" y="138" fill="#f87171" font-size="8">FP32 (CUDA cores):</text><text x="610" y="138" fill="#f87171" font-size="8">67 TFLOPS</text>
  <text x="460" y="156" fill="#a78bfa" font-size="8">TF32 (Tensor Core):</text><text x="610" y="156" fill="#c4b5fd" font-size="8">495 TFLOPS</text>
  <text x="460" y="174" fill="#60a5fa" font-size="8">BF16 (Tensor Core):</text><text x="610" y="174" fill="#93c5fd" font-size="8">990 TFLOPS</text>
  <text x="460" y="192" fill="#34d399" font-size="8" font-weight="600">FP8 (Tensor Core):</text><text x="610" y="192" fill="#6ee7b7" font-size="8" font-weight="600">1,979 TFLOPS</text>

  <text x="380" y="210" fill="#f59e0b" font-size="8" text-anchor="middle">tensor cores deliver 15–30× throughput vs CUDA cores for matrix ops</text>

  <!-- How to use them -->
  <rect x="30" y="230" width="345" height="148" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="202" y="250" fill="#e6edf3" font-size="10" font-weight="600" text-anchor="middle">Programming Tensor Cores</text>

  <text x="50" y="274" fill="#60a5fa" font-size="8.5" font-weight="600">cuBLAS / cuDNN:</text>
  <text x="50" y="290" fill="#8b98a5" font-size="8">automatic for GEMM / conv (just use the library)</text>

  <text x="50" y="310" fill="#34d399" font-size="8.5" font-weight="600">WMMA API (CUDA):</text>
  <text x="50" y="326" fill="#8b98a5" font-size="8">wmma::load, wmma::mma_sync, wmma::store</text>
  <text x="50" y="340" fill="#6b7684" font-size="7.5">warp-level: 32 threads cooperate on one tile</text>

  <text x="50" y="360" fill="#a78bfa" font-size="8.5" font-weight="600">Triton / torch.compile:</text>
  <text x="50" y="376" fill="#8b98a5" font-size="8">tl.dot() auto-uses tensor cores when shapes align</text>

  <!-- Requirements -->
  <rect x="390" y="230" width="340" height="148" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="560" y="250" fill="#e6edf3" font-size="10" font-weight="600" text-anchor="middle">Requirements for Tensor Core Use</text>

  <text x="410" y="274" fill="#f59e0b" font-size="8.5" font-weight="600">Dimension alignment:</text>
  <text x="410" y="290" fill="#8b98a5" font-size="8">M, N, K must be multiples of 16 (or 8 for FP8)</text>

  <text x="410" y="310" fill="#f59e0b" font-size="8.5" font-weight="600">Data type:</text>
  <text x="410" y="326" fill="#8b98a5" font-size="8">inputs: FP16/BF16/FP8/INT8. accum: FP32/FP16</text>

  <text x="410" y="346" fill="#f59e0b" font-size="8.5" font-weight="600">Memory layout:</text>
  <text x="410" y="362" fill="#8b98a5" font-size="8">data must be in shared memory, properly padded</text>

  <text x="410" y="376" fill="#6b7684" font-size="7.5">if any condition not met → falls back to slow CUDA cores</text>

  <!-- Bottom -->
  <rect x="30" y="390" width="700" height="40" rx="6" fill="#080d14" stroke="#233043" stroke-width="1"/>
  <text x="380" y="410" fill="#8b98a5" font-size="8.5" text-anchor="middle">FlashAttention = clever SRAM tiling that keeps tensor cores fed. cuBLAS GEMM = 95% of peak tensor core utilization.</text>
  <text x="380" y="424" fill="#6b7684" font-size="7.5" text-anchor="middle">every modern AI workload is designed around tensor core tile sizes — they define the microarchitecture of ML compute</text>

  <text x="380" y="452" fill="#6b7684" font-size="11" text-anchor="middle">Tensor cores turned GPUs from graphics chips into AI supercomputers — they do 95% of LLM compute.</text>
</svg>

WMMA API:

Matrix Dimensions:

Programming Model:

Matrix Multiplication Example:

// Declare fragments
wmma::fragment<wmma::matrix_a, 16, 16, 16, half, wmma::row_major> a_frag;
wmma::fragment<wmma::matrix_b, 16, 16, 16, half, wmma::col_major> b_frag;
wmma::fragment<wmma::accumulator, 16, 16, 16, float> c_frag;

// Initialize accumulator
wmma::fill_fragment(c_frag, 0.0f);

// Loop over K dimension
for (int k = 0; k < K; k += 16) {
    wmma::load_matrix_sync(a_frag, A + k, K);
    wmma::load_matrix_sync(b_frag, B + k * N, N);
    wmma::mma_sync(c_frag, a_frag, b_frag, c_frag);
}

// Store result
wmma::store_matrix_sync(C, c_frag, N, wmma::mem_row_major);

Performance Optimization:

Mixed Precision:

cuBLAS Integration:

cuDNN Integration:

INT8 Quantization:

FP8 (H100):

Memory Considerations:

Occupancy:

Performance Metrics:

Common Pitfalls:

Frameworks Integration:

Use Cases:

Best Practices:

Tensor Core Programming represents the key to AI performance on NVIDIA GPUs — by utilizing specialized matrix multiplication hardware through WMMA API or cuBLAS/cuDNN libraries, developers achieve 10-20× higher throughput (312 TFLOPS on A100, 989 TFLOPS on H100) compared to CUDA cores, enabling 5-15× faster training and 10-30× faster inference through INT8 quantization, making Tensor Core programming essential for AI workloads where proper utilization can reduce training time from weeks to days.');

tensor core programmingcuda tensor coreswmma apimma instructionstensor core optimization

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.