Examples#
MathDx Tile provides two example suites: CUDA Tile C++ and cuTile Python. Examples with the same file name in both suites allow comparing the two languages. Some examples exist only in Python. Each example launches one or more Tile kernels and checks its numerical result.
The C++ examples are installed under examples/ in the MathDx Tile
runtime archives.
Getting Started#
The first kernel, presenting one transform and one factorization without surrounding machinery.
fft_convolution_1d, the smallest complete fused kernel: a transform, a pointwise multiplication, and an inverse transform, without accessing global memory in between.cholesky_factorandcholesky_solve, each performing a single linear algebra call and illustrating theinfoconvention.factor_reuse, which factors in one kernel and solves in another.fft_convolution_3d_split, which shows how a multi-dimensional transform is staged through global memory when one kernel is not sufficient.reg_least_squaresandblocked_potrf, covering batched throughput, tile padding, and the blocking of a problem larger than a single call.filtered_backprojection_3d, a mixed application containing a Tile kernel and a SIMT kernel in the same translation unit, together with a fused Tile-only alternative.fft_autotuning, which sweeps the batch extent, the CTA size, and theoccupancyhint, as described in Autotuning.
FFT Examples#
The C++ examples are located in cpp/cufftdx and the Python examples in
python/fft. The C++ variants are validated against cuFFT, while the Python
variants use direct or CuPy references.
Example |
What it does |
Routines exercised |
|---|---|---|
|
Real 1D linear convolution in one fused kernel |
|
|
8x8x8 complex convolution, all three axes in one kernel |
|
|
3D real convolution with |
|
|
128³ convolution split into three kernels, staged through global memory |
|
|
8⁵ convolution, staged across five axes |
|
|
Float input and output around a double-precision transform |
|
|
3D low-pass filtered backprojection, as separate Tile and SIMT kernels and as one fused Tile kernel |
|
|
Sweeps the batch extent, the CTA size, and the |
|
Linear Algebra Examples#
The C++ examples are located in cpp/cusolverdx and the Python examples in
python/linalg. The simple group contains one example per routine, each
solving a single system.
The C++ API divides these routines across two headers: triangular_solve,
tril, and triu are declared in cublasdx_tile.hpp under
cublasdx::tiles, and the remainder in cusolverdx_tile.hpp under
cusolverdx::tiles. Python exposes all of them from
nvmath.tile.linalg.
Example |
What it does |
Routines exercised |
|---|---|---|
|
Factors a positive-definite matrix |
|
|
Factors and solves a positive-definite system |
|
|
Solves a general system with partial-pivot LU |
|
|
Factors once, then reuses the Cholesky and LU factors in separate kernels |
|
|
Computes a modified LU factorization |
|
|
Factors a rectangular matrix, forms its thin Q, and applies the implicit Q to another matrix |
|
|
Factors a wide matrix, generates Q explicitly, and applies the implicit Q to another matrix |
|
|
Solves one overdetermined problem twice, against a tall |
|
|
Solves a diagonally dominant tridiagonal system |
|
|
Computes eigenvalues and eigenvectors of a symmetric matrix |
|
|
Computes eigenvalues of a symmetric tridiagonal matrix |
|
|
Computes generalized symmetric-definite eigenvalues in one call, and again by reducing to a standard eigenproblem by hand |
|
|
Computes the thin SVD of a rectangular matrix, with and without singular vectors |
|
|
Computes the singular values of a bidiagonal matrix |
|
The advanced group contains larger examples that combine several
routines. The two mirrored examples are batched with one block per problem and
report throughput. The C++ versions additionally verify their results against
the equivalent batched cuBLAS and cuSolver host APIs.
Example |
What it does |
Routines exercised |
|---|---|---|
|
Solves 10000 regularized 100x8 least-squares problems two ways: a fused kernel that builds the normal equations with tile matmuls and factors them in registers, and a Householder QR on the augmented system |
|
|
Factors 400 512x512 matrices, far too large for one solver call, by walking 32x32 tiles in a left-looking order |
|
|
Solves one 24x42 SGLang MoE load-balancing problem with an affine-scaling interior-point method and a 16+8 blocked Cholesky |
|
Compression#
The C++ examples are in cpp/nvcompdx and the Python examples in
python/compress. Each compresses four chunks, with one chunk per block,
and verifies an exact round trip. The tile variants keep the data and payload
in tiles within one kernel. The direct-memory variants use separate compression
and decompression kernels, aligned payload slots, and per-chunk scratch slices;
only the byte counts are tiles.
Example |
Algorithm |
Uncompressed data |
Data and payload |
|---|---|---|---|
|
LZ4 |
|
Tiles |
|
LZ4 |
|
Global memory |
|
ANS |
|
Tiles |
|
ANS |
|
Global memory |
For the minimal tile round trip and direct-memory kernel excerpts, see nvCOMPDx in Tile and Compression cutile-python API.
Building and Running#
C++ examples#
Configure the C++ example sources against an installed mathdx_tile
package as follows:
cmake -S examples/cpp -B build/tile-examples \
-DCMAKE_CUDA_COMPILER="$CUDACXX" \
-DCUDAToolkit_ROOT=/path/to/cuda \
-DCMAKE_PREFIX_PATH="$MATHDX_TILE"
cmake --build build/tile-examples
ctest --test-dir build/tile-examples --output-on-failure
A full CUDA toolkit is required in addition to the Tile toolchain. The
advanced linear algebra examples link CUDA::cublas and
CUDA::cusolver for their host references, and the FFT examples link
cuFFT. A standard CUDA compiler cannot replace the Tile compiler, as it
does not accept the Tile flags supplied by the mathdx_tile::
targets.
Python examples#
The Python examples require the packages listed in
Requirements, together with cuda-core, NumPy, and CuPy.
Any script may be run directly:
python examples/python/linalg/simple/cholesky_factor.py
Host arrays for the linear algebra and compression examples are NumPy arrays,
with device buffers and streams provided by cuda.core. The FFT examples
use CuPy device arrays.