Simulation / Modeling / Design

Combine Tile Code and SIMT Library Calls in One Kernel with NVIDIA CUDA Tile

Animation comparing red scan points of the Stanford bunny with a reconstructed surface colored by estimated uncertainty.

AI-Generated Summary

  • CUDA 13.5 introduces a preview of Tile/SIMT interoperability that lets tile kernels call device functions from supported NVIDIA SIMT libraries, avoiding intermediate data exchange through global memory.
  • The compiler uses tilelib files shipped with libraries such as MathDx Tile 0.5.0, NVSHMEM 3.9.0, and NVIDIA Warp 1.20.0 to select implementations that match tile shapes, data types, and target GPUs.
  • In cuTile Python, developers call library functions through modules like nvmath.tile.fft or directly via foreign_call from the cuda-tile-preview package, while in C++ they include library Tile headers and call functions from __tile_global__ kernels.
  • A distributed 3D FFT implementation combines cuFFTDx for transforms and NVSHMEM tile API for communication in cuTile Python kernels, achieving performance comparable to cuFFTMp on VR200 NVL72 systems across FP32 and FP64 precisions up to 64 GPUs.
  • A surface reconstruction example fuses cuTile Python Tensor Core matrix multiplies, Warp ray-casting and covariance lookups, and MathDx triangular solves and Cholesky factorization in a single kernel, reducing run times by 1.5x to 2.8x with TF32 Tensor Cores versus FP32.

Next Steps

Powered by NVIDIA Nemotron. AI-generated content may summarize information incompletely. Verify important information. Learn more

NVIDIA CUDA Tile enables you to write GPU kernels in terms of tiles instead of threads. You load a tile of data, operate on it as a whole, and store the result. The compiler maps those operations to threads and manages shared memory and Tensor Cores.

Before CUDA 13.5, tile kernels could not call SIMT (single instruction, multiple threads) library device functions directly. If a computation needed a library operation between two stages of tile code, those stages had to run in separate kernels, exchanging intermediate results through global memory.

CUDA 13.5 introduces a preview of Tile/SIMT interoperability. A tile kernel can now call device functions from supported NVIDIA SIMT libraries, avoiding that intermediate exchange through global memory. This post shows you how to make these calls in Python and C++, how the compiler connects the two programming models, and how applications use interop to combine tile code with SIMT libraries.

How CUDA Tile calls SIMT library functions

In a tile kernel, the compiler decides how each tile is distributed across the threads of a block. SIMT library functions require a specific thread and data layout. An NVIDIA cuFFTDx transform runs on a set number of threads, with each thread holding particular elements, and it may use shared memory and barriers. When tile code calls one of these functions, the compiler uses these requirements to set up the call.

Libraries provide that information in a tilelib, a file with the .tilelib extension that ships with the library. A tilelib lists the functions the library exposes to tile code, with their parameters and result types. For each call in your kernel, the compiler queries the tilelib with the tile shapes, data types, and target GPU, and the tilelib returns one or more SIMT implementations. Each implementation states how many threads it runs on, which elements each thread holds, how much shared memory it needs, and how it synchronizes. An implementation can run one call per thread, one per warp, or one across the whole thread block.

The tile compiler, tileiras, selects an implementation that fits the rest of the kernel, arranges the tile data to match it, allocates the required shared memory, inserts barriers if necessary, and links the SIMT code into the kernel. This happens at compile time, and the result is a single kernel, as shown in Figure 1.

The following library releases provide tilelibs or are scheduled to add them:

Call SIMT libraries from CUDA Tile kernels

The following examples show how to call cuFFTDx from cuTile Python and CUDA Tile C++ to compute a batch of fast Fourier transforms (FFTs). The multi-GPU FFT application later in this post shows the same call in a kernel that combines FFTs and communication.

Call cuFFTDx from cuTile Python

In Python, libraries expose functions that you call inside an @ct.kernel function. MathDx provides these functions through modules such as nvmath.tile.fft, nvmath.tile.linalg, and nvmath.tile.compress. The following FFT call takes a tile and returns a tile.

import cuda.tile as ct
import nvmath.tile.fft as mfft
# Inside a @ct.kernel function:
data = ct.load(signals, (ct.bid(0), 0, 0), shape=(ROWS, N, 2))   # tile code
spectrum = mfft.fft(data, axis=1)                                # SIMT library code: cuFFTDx

