mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 15:28:40 +00:00
Made by tools/layout/move_0216.py (the commit before this one) on db8e0be9c, the final code head of 0.2.16:
- 75 git mv (renames, so `git log --follow` and blame keep working; packaging/acceptance_matrix.md shows as delete + add because its links
changed too) and 3 removals: SETUP.bat, UPDATE.bat and update.sh (setup.py --update pulls the code now);
- 1,425 path edits in 307 files: root-relative paths in CI, Docker, .gitignore and the release scripts; Markdown links; Python and
Node joins from a root that moved with its folder; explicit edits for code that computes a root or names a moved path; tables of
repository paths inside tests.
engine/ holds what CMake builds (src, include, cmake, metal, sycl, spark, third_party, the C++ tests and benches). app/ is the desktop
app and its host (was apps/). terminal/ is the Terminal in the layout of the installed one (strata.py, setup.py, strata_cli,
strata_control, serve, bin, data, ref, crates, the Python tools and tests). docs/ has the documentation, docs/lang/ the translated
READMEs, docs/history and docs/bench-results. tools/ has the repository's own checks, packaging, docker, research and nix.
tests/core/test_tqp_ref.py is a pytest file and stays with the Python tests (terminal/tests/core/).
AGENTS.md, README.md, LICENSE, setup.sh and START-HERE.bat stay at the root.
No behaviour change: the same command lines, the same sources. For this head a replay of the script gave the same numbers and the path
scan (tools/layout/checks/path_scan.py) reports no hit; the suites and the builds run on this commit next.
104 lines
5.1 KiB
C++
104 lines
5.1 KiB
C++
// include/strata/core/device.hpp - P2.S1: the device arena and the runtime's device facts.
|
|
//
|
|
// `DeviceArena` is ONE cudaMalloc per planner region with bump sub-allocation below it and no frees. That is
|
|
// not a simplification for the first version: the memory plan from P1.S9 is fixed at startup, so the set of
|
|
// regions and their sizes is known before anything is allocated, and an allocator that can free would be
|
|
// solving a problem the engine does not have while adding fragmentation and failure modes it does.
|
|
//
|
|
// The reason to get this in early is that the VRAM budget is the binding constraint of the whole design
|
|
// (5.95 GB pooled between KV and the expert cache, 33.97 GB of experts in DRAM). A runtime that discovers at
|
|
// token 4000 that it has overcommitted has already lost; the plan is printed against `cudaMemGetInfo` at
|
|
// startup so the discrepancy is visible immediately.
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace strata::core {
|
|
|
|
struct DeviceInfo {
|
|
int ordinal = -1;
|
|
std::string name;
|
|
int cc_major = 0, cc_minor = 0;
|
|
uint64_t total_bytes = 0; // as reported by cudaMemGetInfo at query time
|
|
uint64_t free_bytes = 0;
|
|
int driver_version = 0, runtime_version = 0;
|
|
int multi_processor_count = 0;
|
|
std::string arch; // HIP: gcnArchName without its feature suffix ("gfx1201"); empty on CUDA
|
|
};
|
|
|
|
// HIP builds: whether GPU `ordinal` can run this binary - its architecture must be one the binary was COMPILED
|
|
// for (STRATA_HIP_ARCHS, set by cmake/hip_backend.cmake) and it must run wave32. "" when it can (or when there
|
|
// is no such device: the caller's own device errors apply), else the reason in a sentence. A binary carried to
|
|
// another card would otherwise fail later with "invalid device function". CUDA builds: always "".
|
|
std::string gpu_arch_problem(int ordinal);
|
|
|
|
// The GPU architectures this binary was compiled for ("gfx1100,gfx1201"); "" on CUDA builds.
|
|
const char* compiled_gpu_archs();
|
|
|
|
// How many devices the runtime enumerates, numbered as HIP_VISIBLE_DEVICES / CUDA_VISIBLE_DEVICES number them; 0 when
|
|
// there is none (or no usable runtime). `device_info` throws on a card this binary cannot run, so a caller that LISTS
|
|
// every card - the ones it has no code for included (`strata-device --list-devices`) - counts them with this first.
|
|
int device_count();
|
|
|
|
// One line per device for `strata-device --list-devices`, without the arch check that `device_info` applies:
|
|
// "arch gfx1201, 15.9 GiB" (HIP) or "compute capability 12.0, 11.9 GiB" (CUDA), plus the device's name. false when
|
|
// the runtime cannot describe it.
|
|
bool device_summary(int ordinal, std::string& name, std::string& detail);
|
|
|
|
// STRATA_PRIMARY_DEVICE (generate.cpp): the ordinal the engine's own session runs on; 0 = the runtime's first
|
|
// visible device (upstream's behavior). The Windows HIP runtime enumerates the cards in a fixed order no
|
|
// HIP_VISIBLE_DEVICES list can change (it only filters), so a PC whose faster card comes second could not run
|
|
// the model on it while the first card served as a helper. The helper expert caches and the peer tier must
|
|
// live on another device. Set once, before any context exists.
|
|
void set_primary_device(int ordinal);
|
|
int primary_device();
|
|
|
|
// Throws when there is no CUDA device. The engine targets sm_120 specifically and must say so rather than
|
|
// run slowly on something else: `CMakeLists.txt` already refuses to COMPILE for another architecture, and
|
|
// this is the matching check at run time (a binary can be carried to a different machine).
|
|
DeviceInfo device_info(int ordinal = 0);
|
|
|
|
/// "" when this build has device code for the current device, else CUDA's error: a build for other GPUs would
|
|
/// otherwise fail at its first kernel launch, with nothing that names the cause.
|
|
std::string device_code_error();
|
|
|
|
class CudaError : public std::runtime_error {
|
|
public:
|
|
CudaError(const std::string& what, int code) : std::runtime_error(what), code_(code) {}
|
|
int code() const { return code_; }
|
|
|
|
private:
|
|
int code_;
|
|
};
|
|
|
|
// One cudaMalloc, bump-allocated below. `poison` fills new allocations with a NaN-ish pattern in a debug
|
|
// build so that reading uninitialised VRAM gives a NaN rather than a plausible number - the same reasoning as
|
|
// the harness work in Phase 1: a wrong value that looks right is the expensive kind.
|
|
class DeviceArena {
|
|
public:
|
|
explicit DeviceArena(uint64_t bytes, int ordinal = 0, bool poison = false);
|
|
~DeviceArena();
|
|
DeviceArena(const DeviceArena&) = delete;
|
|
DeviceArena& operator=(const DeviceArena&) = delete;
|
|
|
|
// `align` must be a power of two; 256 keeps every sub-allocation at a sector boundary.
|
|
void* alloc(uint64_t bytes, uint64_t align = 256);
|
|
|
|
uint64_t capacity() const { return capacity_; }
|
|
uint64_t used() const { return used_; }
|
|
uint64_t peak() const { return used_; } // no frees, so used IS the peak
|
|
int ordinal() const { return ordinal_; }
|
|
void* base() const { return base_; }
|
|
|
|
private:
|
|
void* base_ = nullptr;
|
|
uint64_t capacity_ = 0, used_ = 0;
|
|
int ordinal_ = 0;
|
|
bool poison_ = false;
|
|
};
|
|
|
|
} // namespace strata::core
|