Repolode
NVIDIA

NVIDIA/MatX

A C++20 header-only library for NumPy-style tensor expressions that run on NVIDIA GPUs or multithreaded CPUs, with optional kernel fusion.

Open-source alternative to:NumPyCuPy

Stars
1,451
Forks
131
Open issues
22
Last commit
yesterday

What is it?

MatX is a C++20 numerical computing library that lets developers write array code in a style close to NumPy, including broadcasting, slicing, reductions, linear algebra, FFTs, solvers, and random number generation. Expressions are lazy and are evaluated only when run with a chosen executor, such as the CUDA executor for NVIDIA GPUs, a JIT executor, or a multithreaded host executor.

With MathDx enabled, the CUDA JIT executor can fuse compatible expressions, including supported matrix multiplication, FFT, solver, and random number operations, into a single generated kernel. This removes intermediate temporaries and extra kernel launches. The project is header-only, requires a C++20 toolchain and the CUDA Toolkit for GPU builds, and supports Linux with alpha Windows support.

Host execution can dispatch FFT, BLAS, and LAPACK work to optimized CPU backends such as NVPL, FFTW, OpenBLAS, and BLIS when those options are enabled at build time.

Key features

  • 01NumPy-like arrays with arbitrary rank, views, slicing, and broadcasting.
  • 02Lazy elementwise expressions that run through interchangeable GPU or CPU executors.
  • 03JIT kernel fusion across supported FFT, BLAS, solver, and random number operations.
  • 04Optimized CUDA library usage and host backends including NVPL, FFTW, OpenBLAS, and BLIS.
  • 05Header-only integration with CMake and Conan packaging.

Use cases

  • Porting NumPy-style numerical code from Python into C++ while keeping GPU performance.
  • Building signal processing pipelines that combine FFTs with elementwise math on NVIDIA GPUs.
  • Running batched linear algebra or option pricing style computations on GPUs or multithreaded CPUs.
  • Prototyping numerical kernels without hand-writing CUDA plumbing.

Quick start

  1. 1

    Add the repository to your CMake project and link its interface target

    add_subdirectory(path/to/MatX)
  2. 2

    Include the API in your source file

    #include <matx.h>
  3. 3

    Build MatX examples and tests locally

    cmake -S . -B build -DMATX_BUILD_EXAMPLES=ON -DMATX_BUILD_TESTS=ON
  4. 4

    Compile the build and run the test suite

    cmake --build build -j

Things to know

  • Requires NVIDIA GPUs for the CUDA executor; CPU execution is also supported.
  • JIT kernel fusion is experimental and needs the -DMATX_EN_MATHDX=ON option with a supported shape or operation.
  • Some host reductions and transforms remain single-threaded.

In collections

Topics

FAQ

What is MatX?
A C++20 header-only library for NumPy-style tensor expressions that run on NVIDIA GPUs or multithreaded CPUs, with optional kernel fusion. MatX is a C++20 numerical computing library that lets developers write array code in a style close to NumPy, including broadcasting, slicing, reductions, linear algebra, FFTs, solvers, and random number generation. Expressions are lazy and are evaluated only when run with a chosen executor, such as the CUDA executor for NVIDIA GPUs, a JIT executor, or a multithreaded host executor.
Is MatX free to use? What license does it have?
MatX is open source under the BSD-3-Clause license. Check the license terms before using it in commercial products.
Is MatX still maintained?
Actively maintained. The last commit to MatX was on Nov 6, 2026.
What can I use MatX for?
Porting NumPy-style numerical code from Python into C++ while keeping GPU performance. Building signal processing pipelines that combine FFTs with elementwise math on NVIDIA GPUs. Running batched linear algebra or option pricing style computations on GPUs or multithreaded CPUs. Prototyping numerical kernels without hand-writing CUDA plumbing.
How do I install MatX?
Add the repository to your CMake project and link its interface target: add_subdirectory(path/to/MatX) Include the API in your source file: #include <matx.h> Build MatX examples and tests locally: cmake -S . -B build -DMATX_BUILD_EXAMPLES=ON -DMATX_BUILD_TESTS=ON Compile the build and run the test suite: cmake --build build -j
Where can I get MatX?
The source code and installation instructions are on GitHub: https://github.com/NVIDIA/MatX

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects

An open-source book and code collection of modern CUDA learning notes, with 200+ kernels covering HGEMM, FP8/FP4 GEMM, and Flash-Attention.

Learning Resources#cuda#gpu#tensor-cores
12.2K+17 this week1.3KCudaGPL-3.0Updated 2 days ago