prefill

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package prefill lowers block-FP8 prefill projections to Tile IR.

This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.

Package prefill lowers block-FP8 prefill projections to Tile IR.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockFP8

type BlockFP8 struct {
	Tokens, Outputs, Depth int
}

BlockFP8 describes a static token-major prefill projection for sm_121a. Grid returns the required launch geometry. There are five device pointers, in this order:

  • x: E4M3FN activations [Tokens, Depth]
  • w: E4M3FN weights [Outputs, Depth]
  • xs: float32 activation scales [Depth/128, Tokens]
  • ws: float32 weight scales [ceil(Outputs/128), Depth/128]
  • y: float32 results [Tokens, Outputs]

All arrays are dense row-major and their storage must be disjoint. Tokens must be at least 64. Depth must be a positive multiple of 128. Partial token and output tiles are padded on load and clipped on store. Input producers and output consumers must be ordered on the launch stream or through explicit stream synchronization.

func (BlockFP8) Compile

func (p BlockFP8) Compile(ctx context.Context, opts ...tileir.Option) (*Program, error)

Compile assembles the projection for compute capability 12.1. The options configure tileiras, for example tileir.WithPath. Compile never opens a GPU.

func (BlockFP8) CompileDynamic

func (p BlockFP8) CompileDynamic(ctx context.Context, opts ...tileir.Option) (*Program, error)

CompileDynamic assembles DynamicModule. The resulting kernel can launch any admitted token count from 64 up to Tokens with the same cubin.

func (BlockFP8) CompileOverlap

func (p BlockFP8) CompileOverlap(ctx context.Context, opts ...tileir.Option) (*Program, error)

CompileOverlap assembles the K128 panel with a loop-carried successor load. It uses the same launch and buffer requirements as CompilePanel.

func (BlockFP8) CompilePanel

func (p BlockFP8) CompilePanel(ctx context.Context, opts ...tileir.Option) (*Program, error)

CompilePanel assembles PanelModule and checks the packed, aligned launch contract. Its runtime-token ABI is the same as CompileDynamic.

func (BlockFP8) CompileWideOverlap

func (p BlockFP8) CompileWideOverlap(ctx context.Context, opts ...tileir.Option) (*Program, error)

CompileWideOverlap assembles the staged K128 panel with 64 output columns per CTA. Buffers follow the CompileOverlap contract.

func (BlockFP8) DynamicModule

func (p BlockFP8) DynamicModule() (*tileir.Module, error)

DynamicModule lowers a projection with the same buffer layouts as Module and a final int32 token count argument. Tokens is its admitted upper bound. Activation scale rows are packed using the actual token count as the stride.

func (BlockFP8) Grid

func (p BlockFP8) Grid() ([3]int, error)

Grid returns the tile launch grid after checking the projection dimensions.

func (BlockFP8) Module

func (p BlockFP8) Module() (*tileir.Module, error)

Module lowers the projection. It uses ordinary E4M3 mmaf and keeps the checkpoint's float32 scales. For each K128 group it accumulates four K32 products, multiplies the scales, and performs one float32 FMA into the output accumulator. Hardware mmaf_scaled has different scale encodings.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/tile/prefill"
)

func main() {
	p := prefill.BlockFP8{Tokens: 65, Outputs: 160, Depth: 256}
	grid, err := p.Grid()
	if err != nil {
		fmt.Println(err)
		return
	}
	mod, err := p.Module()
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(mod.Functions[0].Name, grid)
}
Output:
block_fp8_prefill [2 10 1]

func (BlockFP8) PanelGrid

func (p BlockFP8) PanelGrid() ([3]int, error)

PanelGrid returns the launch geometry of PanelModule at the actual shape.

func (BlockFP8) PanelModule

func (p BlockFP8) PanelModule() (*tileir.Module, error)

PanelModule lowers a runtime-token projection with 32 output columns per tile and whole K128 panel loads. The activation and weight base addresses must be aligned to 16 bytes. The four K32 products and FP32 scale application are the same as DynamicModule.

type Buffers

type Buffers struct {
	Activations, Weights           cuda.Slice[uint8]
	ActivationScales, WeightScales cuda.Slice[float32]
	Output                         cuda.Slice[float32]
}

Buffers supplies the device slices in a BlockFP8 projection. Each slice must have room for its documented shape. Extra elements are ignored.

type Kernel

type Kernel struct {
	// contains filtered or unexported fields
}

Kernel is a loaded projection. Its zero value is closed.

func (*Kernel) Close

func (k *Kernel) Close() error

Close unloads the device program. The caller must finish all launches, including graph replays, before closing it.

func (*Kernel) Launch

func (k *Kernel) Launch(stream *cuda.Stream, b Buffers) error

Launch enqueues the projection on stream. Buffers must remain live until the stream has finished all uses, including replays if this launch was captured in a graph.

func (*Kernel) LaunchTokens

func (k *Kernel) LaunchTokens(stream *cuda.Stream, tokens int, b Buffers) error

LaunchTokens sets the actual token count for a dynamic kernel. Static kernels accept only their compiled token count. The buffer lifetime requirement is the same as for Launch.

type Program

type Program struct {
	// contains filtered or unexported fields
}

Program is an offline-assembled projection and its compiler-required launch geometry. A Program may be loaded independently on multiple devices.

func (*Program) Load

func (p *Program) Load(dev *cuda.Device) (*Kernel, error)

Load loads a compiled projection on a compute capability 12.1 device.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL