Archived
Merge upstream main (v1.12 -> v1.15.1, 408 commits) into the SYCL port
Conflicts from the old m2xfp branch take upstream's version. Two libxe2 fixes the merge needs:
- rad_plugin_abi_layout: the plugin now exports the ABI layout hash the loader checks.
- gemm_nt_q_w4a16: upstream 492d33c sends bf16 activations to the w4a16 GEMM (the separate cast
is gone); the fast kernel took only f16, so every call fell back to the exact path (decode
~2.5 tok/s). A bf16 activation is narrowed to f16 (round to nearest even) into a workspace first,
the dropped cast bit for bit; decode back to ~57 tok/s on one request.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
7580ec3d17
937 files changed
+285776
-8914
No files matched your search
+304
-5
@@ -534,6 +534,52 @@ int ref_act_mul_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return binary_shape(p, n_p, operand, "act_mul", out);
|
||||
}
|
||||
|
||||
int ref_position_scale_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
if (M <= 0 || n <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, n});
|
||||
o.t_idx({M}, 32768, -1, 0);
|
||||
return o.finish("position_scale", operand, out);
|
||||
}
|
||||
|
||||
int ref_embed_attn_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "head_dim", 0);
|
||||
const int64_t G = gi(p, n_p, "gqa", 1), S = n_seq_of(p, n_p);
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, G * D});
|
||||
o.t(act_dt(p, n_p), {M, D});
|
||||
o.t(act_dt(p, n_p), {M, D});
|
||||
o.t_idx({S + 1}, 0, -1, (uint32_t)RAD_OPD_F_IDX_CU);
|
||||
o.t(act_dt(p, n_p), {M, G * D});
|
||||
return o.finish("embed_attn", operand, out);
|
||||
}
|
||||
|
||||
int ref_ministral_rope_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "head_dim", 0);
|
||||
const int64_t H = gi(p, n_p, "n_head", 0), K = gi(p, n_p, "n_head_kv", 0);
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, (H + 2 * K) * D});
|
||||
o.t_idx({M}, 32768, -1, 0);
|
||||
return o.finish("ministral_rope", operand, out);
|
||||
}
|
||||
|
||||
int ref_pixtral_rope_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "head_dim", 0),
|
||||
H = gi(p, n_p, "n_head", 0);
|
||||
if (M <= 0 || D <= 0 || D % 4 || H <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), {M, 3 * H * D});
|
||||
o.t_idx({2, M}, 80, -1, 0);
|
||||
return o.finish("pixtral_rope", operand, out);
|
||||
}
|
||||
|
||||
int ref_pixtral_merge_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
/* The coordinates describe complete raster grids. Random independent indices cannot make
|
||||
* a legal fixture: callers provide the grid and its patch data together. */
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
|
||||
int ref_seg_mean_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
@@ -546,6 +592,25 @@ int ref_seg_mean_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return o.finish("seg_mean", operand, out);
|
||||
}
|
||||
|
||||
int ref_seg_softmax_pool_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
if (M <= 0 || n <= 0) return RAD_E_UNSUPPORTED;
|
||||
const int64_t S = n_seq_of(p, n_p);
|
||||
Opd o;
|
||||
o.t(D, { M }); /* score, one a row of v */
|
||||
o.t(D, { M, n }); /* v */
|
||||
o.t_idx({ S + 1 }, 0, -1, (uint32_t)RAD_OPD_F_IDX_CU); /* cu_seqlens */
|
||||
o.t(D, { S, n }); /* y */
|
||||
return o.finish("seg_softmax_pool", operand, out);
|
||||
}
|
||||
|
||||
int ref_seg_mean_bf16_sum_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
if (act_dt(p, n_p) != RAD_BF16)
|
||||
return RAD_E_UNSUPPORTED;
|
||||
return ref_seg_mean_shape(p, n_p, operand, out);
|
||||
}
|
||||
|
||||
int ref_pool_rows_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t n = gi(p, n_p, "n", 0), k = gi(p, n_p, "k", 0);
|
||||
@@ -559,6 +624,16 @@ int ref_pool_rows_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out
|
||||
return o.finish("pool_rows", operand, out);
|
||||
}
|
||||
|
||||
int ref_pool_cols_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t n = gi(p, n_p, "n", 0), k = gi(p, n_p, "k", 0), M = gi(p, n_p, "M", 0);
|
||||
if (M <= 0 || n <= 0 || k <= 0 || n % k) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(D, { M, n }); /* x */
|
||||
o.t(D, { M, n / k }); /* y */
|
||||
return o.finish("pool_cols", operand, out);
|
||||
}
|
||||
|
||||
int ref_relu_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
@@ -1336,6 +1411,18 @@ int ref_attn_paged_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* ou
|
||||
return o.finish("attn_paged", operand, out);
|
||||
}
|
||||
|
||||
/* attn_paged's operands and its tree's parents, each row an ordinary causal one (-2): a drawn
|
||||
* plane would name parents that are not a tree. */
|
||||
int ref_attn_paged_tree_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
if (operand < 8) return ref_attn_paged_shape(p, n_p, operand, out);
|
||||
const int64_t M = gi(p, n_p, "q_len", 0);
|
||||
if (M <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
for (int i = 0; i < 8; ++i) o.skip();
|
||||
o.t_idx({ M }, 0, -2, 0); /* spec_parent */
|
||||
return o.finish("attn_paged_tree", operand, out);
|
||||
}
|
||||
|
||||
int ref_attn_dense_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t hd = gi(p, n_p, "head_dim", 0);
|
||||
@@ -1470,6 +1557,31 @@ int ref_kv_store_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return o.finish("kv_store", operand, out);
|
||||
}
|
||||
|
||||
/* The streamed store: kv_store's geometry plus the mirror (one block a row at the ring's pitch)
|
||||
* and the residency map. The described call touches one block, resident in slot 0: the draw
|
||||
* cannot express an injective map, and two blocks drawing one slot would race on a ring byte.
|
||||
* Partly resident maps and mirror-only writes are built by hand in tests/ref_test.cpp and in
|
||||
* libavx's hand cases. `M <= block_size` keeps every token on its own position of that block. */
|
||||
int ref_kv_store_streamed_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t hd = gi(p, n_p, "head_dim", 0);
|
||||
const int64_t kvh = gi(p, n_p, "n_head_kv", 0);
|
||||
const int64_t bs = gi(p, n_p, "block_size", 0);
|
||||
if (M <= 0 || hd <= 0 || kvh <= 0 || bs <= 0 || M > bs) return RAD_E_UNSUPPORTED;
|
||||
const uint32_t kv = dt_parse(gs(p, n_p, "kv_dtype"));
|
||||
const uint32_t KV = kv == (uint32_t)RAD_DT_INVALID ? (uint32_t)RAD_F8E4M3 : kv;
|
||||
const int64_t row = kvh * bs * 2 * hd * (KV == (uint32_t)RAD_BF16 ? 2 : 1);
|
||||
|
||||
Opd o;
|
||||
o.t((uint32_t)RAD_BF16, { M, kvh, hd }); /* k */
|
||||
o.t((uint32_t)RAD_BF16, { M, kvh, hd }); /* v */
|
||||
o.t_idx({ M }, bs, -1, (uint32_t)RAD_OPD_F_IDX_UNIQUE); /* slot_mapping, one block */
|
||||
o.t(KV, { 1, kvh, bs, 2 * hd }); /* kv_cache, INOUT */
|
||||
o.t_idx({ 1 }, 1, -1, 0); /* res -- resident in slot 0 */
|
||||
o.t((uint32_t)RAD_U8, { 1, row }); /* host, INOUT */
|
||||
return o.finish("kv_store_streamed", operand, out);
|
||||
}
|
||||
|
||||
int ref_rope_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t hd = gi(p, n_p, "head_dim", 0);
|
||||
@@ -1659,6 +1771,27 @@ int ref_qsa_work_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return o.finish("qsa_work", operand, out);
|
||||
}
|
||||
|
||||
/* The residency map and the two byte planes. `sel` is block ids, -1 past `nsel`. A described map
|
||||
* can only be all-resident (no draw expresses -1), so a tool's cold call exercises the epoch, the
|
||||
* rewrite and the bookkeeping, never a miss, eviction or copy; those cases are built by hand in
|
||||
* tests/ref_test.cpp and in libavx's hand cases. */
|
||||
int ref_kv_resolve_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), blocks = gi(p, n_p, "blocks", 0);
|
||||
const int64_t slots = gi(p, n_p, "slots", 0), pitch = gi(p, n_p, "sel_pitch", 0);
|
||||
const int64_t bbytes = gi(p, n_p, "block_bytes", 0);
|
||||
if (M <= 0 || blocks <= 0 || slots <= 0 || pitch <= 0 || bbytes <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t_idx({ M, pitch }, blocks, -1, 0); /* sel -- one block id an entry */
|
||||
o.t_idx({ M }, pitch + 1, -1, 0); /* nsel -- 0 .. sel_pitch */
|
||||
o.t_idx({ blocks }, slots, -1, 0); /* res -- every block resident, no -2 */
|
||||
o.t_idx({ slots }, blocks, -1, 0); /* slot_block -- the reverse map */
|
||||
o.t_idx({ slots, 2 }, 2, 0, 0); /* slot_state -- cold: epoch 0, no reference */
|
||||
o.t_idx({ 16 }, 2, 0, 0); /* ctl -- cold: epoch 0, hand 0 */
|
||||
o.t((uint32_t)RAD_U8, { blocks, bbytes }); /* host -- the layer's mirror, a block a row */
|
||||
o.t((uint32_t)RAD_U8, { slots, bbytes }); /* kv_cache -- the layer's ring, a block a row */
|
||||
return o.finish("kv_resolve", operand, out);
|
||||
}
|
||||
|
||||
/* `delta` is described as the whole [T, 2 * taps * NG] coefficient projection, of which the op
|
||||
* reads the first taps * NG columns at the row pitch: the form the architecture issues, and the
|
||||
* pitch libr4d requires. */
|
||||
@@ -2062,6 +2195,30 @@ int ref_dflash_select_shape(const RadParam* p, int n_p, int operand, RadOpdDesc*
|
||||
return o.finish("dflash_select", operand, out);
|
||||
}
|
||||
|
||||
/* dflash_select's operands, then `nodes` tokens and parents a sequence. */
|
||||
int ref_dflash_tree_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
const int64_t steps = gi(p, n_p, "steps", 0);
|
||||
const int64_t K = gi(p, n_p, "top_k", 0);
|
||||
const int64_t R = gi(p, n_p, "rank", 0);
|
||||
const int64_t nv = gi(p, n_p, "n_vocab", 0);
|
||||
const int64_t astr = gi(p, n_p, "anchor_stride", 1);
|
||||
const int64_t N = gi(p, n_p, "nodes", steps);
|
||||
if (M <= 0 || steps <= 0 || K <= 0 || R <= 0 || nv <= 0 || astr <= 0 || N <= 0)
|
||||
return RAD_E_UNSUPPORTED;
|
||||
const int64_t rows = M * steps;
|
||||
Opd o;
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { rows, K }, nv, -1, 0); /* cand */
|
||||
o.t((uint32_t)RAD_F32, { rows, K }); /* unary */
|
||||
o.t((uint32_t)RAD_BF16, { rows, R }); /* hp */
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { M * astr }, nv, -1, 0); /* anchor */
|
||||
o.t((uint32_t)RAD_BF16, { nv, R }); /* pred */
|
||||
o.t((uint32_t)RAD_BF16, { nv, R }); /* succ */
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { M, N }, nv, -1, 0); /* tokens */
|
||||
o.t_idx_dt((uint32_t)RAD_I32, { M, N }, N + 1, -1, 0); /* parents */
|
||||
return o.finish("dflash_tree", operand, out);
|
||||
}
|
||||
|
||||
/* ================================================================== gated delta net
|
||||
*
|
||||
* The layouts are libref/ref_gdn.cpp's:
|
||||
@@ -2602,6 +2759,7 @@ int ref_rms_mod_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
o.t_idx({ 2 }, 0, -1, (uint32_t)RAD_OPD_F_IDX_CU); /* cu_seqlens */
|
||||
o.t(D, { M, n }); /* x, INOUT */
|
||||
o.t(D, { M, n }); /* z */
|
||||
o.skip(); /* colmap: the sweep passes none */
|
||||
return o.finish("rms_mod", operand, out);
|
||||
}
|
||||
int ref_rms_mod_quant_fp8_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
@@ -2625,6 +2783,7 @@ int ref_rms_mod_quant_fp8_shape(const RadParam* p, int n_p, int operand, RadOpdD
|
||||
o.t((uint32_t)RAD_F8E4M3, { M, n }); /* q */
|
||||
o.t((uint32_t)RAD_F32, { M, ng }); /* scale */
|
||||
o.t(D, { M, n }); /* z */
|
||||
o.skip(); /* colmap: the sweep passes none */
|
||||
return o.finish("rms_mod_quant_fp8", operand, out);
|
||||
}
|
||||
/* The sampler's three scalars in (0, 1), the state f32. */
|
||||
@@ -2639,6 +2798,20 @@ int ref_flow_x0_step_shape(const RadParam* p, int n_p, int operand, RadOpdDesc*
|
||||
o.t(F, { M, n }); /* x, INOUT */
|
||||
return o.finish("flow_x0_step", operand, out);
|
||||
}
|
||||
int ref_flow_res_multistep_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const uint32_t F = (uint32_t)RAD_F32;
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), { M, n }); /* v */
|
||||
o.t(F, { M, n }); /* x0, INOUT */
|
||||
o.t_fill(F, { 1 }, (uint32_t)RAD_FILL_SIGMOID, 0); /* sigma */
|
||||
o.t_fill(F, { 1 }, (uint32_t)RAD_FILL_SIGMOID, 0); /* r */
|
||||
o.t_fill(F, { 1 }, (uint32_t)RAD_FILL_SIGMOID, 0); /* hb1 */
|
||||
o.t_fill(F, { 1 }, (uint32_t)RAD_FILL_SIGMOID, 0); /* hb2 */
|
||||
o.t_fill(F, { 1 }, (uint32_t)RAD_FILL_SIGMOID, 0); /* order */
|
||||
o.t(F, { M, n }); /* x, INOUT */
|
||||
return o.finish("flow_res_multistep", operand, out);
|
||||
}
|
||||
int ref_gate_add_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
@@ -2650,10 +2823,11 @@ int ref_gate_add_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
return o.finish("gate_add", operand, out);
|
||||
}
|
||||
int ref_timestep_embed_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0), G = gi(p, n_p, "curve", 0);
|
||||
Opd o;
|
||||
o.t_fill((uint32_t)RAD_F32, { M }, (uint32_t)RAD_FILL_SIGMOID, 0); /* t: a sigma in (0, 1) */
|
||||
o.t(act_dt(p, n_p), { M, n }); /* y */
|
||||
if (G > 0) o.t((uint32_t)RAD_F32, { G, n }); else o.skip(); /* table */
|
||||
return o.finish("timestep_embed", operand, out);
|
||||
}
|
||||
int ref_gather_rows2_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
@@ -2981,6 +3155,22 @@ static int64_t tile_count(int64_t len, int64_t tile, int64_t overlap) {
|
||||
return nt;
|
||||
}
|
||||
|
||||
/* The encoder's split (ref_video.cpp split_tiles_axis) over one axis: the tile count and the
|
||||
* tiles' extent sum along it, a lone tile short of `tile` if the axis is. -1 where the split
|
||||
* refuses. The drawn encode planes are `axis_len` long, so the shape fns can size the tile
|
||||
* operands exactly. */
|
||||
static int64_t axis_split(int64_t len, int64_t tile, int64_t overlap, int64_t* ext) {
|
||||
if (len <= 0 || tile <= 0 || overlap < 0 || overlap >= tile) return -1;
|
||||
if (tile >= len) {
|
||||
*ext = len;
|
||||
return 1;
|
||||
}
|
||||
const int64_t nt = tile_count(len, tile, overlap);
|
||||
/* The extents telescope: sum of the tiles = len + sum of the overlaps = `tile` nt. */
|
||||
*ext = tile * nt;
|
||||
return nt;
|
||||
}
|
||||
|
||||
/* A 2 x 2 x 2 grid of patches. */
|
||||
int ref_patch_unfold_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), C = gi(p, n_p, "C", 0);
|
||||
@@ -3133,6 +3323,61 @@ int ref_flow_renoise_shape(const RadParam* p, int n_p, int operand, RadOpdDesc*
|
||||
return o.finish("flow_renoise", operand, out);
|
||||
}
|
||||
|
||||
/* aug in [0, 1); the condition rows f32. */
|
||||
int ref_cond_aug_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const double aug = rad_param_getf(p, n_p, "aug", -1.0);
|
||||
if (M <= 0 || n <= 0 || !(aug >= 0.0 && aug < 1.0)) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t_idx({ 2 }, (int64_t)1 << 30, -1, 0); /* seed: two words */
|
||||
o.t((uint32_t)RAD_F32, { M, n }); /* x, INOUT */
|
||||
return o.finish("cond_aug", operand, out);
|
||||
}
|
||||
|
||||
/* ---- the tiled encoder. The drawn frame is 20 latent units a side; with the sweep's tile of
|
||||
* 16 and overlap of 4 the split lays 2 x 2 full tiles over it, so the crops, the plan's level
|
||||
* triples and the blends all draw non-trivial. The kernels size by the geom; these only draw a
|
||||
* plane that one gives them. */
|
||||
int ref_vtile_plan_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), tile = gi(p, n_p, "tile", 0);
|
||||
const int64_t ov = gi(p, n_p, "overlap", 0), ratio = gi(p, n_p, "ratio", 0);
|
||||
int64_t e = 0;
|
||||
const int64_t nt = axis_split(20, tile, ov, &e);
|
||||
if (M <= 0 || nt < 0 || ratio <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t_idx({ 3 }, 0, 20 * ratio, 0); /* geom: (_, H, W) pixels */
|
||||
o.t((uint32_t)RAD_I32, { M, 22 }); /* y: one row a tile */
|
||||
return o.finish("vtile_plan", operand, out);
|
||||
}
|
||||
|
||||
int ref_vtile_crop_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), tile = gi(p, n_p, "tile", 0);
|
||||
const int64_t ov = gi(p, n_p, "overlap", 0), ratio = gi(p, n_p, "ratio", 0);
|
||||
int64_t e = 0;
|
||||
const int64_t nt = axis_split(20, tile, ov, &e);
|
||||
if (M <= 0 || nt < 0 || ratio <= 0) return RAD_E_UNSUPPORTED;
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
Opd o;
|
||||
o.t(D, { 20 * ratio * (20 * ratio), 3 }); /* x: the pixel plane */
|
||||
o.t_idx({ 3 }, 0, 20 * ratio, 0); /* geom: (_, H, W) pixels */
|
||||
o.t(D, { M, 3 }); /* y: the tiles' pixels */
|
||||
return o.finish("vtile_crop", operand, out);
|
||||
}
|
||||
|
||||
int ref_vtile_join_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), tile = gi(p, n_p, "tile", 0);
|
||||
const int64_t ov = gi(p, n_p, "overlap", 0), n = gi(p, n_p, "n", 0);
|
||||
int64_t e = 0;
|
||||
const int64_t nt = axis_split(20, tile, ov, &e);
|
||||
if (M <= 0 || nt < 0 || n <= 0) return RAD_E_UNSUPPORTED;
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
Opd o;
|
||||
o.t(D, { e * e, n }); /* x: the tiles' moments */
|
||||
o.t_idx({ 3 }, 0, 20, 0); /* geom: (_, lat_h, lat_w) */
|
||||
o.t(D, { M, n }); /* y: the canvas */
|
||||
return o.finish("vtile_join", operand, out);
|
||||
}
|
||||
|
||||
/* ================================================================== video sparse attention
|
||||
*
|
||||
* The tiles come from the values of `segs` and `geom`, which a description draws only as
|
||||
@@ -3239,19 +3484,32 @@ int ref_attn_vsa_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out)
|
||||
* REF_LANES lanes, as the image generator's are. */
|
||||
static int64_t two_seqs(int64_t M) { return M >= 4 ? 2 : 1; }
|
||||
|
||||
/* `M` is the input rows; with `stride` > 1 (bf16, one sequence, explicit `pad`) the output is
|
||||
* PyTorch's strided length, `M` being the rows of the one sequence `cu_seqlens` must cover. */
|
||||
int ref_conv1d_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), cin = gi(p, n_p, "cin", 0), cout = gi(p, n_p, "cout", 0);
|
||||
const int64_t k = gi(p, n_p, "k", 0), causal = gi(p, n_p, "causal", 0);
|
||||
if (M <= 0 || cin <= 0 || cout <= 0 || k <= 0 || (!causal && (k & 1) == 0))
|
||||
const int64_t st = gi(p, n_p, "stride", 1), pp = gi(p, n_p, "pad", -1);
|
||||
const int64_t dil = gi(p, n_p, "dil", 1);
|
||||
const bool padded = pp >= 0 && st > 1; /* the zero-padded strided form (explicit `pad`) */
|
||||
if (M <= 0 || cin <= 0 || cout <= 0 || k <= 0 || (!causal && st <= 1 && (k & 1) == 0) ||
|
||||
st < 1 || (pp >= 0 && (st <= 1 || causal)) ||
|
||||
(st > 1 && pp < 0 && (!causal || dil * (k - 1) + 1 < st || M % st)) ||
|
||||
(!padded && gi(p, n_p, "cu_div", 1) != 1))
|
||||
return RAD_E_UNSUPPORTED;
|
||||
const uint32_t D = act_dt(p, n_p);
|
||||
const int64_t S = two_seqs(M);
|
||||
if (padded && D != (uint32_t)RAD_BF16) return RAD_E_UNSUPPORTED;
|
||||
/* A strided convolution is described over one sequence: two would each need a whole number
|
||||
* of strides. Bounds in coarser units (cu_div) are not drawn; ref_test checks them. */
|
||||
const int64_t S = st > 1 ? 1 : two_seqs(M);
|
||||
const int64_t O = padded ? (M + 2 * pp - dil * (k - 1) - 1) / st + 1 : M / st;
|
||||
if (O <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t(D, { M, cin }); /* x */
|
||||
o.t(D, { cout, cin, k }); /* w */
|
||||
o.t_idx({ S + 1 }, 0, -1, (uint32_t)RAD_OPD_F_IDX_CU); /* cu_seqlens */
|
||||
o.t(D, { M, cout }); /* res */
|
||||
o.t(D, { M, cout }); /* y */
|
||||
o.t(D, { O, cout }); /* res */
|
||||
o.t(D, { O, cout }); /* y */
|
||||
o.t(D, { cout }); /* b */
|
||||
return o.finish("conv1d", operand, out);
|
||||
}
|
||||
@@ -3329,6 +3587,22 @@ int ref_rvq_embed_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out
|
||||
return o.finish("rvq_embed", operand, out);
|
||||
}
|
||||
|
||||
int ref_vq_encode_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), n = gi(p, n_p, "n", 0);
|
||||
const int64_t dim = gi(p, n_p, "dim", 0), bins = gi(p, n_p, "bins", 0);
|
||||
if (M <= 0 || n <= 0 || dim <= 0 || bins <= 0) return RAD_E_UNSUPPORTED;
|
||||
const uint32_t F = (uint32_t)RAD_F32;
|
||||
Opd o;
|
||||
o.t(act_dt(p, n_p), { M, n }); /* x, INOUT */
|
||||
o.t(F, { dim, n }); /* in_w */
|
||||
o.t(F, { dim }); /* in_b */
|
||||
o.t(F, { bins, dim }); /* cb */
|
||||
o.t(F, { n, dim }); /* out_w */
|
||||
o.t(F, { n }); /* out_b */
|
||||
o.t_idx({ M }, bins, -1, 0); /* codes, OUT */
|
||||
return o.finish("vq_encode", operand, out);
|
||||
}
|
||||
|
||||
int ref_frame_mix_store_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), D = gi(p, n_p, "n_embd", 0), L = gi(p, n_p, "L", 0);
|
||||
const int64_t st = gi(p, n_p, "stride", 0);
|
||||
@@ -3356,6 +3630,21 @@ int ref_end_status_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* ou
|
||||
return o.finish("end_status", operand, out);
|
||||
}
|
||||
|
||||
int ref_ras_pick_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), rep = gi(p, n_p, "rep", 1), W = gi(p, n_p, "win", 0);
|
||||
const int64_t hi = gi(p, n_p, "hi", 0);
|
||||
if (M <= 0 || rep < 1 || W <= 0 || hi <= 0 || M > REF_LANES) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
/* Picks over a small band so the windows repeat them often enough to exercise the redraw. */
|
||||
const int64_t band = std::min<int64_t>(hi + 2, 12);
|
||||
o.t_idx({ rep * M }, band, -1, 0); /* first */
|
||||
o.t_idx({ rep * M }, band, -1, 0); /* alt */
|
||||
o.t_idx({ M }, REF_LANES, -1, (uint32_t)RAD_OPD_F_IDX_UNIQUE); /* lane */
|
||||
o.t_idx({ REF_LANES * W }, band, -1, 0); /* hist, INOUT */
|
||||
o.t_idx({ rep * M }, band, -1, 0); /* ids, OUT */
|
||||
return o.finish("ras_pick", operand, out);
|
||||
}
|
||||
|
||||
int ref_frame_store_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), K = gi(p, n_p, "n_codes", 0);
|
||||
const int64_t st = gi(p, n_p, "stride", 0), rep = gi(p, n_p, "rep", 1);
|
||||
@@ -3494,6 +3783,16 @@ int ref_int_affine_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* ou
|
||||
return o.finish("int_affine", operand, out);
|
||||
}
|
||||
|
||||
int ref_sub_i32_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0);
|
||||
if (M <= 0) return RAD_E_UNSUPPORTED;
|
||||
Opd o;
|
||||
o.t_idx({ M }, 100000, -1, 0); /* x */
|
||||
o.t_idx({ 1 }, 1000, -1, 0); /* s */
|
||||
o.t_idx({ M }, 1, -1, 0); /* y */
|
||||
return o.finish("sub_i32", operand, out);
|
||||
}
|
||||
|
||||
/* ================================================================== LTX-2 (ref_ltx.cpp) */
|
||||
int ref_rope_split_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* out) {
|
||||
const int64_t M = gi(p, n_p, "M", 0), nh = gi(p, n_p, "n_head", 0);
|
||||
|
||||
Reference in new issue
Block a user