[Engine] Tesla P100: the rule for the FP16 prompt path with few-row experts as the default (not switched on yet)

On a Tesla P100 (compute capability 6.0, the STRATA_EXPERIMENTAL_SM60 build) the
prompt experts will take the FP16 path instead of MMQ, with the few-row experts
of the previous commit on the quantized grouped kernels. The rule is in
include/strata/prefill/gp100_prompt_default.hpp (gp100_prompt_default_test): only
with STRATA_PREFILL_MMQ unset (an explicit value keeps its old meaning), every
visible CUDA card compute capability 6.0, and none of STRATA_MMQ_WS=1,
STRATA_EXPERT_NIBBLE=1 and --peer-device (the prompt peer computes on MMQ only;
generate.cpp records the flag). prefill.cpp gp100_fp16_default() evaluates it
once; mmq_plan() takes it and the manifest names the reason; the few-row switch
STRATA_PF_FEWROWS takes it as its default.

kGp100Default in the header is false in this commit, so nothing changes yet: the
next commit sets it true. Settings register: STRATA_PREFILL_MMQ's read sites.
This commit is contained in:
Niko1221 committed 2026-11-12 08:57:08 +01:00
1 parent af5803e4be
commit 62b6a47ea4
6 files changed
+147 -5

No files matched your search

