Git Product home page Git Product logo

sgemm_cuda's Introduction

Fast CUDA SGEMM from Scratch

Step-by-step optimization of matrix multiplication, implemented in CUDA. For an explanation of each kernel, see siboehm.com/CUDA-MMM.

Overview

Running the kernels on a NVIDIA A6000 (Ampere):

GFLOPs at matrix size 4096x4096:

Kernel GFLOPs/s Performance relative to cuBLAS
1: Naive 309.0 1.3%
2: GMEM Coalescing 1986.5 8.5%
3: SMEM Caching 2980.3 12.8%
4: 1D Blocktiling 8474.7 36.5%
5: 2D Blocktiling 15971.7 68.7%
7: Avoid Bank Conflicts (Linearize) 16213.4 69.7%
8: Avoid Bank Conflicts (Offset) 16459.2 70.8%
11: Double Buffering 17278.3 74.3%
6: Vectorized Mem Access 18237.3 78.4%
9: Autotuning 19721.0 84.8%
10: Warptiling 21779.3 93.7%
0: cuBLAS 23249.6 100.0%

Setup

  1. Install dependencies: CUDA toolkit 12, Python (+ Seaborn), CMake, Ninja. See environment.yml.
  2. Configure NVCC compilation parameters. Look up your GPUs compute capability here. Then configure the CMakeLists.txt and change:
    set(CUDA_COMPUTE_CAPABILITY 80)
  3. Build: mkdir build && cd build && cmake .. && cmake --build .
  4. Run one of the kernels: DEVICE=<device_id> ./sgemm <kernel number>
  5. Profiling via NVIDIA Nsight Compute (ncu): make profile KERNEL=<kernel number>

Credit goes to wangzyon/NVIDIA_SGEMM_PRACTICE for the benchmarking setup.

sgemm_cuda's People

Contributors

siboehm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.