NVIDIA/MatX

An efficient C++20 GPU numerical computing library with Python-like syntax

NVIDIA / MatX – Fast, NumPy‑style tensor computing in C++

What it is – MatX is a header‑only C++20 library that lets you write NumPy‑like array code (tensors, broadcasting, reductions, FFTs, linear‑algebra, random numbers, etc.) while keeping full control of the execution model. The same expression can be run on an NVIDIA GPU, on a multi‑core CPU, or on a JIT‑generated fused kernel, simply by swapping the executor.

Why it matters – GPU‑accelerated numerical work usually requires hand‑written CUDA kernels or separate library calls (cuBLAS, cuFFT, cuRAND, …). MatX hides that plumbing: you compose a lazy expression, then let the library either call the existing CUDA libraries or generate a single kernel that fuses the whole pipeline. The README shows that this can cut implementation code by >90 % and give 1.5‑2× speed‑ups over a hand‑tuned CUDA + cuFFT workflow.

Key features

  • NumPy‑style API – make_tensor, broadcasting, slicing, element‑wise ops, matmul, fft, tanh, etc.
  • Lazy expression graph – operations are recorded and only materialised when .run(executor) is called.
  • Multiple executors
    • cudaExecutor – runs each operation with the appropriate CUDA library.
    • CUDAJITExecutor – fuses compatible ops (cuBLASDx, cuSolverDx, cuFFTDx, cuRANDDx) into one runtime‑generated kernel.
    • AllThreadsHostExecutor – multithreaded CPU path using OpenMP and optional back‑ends (NVPL, FFTW, OpenBLAS, BLIS).
  • Header‑only – just add the repo and link matx::matx; no separate binary install needed.
  • Cross‑platform – Linux fully supported; Windows in alpha. Works with any C++20 compiler and CUDA Toolkit.
  • Benchmarks – FFT pipeline runs 1.61× faster when fused; Black‑Scholes pricing runs 184× faster than NumPy on the same GPU.

Typical workflow

#include <matx.h>
auto x = matx::make_tensor<float>({1024,256});
auto w = matx::make_tensor<float>({256,128});
auto b = matx::make_tensor<float>({128});
auto y = matx::tanh(matx::matmul(x,w) + b);
(y = y).run(matx::cudaExecutor{});   // or CUDAJITExecutor{}, or host executor

The code looks like ordinary NumPy, but the library decides whether to launch separate kernels, call cuBLAS, or generate a fused kernel.

Getting started – Clone the repo, enable examples with -DMATX_BUILD_EXAMPLES=ON, and link the interface target. The project also ships on Conan for easy package management.

Community & support – Discussions on GitHub, issue tracker for bugs/feature requests, BSD‑3‑Clause license, semantic versioning.


All statements are taken directly from the repository’s README; no external claims are added.

Related

  • Project
  • Project
  • Project
  • Project
  • Project