Code Inspection

Compiling a signature

cuTile.code_tiledFunction
code_tiled([io::IO], job::TileJob; debuginfo=false, remarks=false)
code_tiled([io::IO], f, argtypes; debuginfo=false, remarks=false, kwargs...)

Print the CUDA Tile IR for a Julia function as a textual MLIR representation. Analogous to code_llvm. Keyword arguments are those of tile_job: by default the code targets the current CUDA device, as a launch would. To inspect the job of an actual launch, use @device_code_tiled.

Set remarks=true to also run tileiras and print its optimization remarks. This requires tileiras 13.4 or newer.

source
cuTile.code_typedFunction
code_typed(job::TileJob) -> Vector{Pair{IRCode, DataType}}
code_typed(f, argtypes; kwargs...) -> Vector{Pair{IRCode, DataType}}

Return typed code for a cuTile function. Analogous to Base.code_typed. Keyword arguments are those of tile_job; without any, no toolchain or device is needed.

source
cuTile.code_ircodeFunction
code_ircode(mi::MethodInstance; world, always_inline=true) -> (IRCode, rettype)

Get optimized IRCode for a MethodInstance using cuTile's overlay method table. If always_inline=true (default), forces all functions to be inlined.

source
cuTile.code_structuredFunction
code_structured(job::TileJob; optimize=true) -> Vector{Pair{StructuredIRCode, DataType}}
code_structured(f, argtypes; optimize=true, kwargs...)

Return the structured IR for a cuTile function, after the optimization passes unless optimize=false. Keyword arguments are those of tile_job; without any, no toolchain or device is needed.

source
cuTile.code_ptxFunction
code_ptx([io::IO], job::TileJob)
code_ptx([io::IO], f, argtypes; kwargs...)

Print the PTX that tileiras generates for a Julia function. This shows the thread-level SIMT program the tile-level kernel is lowered to, with every compiler decision (thread mapping, CTA size, pipelining, synchronization) already made. Keyword arguments are those of tile_job; to inspect the job of an actual launch, use @device_code_ptx.

Unstable

The PTX is recorded by tileiras in an undocumented CUBIN section and may go away.

source
cuTile.code_sassFunction
code_sass([io::IO], job::TileJob)
code_sass([io::IO], f, argtypes; kwargs...)

Print the SASS machine code that a Julia function compiles to, by assembling the Tile IR with tileiras and disassembling the resulting CUBIN with nvdisasm. Keyword arguments are those of tile_job. For the binary a launch actually loaded, use CUDA.@device_code_sass.

source

Jobs

cuTile.TileJobType
TileJob

A compilation request containing a MethodInstance, its world age and any constant arguments, plus the target architecture, bytecode version, compilation hints, and kernel name. Construct jobs with tile_job and pass them to the reflection functions to inspect that configuration.

Jobs are immutable and compare structurally, so equal jobs are ===.

source
cuTile.tile_jobFunction
tile_job(f, argtypes; world=Base.get_world_counter(), kwargs...) -> TileJob
tile_job(mi::MethodInstance, world; const_argtypes=nothing, kwargs...) -> TileJob

Create a TileJob for f and argtypes (which may contain Constant{T,V} types), or for a method instance with the given const-seeded argument types. Keyword arguments configure the compilation:

  • bytecode_version: the Tile IR bytecode version to emit; defaults to bytecode_version(), i.e. the bytecode_version preference or the newest version the selected tileiras accepts.
  • sm_arch: the target architecture; defaults to the current CUDA device's. Combinations the bytecode does not support are rejected.
  • opt_level, num_ctas, occupancy, num_worker_warps: compilation hints overriding the kernel's @compiler_options.
  • name: the kernel's name in the bytecode; defaults to the method's.
source

Intercepting a launch

cuTile.@device_code_tiledMacro
@device_code_tiled [io=stdout] [remarks=false] expression

Print the Tile IR (MLIR) for all kernels compiled while evaluating the expression. With remarks=true, also print tileiras optimization remarks for each kernel.

Example

@device_code_tiled @cuda backend=cuTile blocks=grid vadd(a, b, c)
source
cuTile.@device_code_structuredMacro
@device_code_structured [io=stdout] [optimize=true] expression

Print the StructuredIRCode for all kernels compiled while evaluating the expression.

Example

@device_code_structured @cuda backend=cuTile blocks=grid vadd(a, b, c)
source
cuTile.@device_code_ptxMacro
@device_code_ptx [io=stdout] expression

Print the PTX generated by tileiras for all kernels compiled while evaluating the expression. Unstable, like code_ptx.

Example

@device_code_ptx @cuda backend=cuTile blocks=grid vadd(a, b, c)
source

@device_code_typed and @device_code_warntype are shared with GPUCompiler; they work for cuTile kernels through the shared compile hook.

CUDA.@device_code_sass works for cuTile kernels: it intercepts module loads at the driver level (via CUPTI), so it captures any backend's kernels without backend-specific support.