data holds ROWS signals of length N, and mfft.fft transforms each one. These modules wrap foreign_call, a function in the cuda-tile-preview package that invokes functions exposed by a tilelib. You can use it to call a library that ships a tilelib but no Python module. The following example makes the same FFT call directly through the cuFFTDx tilelib:

from cuda import tile_preview as tp # pip install cuda-tile-preview

CUFFTDX = tp.Tilelib(path="/path/to/cufftdx.tilelib", version="0.5.0")

# Inside the kernel, in place of mfft.fft:
(spectrum,) = tp.foreign_call(
    tilelibs=(CUFFTDX,),
    symbol_name="fft",
    constant_params=(2, 1, ROWS, N, ct.float32),   # transform axis, tile shape, precision
    inputs=(ct.reshape(data, (1, ROWS, N, 2)),),
    output_types=((ct.float32, (1, ROWS, N, 2)),),
)
spectrum = ct.reshape(spectrum, (ROWS, N, 2))

Each argument of foreign_call tells the compiler something it needs:

  • tilelibs: Libraries to search for the function. Each tilelib version contributes to the cuTile compilation cache key; changing it triggers kernel recompilation.
  • symbol_name: Name of the function to call.
  • constant_params: Compile-time parameters. The library uses them to choose and generate an implementation. In this example, they’re the transform axis, the tile shape, and the precision. The cuFFTDx function takes a 3D batch of signals, so the call adds a leading dimension of size 1.
  • inputs: Tiles and scalars passed at run time.
  • output_types: Data type and shape of each result.

The library modules make these calls for you. They locate the tilelib, derive constant parameters from tile shapes, and report shape and type errors.

Call cuFFTDx from CUDA Tile C++

In C++, include the library’s Tile header and call its functions from a __tile_global__ kernel:

#include "cufftdx_tile.hpp"

// Inside a __tile_global__ function; data is a ct::tile<float, ct::shape<ROWS, N, 2>>:
const auto spectrum = cufftdx::tiles::fft(data, cufftdx::tiles::axis<1>);

The header declares the library function as a foreign function. At compile time, the compiler obtains its implementation from the tilelib. The cuFFTDx header declares its FFT as follows:

template <size_t AXIS, size_t DIM0, size_t DIM1, size_t DIM2, typename T>
__experimental_foreign_decl__ __experimental_foreign_name__("fft")
ct::tile<T, ct::shape<DIM0, DIM1, DIM2, 2>> fft(
    [[cutile::experimental_inout]] ct::tile<T, ct::shape<DIM0, DIM1, DIM2, 2>> data);

The template parameters play the role of constant_params in Python, and the signature gives the input and output types. cufftdx::tiles::fft wraps this declaration the same way mfft.fft wraps foreign_call.

To compile, enable Tile and the SIMT preview in nvcc, and pass each tilelib to tileiras with -l:

nvcc -std=c++20 -arch=native --enable-tile --tile-preview simt \
     -Xtileiras -l="$MATHDX_TILE/lib/cufftdx.tilelib" \
     -I"$MATHDX_TILE/include" my_kernel.cu -o my_kernel

Use a block-size argument of 1 in the launch syntax, as in my_kernel<<<grid, 1>>>(...). The compiler determines the actual number of threads per block. If you compile Tile IR with tileiras directly, pass the same -l option. Libraries also provide CMake targets, such as mathdx_tile::cufftdx, that add these flags.

Set tile shapes, data types, and warp-count hints

You choose which library function to call, its compile-time parameters, the shapes and types of the tiles you pass, and where to place the call in your kernel. Code before and after the call is compiled into the same kernel. The compiler selects a compatible implementation, maps tile elements to threads, allocates the required shared memory, and inserts barriers as needed.

A tile kernel doesn’t declare its thread count, but a library implementation needs one. You can steer the choice with a hint: num_worker_warps in @ct.kernel, or [[cutile::hint(0, num_worker_warps_per_cta = …)]] in C++. For some functions, the hint is required. Large FFTs, for example, are implemented only at specific warp counts, so you pass the warp count with the hint or the kernel won’t compile. Libraries may also provide tuned settings, such as suggested_tile_config for FFTs, which returns a configuration with a suggested warp count and batches per block for a given size, precision, and GPU.

