mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 23:08:36 +00:00
prefill fused experts: the down-rotation, FP16-down and P1A state per host thread
On a layer split each stage reads its prompt chunks on a host thread of its
own, at the same time as the next stage (run_impl hands the next stage its
chunk and goes on with its own next chunk). The fused expert kernels kept
three pieces of per-call state in process-wide variables that each stage's
thread sets per layer or per launch:
- g_rot_on / g_rot_signs (set_down_rotation, the Hadamard-folded down of the
Gyro trellis layers): the sign vector is on the device of the stage that set
it, so CUDA0's rot_quant_h_kernel could read CUDA1's vector. Without peer
access that is an illegal address on CUDA0, reported at the next checked
sync, the layer split's hand-off ("prefill: the layer split's hand-off: an
illegal memory access was encountered", Boston, 2x RTX A6000, Gyro-S, a
36,316-token prompt in five 8,192-token chunks). With peer access it is
another layer's signs, or FP32 and int8 H mixed up: wrong numbers.
- g_dm16_want / g_dm16_used (STRATA_PF_DM16): another stage could flip which
form of the down rows the combine reads.
- g_p1a_x16 / g_p1a_h_bytes / g_p1a_used (STRATA_PF_P1A, HIP): another stage
could hand a gfx1151 launch its own device's FP16 rows.
All of them are now thread_local. prefill.cpp sets, launches and reads back on
one thread (run_impl 5491-5567 and 5541-5553, the staged entry 6709-6711, the
layer-major walk 8307-8308), so a path with one thread does exactly what it
did before; only the stages of a split stop seeing each other's state.
Static analysis; not built, not run.
This commit is contained in:
1 parent
4d3e390b2f
commit
09b6038869
1 file changed
+12
-7
@@ -3047,7 +3047,9 @@ void quantize_act_native(const float* x, int64_t rows, int64_t cols, void* xa, v
|
||||
}
|
||||
|
||||
// The down rows as FP16 (opt-in per call: the prompt path asks, STRATA_PF_DM16): dm_f16_used() tells which form the last call wrote.
|
||||
static bool g_dm16_want = false, g_dm16_used = false;
|
||||
// Per host thread, like g_rot_* below: on a layer split each stage reads its chunks on a thread of its own, at the same time as the
|
||||
// others (prefill.cpp run_impl hands the next stage its chunk and goes on), and asks, launches and reads back on that thread.
|
||||
static thread_local bool g_dm16_want = false, g_dm16_used = false;
|
||||
void want_dm_f16(bool on) { g_dm16_want = on; }
|
||||
bool dm_f16_used() { return g_dm16_used; }
|
||||
|
||||
@@ -3056,10 +3058,10 @@ bool dm_f16_used() { return g_dm16_used; }
|
||||
// when the prompt path handed over the FP16 input (p1a_input), the down rows go out as FP16 (want_dm_f16) and H has room for FP16 rows;
|
||||
// every other call, and every call with the switch off, runs as before.
|
||||
#if defined(__HIPCC__)
|
||||
static const void* g_p1a_x16 = nullptr;
|
||||
static size_t g_p1a_h_bytes = 0;
|
||||
static thread_local const void* g_p1a_x16 = nullptr; // (per host thread: a stage's own device's FP16 rows, see g_dm16_want)
|
||||
static thread_local size_t g_p1a_h_bytes = 0;
|
||||
#endif
|
||||
static bool g_p1a_used = false;
|
||||
static thread_local bool g_p1a_used = false;
|
||||
bool p1a_wanted() {
|
||||
#if defined(__HIPCC__)
|
||||
static const bool on = [] {
|
||||
@@ -3094,9 +3096,12 @@ bool p1a_takes_pair(int gu_type, int d_type) { return p1a_wanted() && p1a::takes
|
||||
bool p1a_takes_pair(int, int) { return false; } // (namespace p1a, moe_p1a.hpp, exists in HIP builds only)
|
||||
#endif
|
||||
|
||||
// (CUDA, STRATA_PF_FUSED_TQ=1) a Hadamard-folded down (set_down_rotation): on, and the down input's sign vector
|
||||
static const float* g_rot_signs = nullptr;
|
||||
static bool g_rot_on = false;
|
||||
// (CUDA, STRATA_PF_FUSED_TQ=1) a Hadamard-folded down (set_down_rotation): on, and the down input's sign vector.
|
||||
// Per host thread: the sign vector lives on the device of the stage that set it (hadamard_device_signs), and on a layer split the
|
||||
// stages' threads set and clear it per layer at the same time; one process-wide copy let CUDA0's kernels read CUDA1's vector
|
||||
// (an illegal address without peer access, another layer's signs with it). prefill.cpp sets, launches and clears on one thread.
|
||||
static thread_local const float* g_rot_signs = nullptr;
|
||||
static thread_local bool g_rot_on = false;
|
||||
void set_down_rotation(bool on, const float* signs) { g_rot_on = on; g_rot_signs = on ? signs : nullptr; }
|
||||
void hadamard128_rows(float* x, int64_t rows, int64_t cols, const float* signs, void* stream) {
|
||||
if (rows <= 0) return;
|
||||
|
||||
Reference in new issue
Block a user