Turing port: run on RTX 20 (sm_75) and newer
Rebased onto main (0.1.22): the portable pre-sm_80 QSA scorer and the sm_80 guard on the tensor-core prompt attention are already in main, so this is the rest of the port. - the runtime floor: device_info refuses anything older than compute capability 7 (main's runtime check still requires sm_120, so a binary built for sm_75 would never start), - fused_gr: the down kernel carries the tokens in slices that fit the card's shared-memory opt-in (Turing, 64 KB: 6-token slices; 4 tokens when the card reports no opt-in, under the 48 KB default), merged on top of main's per-device opt-in - full 8-token windows no longer fail on Turing with "invalid argument", - the setup/CMake floor is 7.5 (RTX 20 / 30 / 40 / 50) without an experimental flag: CMake's arch refusals, setup.py's gpu_problem and the GPU hints and error texts, - docs/MULTI_GPU.md says what a Turing card actually runs. Verified end-to-end on RTX 2070 (sm_75, 0.1.20 base): model loads, OpenAI/ Anthropic API serving works, greedy output identical to the sm_120 build. Merged (PR #87) with two changes: the runtime floor is 7.5 exactly (major*10+minor < 75; the PR let Volta 7.0/7.2 through), kept beside main's HIP check; and a card reporting no shared-memory opt-in slices the tokens to what fits the 48 KB default for its own tile (4 tokens on CUDA, all 8 with HIP's smaller tile, so gfx1100 keeps one launch).
This commit is contained in:
1 parent
c81819a87c
commit
ddfb98a6ea
5 files changed
+44
-21
No files matched your search
+5
-4
@@ -62,14 +62,15 @@ if(STRATA_ENABLE_CUDA)
|
||||
endif()
|
||||
foreach(_a IN LISTS CMAKE_CUDA_ARCHITECTURES)
|
||||
string(REGEX REPLACE "-.*$" "" _base "${_a}") # 120-real / 120-virtual are still 120
|
||||
# Plan v0.3 P6: developed and measured on sm_120 (RTX 50); the kernels need sm_80 or newer (tf32 mma in
|
||||
# the attention scorer, bf16 math), so RTX 30 (86) and RTX 40 (89) build too. Older cards are refused.
|
||||
# Turing port: developed and measured on sm_120 (RTX 50); the tf32 mma in the QSA scorer has a
|
||||
# portable fp32-FMA fallback, so RTX 20 (75), 30 (86), RTX 40 (89) and RTX 50 (120) build too.
|
||||
# Pre-sm_75 is refused.
|
||||
if(_base STREQUAL "native" OR _base STREQUAL "all" OR _base STREQUAL "all-major")
|
||||
continue()
|
||||
endif()
|
||||
if(_base LESS 80 AND NOT STRATA_EXPERIMENTAL_SM75) # the A/B of a Turing card as a layer-split stage
|
||||
if(_base LESS 75)
|
||||
message(FATAL_ERROR
|
||||
"Strata needs an NVIDIA GPU of compute capability 8.0 or newer (RTX 30 / 40 / 50 series), but "
|
||||
"Strata needs an NVIDIA GPU of compute capability 7.5 or newer (RTX 20 / 30 / 40 / 50 series), but "
|
||||
"CMAKE_CUDA_ARCHITECTURES is '${CMAKE_CUDA_ARCHITECTURES}'.")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
+2
-2
@@ -96,8 +96,8 @@ into the card that owns the layer.
|
||||
capped to leave room for them.
|
||||
- On Windows only 8 GiB of the expert arena is pinned (more, mapped into two GPU contexts, leaves WDDM refusing
|
||||
allocations); the PCIe share covers those layers.
|
||||
- Every card needs compute capability 8.0 (RTX 30 or newer). A Turing card (RTX 20, sm_75) builds only with the
|
||||
experimental `-DSTRATA_EXPERIMENTAL_SM75=ON`.
|
||||
- Every card needs compute capability 7.5 (RTX 20 or newer). The pre-sm_80 QSA scorer path is fp32 FMAs, so a
|
||||
Turing card runs the same kernels instead of the tensor-core prompt attention.
|
||||
|
||||
## Measured
|
||||
|
||||
|
||||
@@ -285,8 +285,8 @@ def cc(g) -> str:
|
||||
|
||||
def gpu_problem(g, together=False):
|
||||
"""Why Strata cannot use this card, in plain words (None: it can)."""
|
||||
if int(g["arch"]) < 80:
|
||||
return (f"not supported - older than the RTX 30 series (compute capability {cc(g)}; Strata needs 8.0 or "
|
||||
if int(g["arch"]) < 75:
|
||||
return (f"not supported - older than the RTX 20 series (compute capability {cc(g)}; Strata needs 7.5 or "
|
||||
"newer)")
|
||||
if together and g["vram_gb"] < SPLIT_MIN_VRAM_GB - 0.5:
|
||||
return (f"not supported together with other GPUs - {g['vram_gb']:.0f} GB of VRAM (a card sharing the model "
|
||||
@@ -349,7 +349,7 @@ def check_gpus(sel, found, what="") -> None:
|
||||
ones = " or ".join(f"--gpu {x['index']}" for x in single)
|
||||
both = "--gpus " + ",".join(str(x["index"]) for x in can) if can else ""
|
||||
hint = ((f"use these together: {both}" + (f" (or one card: {ones})" if not together else "")) if can else
|
||||
f"use one card: {ones}" if single else "Strata needs an NVIDIA RTX 30 series or newer card")
|
||||
f"use one card: {ones}" if single else "Strata needs an NVIDIA RTX 20 series or newer card")
|
||||
fail(f"GPU {i}{'' if g is None else ' (' + g['name'] + ')'} {what}cannot be used: {p}", hint)
|
||||
|
||||
|
||||
@@ -384,7 +384,7 @@ def choose_gpus(a, found) -> list:
|
||||
single = sorted([g for g in found if gpu_problem(g) is None], key=lambda x: (-round(x["vram_gb"]), x["index"]))
|
||||
if not single:
|
||||
gpu_table(found)
|
||||
fail("none of your GPUs can run Strata", "it needs an NVIDIA RTX 30 series or newer (compute capability 8.0+)")
|
||||
fail("none of your GPUs can run Strata", "it needs an NVIDIA RTX 20 series or newer (compute capability 7.5+)")
|
||||
can = together_ok(found)
|
||||
if not can:
|
||||
return [single[0]["index"]]
|
||||
|
||||
+8
-7
@@ -33,7 +33,7 @@ DeviceInfo device_info(int ordinal) {
|
||||
#if defined(STRATA_USE_HIP)
|
||||
throw CudaError("no HIP device is present; this backend targets gfx1100 wave32", -1);
|
||||
#else
|
||||
throw CudaError("no CUDA device is present; Strata needs an NVIDIA GPU of compute capability 8.0 or newer", -1);
|
||||
throw CudaError("no CUDA device is present; Strata needs an NVIDIA GPU (RTX 20 series or newer)", -1);
|
||||
#endif
|
||||
}
|
||||
if (ordinal < 0 || ordinal >= count) {
|
||||
@@ -60,19 +60,20 @@ DeviceInfo device_info(int ordinal) {
|
||||
check(cudaDriverGetVersion(&d.driver_version), "cudaDriverGetVersion");
|
||||
check(cudaRuntimeGetVersion(&d.runtime_version), "cudaRuntimeGetVersion");
|
||||
|
||||
// The kernels need sm_80 or newer (tf32 mma in the attention scorer, bf16 math) - the same floor the
|
||||
// arch guard in CMakeLists enforces at build time (RTX 30 / 40 / 50). Anything older is caught here,
|
||||
// because a binary can be carried to a machine with an older card and would otherwise silently take
|
||||
// whatever path the driver chose. The HIP backend is validated on gfx1100 (wave32) only.
|
||||
// The engine supports compute capability 7.5 and newer (Turing: the QSA scorer's tf32 mma has a portable
|
||||
// fp32-FMA fallback below sm_80, the tensor-core prompt kernels refuse and fall back). Compiling for a
|
||||
// supported arch is enforced by CMake; RUNNING on an older card is caught here, because a binary can be carried
|
||||
// to a machine with an older card and would otherwise silently take whatever path the driver chose. The HIP
|
||||
// backend is validated on gfx1100 (wave32) only.
|
||||
#if defined(STRATA_USE_HIP)
|
||||
if (std::strncmp(p.gcnArchName, "gfx1100", 7) != 0 || p.warpSize != 32) {
|
||||
throw CudaError("HIP backend requires validated gfx1100 wave32 hardware", -1);
|
||||
}
|
||||
#else
|
||||
if (d.cc_major < 8) {
|
||||
if (d.cc_major * 10 + d.cc_minor < 75) {
|
||||
throw CudaError("device " + d.name + " reports compute capability " + std::to_string(d.cc_major) +
|
||||
"." + std::to_string(d.cc_minor) +
|
||||
"; Strata needs an NVIDIA GPU of compute capability 8.0 or newer (RTX 30 / 40 / 50)",
|
||||
"; Strata needs compute capability 7.5 or newer (RTX 20 / 30 / 40 / 50 series)",
|
||||
-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -325,19 +325,40 @@ void fused_gr_read_multi(const FusedGrArgs* a, int n_tok, float* xn_scratch, voi
|
||||
// the shared-memory opt-in is a per-DEVICE setting: once per device, not once per process (a layer split
|
||||
// runs this kernel on two cards)
|
||||
static bool attr[64] = {};
|
||||
static int chunk[64] = {}; // Turing port: tokens the down kernel may carry in one launch on this card
|
||||
int dev = 0;
|
||||
cudaGetDevice(&dev);
|
||||
if (dev < 0 || dev >= 64 || !attr[dev]) {
|
||||
if (dev >= 0 && dev < 64 && !attr[dev]) {
|
||||
// at most what the card allows (Turing: 64 KB - enough for windows of up to 6 tokens)
|
||||
int optin = 0;
|
||||
cudaDeviceGetAttribute(&optin, cudaDevAttrMaxSharedMemoryPerBlockOptin, dev);
|
||||
int want = (int) (kFusedGrMaxT * TILE * sizeof(float));
|
||||
if (optin > 0 && want > optin) want = optin;
|
||||
cudaFuncSetAttribute(gr_down_multi_kernel, cudaFuncAttributeMaxDynamicSharedMemorySize, want);
|
||||
cudaGetLastError();
|
||||
if (dev >= 0 && dev < 64) attr[dev] = true;
|
||||
cudaGetLastError(); // drop any error the attempt left behind
|
||||
// Turing port: the down kernel stages n_tok*TILE floats of dynamic shared memory - 80 KB at the full
|
||||
// 8 tokens. A card whose opt-in is below that (Turing: 64 KB, so 7+ tokens fail to launch as
|
||||
// "invalid argument") processes the tokens in slices that fit; a card that reports no opt-in gets what
|
||||
// fits the 48 KB default (4 tokens of the CUDA tile; all 8 of HIP's smaller tile). The down kernel's
|
||||
// outputs (lo, inject_out) are strictly per-token, so the chunk boundaries are safe, and the up kernel
|
||||
// below still sees every token of the batch in one launch.
|
||||
const int capacity = (optin > 0 ? optin : 48 * 1024) / (int) (TILE * sizeof(float));
|
||||
chunk[dev] = capacity < 1 ? 1 : (capacity > kFusedGrMaxT ? kFusedGrMaxT : capacity);
|
||||
attr[dev] = true;
|
||||
}
|
||||
const int chunk_tok = (dev >= 0 && dev < 64 && chunk[dev]) ? chunk[dev] : kFusedGrMaxT;
|
||||
if (chunk_tok >= n_tok) {
|
||||
gr_down_multi_kernel<<<DOWN_BLOCKS + 1, THREADS, (size_t) n_tok * TILE * sizeof(float), st>>>(m);
|
||||
} else {
|
||||
for (int c0 = 0; c0 < n_tok; c0 += chunk_tok) {
|
||||
const int ct = n_tok - c0 < chunk_tok ? n_tok - c0 : chunk_tok;
|
||||
GrMulti c{};
|
||||
c.xn = xn_scratch + (size_t) c0 * D;
|
||||
c.T = ct;
|
||||
for (int k = 0; k < ct; ++k) c.a[k] = a[c0 + k];
|
||||
gr_down_multi_kernel<<<DOWN_BLOCKS + 1, THREADS, (size_t) ct * TILE * sizeof(float), st>>>(c);
|
||||
}
|
||||
}
|
||||
gr_down_multi_kernel<<<DOWN_BLOCKS + 1, THREADS, (size_t) n_tok * TILE * sizeof(float), st>>>(m);
|
||||
if (stamp_buf) gpu_stamp(stamp_buf, stamp_i0 + 1, stream);
|
||||
gr_up_multi_kernel<<<UPM_BLOCKS, THREADS, 0, st>>>(m);
|
||||
const cudaError_t e = cudaGetLastError();
|
||||
|
||||
Reference in new issue
Block a user