+5
View File
@@ -440,6 +440,11 @@ if(STRATA_BUILD_TESTS)
target_include_directories(fewrows_rule_test PRIVATE include)
add_test(NAME fewrows_rule_test COMMAND fewrows_rule_test)
# Tesla P100: when the prompt experts take the FP16 path by default instead of MMQ (header-only, no GPU)
add_executable(gp100_prompt_default_test tests/prefill/gp100_prompt_default_test.cpp)
target_include_directories(gp100_prompt_default_test PRIVATE include)
add_test(NAME gp100_prompt_default_test COMMAND gp100_prompt_default_test)
# PR #4844: the adaptive tier's copy-in range across serial, pipelined and drained rounds (header-only, no GPU)
add_executable(adaptive_range_test tests/program/adaptive_range_test.cpp)
target_include_directories(adaptive_range_test PRIVATE include)
+8 -2
View File
@@ -23837,7 +23837,7 @@
"reads": [
{
"file": "src/prefill/prefill.cpp",
"line": 5830,
"line": 5872,
"backend": "cuda-hip",
"fn": "getenv"
}
@@ -23853,7 +23853,7 @@
"doc_mentions": [],
"status": "research",
"owner": "prefill",
"note": "[reviewed] Research switch, off unless set (\"0\" off, anything else on; src/prefill/fewrows.hpp): on the FP16 prompt path an expert with 1..12 rows runs on the quantized grouped kernels (no dequantize) instead of dequantize + FP16 GEMMs; native packs without APR only. Tesla P100 numbers in phaseA-tests/par/RESULTS-P4-FALLBACK.md. Not documented for users",
"note": "[reviewed] Research switch, off unless set (\"0\" off, anything else on; src/prefill/fewrows.hpp), except that the Tesla P100 prompt default turns it on when gp100_prompt_default.hpp's kGp100Default is true. On the FP16 prompt path an expert with 1..12 rows runs on the quantized grouped kernels (no dequantize) instead of dequantize + FP16 GEMMs; native packs without APR only. Tesla P100 numbers in phaseA-tests/par/RESULTS-P4-FALLBACK.md. Not documented for users",
"retire_after": "",
"retired_in": ""
},
@@ -28850,6 +28850,12 @@
"backend": "cuda-hip",
"fn": "getenv"
},
{
"file": "src/prefill/prefill.cpp",
"line": 5872,
"backend": "cuda-hip",
"fn": "getenv"
},
{
"file": "sycl/src/prefill/prefill.cpp",
"line": 312,
@@ -0,0 +1,35 @@
// include/strata/prefill/gp100_prompt_default.hpp - Tesla P100 (GP100, compute capability 6.0): whether the prompt experts take the FP16
// path by default instead of MMQ (prefill.cpp, mmq_plan()), with the few-row experts on the quantized grouped kernels (fewrows.hpp).
// GP100 has no __dp4a, so MMQ runs on the bit-exact emulation there; with the few-row route the FP16 path is at 0.95 / 0.91 / 0.93 / 1.00
// of MMQ's prompt speed at 300 / 1,000 / 2K / 4K tokens and above it from 8K (lane P4-FALLBACK, 11-11). The rule is kept here, free of
// CUDA, so a test can walk its cases.
#pragma once
#include <atomic>
namespace strata::prefill {
/// The whole default: false keeps MMQ on the P100 as before; true makes the rule below the P100's default. One line.
constexpr bool kGp100Default = false;
struct Gp100PromptInputs {
const char* env = nullptr; // STRATA_PREFILL_MMQ as read (nullptr: unset; any value keeps its old meaning: 0 FP16 path, else MMQ)
bool all_cc60 = false; // every visible CUDA card is compute capability 6.0 (one process, one decision)
bool mmq_ws = false; // STRATA_MMQ_WS=1 is in force: its weight-stationary kernels are MMQ's products
bool nibble = false; // STRATA_EXPERT_NIBBLE=1: the FP16 path would read the converted slots as GGUF blocks
bool peer_device = false; // --peer-device: the prompt peer (Prefill::set_peer) computes on MMQ only
};
/// true: the FP16 path is this process's default for the prompt experts. Only with the variable unset, so an explicit
/// STRATA_PREFILL_MMQ=1 or =0 means what it always meant.
inline bool gp100_fp16_rule(const Gp100PromptInputs& in) {
return in.env == nullptr && in.all_cc60 && !in.mmq_ws && !in.nibble && !in.peer_device;
}
/// Set by generate.cpp from --peer-device before any prompt path exists (mmq_plan() reads it once, at its first use).
inline std::atomic<bool>& peer_device_requested() {
static std::atomic<bool> v{false};
return v;
}
} // namespace strata::prefill
+46 -3
View File
@@ -9,6 +9,7 @@
#include "strata/prefill/pf_fused_override.hpp"
#include "strata/prefill/staged_group_rule.hpp"
#include "strata/prefill/fewrows.hpp"
#include "strata/prefill/gp100_prompt_default.hpp"
#if defined(STRATA_HAVE_DFLASH2)
#include "strata/kernels/dflash2.hpp"
#endif
@@ -1601,15 +1602,55 @@ bool pf_wmma() {
return on;
#endif
}
// Tesla P100 (GP100, compute capability 6.0; the STRATA_EXPERIMENTAL_SM60 build): the prompt experts take the FP16 path
// by default instead of MMQ, with the few-row experts (fewrows.hpp) on the quantized grouped kernels. GP100 has no
// __dp4a (MMQ runs on the bit-exact emulation in dp4a.hpp), and with the few-row route the FP16 path is at 0.95 / 0.91 /
// 0.93 / 1.00 of MMQ's prompt speed at 300 / 1,000 / 2K / 4K and above it from 8K (lane P4-FALLBACK, 11-11:
// phaseA-tests/par/RESULTS-P4-FALLBACK.md). Only when EVERY visible CUDA card is cc 6.0 (one process, one decision),
// and not with what needs MMQ: STRATA_MMQ_WS=1 (its weight-stationary kernels are MMQ's products), STRATA_EXPERT_NIBBLE=1
// (the FP16 path reads GGUF blocks) and --peer-device (the prompt peer computes on MMQ only). An explicit
// STRATA_PREFILL_MMQ keeps its old meaning. The rule: gp100_prompt_default.hpp (gp100_prompt_default_test);
// kGp100Default there is the one line that turns it on.
bool gp100_fp16_default(const char* env) {
#if defined(__HIPCC__) || !defined(STRATA_EXPERIMENTAL_SM60)
(void) env;
return false;
#else
if (!kGp100Default || env != nullptr) return false;
static const bool on = [] {
Gp100PromptInputs in;
in.mmq_ws = ws::mode() != 0;
in.nibble = strata::core::nibble::config().on;
in.peer_device = peer_device_requested().load();
in.all_cc60 = true;
int n = 0;
if (cudaGetDeviceCount(&n) != cudaSuccess || n <= 0) { cudaGetLastError(); in.all_cc60 = false; }
for (int d = 0; in.all_cc60 && d < n; ++d) {
int major = 0, minor = 0;
if (cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, d) != cudaSuccess ||
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, d) != cudaSuccess) {
cudaGetLastError();
in.all_cc60 = false;
} else if (major != 6 || minor != 0) {
in.all_cc60 = false;
}
}
return gp100_fp16_rule(in);
}();
return on;
#endif
}
const MmqPlan& mmq_plan() {
static const MmqPlan plan = [] {
MmqPlan p;
const auto& lay = strata::kernels::cpu::expert_layout();
const char* env = std::getenv("STRATA_PREFILL_MMQ");
#if defined(STRATA_PF_OWN_ONLY)
const bool gp100 = false; // no MMQ in this build: the FP16 path is not a default of the P100 rule here
const bool on = fused::built() && (env == nullptr || std::atoi(env) != 0); // P4-SPLIT: no MMQ tile anywhere, the fused-only layers below
#else
const bool on = mmq::built() && (env == nullptr || std::atoi(env) != 0);
const bool gp100 = mmq::built() && gp100_fp16_default(env);
const bool on = mmq::built() && !gp100 && (env == nullptr || std::atoi(env) != 0);
#endif
const int64_t layers = lay.native ? (int64_t) lay.fmt.size() : lay.n_layers;
p.layer.assign((size_t) std::max<int64_t>(layers, 0), 0);
@@ -1658,7 +1699,9 @@ const MmqPlan& mmq_plan() {
if (mf) {
if (!on) {
strata::core::manifest::instance().path("prefill", "experts", false,
mmq::built() ? "STRATA_PREFILL_MMQ=0" : "this build has no MMQ (ggml sources were not available)",
!mmq::built() ? "this build has no MMQ (ggml sources were not available)"
: gp100 ? "Tesla P100 (compute capability 6.0): the FP16 path is the default there"
: "STRATA_PREFILL_MMQ=0",
"the expert products take the FP16 path");
} else if (layers <= 0) {
strata::core::manifest::instance().path("prefill", "experts", false, "no expert layout loaded", "");
@@ -5964,7 +6007,7 @@ bool Prefill::run_impl(const int64_t* tokens, int64_t n, int64_t pos0, std::stri
// expert) is released once the blob is read; `cslot`: the expert-cache slot the blob is in (-1:
// a ring slot or the peer's), which STRATA_MMQ_DIRECT reads in place
// Few-row experts (fewrows.hpp): research switch STRATA_PF_FEWROWS, off unless set
static const bool fr_env = fewrows_switch(std::getenv("STRATA_PF_FEWROWS"), false);
static const bool fr_env = fewrows_switch(std::getenv("STRATA_PF_FEWROWS"), gp100_fp16_default(std::getenv("STRATA_PREFILL_MMQ")));
bool fr_q_done = false; // the layer's rows quantized to q8_1 (once per layer)
auto compute = [&](size_t j, const uint8_t* blob_dev, int slot, int32_t cslot) -> bool {
const int32_t e = order[j];
+3
View File
@@ -93,6 +93,7 @@
#include "strata/prefill/kva_floor.hpp"
#include "strata/prefill/prefill.hpp"
#include "strata/prefill/pf_fused_override.hpp"
#include "strata/prefill/gp100_prompt_default.hpp"
#include "strata/core/sm120_series.hpp"
#if defined(STRATA_PREFILL_MMQ)
#include "strata/prefill/moe_mmq.hpp"
@@ -4160,6 +4161,8 @@ int main(int argc, char** argv) {
}
}
strata::core::set_peer_portable(o.peer_device >= 1); // multi-GPU: the Portable flag on mapped host buffers only with a peer device (before any allocation)
// Tesla P100: the prompt peer computes on MMQ only, so with --peer-device the GP100 FP16-path default stands aside (gp100_prompt_default.hpp)
strata::prefill::peer_device_requested().store(o.peer_device >= 1);
{ // the RAM guard (parking, session save/restore): --memory-limit-mib, else STRATA_MEMORY_LIMIT_MIB, else none
int64_t mib = o.memory_limit_mib;
if (mib < 0) {
@@ -0,0 +1,50 @@
// The Tesla P100 prompt-expert default (gp100_prompt_default.hpp): the FP16 path only with STRATA_PREFILL_MMQ unset, every visible card
// cc 6.0, and nothing in force that needs MMQ (STRATA_MMQ_WS=1, STRATA_EXPERT_NIBBLE=1, --peer-device). Header-only, no GPU.
#include <cstdio>
#include "strata/prefill/gp100_prompt_default.hpp"
using strata::prefill::Gp100PromptInputs;
using strata::prefill::gp100_fp16_rule;
static int failed = 0;
#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
int main() {
Gp100PromptInputs p100;
p100.all_cc60 = true;
CHECK(gp100_fp16_rule(p100)); // one or more P100s, nothing set: the FP16 path
Gp100PromptInputs other = p100;
other.all_cc60 = false; // any card that is not cc 6.0 (a P40, a V100, a mixed rig): MMQ as before
CHECK(!gp100_fp16_rule(other));
for (const char* v : {"1", "0", "2", ""}) { // an explicit setting keeps its old meaning; the rule stands aside
Gp100PromptInputs e = p100;
e.env = v;
CHECK(!gp100_fp16_rule(e));
}
Gp100PromptInputs ws = p100;
ws.mmq_ws = true;
CHECK(!gp100_fp16_rule(ws));
Gp100PromptInputs nib = p100;
nib.nibble = true;
CHECK(!gp100_fp16_rule(nib));
Gp100PromptInputs peer = p100; // two P100s with --peer-device keep MMQ and the prompt peer
peer.peer_device = true;
CHECK(!gp100_fp16_rule(peer));
CHECK(!strata::prefill::peer_device_requested().load()); // off until generate.cpp sees --peer-device
strata::prefill::peer_device_requested().store(true);
CHECK(strata::prefill::peer_device_requested().load());
if (failed) {
std::fprintf(stderr, "gp100_prompt_default_test: %d failed\n", failed);
return 1;
}
std::printf("gp100_prompt_default_test: ok\n");
return 0;
}