mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +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.
72 lines
3.0 KiB
C++
72 lines
3.0 KiB
C++
// Compare all output bits against the existing router, including ties, NaN
|
|
// tails and the fast kernel's forced serial-sum fallback. Also time decode calls.
|
|
#include <sycl/sycl.hpp>
|
|
#include <dpct/dpct.hpp>
|
|
#include "strata/sycl_queue.hpp"
|
|
#include "strata/kernels/router_top10.hpp"
|
|
#include <chrono>
|
|
#include <cmath>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
#include <random>
|
|
#include <vector>
|
|
|
|
static int compare(int experts, int k, int rows) {
|
|
auto& q = *strata::q_of(nullptr);
|
|
std::mt19937 rng(17);
|
|
std::normal_distribution<float> normal(0, 2);
|
|
std::vector<float> logits((size_t)rows * experts);
|
|
for (size_t i = 0; i < logits.size(); ++i) {
|
|
const size_t r = i / experts;
|
|
float x = normal(rng) * (r % 7 == 5 ? 40 : 1);
|
|
if (r % 3 == 1) x = std::round(x * 4) / 4;
|
|
if (r % 3 == 2) x = std::round(x * 64) / 64;
|
|
if (r % 1000 == 999 && i % experts == 77) x = NAN;
|
|
if (r % 1000 == 998) x = 1;
|
|
logits[i] = x;
|
|
}
|
|
float* dl = sycl::malloc_device<float>(logits.size(), q);
|
|
q.memcpy(dl, logits.data(), logits.size() * sizeof(float));
|
|
const size_t n = (size_t)rows * k;
|
|
float* dw[3]; int* di[3];
|
|
std::vector<float> weights[3]; std::vector<int> ids[3];
|
|
for (int v = 0; v < 3; ++v) {
|
|
dw[v] = sycl::malloc_device<float>(n, q);
|
|
di[v] = sycl::malloc_device<int>(n, q);
|
|
q.memset(dw[v], 0x3c, n * sizeof(float));
|
|
q.memset(di[v], 0x11, n * sizeof(int));
|
|
if (!strata::kernels::router_top10_variant(dl, rows, experts, k, di[v], dw[v], &q, v)) return 2;
|
|
weights[v].resize(n); ids[v].resize(n);
|
|
q.memcpy(weights[v].data(), dw[v], n * sizeof(float));
|
|
q.memcpy(ids[v].data(), di[v], n * sizeof(int));
|
|
q.wait_and_throw();
|
|
}
|
|
int fails = 0;
|
|
for (int v = 1; v < 3; ++v) {
|
|
int bad = 0;
|
|
for (int r = 0; r < rows; ++r)
|
|
if (std::memcmp(ids[0].data() + (size_t)r*k, ids[v].data() + (size_t)r*k, k*sizeof(int)) ||
|
|
std::memcmp(weights[0].data() + (size_t)r*k, weights[v].data() + (size_t)r*k, k*sizeof(float))) ++bad;
|
|
std::printf("experts %d k %d rows %d variant %d: %d rows differ\n", experts, k, rows, v, bad);
|
|
fails += bad != 0;
|
|
}
|
|
for (int v = 0; v < 2; ++v) {
|
|
constexpr int reps = 300;
|
|
auto start = std::chrono::steady_clock::now();
|
|
for (int r = 0; r < reps; ++r)
|
|
strata::kernels::router_top10_variant(dl + (r % 64)*experts, 1, experts, k, di[v], dw[v], &q, v);
|
|
q.wait_and_throw();
|
|
auto us = std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now()-start).count()/reps;
|
|
std::printf("variant %d single-token call: %.2f us (host submission + execution)\n", v, us);
|
|
}
|
|
for (int v = 0; v < 3; ++v) { sycl::free(dw[v], q); sycl::free(di[v], q); }
|
|
sycl::free(dl, q);
|
|
return fails;
|
|
}
|
|
|
|
int main() {
|
|
int failures = compare(512, 10, 65536) + compare(256, 8, 8192) + compare(256, 10, 8192) + compare(512, 32, 1024);
|
|
std::printf("FAILURES: %d\n", failures);
|
|
return failures != 0;
|
|
}
|