Compute distributed 3D FFTs with cuFFTDx and NVSHMEM

Distributed 3D FFTs underpin large-scale scientific computing, including molecular dynamics, turbulence and plasma simulation, and spectral partial differential equation (PDE) solvers. At these scales, the grid can be spread across many GPUs and nodes. With Tile/SIMT interop, you can write a distributed FFT in cuTile Python, with cuFFTDx for the FFTs and NVSHMEM’s tile API for communication, both called from cuTile kernels.

The example uses a slab decomposition (partitioning the grid into slices along one axis) and three kernels. They transform along Y locally, then along Z, and then along X once the data has been exchanged. In the Z kernel, each block computes its FFTs and sends the result directly to the remote GPU. This fuses the computation of local FFTs with communication, so the two can overlap.

import cuda.tile as ct
import nvmath.tile.fft as mfft                          # cuFFTDx
from nvshmem.core.device.tile import my_pe, put_block   # NVSHMEM

cfg = mfft.suggested_tile_config("fft", 3, 2, N, ct.float32, "sm_100")  # axis 2 = Z

@ct.kernel(num_worker_warps=cfg.num_worker_warps)
def fft_kernel_z(input_data, output_data, num_pes: ct.Constant[int]):
    B = cfg.batches_per_block
    y, x = ct.bid(0), ct.bid(1)
    data = ct.load(input_data, (x, y, 0, 0), shape=(1, B, N, 2))
    result = mfft.fft(data, axis=2)                      # cuFFTDx

    # Slab.X -> Slab.Y: pick the rank and local offset that own these rows
    slab = N // num_pes
    dst_pe = (y * B) // slab
    dst_x = my_pe() * slab + x
    dst_y = (y * B) % slab
    dest = output_data.slice(axis=0, start=dst_x, stop=dst_x + 1)
    dest = dest.slice(axis=1, start=dst_y, stop=dst_y + B)

    put_block(dest, ct.reshape(result, (B * N * 2,)),    # NVSHMEM
              ct.astype(dst_pe, ct.int32))

The benchmark compares this implementation with NVIDIA cuFFTMp, the multi-GPU FFT library, on a VR200 NVL72 system. The sweep covered complex-to-complex FP32 and FP64 FFTs with grid sizes from 512³ to 2048³ on 1 to 64 GPUs. Across the sweep, CUDA Tile shows performance comparable to cuFFTMp in both precisions and shows similar scaling out to 64 GPUs (Figures 2 and 3).

Reconstruct surfaces with cuTile Python, Warp, and MathDx

This example reconstructs a surface from a 3D scan and estimates uncertainty across the result, using GeoSPSR, which builds on Stochastic Poisson Surface Reconstruction. A Gaussian process fitted to the scanned points and their estimated surface normals yields a probability distribution over possible surfaces: Figure 4 shows the reconstruction, and the heat map is its uncertainty, sampled on that surface.

At each surface query point, the kernel solves a triangular system using the Cholesky factor (computed once) of the scan points’ covariance matrix. The right-hand side is the vector of covariances between the query point and the scan points. The solution contributes to the surface estimate and its uncertainty at that point. A view planner casts rays from each candidate camera position, one per pixel, queries the posterior where the rays intersect the current reconstruction, and picks the view with the most uncertainty. In Figure 4, that is the view facing the missing patch.

This maps naturally onto tiles. In this implementation, a tile is a group of 32 query points; one thread block owns it and works through the Cholesky factor in panels of 64 rows, loading one panel at a time (the factor is shared by every tile and stays resident in L2). The implementation divides the work among cuTile Python, Warp, and MathDx:

  • cuTile Python: Defines the kernel’s loads, reductions, and 64 × 64 by 64 × 32 multiplies that fold each already-solved panel into the current one, run as TensorFloat-32 (TF32) Tensor Core matrix multiply-accumulate (MMA) operations with FP32 accumulation.
  • Warp: Supplies the per-element SIMT pieces: the ray cast against the current reconstruction (wp.mesh_query_ray) and the scattered table lookups that build each panel’s covariance entries, both defined with @wp.func.
  • MathDx: Supplies the dense linear algebra through nvmath.tile.linalg: cuBLASDx trsm for the 64 × 64 triangular solve on every panel, and cuSolverDx potrf plus trsm for the one-time Cholesky factorization.

