For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Mojo function
gemv_and_partial_norm_with_scratch
def gemv_and_partial_norm_with_scratch[c_type: DType, a_type: DType, TraceBufT: TraceBuf = NullTrace, //, *, transpose_b: Bool = True, pdl_level: PDLLevel = PDLLevel(), tile_n: Int = Int(4), num_threads: Int = Int(256), enable_trace: Bool = False](normed_output: TileTensor[c_type, Storage=normed_output.Storage, address_space=normed_output.address_space, linear_idx_type=normed_output.linear_idx_type], unnormed_output: TileTensor[c_type, Storage=unnormed_output.Storage, address_space=unnormed_output.address_space, linear_idx_type=unnormed_output.linear_idx_type], act: TileTensor[a_type, Storage=act.Storage, address_space=act.address_space, linear_idx_type=act.linear_idx_type], weight: TileTensor[a_type, Storage=weight.Storage, address_space=weight.address_space, linear_idx_type=weight.linear_idx_type], gamma: TileTensor[a_type, Storage=gamma.Storage, address_space=gamma.address_space, linear_idx_type=gamma.linear_idx_type], eps: Float32, finish_counter: Pointer[Int32, MutAnyOrigin, _safe=False], ctx: DeviceContext, trace_buf: TraceBufT = NullTrace())
Fused path with caller-provided scratch.
finish_counter must be zero-initialized on first use. The kernel
resets it to zero before returning so the same buffer can be
reused across calls without an external memset.
Set enable_trace=True and pass a GmemTrace(ptr) to record per-
block timestamps into ptr (sized num_normed_blocks * GEMV_TRACE_EVENTS_PER_BLOCK u64s). When disabled (default), the
trace path dead-code-eliminates, yielding byte-identical PTX to
the untraced kernel.
Parameters:
- βc_type (
DType): Output dtype. - βa_type (
DType): Activation / weight / gamma dtype. - βTraceBufT (
TraceBuf): Trace-buffer implementation. Defaults toNullTracefor zero-overhead untraced runs. - βtranspose_b (
Bool): IfTrue,weightis row-major[N, K]used asweight.T. - βpdl_level (
PDLLevel): Programmatic Dependent Launch level. - βtile_n (
Int): Comptime tile width in columns. - βnum_threads (
Int): Comptime threads per block. - βenable_trace (
Bool): WhenTrue, record per-phase timestamps intotrace_buf. WhenFalse(default), all record sites compile away.
Args:
- βnormed_output (
TileTensor[c_type, Storage=normed_output.Storage, address_space=normed_output.address_space, linear_idx_type=normed_output.linear_idx_type]):[M, N_normed]output buffer. Holdsrms_norm(y[:, :N_normed], gamma, eps)on return. - βunnormed_output (
TileTensor[c_type, Storage=unnormed_output.Storage, address_space=unnormed_output.address_space, linear_idx_type=unnormed_output.linear_idx_type]):[M, N - N_normed]output buffer. Holdsy[:, N_normed:]on return. - βact (
TileTensor[a_type, Storage=act.Storage, address_space=act.address_space, linear_idx_type=act.linear_idx_type]):[M, K]activations. - βweight (
TileTensor[a_type, Storage=weight.Storage, address_space=weight.address_space, linear_idx_type=weight.linear_idx_type]):[N, K]weights (whentranspose_b=True). - βgamma (
TileTensor[a_type, Storage=gamma.Storage, address_space=gamma.address_space, linear_idx_type=gamma.linear_idx_type]):[N_normed]RMS norm scale. - βeps (
Float32): RMS norm epsilon. - βfinish_counter (
Pointer[Int32, MutAnyOrigin, _safe=False]): Single-Int32device counter. Must be zero-initialized on first use; the kernel resets it to zero before returning. - βctx (
DeviceContext): Device context. - βtrace_buf (
TraceBufT): Trace-buffer instance. Defaults toNullTrace().
Raises:
Error: If the kernel launch fails.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!