A fast, ergonomic N-dimensional tensor library in Nim with CPU, CUDA and OpenCL backends, aimed at numerical computing and deep learning.
- 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
Add the repository to your CMake project and link its interface target
add_subdirectory(path/to/MatX) - 2
Include the API in your source file
#include <matx.h> - 3
Build MatX examples and tests locally
cmake -S . -B build -DMATX_BUILD_EXAMPLES=ON -DMATX_BUILD_TESTS=ON - 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
CUDA C++ template library and Python DSL for writing high-performance GEMM and related linear algebra kernels on NVIDIA GPUs.
NCCL is NVIDIA's library of optimized GPU communication primitives such as all-reduce and all-gather for single- and multi-node training.
A C++ and Python GPU compute framework built on Vulkan that runs general-purpose workloads on AMD, Qualcomm, NVIDIA and other vendors' GPUs.
A self-evolving GPU kernel agent that optimizes CUDA and CuTe DSL kernels by promoting each accepted kernel to the next reference.
An open-source book and code collection of modern CUDA learning notes, with 200+ kernels covering HGEMM, FP8/FP4 GEMM, and Flash-Attention.