Until now, using these together required separate kernels with intermediate results written to global memory between them. CUDA 13.5 Tile/SIMT interop supports calls to a Warp function and a MathDx routine from a cuTile kernel, so the ray cast, the covariance gather, the Tensor Core updates, and the solves share one kernel:

import warp as wp
import cuda.tile as ct
import nvmath.tile.linalg as la
import warp.experimental.cutile as wpct

@wp.func
def ray_point(mesh: wp.uint64, o: wp.vec3, d: wp.vec3, off: float) -> wp.vec3:
    """Point at offset ``off`` along the ray past its hit on the current reconstruction."""
    q = wp.mesh_query_ray(mesh, o, d, 1.0e3)
    if q.result:
        return o + d * (q.t + off)
    return wp.vec3(1.0e3, 1.0e3, 1.0e3) # miss: a far sentinel the host masks out

# the same function, as a .tilelib
ray_pt = wpct.foreign_func(ray_point, uniform={"mesh"})

# likewise for the covariance lookup
kfv = wpct.foreign_func(kfv_sample, uniform={"grid"})

# inside the cuTile kernel; one tile = 32 query points owned by this thread block
# Warp: cast the rays against the current surface
q = ray_pt(mesh_id, o, d, off)

# panel i: rows 64i..64i+63 of the factor
for i in range(NB):

    # Warp: covariances with this panel's 64 scan points
    r = kfv(cov_table, q - p_i)
    mean = mean + ct.sum(r * alpha_i, axis=(1, 2))
    t = ct.reshape(ct.permute(r, (1, 0, 2)), (B, NRHS))

    # off-diagonal blocks L[i, j], one per solved panel
    for j in range(i):
# cuTile: 64x64 by 64x32, TF32 tensor cores, fp32 accumulate
       t = ct.mma(-L[i, j], W[j], t)

    # cuBLASDx: triangular solve with the diagonal block L[i, i]
    W_i = la.triangular_solve(L[i, i], t, la.FillMode.LOWER, la.DiagMode.NON_UNIT, la.SideMode.LEFT)

    # running sum for the uncertainty
    ssq = ssq + ct.sum(W_i * W_i, axis=0)

var = var_f - ct.sum(ct.reshape(ssq, (Q, PAD)), axis=1)

[Condensed from the example; loads and reshapes are omitted. The factorization uses the same three pieces: potrf on the diagonal panels, trsm on the panel rows, and TF32 MMA for the updates.]

Running the matrix multiplies on Tensor Cores is a one-line change in the cuTile code, and it reduces run times across all three routines (Table 1).

RoutineFP32 (s)TF32 Tensor Cores (s)Speedup
Cholesky factorization0.290.102.8x
Surface queries1.711.111.5x
View planning0.710.411.7x
Table 1. GeoSPSR routine run times on an NVIDIA GeForce RTX 5090 GPU with 4,096 scan points. The configurations differ only in the precision of the matrix multiplies within each routine

With TF32, the results match a double-precision solve within 2e-6 for the mean and 6e-6 for the variance.

Not only is it convenient to use different libraries together like this, it also avoids writing intermediate covariance rows to global memory. For one planning pass, the covariance rows would come to 6.4 GB; in the fused kernel, each panel’s rows are produced, used by the update and the solve, and discarded without materializing the full covariance array in global memory.

Enable the CUDA 13.5 Tile/SIMT interoperability preview

Tile/SIMT interop is available in CUDA 13.5 as a preview, so you can start building with it now and tell us what works for you. Enable it with --tile-preview simt in nvcc, or by installing the cuda-tile-preview package for cuTile Python. Library APIs built on interop, such as nvmath.tile, are also in preview.

While it’s in preview, the APIs and the way libraries plug into the compiler can change between CUDA releases in response to feedback. Use library releases built for your CUDA version, and check the release notes when you upgrade.

In CUDA 13.5, tile code can call the library functions that tilelibs provide. Support for calling your own __device__ functions is planned for a later release.

Acknowledgments

Jared Roesch, Nachi Gargi, Aman LaChapelle, Matthias Springer, Jaydeep Marathe, Ziheng Deng, Melody Shih, Benjamin Glick, Trent Nelson, and other NVIDIA engineers.

Discuss (0)

Tags