Archived
Merge upstream main (v1.15.1 -> v1.17.0, 152 commits) into the SYCL port
Conflicts, both sides kept:
- abi: RAD_ABI_VERSION 37 (upstream); the fork's RadBuildCtx.plain_norm after upstream's
expert_file_tier, widened to int64_t so it starts past ABI 37's 208-byte struct instead of in
its tail padding (abi_layout_test); RadSyclStream rows after RadShapeGen*.
- arch/common/rad_block_gdn_fp8.h: upstream's q8_rot guard and the fork's o_plain guard
combined; the decode-row q_o.step only where q_o is declared (!o_plain).
- docs/OPS.md: upstream's optional params on sample_logprobs, the fork's q_temp on
mtp_couple_propose.
Also ignores /baseline-models/ (local model copies).
Host tests: arch_test's MTP lint/graph-pin failures are unchanged from before the merge (the
fork's mtp.fc LinearFP8, 10a99a5); avx_check's hand-built moe_gemm_q w4a8 case also fails on
upstream's own files; images/videos need FFmpeg; three binaries over their CPU budget on this VM.
SYCL card tests 3/3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
45f3b510c7
365 files changed
+56942
-6331
No files matched your search
+18
-3
@@ -21,7 +21,7 @@ extern "C" {
|
||||
* (e.g. rad_plugin_reference) is not a change of shape: a plugin without it gets the default.
|
||||
* rad_sycl.h is versioned on its own (RAD_SYCL_STREAM_VERSION), since only SYCL kernel libraries
|
||||
* read it. */
|
||||
#define RAD_ABI_VERSION 32u
|
||||
#define RAD_ABI_VERSION 37u
|
||||
|
||||
/* ================================================================== plugin identity */
|
||||
/* One value per plugin, not flags (QUANT is 3). RAD_PLUGIN_QUANT is a quantiser plugin:
|
||||
@@ -62,6 +62,16 @@ typedef struct RadArgs {
|
||||
void* instance; /* whatever init() returned for this resolved instance */
|
||||
int rank; /* tensor-parallel rank and world size, for collectives */
|
||||
int world_size;
|
||||
/* ABI 35: host-side maximum KV length represented by this exact launch operand (a seqused
|
||||
* span or a supported one-sequence prefill boundary), or -1 when it cannot be proven. In a
|
||||
* decode, verify or draft pass of an architecture with no rad_arch_pass_key it is instead the
|
||||
* step's context bound plus its longest query, which the recorded pass's key holds. Plugins
|
||||
* must not infer it from a device pointer or synchronously read device memory to get it. */
|
||||
int32_t kv_used_max_h;
|
||||
/* The current rank's WGP count (HIP multiProcessorCount on RDNA); lets split launchers use
|
||||
* exactly the same per-device occupancy as architecture pass-key callbacks without querying
|
||||
* the process-global current device on the hot path. */
|
||||
int32_t wgp_count;
|
||||
} RadArgs;
|
||||
|
||||
/* Read a parameter by key. Inline definitions, because a plugin links only the ABI headers and
|
||||
@@ -467,15 +477,20 @@ typedef struct RadKernelInfo {
|
||||
* against: a named skip, not a failure. */
|
||||
RadUnrelayoutFn unrelayout;
|
||||
/* The chain of conventional ops this kernel computes in one launch, or null if it is not a
|
||||
* fusion. Non-null also counts in rad-kbench's fusion-claim column.
|
||||
* fusion. Non-null also counts in rad-kbench's fusion-claim column. */
|
||||
RadFuseFn replaces;
|
||||
/* Flags describing runtime behavior relevant to core safety decisions. Zero means none.
|
||||
*
|
||||
* Keep this field last. Kernel tables are positional aggregate initialisers
|
||||
* (`{..., nullptr, nullptr, r4d_rad_embed_lookup, nullptr, ...}`), so a field inserted
|
||||
* anywhere else shifts every later initialiser, and since `nullptr` converts to any function
|
||||
* pointer type, part of that shift would still compile. Append new fields after this one. */
|
||||
RadFuseFn replaces;
|
||||
uint64_t capabilities;
|
||||
} RadKernelInfo;
|
||||
|
||||
/* This row's launch grid can depend on live seqused during prefill. */
|
||||
#define RAD_KERNEL_CAP_DYNAMIC_PREFILL_SPLIT (1ull << 0)
|
||||
|
||||
/* ================================================================== kernel plugin exports */
|
||||
/* Every kernel plugin exports the whole set. The first plugin in hierarchy order to declare an op
|
||||
* fixes its schema; a later plugin declaring the same op name with a different schema is refused
|
||||
|
||||
@@ -26,6 +26,7 @@ ABI_FIELD(RadArchProbe, state_f16_ok)
|
||||
ABI_FIELD(RadArchProbe, tree_pays)
|
||||
ABI_FIELD(RadArchProbe, gen_max_pixels)
|
||||
ABI_FIELD(RadArchProbe, gen_max_refs)
|
||||
ABI_FIELD(RadArchProbe, gen_shape)
|
||||
ABI_STRUCT(RadArgs)
|
||||
ABI_FIELD(RadArgs, t)
|
||||
ABI_FIELD(RadArgs, n_t)
|
||||
@@ -36,6 +37,8 @@ ABI_FIELD(RadArgs, scratch_bytes)
|
||||
ABI_FIELD(RadArgs, instance)
|
||||
ABI_FIELD(RadArgs, rank)
|
||||
ABI_FIELD(RadArgs, world_size)
|
||||
ABI_FIELD(RadArgs, kv_used_max_h)
|
||||
ABI_FIELD(RadArgs, wgp_count)
|
||||
ABI_STRUCT(RadBatch)
|
||||
ABI_FIELD(RadBatch, phase)
|
||||
ABI_FIELD(RadBatch, step)
|
||||
@@ -93,6 +96,15 @@ ABI_FIELD(RadBatch, plugin_words)
|
||||
ABI_FIELD(RadBatch, plugin_cu)
|
||||
ABI_FIELD(RadBatch, plugin_words_h)
|
||||
ABI_FIELD(RadBatch, plugin_cu_h)
|
||||
ABI_FIELD(RadBatch, sgen_b)
|
||||
ABI_FIELD(RadBatch, kv_used_max_h)
|
||||
ABI_FIELD(RadBatch, positions_h)
|
||||
ABI_FIELD(RadBatch, n_bidi)
|
||||
ABI_FIELD(RadBatch, bidi_row)
|
||||
ABI_FIELD(RadBatch, bidi_n)
|
||||
ABI_FIELD(RadBatch, bidi_seq)
|
||||
ABI_FIELD(RadBatch, bidi_used)
|
||||
ABI_FIELD(RadBatch, anchor_rows)
|
||||
ABI_STRUCT(RadBufDecl)
|
||||
ABI_FIELD(RadBufDecl, dtype)
|
||||
ABI_FIELD(RadBufDecl, rank)
|
||||
@@ -134,6 +146,7 @@ ABI_FIELD(RadBuildCtx, calib_layer_hi)
|
||||
ABI_FIELD(RadBuildCtx, calib_tokens)
|
||||
ABI_FIELD(RadBuildCtx, gen_max_pixels)
|
||||
ABI_FIELD(RadBuildCtx, gen_max_refs)
|
||||
ABI_FIELD(RadBuildCtx, expert_file_tier)
|
||||
ABI_FIELD(RadBuildCtx, plain_norm)
|
||||
ABI_STRUCT(RadAudioGenBatch)
|
||||
ABI_FIELD(RadAudioGenBatch, n_lane)
|
||||
@@ -312,6 +325,7 @@ ABI_FIELD(RadEncoderDecl, max_patches)
|
||||
ABI_FIELD(RadEncoderDecl, n_embd)
|
||||
ABI_FIELD(RadEncoderDecl, out)
|
||||
ABI_FIELD(RadEncoderDecl, one_grid)
|
||||
ABI_FIELD(RadEncoderDecl, bidirectional)
|
||||
ABI_STRUCT(RadEncoding)
|
||||
ABI_FIELD(RadEncoding, scheme)
|
||||
ABI_FIELD(RadEncoding, transform)
|
||||
@@ -501,6 +515,7 @@ ABI_FIELD(RadKVGroupBatch, state_index_pitch)
|
||||
ABI_FIELD(RadKVGroupBatch, block_size)
|
||||
ABI_FIELD(RadKVGroupBatch, max_blocks)
|
||||
ABI_FIELD(RadKVGroupBatch, stream)
|
||||
ABI_FIELD(RadKVGroupBatch, seqused_h)
|
||||
ABI_STRUCT(RadKVGroupDecl)
|
||||
ABI_FIELD(RadKVGroupDecl, kind)
|
||||
ABI_FIELD(RadKVGroupDecl, dtype)
|
||||
@@ -542,6 +557,7 @@ ABI_FIELD(RadKernelInfo, relayout)
|
||||
ABI_FIELD(RadKernelInfo, opd_shape)
|
||||
ABI_FIELD(RadKernelInfo, unrelayout)
|
||||
ABI_FIELD(RadKernelInfo, replaces)
|
||||
ABI_FIELD(RadKernelInfo, capabilities)
|
||||
ABI_STRUCT(RadLayout)
|
||||
ABI_FIELD(RadLayout, tag)
|
||||
ABI_FIELD(RadLayout, dtype)
|
||||
@@ -700,6 +716,44 @@ ABI_FIELD(RadSampleParams, hist_len)
|
||||
ABI_FIELD(RadSampleParams, mask_row)
|
||||
ABI_FIELD(RadSampleParams, flags)
|
||||
ABI_FIELD(RadSampleParams, dry_rep_limit)
|
||||
ABI_STRUCT(RadShapeGenBatch)
|
||||
ABI_FIELD(RadShapeGenBatch, lane)
|
||||
ABI_FIELD(RadShapeGenBatch, patches)
|
||||
ABI_FIELD(RadShapeGenBatch, step)
|
||||
ABI_FIELD(RadShapeGenBatch, n_steps)
|
||||
ABI_FIELD(RadShapeGenBatch, sigma)
|
||||
ABI_FIELD(RadShapeGenBatch, sigma_next)
|
||||
ABI_FIELD(RadShapeGenBatch, cfg)
|
||||
ABI_FIELD(RadShapeGenBatch, pair)
|
||||
ABI_FIELD(RadShapeGenBatch, lanes)
|
||||
ABI_FIELD(RadShapeGenBatch, flags)
|
||||
ABI_FIELD(RadShapeGenBatch, seed)
|
||||
ABI_FIELD(RadShapeGenBatch, lat_cu)
|
||||
ABI_FIELD(RadShapeGenBatch, n_query)
|
||||
ABI_FIELD(RadShapeGenBatch, query)
|
||||
ABI_FIELD(RadShapeGenBatch, query_cu)
|
||||
ABI_STRUCT(RadShapeGenDecl)
|
||||
ABI_FIELD(RadShapeGenDecl, name)
|
||||
ABI_FIELD(RadShapeGenDecl, canvas)
|
||||
ABI_FIELD(RadShapeGenDecl, border_ratio)
|
||||
ABI_FIELD(RadShapeGenDecl, enc_size)
|
||||
ABI_FIELD(RadShapeGenDecl, enc_patch)
|
||||
ABI_FIELD(RadShapeGenDecl, pix_mean)
|
||||
ABI_FIELD(RadShapeGenDecl, pix_std)
|
||||
ABI_FIELD(RadShapeGenDecl, latent_rows)
|
||||
ABI_FIELD(RadShapeGenDecl, latent_channels)
|
||||
ABI_FIELD(RadShapeGenDecl, step_rows)
|
||||
ABI_FIELD(RadShapeGenDecl, default_steps)
|
||||
ABI_FIELD(RadShapeGenDecl, max_steps)
|
||||
ABI_FIELD(RadShapeGenDecl, default_guidance)
|
||||
ABI_FIELD(RadShapeGenDecl, bounds)
|
||||
ABI_FIELD(RadShapeGenDecl, level)
|
||||
ABI_FIELD(RadShapeGenDecl, default_resolution)
|
||||
ABI_FIELD(RadShapeGenDecl, min_resolution)
|
||||
ABI_FIELD(RadShapeGenDecl, max_resolution)
|
||||
ABI_FIELD(RadShapeGenDecl, max_lanes)
|
||||
ABI_FIELD(RadShapeGenDecl, max_query)
|
||||
ABI_FIELD(RadShapeGenDecl, field_out)
|
||||
ABI_STRUCT(RadSyclStream)
|
||||
ABI_FIELD(RadSyclStream, magic)
|
||||
ABI_FIELD(RadSyclStream, version)
|
||||
|
||||
+110
-2
@@ -295,6 +295,13 @@ typedef struct RadBuildCtx {
|
||||
* fixed buffers ignores them, and the core says so at startup. */
|
||||
int64_t gen_max_pixels;
|
||||
int64_t gen_max_refs;
|
||||
|
||||
/* ---- appended in ABI 37 (where a routed expert may live) */
|
||||
/* --weights-disk-tier: nonzero when weights may stay in the container. An expert read from the
|
||||
* drive has to be stored whole, so a plugin that can lay its routed experts out either way
|
||||
* keeps them whole for this; 0 leaves it free to split them across the ranks by width. */
|
||||
int expert_file_tier;
|
||||
|
||||
/* ---- appended in the SYCL fork (the plain block norm) */
|
||||
/* Nonzero: where no reader of a block norm's output takes its E4M3 code pair (every reader a
|
||||
* 4-bit or plain bf16 projection, which reads the bf16 plane), the plugin may run the norm as
|
||||
@@ -303,8 +310,9 @@ typedef struct RadBuildCtx {
|
||||
* quantising norm is bound by libref's ordered sum of squares while its `rmsnorm` is a fast
|
||||
* row (docs/SYCL_PROGRESS.md); 0 elsewhere, so other backends declare what they did.
|
||||
*
|
||||
* Trailing and zero-defaulted, so a plugin built against the older struct is unchanged. */
|
||||
int plain_norm;
|
||||
* Trailing and zero-defaulted, so a plugin built against the older struct is unchanged. 64-bit
|
||||
* so it starts past the end of ABI 37's struct, not in the padding after expert_file_tier. */
|
||||
int64_t plain_norm;
|
||||
} RadBuildCtx;
|
||||
|
||||
/* ================================================================== control vectors */
|
||||
@@ -896,6 +904,13 @@ typedef struct RadEncoderDecl {
|
||||
* position tables or kernels are per geometry; the core ends a pass where the grid changes.
|
||||
* 0 packs segments of any grid into a pass. */
|
||||
int32_t one_grid;
|
||||
|
||||
/* ---- appended in ABI 32 (runs the language model reads both ways) */
|
||||
/* 1: the language model attends the placeholders of one picture or video frame to each other
|
||||
* both ways (Gemma 4's use_bidirectional_attention "vision"), text before and after them
|
||||
* causally. The core then ends no prefill chunk inside such a run and states each trunk pass's
|
||||
* runs (RadBatch::n_bidi). 0 for an audio encoder. */
|
||||
int32_t bidirectional;
|
||||
} RadEncoderDecl;
|
||||
|
||||
int rad_declare_encoder(RadBuilder* b, const RadEncoderDecl* d);
|
||||
@@ -1481,6 +1496,87 @@ typedef struct RadVideoGenDecl {
|
||||
|
||||
int rad_declare_video_generator(RadBuilder* b, const RadVideoGenDecl* d);
|
||||
|
||||
/* ================================================================== the shape generator */
|
||||
/* A program that makes a 3-D shape from one picture: an image encoder reads the picture, a
|
||||
* denoiser steps a set of latent rows by flow matching, guided against an unconditioned branch,
|
||||
* and a decoder turns the latent into an occupancy field that the core samples at points of its
|
||||
* choosing and meshes. The core drives the passes (RadBatch::gen, RadShapeGenBatch), one request
|
||||
* a pass:
|
||||
*
|
||||
* RAD_GEN_PASS_SCOND the request's picture through the image encoder into the request's
|
||||
* lane: what the denoiser reads of it at every step, for both branches
|
||||
* (the picture's and the unconditioned one).
|
||||
* RAD_GEN_PASS_SSTEP one denoising step of one lane over both branches, `step_rows` rows:
|
||||
* each branch's conditioning and latent, laid out as the plugin likes, the
|
||||
* latents two entries of `latent_rows` (the conditioned first) for the
|
||||
* image generator's sampler ops. The first step draws the lane's noise.
|
||||
* RAD_GEN_PASS_SLATENT the lane's final latent through the decoder's network, into the lane:
|
||||
* what every query pass of the request reads. Runs once, after the last
|
||||
* step.
|
||||
* RAD_GEN_PASS_SQUERY the field at `n_query` points (RadShapeGenBatch::query, at most
|
||||
* `max_query`), one f32 a point in `field_out`, which the core reads
|
||||
* back.
|
||||
*
|
||||
* The picture. The core decodes it with its alpha (opaque without one) and prepares it as
|
||||
* Hunyuan3D-2's ImageProcessorV2 and image encoder do: the alpha's bounding box (its last row and
|
||||
* column left out, as the reference's slice leaves them) scaled with OpenCV's INTER_AREA to
|
||||
* (1 - border_ratio) of the longer side of the square that holds the picture, centred on it and
|
||||
* flattened onto white; that square resized to `canvas` x `canvas` with INTER_CUBIC; then as 0..1
|
||||
* values bilinearly resized to `enc_size` x `enc_size` (half-pixel centres, torchvision's), each
|
||||
* channel normalised by `pix_mean` and `pix_std`, and cut into (enc_size / enc_patch)^2 patches of
|
||||
* enc_patch x enc_patch pixels, row-major, each patch's values channel-major then row-major (a
|
||||
* convolution's weight order). An SCOND pass carries those patches.
|
||||
*
|
||||
* The sampler: a request's `steps` are sigma grid points, sigma_i = i / (steps - 1) for i in
|
||||
* [0, steps), numpy's linspace(0, 1) taken to f32; the latent starts as noise at sigma 0 and an
|
||||
* evaluation at each sigma but the last steps it to the next (the reference evaluates at the
|
||||
* last too, against itself, a step of zero). The model's timestep is sigma, the guided velocity
|
||||
* neg + cfg (pos - neg), and the step x + (sigma_next - sigma) v.
|
||||
*
|
||||
* The field: the decoder's logit at a point, inside the shape above `level`. The core samples the
|
||||
* cube [-bounds, bounds]^3 on a grid of `resolution` cells a side ((resolution + 1)^3 points,
|
||||
* numpy's linspace in f32 along each axis), coarse to fine as FlashVDM's hierarchical decoding
|
||||
* does: the whole grid at the coarsest level (resolution halved while it stays at least 63), then
|
||||
* at each finer level only the points near where the coarser one crosses `level` or is within
|
||||
* 0.95 of it. The surface is marching cubes over the finest grid, a vertex at grid index g placed
|
||||
* at g 2 bounds / (resolution + 1) - bounds, as the reference places it.
|
||||
*
|
||||
* A program declares exactly one of this, the other generators, logits or pooled vectors. */
|
||||
enum { RAD_GEN_PASS_SCOND = 15, RAD_GEN_PASS_SSTEP = 16, RAD_GEN_PASS_SLATENT = 17,
|
||||
RAD_GEN_PASS_SQUERY = 18 };
|
||||
|
||||
typedef struct RadShapeGenDecl {
|
||||
const char* name; /* "hunyuan3d-2" -- the served model id and messages */
|
||||
|
||||
/* The picture (above). */
|
||||
int64_t canvas;
|
||||
double border_ratio;
|
||||
int64_t enc_size, enc_patch;
|
||||
double pix_mean[3], pix_std[3];
|
||||
|
||||
/* The latent: `latent_rows` rows of `latent_channels` a branch; a step's rows, both branches
|
||||
* with their conditioning. */
|
||||
int64_t latent_rows, latent_channels, step_rows;
|
||||
|
||||
/* The sampler (above) and the guidance a request that names none runs at. */
|
||||
int64_t default_steps, max_steps;
|
||||
double default_guidance;
|
||||
|
||||
/* The field (above): the cube's half side, the iso value, and the grid's resolution a request
|
||||
* that names none is sampled at, with the range a request may name. */
|
||||
double bounds;
|
||||
double level;
|
||||
int64_t default_resolution, min_resolution, max_resolution;
|
||||
|
||||
/* `max_lanes` requests may hold state at once. `field_out` is a device f32 buffer of at least
|
||||
* `max_query` elements. */
|
||||
int64_t max_lanes;
|
||||
int64_t max_query;
|
||||
rad_buf field_out;
|
||||
} RadShapeGenDecl;
|
||||
|
||||
int rad_declare_shape_generator(RadBuilder* b, const RadShapeGenDecl* d);
|
||||
|
||||
/* ================================================================== diagnostics */
|
||||
/* A plugin may annotate the graph dump. Free-form, printed under --debug-graph. */
|
||||
void rad_note(RadBuilder* b, const char* fmt, ...);
|
||||
@@ -1615,6 +1711,12 @@ typedef struct RadArchProbe {
|
||||
* gen_patches answer for them. */
|
||||
int64_t gen_max_pixels;
|
||||
int64_t gen_max_refs;
|
||||
|
||||
/* ---- appended in ABI 33 (the shape generator) */
|
||||
/* Nonzero for a shape generator, which the engine sizes as it does a video generator from
|
||||
* `gen_rows` (its largest pass: a step's two branches, or a query pass's points). It keeps no
|
||||
* KV. */
|
||||
int32_t gen_shape;
|
||||
} RadArchProbe;
|
||||
|
||||
int rad_arch_probe(const RadModelMeta* meta, RadArchProbe* out);
|
||||
@@ -1856,6 +1958,12 @@ int rad_arch_declare(RadBuilder* b, const RadModelMeta* meta, const RadB
|
||||
struct RadCtx;
|
||||
struct RadBatch;
|
||||
void rad_arch_step(struct RadCtx* c, const struct RadBatch* batch);
|
||||
/* Optional. Return a stable fingerprint of actual dispatch geometry whose grid depends on live
|
||||
* per-group seqused values. `kv_used_max_h[g]` is the host maximum for batch->kv[g], and
|
||||
* rad_ctx_wgp_count(c) supplies the device's WGP count. Return 0 when exact geometry is unknown;
|
||||
* that pass runs live and is not recorded. */
|
||||
uint64_t rad_arch_pass_key(struct RadCtx* c, const struct RadBatch* batch,
|
||||
const int32_t* kv_used_max_h);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/* rad_prefill_split.h -- host-pure live-KV prefill split law shared by libr4d launchers and
|
||||
* architecture pass-key callbacks. Keep this independent of HIP so callbacks can run before tape
|
||||
* lookup without a device copy or launch.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
/* `bq` query positions per workgroup, `tile` keys per KV tile. `units` counts the workgroups that
|
||||
* do work: a ragged batch's grid is sized from its longest sequence, but a shorter sequence's
|
||||
* tiles past its end exit at once. Each split keeps at least eight tiles of the supplied context.
|
||||
*/
|
||||
static inline int rad_prefill_splits_law(int bq, int tile, int q_len, int total_q, int num_seqs,
|
||||
int kv_heads, int max_ctx, int wgps) {
|
||||
const long n = std::max(1, num_seqs);
|
||||
const long qt = std::min(n * ((std::max(1, q_len) + bq - 1) / bq),
|
||||
(std::max(1, total_q) + (long)(bq - 1) * n) / bq);
|
||||
const long units = (long)std::max(1, kv_heads) * std::max(1L, qt);
|
||||
if (units >= wgps) return 1;
|
||||
const int s1 = (int)(wgps / units), s2 = (int)(2L * wgps / units);
|
||||
int sp = s2 > 2 * s1 ? s2 : s1;
|
||||
const int cap = ((max_ctx > 0 ? max_ctx : (1 << 30) - 1) + tile - 1) / tile / 8;
|
||||
sp = std::min(sp, std::max(1, cap));
|
||||
return std::max(1, std::min(sp, 64));
|
||||
}
|
||||
|
||||
/* The launcher's live-context refinement of the initial model-bound law. */
|
||||
static inline int rad_prefill_splits_for_live(int bq, int tile, int q_len, int total_q,
|
||||
int num_seqs, int kv_heads, int max_ctx,
|
||||
int used_ctx, int wgps) {
|
||||
int splits = rad_prefill_splits_law(bq, tile, q_len, total_q, num_seqs, kv_heads, max_ctx,
|
||||
wgps);
|
||||
if (splits > 1 && used_ctx > 0 && (max_ctx <= 0 || used_ctx < max_ctx))
|
||||
splits = rad_prefill_splits_law(bq, tile, q_len, total_q, num_seqs, kv_heads, used_ctx,
|
||||
wgps);
|
||||
return splits;
|
||||
}
|
||||
|
||||
/* Fingerprint one actual launch tuple in packet-global sizes. Use this instead of the raw context
|
||||
* so equal split grids share a recording key as live context advances. */
|
||||
static inline uint64_t rad_prefill_grid_key(int q_len, int bq, int splits, int kv_heads,
|
||||
int num_seqs, int threads) {
|
||||
const uint64_t gx = (uint64_t)((std::max(1, q_len) + bq - 1) / bq) *
|
||||
(uint64_t)std::max(1, splits) * (uint64_t)threads;
|
||||
const uint64_t gy = (uint64_t)std::max(1, kv_heads);
|
||||
const uint64_t gz = (uint64_t)std::max(1, num_seqs);
|
||||
uint64_t h = 0x9e3779b97f4a7c15ull;
|
||||
const uint64_t grid[3] = {gx, gy, gz};
|
||||
for (uint64_t v : grid) {
|
||||
h ^= v + 0x9e3779b97f4a7c15ull + (h << 6) + (h >> 2);
|
||||
h *= 0xbf58476d1ce4e5b9ull;
|
||||
}
|
||||
return h | 1;
|
||||
}
|
||||
+80
-1
@@ -68,8 +68,10 @@ typedef struct RadKVGroupBatch {
|
||||
int64_t state_index_pitch;
|
||||
int64_t block_size;
|
||||
int64_t max_blocks;
|
||||
/* Null unless this group streams (RadKVStream). Trailing and zero-defaulted. */
|
||||
/* Null unless this group streams (RadKVStream). */
|
||||
const RadKVStream* stream;
|
||||
/* ABI 35: host mirror of seqused, retained through this batch for exact sliced-launch bounds. */
|
||||
const int32_t* seqused_h;
|
||||
} RadKVGroupBatch;
|
||||
|
||||
typedef struct RadBatch {
|
||||
@@ -325,6 +327,42 @@ typedef struct RadBatch {
|
||||
const int32_t* plugin_cu; /* [n_seq + 1] device */
|
||||
const int32_t* plugin_words_h;
|
||||
const int32_t* plugin_cu_h;
|
||||
|
||||
/* ---- appended in ABI 33 (the shape generator) */
|
||||
/* A shape generator's pass (rad_declare_shape_generator; `gen` is one of its
|
||||
* RAD_GEN_PASS_S*): its payload. Null on every other step. */
|
||||
const struct RadShapeGenBatch* sgen_b;
|
||||
|
||||
/* ---- appended in ABI 34: host-side max seqused per entry of kv[], for an architecture's
|
||||
* optional recorded-pass geometry key. Null when the batch has no host summary. */
|
||||
const int32_t* kv_used_max_h;
|
||||
/* ABI 35: host mirror of positions, for a one-sequence prefill op whose exact KV bound is the
|
||||
* position immediately after its first query piece. Valid through the batch's issue pass. */
|
||||
const int32_t* positions_h;
|
||||
/* ---- appended in ABI 35 (runs read both ways) */
|
||||
/* The runs of a trunk pass whose rows attend to each other both ways
|
||||
* (RadEncoderDecl::bidirectional): a picture's or a video frame's placeholders inside one
|
||||
* sequence's chunk. The pass attends them causally like every other row; the plugin attends a
|
||||
* run's rows again without the causal bound, over the keys before `bidi_used` (the position
|
||||
* after the run's last token), in place of that result. The scheduler ends no chunk inside such
|
||||
* a run, so its keys are this pass's or, after a prefix hit, the cache's; a run longer than any
|
||||
* step is cut where its chunk ends, and that chunk's rows see the run up to the cut.
|
||||
*
|
||||
* host: n_bidi and, per run, its first row in this pass, its rows and the index of its sequence
|
||||
* in the per-sequence arrays; device: [n_bidi] the keys a run's rows see. 0 runs on every other
|
||||
* pass. */
|
||||
int64_t n_bidi;
|
||||
const int32_t* bidi_row; /* host */
|
||||
const int32_t* bidi_n; /* host */
|
||||
const int32_t* bidi_seq; /* host */
|
||||
const int32_t* bidi_used; /* device */
|
||||
/* ---- appended in ABI 36 (a block drafter's anchor row) */
|
||||
/* A block drafter's query pass (draft_pass 1): [n_seq] device, for each drafting sequence the
|
||||
* row of its last committed position in the context pass just run, whose rows are the verify
|
||||
* step's in order. -1 for a row the card did not position. A drafter that conditions on the
|
||||
* context state at the anchor (LiLiCorr) gathers it there; the query rows themselves sit past
|
||||
* that position. Null on every other pass. */
|
||||
const int32_t* anchor_rows;
|
||||
} RadBatch;
|
||||
|
||||
/* What a generator pass carries beside the step batch's own fields, which keep their meanings:
|
||||
@@ -712,6 +750,44 @@ typedef struct RadVideoGenBatch {
|
||||
|
||||
enum { RAD_SAMPLER_EULER = 0, RAD_SAMPLER_RES_MULTISTEP = 1 };
|
||||
|
||||
/* What a shape generator's pass carries beside the step batch's own fields (rad_builder.h,
|
||||
* RadShapeGenDecl, describes the passes). Every pass is one request's, in lane `lane`:
|
||||
*
|
||||
* SCOND `n_tok` is the picture's patches, `patches` [n_tok, 3 enc_patch^2] f32.
|
||||
* SSTEP `n_tok` is step_rows. The two branches' latents are entries 0 (the picture's) and 1
|
||||
* (the unconditioned one) of the image generator's sampler ops (`randn_lanes`,
|
||||
* `lane_gather`, `flow_euler`): `lat_cu` bounds them and the per-entry arrays are
|
||||
* theirs, entry 0 guided against entry 1 (`pair` {1, -2}) at the request's scale.
|
||||
* SLATENT `n_tok` is latent_rows; nothing of the pass's own.
|
||||
* SQUERY `n_tok` is n_query, `query` [n_query, 3] f32: x, y, z a point, and `query_cu`
|
||||
* {0, n_query}.
|
||||
*
|
||||
* `lanes` and `lat_cu` are staged on every pass; the latent's rows are lat_cu[0..1]. Every
|
||||
* pointer is device memory. */
|
||||
typedef struct RadShapeGenBatch {
|
||||
int32_t lane;
|
||||
|
||||
/* ---- SCOND */
|
||||
const float* patches;
|
||||
|
||||
/* ---- SSTEP: the step (from 0) of the request's `n_steps` evaluations, then the two
|
||||
* entries' sampler operands, [2] each but `seed` [2, 2] (low word first) and `lat_cu` [3]. */
|
||||
int32_t step, n_steps;
|
||||
const float* sigma;
|
||||
const float* sigma_next;
|
||||
const float* cfg;
|
||||
const int32_t* pair;
|
||||
const int32_t* lanes;
|
||||
const int32_t* flags; /* RAD_GEN_F_FIRST on entry 0 of the first step */
|
||||
const uint32_t* seed;
|
||||
const int32_t* lat_cu;
|
||||
|
||||
/* ---- SQUERY */
|
||||
int64_t n_query;
|
||||
const float* query;
|
||||
const int32_t* query_cu;
|
||||
} RadShapeGenBatch;
|
||||
|
||||
/* RadVideoGenBatch::enc_kind: the media an encode pass carries, numbered from 1 within a kind. A
|
||||
* keyframe is 1 for the first frame and 2 for the last. */
|
||||
enum {
|
||||
@@ -861,6 +937,9 @@ int rad_kv_stage_layer(RadCtx* c, rad_kvgroup group, const RadKVGrou
|
||||
int rad_kv_stage_next(RadCtx* c, rad_kvgroup group, int layer);
|
||||
int rad_rank(RadCtx* c);
|
||||
int rad_world_size(RadCtx* c);
|
||||
/* Workgroups the current rank's card can run concurrently (HIP multiProcessorCount on RDNA;
|
||||
* 32 on the host backend or when the backend has no positive count). */
|
||||
int rad_ctx_wgp_count(RadCtx* c);
|
||||
RadStream rad_stream(RadCtx* c);
|
||||
|
||||
/* The routing result for a MoE layer, resolved on device against the current residency table.
|
||||
|
||||
Reference in new issue
Block a user