Skip to main content
Back

NVIDIA's MatX Hits v1.0 and Runs 2100x Faster Than NumPy

NVIDIA's MatX hits v1.0.0 with CUDA JIT kernel fusion, bringing NumPy-style C++ tensor code to near-native GPU performance

Pro

Repo, Full Access
  • v1.0.0 released: NVIDIA's MatX hits its first stable release, now requiring C++20 and CUDA 12.2.1+.
  • CUDA JIT kernel fusion: New CUDAJitExecutor compiles and caches fused kernels at runtime, converting runtime parameters to compile-time for faster execution.
  • FFT + GEMM fusion via MathDx: MatX can now fuse FFT and BLAS operations into larger arithmetic expressions using NVIDIA's MathDx libraries.
  • 2100x faster than NumPy, 4x faster than CuPy: Benchmarked on an FFT resampler running on an A100 GPU vs. a Xeon CPU.
  • Header-only, BSD-3 licensed: Drop into any CMake project; supports Volta through Blackwell GPUs and CPU execution with multithreading.
  • New primitives: SAR backprojection transform, experimental sparse tensor type, and cuBLASDx integration added in this release.

MatX is NVIDIA's open-source C++20 library for GPU-accelerated numerical computing, and it just hit its first stable release: v1.0.0. The pitch is simple but powerful: write tensor math that looks like NumPy or MATLAB, and get performance that blows both out of the water. On a benchmark FFT resampler, the MatX version runs in 2.54ms on an A100 versus 5360ms for NumPy on a Xeon CPU and 10.6ms for CuPy on the same A100.

That's not a typo. The MatX version shows a 2100x speedup over NumPy, and over 4x faster than CuPy on the same GPU. The code to achieve this is roughly the same length and complexity as the Python equivalent, which is the whole point.

The Gap MatX Is Closing

The typical workflow for GPU numerical computing has always involved a painful tradeoff: write high-level Python (NumPy, SciPy) and leave massive performance on the table, or drop down to raw CUDA and spend weeks writing and debugging kernels. CuPy closes part of that gap by running NumPy-style code on the GPU, but it still carries Python overhead and can't match hand-tuned C++.

MatX is a modern C++ library for numerical computing on NVIDIA GPUs and CPUs, with compile-time expression evaluation for generating GPU kernels and near-native performance while using a syntax similar to Python or MATLAB. The goal is to make the C++ version feel like a direct translation of the Python version, not a rewrite.

How It Actually Works

The core trick behind MatX's performance is lazy evaluation combined with expression templates. When you write an expression like A = B * cos(C) / D, MatX doesn't immediately execute each operation. Instead, it uses lazy evaluation to reduce the total number of memory loads and stores, by overloading each operator so that instead of performing the operation, it returns an object representing that operation when it's needed.

The entire expression generates a single C++ type representing the equation, and when you ask for element (0,0), the value is computed on-the-fly without storing any intermediate values. In practice, this means a chain of five operations becomes one GPU kernel pass instead of five, dramatically reducing the costly round-trips to GPU global memory.

The v1.0.0 release takes this further with a new CUDAJitExecutor. CUDA JIT support via this new executor makes a second pass at compilation and caches the resulting kernel for future use. JIT allows MatX to convert many runtime parameters into compile-time parameters, reducing the computations needed in the kernel. It also unlocks something new: it optionally enables kernel fusion support of the NVIDIA MathDx libraries, allowing MatX to potentially fuse FFT and GEMM operations into other arithmetic expressions if certain criteria are met.

What's New in v1.0.0

Release 1.0.0 marks a major update for MatX. It is the first version to require C++20 support for both the CUDA and host compilers, meaning CUDA versions lower than 12.2.1 are not supported. The headline additions are:

  • CUDA JIT Kernel Fusion: Compile and cache fused kernels at runtime. FFT and BLAS (GEMM) fusion via MathDx are supported now, with more to come.
  • cuBLASDx Support: Integration with NVIDIA's device-side BLAS library, enabling GEMM operations to be fused directly into larger kernel expressions.
  • Full Logging: Route verbose execution traces to stdout or a file, useful for debugging which code path MatX is taking.
  • Compile-time Operator Properties: Fine-grained control over individual operators, like changing the accumulation type of a reduction.
  • SAR Backprojection Transform: A new signal processing primitive for synthetic aperture radar imaging.
  • Experimental Sparse Tensor Type: Early support for sparse tensors, opening the door to sparse linear algebra workloads.
  • C++20 Concepts for Error Messages: Replaced SFINAE (an older C++ template trick) with C++20 Concepts, making compiler errors dramatically more readable.

The Full Operator Library

MatX isn't just a tensor wrapper. It leverages optimized backend libraries like cuBLAS and cuFFT for maximum performance, with an intuitive Python-like API that makes code readable and familiar. The operator surface covers:

  • Linear algebra: matmul, einsum, svd, eig, qr, lu, chol, solve, pinv
  • Signal processing: fft, fft2, conv1d, conv2d, resample_poly, pwelch, windowing functions
  • Radar-specific: ambgfun (ambiguity function), mvdr (beamforming), sar_bp (SAR backprojection)
  • Statistics: mean, var, stdd, corr, hist, percentile
  • I/O: read/write .npy, .mat, .csv files directly
  • Visualization: plot tensors directly to a browser via line, scatter, surf, contour

CPU Support Is a First-Class Citizen

CPU/Host execution support is nearly on par with GPU support. All elementwise operators, reductions, and FFT/BLAS/LAPACK transforms are supported, and most host functions support multithreading. This matters for teams that prototype on CPU and deploy on GPU, or that run mixed workloads. The same MatX code runs on both without changes.

On the hardware side, MatX has been tested on and supports Volta, Ampere, Ada, Hopper, and Blackwell GPU architectures, and Jetson products are supported with JetPack 5.0 or above.

Getting Started

MatX is a header-only library that does not require compiling for use in your applications. Drop it into your CMake project and link against matx::matx:

add_subdirectory(path/to/matx)
target_link_libraries(MyProject matx::matx)

A quick taste of what the API looks like in practice:

#include <matx.h>
using namespace matx;
// Create two 1024x1024 float tensors on GPU
auto A = make_tensor<float>({1024, 1024});
auto B = make_tensor<float>({1024, 1024});
auto C = make_tensor<float>({1024, 1024});
// Element-wise expression -- fused into one kernel
(C = A * sin(B) + 1.0f).run(cudaExecutor{});

The entire expression is fused into a single GPU kernel automatically. No manual kernel writing required. CUDA 12.2.1 and g++9, nvc++ 24.5, or clang 17 or newer is required. MatX is free and released under the BSD-3-Clause license.

Where It Falls Short

A few real limitations to know before adopting it:

  • Linux only: Windows support is currently absent due to the time required to test it.
  • JIT is experimental: There may be bugs that don't occur with JIT disabled, and new features are being added over time.
  • Sparse tensors are experimental: The new sparse tensor type is early-stage and not production-ready.
  • Compile times: Depending on what options are enabled, compiling could take very long without parallelism enabled.

For HPC teams, signal processing engineers, and anyone building custom GPU compute pipelines who already lives in C++, MatX v1.0.0 is a serious tool. The JIT fusion layer in particular changes the calculus: you can now write readable, composable tensor expressions and have the compiler figure out how to fuse them into optimal kernels, without touching a single CUDA intrinsic. The quick start guide and a set of Jupyter notebooks are available to get up to speed quickly.