Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
sycl: port upstream 0.1.35 (re-migration of its changed engine files)
maxfridbe05c90db58682
diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txtindex 1bda26d65..db55f9409 100644--- a/sycl/CMakeLists.txt+++ b/sycl/CMakeLists.txt@@ -10,7 +10,7 @@## Device code is JIT-compiled from SPIR-V unless STRATA_SYCL_AOT names a device (bmg-g31 for the Arc Pro B70).cmake_minimum_required(VERSION 3.24)-project(strata_sycl VERSION 0.1.33 LANGUAGES C CXX) # the upstream engine version this port tracks+project(strata_sycl VERSION 0.1.35 LANGUAGES C CXX) # the upstream engine version this port tracksset(STRATA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)set(CMAKE_CXX_STANDARD 20)set(CMAKE_CXX_STANDARD_REQUIRED ON)diff --git a/sycl/src/core/device.dp.cpp b/sycl/src/core/device.dp.cppindex fad48c260..a01a6cb63 100644--- a/sycl/src/core/device.dp.cpp+++ b/sycl/src/core/device.dp.cpp@@ -90,6 +90,57 @@ const char* compiled_gpu_archs() {#endif}+int device_count() try {+ int count = 0;+ if (DPCT_CHECK_ERROR(count = dpct::device_count()) !=+ 0) { // HIP without a usable device reports an error, not 0+ /*+ DPCT1026: The call to cudaGetLastError was removed because this+ functionality is redundant in SYCL.+ */+ return 0;+ }+ return count < 0 ? 0 : count;+}+catch (sycl::exception const &exc) {+ std::cerr << exc.what() << "Exception caught at file:" << __FILE__+ << ", line:" << __LINE__ << std::endl;+ std::exit(1);+}++bool device_summary(int ordinal, std::string &name, std::string &detail) try {+ dpct::device_info p{};+ if (ordinal < 0 || ordinal >= device_count() ||+ DPCT_CHECK_ERROR(dpct::get_device(ordinal).get_device_info(p)) != 0) {+ /*+ DPCT1026: The call to cudaGetLastError was removed because this+ functionality is redundant in SYCL.+ */+ return false;+ }+ char buf[160];+#if defined(STRATA_USE_HIP)+ std::snprintf(buf, sizeof(buf), "arch %s, %.1f GiB, wave%d", base_arch(p.gcnArchName).c_str(),+ (double) p.totalGlobalMem / (1024.0 * 1024 * 1024), p.warpSize);+#else+ /*+ DPCT1005: The SYCL device version is different from CUDA Compute+ Compatibility. You may need to rewrite this code.+ */+ std::snprintf(buf, sizeof(buf), "compute capability %d.%d, %.1f GiB",+ p.get_major_version(), p.get_minor_version(),+ (double)p.get_global_mem_size() / (1024.0 * 1024 * 1024));+#endif+ name = p.get_name();+ detail = buf;+ return true;+}+catch (sycl::exception const &exc) {+ std::cerr << exc.what() << "Exception caught at file:" << __FILE__+ << ", line:" << __LINE__ << std::endl;+ std::exit(1);+}+std::string gpu_arch_problem(int ordinal) {#if defined(STRATA_USE_HIP)int count = 0;diff --git a/sycl/src/core/expert_source.cpp b/sycl/src/core/expert_source.cppindex 6ba5598e9..645b2cfb6 100644--- a/sycl/src/core/expert_source.cpp+++ b/sycl/src/core/expert_source.cpp@@ -1054,6 +1054,22 @@ bool FileExpertSource::pin_cache_complement(uint64_t bytes = 0;if (!detail::make_cache_complement_plan(n_layers_, n_expert_, layer_blob_bytes_, primary_gpu_pairs,additional_gpu_pairs, offsets, bytes, err)) return false;+#if defined(_WIN32)+ // #467: the GPU cache's pre-fill touched its experts through the mapping (~19 GiB on a 24 GB card), and Windows+ // counts those file pages in this process's working set, not as available: a 32 GB PC read 0.44 GiB here+ // (20.7 GiB before the start). Trimmed, they move to the standby list (still cached, counted as available).+ // Resident mode only: nothing else calls this function. Locked/pinned pages stay; the rest fault back softly.+ {+ uint64_t before = 0, after = 0;+ const bool read_before = available_memory_bytes(before);+ (void) SetProcessWorkingSetSize(GetCurrentProcess(), (SIZE_T) -1, (SIZE_T) -1);+ if (read_before && available_memory_bytes(after))+ std::fprintf(stderr, "FileExpertSource: available RAM %.2f GiB, %.2f GiB after the mapped experts left the "+ "process working set (#467)\n",+ (double) before / 1073741824.0, (double) after / 1073741824.0);+ }+#endif+ const bool what_fits = budget_bytes == kResidentWhatFits; // #467: the soft mode's second tryuint64_t budget_physical = 0; // #403: the RAM reading a budget was sized from (0: no budget)if (budget_bytes > 0) {// CS-T: a RAM budget. The complement's experts in `rank` order (the expert profile, hottest first) while@@ -1071,10 +1087,16 @@ bool FileExpertSource::pin_cache_complement(// lower). An unclamped budget is unchanged.const uint64_t margin = 256ull << 20;const uint64_t clamped = room > margin ? room - margin : 0;- std::fprintf(stderr, "FileExpertSource: --resident-budget-gib %.2f is more than the RAM has room for "- "(%.2f GiB available minus %.0f GiB headroom and a 0.25 GiB margin): %.2f GiB\n",- (double) budget_bytes / 1073741824.0, (double) physical / 1073741824.0,- (double) headroom_bytes / 1073741824.0, (double) clamped / 1073741824.0);+ if (what_fits)+ std::fprintf(stderr, "FileExpertSource: RAM room for the complement: %.2f GiB (%.2f GiB available "+ "minus %.0f GiB headroom and a 0.25 GiB margin)\n",+ (double) clamped / 1073741824.0, (double) physical / 1073741824.0,+ (double) headroom_bytes / 1073741824.0);+ else+ std::fprintf(stderr, "FileExpertSource: --resident-budget-gib %.2f is more than the RAM has room for "+ "(%.2f GiB available minus %.0f GiB headroom and a 0.25 GiB margin): %.2f GiB\n",+ (double) budget_bytes / 1073741824.0, (double) physical / 1073741824.0,+ (double) headroom_bytes / 1073741824.0, (double) clamped / 1073741824.0);budget_bytes = clamped;}std::vector<uint64_t> ranked(offsets.size(), kNoComplement);@@ -1091,6 +1113,10 @@ bool FileExpertSource::pin_cache_complement(at += b;++held;}+ if (what_fits && held == 0) { // #467: nothing to keep - the caller's plain mmap fallback, not an empty copy+ err = "FileExpertSource: the RAM has no room for any expert of the complement";+ return false;+ }std::fprintf(stderr, "FileExpertSource: RAM budget %.2f GiB: %lld of the %.2f GiB of experts the GPU cache does ""not hold, by profile rank; the rest are read from the files\n",(double) budget_bytes / 1073741824.0, (long long) held, (double) bytes / 1073741824.0);diff --git a/sycl/src/core/native_head.cpp b/sycl/src/core/native_head.cppindex fd3f2bfea..6b5a938f5 100644--- a/sycl/src/core/native_head.cpp+++ b/sycl/src/core/native_head.cpp@@ -210,10 +210,10 @@ bool NativeEmbed::load(const std::vector<std::string> &shards, int64_t n_embd,bytes_, dpct::get_in_order_queue())) !=0 ||/*- DPCT1114: cudaMemcpy is migrated to asynchronization- memcpy, assuming in the original code the source host memory is- pageable memory. If the memory is not pageable, call wait() on- event return by memcpy API to ensure synchronization behavior.+ DPCT1114: cudaMemcpy is migrated to asynchronization memcpy,+ assuming in the original code the source host memory is pageable+ memory. If the memory is not pageable, call wait() on event+ return by memcpy API to ensure synchronization behavior.*/DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(d, gguf.tensor_data(*t), bytes_).wait()) != 0) {@@ -233,10 +233,31 @@ bool NativeEmbed::load(const std::vector<std::string> &shards, int64_t n_embd,} else {std::memcpy(host_, gguf.tensor_data(*t), bytes_);void* d = nullptr;+#if defined(STRATA_USE_HIP)+ // #325: the Windows HIP stack can refuse the device alias of a mapped allocation (and, when it gives+ // one, it is the host address itself - unified addressing; kernels read it correctly there, a+ // device-to-device copy into it does not land: tests/hip/mapped_alias). The table is only gathered from,+ // so without an alias it goes into VRAM like the unpinnable case above, instead of failing the start.+ if (cudaHostGetDevicePointer(&d, host_, 0) != cudaSuccess || d == nullptr) {+ cudaGetLastError();+ d = nullptr;+ if (cudaMalloc(&d, bytes_) != cudaSuccess ||+ cudaMemcpy(d, gguf.tensor_data(*t), bytes_, cudaMemcpyHostToDevice) != cudaSuccess) {+ if (d) cudaFree(d);+ cudaGetLastError();+ err = "native embedding: no device alias for the mapped table, and no VRAM to copy it into";+ return false;+ }+ cudaFreeHost(host_); // the destructor frees dev_ when host_ is null+ host_ = nullptr;+ std::fprintf(stderr, "strata: native embedding: no device alias for the mapped table, kept in VRAM\n");+ }+#elseif (DPCT_CHECK_ERROR(d = (void *)host_) != 0) {err = "native embedding: no device alias for the mapped table";return false;}+#endifdev_ = d;}type_ = (int) t->type;diff --git a/sycl/src/prefill/gemm.dp.cpp b/sycl/src/prefill/gemm.dp.cppindex 50d8541a5..c4069b684 100644--- a/sycl/src/prefill/gemm.dp.cpp+++ b/sycl/src/prefill/gemm.dp.cpp@@ -45,6 +45,23 @@ void ck(int s, const char *what) {}}+// #247/#325: on Windows (seen on gfx1201), hipBLAS can return success with the correct BF16/FP16 product for some+// shapes (hc up once T >= 96, the router) and still leave hipErrorInvalidValue set, which the next kernel's error+// check turns into an exit. The multiply has finished, so that one stale error is cleared after a GEMM that succeeded;+// any other error still stops the engine. Windows only: on Linux a stale hipErrorInvalidValue is a real error from+// an earlier call and keeps being reported. A no-op everywhere else (CUDA compiles none of it).+#if defined(__HIPCC__) && defined(_WIN32)+void absorb_hipblas_sticky(const char* what) {+ const hipError_t sticky = hipGetLastError();+ if (sticky == hipSuccess || sticky == hipErrorInvalidValue) return;+ std::fprintf(stderr, "prefill gemm: %s left %s\n", what, hipGetErrorString(sticky));+ std::exit(1);+}+#define STRATA_ABSORB_HIPBLAS_STICKY(what) absorb_hipblas_sticky(what)+#else+#define STRATA_ABSORB_HIPBLAS_STICKY(what) ((void) 0)+#endif+// A setup call whose failure the engine survives (the handle keeps its defaults), as before #240 - but said.void note(int s, const char *what) {if (s != 0) std::fprintf(@@ -429,6 +446,7 @@ void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64#if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE)if (try_hipblaslt(hipblaslt_state_, strata::prefill::hipblaslt::InputType::bf16, X, W, Y, T, N, K, ldy,beta, stream_)) {+ STRATA_ABSORB_HIPBLAS_STICKY("hipBLASLt bf16");return;}#endif@@ -441,6 +459,7 @@ void Gemm::bf16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64dpct::library_data_t::real_float, (int)ldy,dpct::compute_type::f32)),"cublasGemmEx");+ STRATA_ABSORB_HIPBLAS_STICKY("cublasGemmEx");}void Gemm::f16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_t N, int64_t K, int64_t ldy,@@ -451,6 +470,7 @@ void Gemm::f16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_#if defined(__HIPCC__) && defined(STRATA_HIPBLASLT_AVAILABLE)if (try_hipblaslt(hipblaslt_state_, strata::prefill::hipblaslt::InputType::f16, X, W, Y, T, N, K, ldy,beta, stream_)) {+ STRATA_ABSORB_HIPBLAS_STICKY("hipBLASLt f16");return;}#endif@@ -462,6 +482,7 @@ void Gemm::f16(const uint16_t* X, const uint16_t* W, float* Y, int64_t T, int64_dpct::library_data_t::real_float, (int)ldy,dpct::compute_type::f32)),"cublasGemmEx f16");+ STRATA_ABSORB_HIPBLAS_STICKY("cublasGemmEx f16");}void Gemm::native(const uint16_t* X, int ggml_type, const void* W_blocks, float* Y, int64_t T, int64_t N, int64_t K,diff --git a/sycl/src/prefill/prefill.cpp b/sycl/src/prefill/prefill.cppindex 3a1698170..9aeeec065 100644--- a/sycl/src/prefill/prefill.cpp+++ b/sycl/src/prefill/prefill.cpp@@ -49,6 +49,7 @@namespace strata::prefill::mmq {bool built() { return false; }bool supported(int) { return false; }+bool fits(int, int64_t) { return false; }size_t matrix_bytes(int, int64_t, int64_t) { return 0; }size_t q8_bytes(int64_t, int64_t) { return 0; }void quantize(const float*, const int32_t*, void*, int, int64_t, int64_t, int64_t, void*) {}@@ -547,7 +548,8 @@ const MmqPlan& mmq_plan() {p.fallback = !on || layers <= 0;for (int64_t l = 0; on && l < layers; ++l) {const int gt = lay.native ? lay.fmt[(size_t) l].gu_type : 42, dt = lay.native ? lay.fmt[(size_t) l].d_type : 42;- if (!mmq::supported(gt) || !mmq::supported(dt)) { p.fallback = true; continue; }+ // #420: a tile on every GPU for these shapes (gate+up: 1280 rows, down: N rows), else the FP16 path+ if (!mmq::fits(gt, 1280) || !mmq::fits(dt, N)) { p.fallback = true; continue; }p.layer[(size_t) l] = 1;p.any = true;p.gu_max = std::max(p.gu_max, mmq::matrix_bytes(gt, 1280, N));@@ -912,7 +914,7 @@ bool Prefill::draft_kv(core::MtpDrafter& mtp, const float* R_rows, const int32_t// E-9: the drafter's Q8_0 matrices through Q8_1 x Q8_0 MMQ - its own pass's integer dot products (mmvq), so// its K/V stay close to what the drafter computes itself; STRATA_MTP_BATCH_F16=1: FP16 GEMMs (the A/B)static const bool f16_only = [] { const char* v = std::getenv("STRATA_MTP_BATCH_F16"); return v && v[0] == '1'; }();- const bool q8 = !f16_only && mmq::built() && mmq::supported(kQ8_0);+ const bool q8 = !f16_only && mmq::built() && mmq::fits(kQ8_0, Nn) && mmq::fits(kQ8_0, KV); // #420const uint64_t per_row = 4 * (2 * Nn + 4 * HCN + LR + HC + Nn + 2 * KV + 1) + 2 * (Nn + 2 * HCN + LR + Nn) + 64 +(q8 ? (uint64_t) mmq::q8_bytes(g.hc, Nn) + 4 * g.hc : 0);// SYCL port: B is the batch buffers' capacity, not the row count (each batch uses nb <= B rows), so a shortdiff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cppindex 933009314..75a3304f8 100644--- a/sycl/src/program/generate.cpp+++ b/sycl/src/program/generate.cpp@@ -2370,10 +2370,10 @@ int main(int argc, char **argv) try {st.mrope = sycl::malloc_device<int32_t>(mrope_host.size(), dpct::get_in_order_queue())) != 0 ||/*- DPCT1114: cudaMemcpy is migrated to asynchronization- memcpy, assuming in the original code the source host memory is- pageable memory. If the memory is not pageable, call wait() on- event return by memcpy API to ensure synchronization behavior.+ DPCT1114: cudaMemcpy is migrated to asynchronization memcpy,+ assuming in the original code the source host memory is pageable+ memory. If the memory is not pageable, call wait() on event+ return by memcpy API to ensure synchronization behavior.*/DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(st.mrope, mrope_host.data(),@@ -2742,22 +2742,30 @@ int main(int argc, char **argv) try {DPCT_CHECK_ERROR(dev = dpct::get_current_device_id()) == 0 &&DPCT_CHECK_ERROR(dpct::get_device(dev).get_device_info(p)) == 0;/*- DPCT1010: SYCL uses exceptions to report errors and does not use- the error codes. The cudaGetLastError function call was replaced with 0.- You need to rewrite this code.+ DPCT1010: SYCL uses exceptions to report errors and does not use the+ error codes. The cudaGetLastError function call was replaced with 0. You+ need to rewrite this code.*/if (!named) 0;const char *name =named && p.get_name()[0] ? p.get_name() : "(an unnamed GPU)";#if defined(STRATA_USE_HIP)std::fprintf(stderr, "strata generate: GPU %d: %s (%s)\n", dev, name, named ? p.gcnArchName : "?");+#if defined(_WIN32)+ // #468 #461: which HIP runtime was loaded - the bundled one beside the exe, or an AMD driver's System32 copy+ if (HMODULE h = GetModuleHandleA("amdhip64_7.dll")) {+ char path[MAX_PATH] = {};+ if (GetModuleFileNameA(h, path, MAX_PATH) > 0)+ std::fprintf(stderr, "strata generate: HIP runtime %s\n", path);+ }+#endif#elsestd::fprintf(stderr, "strata generate: GPU %d: %s, compute capability %d.%d%s\n",dev, name,/*- DPCT1005: The SYCL device version is different from CUDA- Compute Compatibility. You may need to rewrite this code.+ DPCT1005: The SYCL device version is different from CUDA Compute+ Compatibility. You may need to rewrite this code.*/strata::cc_major_of(p.get_major_version()),strata::cc_minor_of(p.get_minor_version()),@@ -3422,8 +3430,8 @@ int main(int argc, char **argv) try {std::fprintf(stderr, "strata generate: routing-aware prefetch of the file tier on (the next layer's router)\n");} else {/*- DPCT1010: SYCL uses exceptions to report errors and does not- use the error codes. The cudaGetLastError function call was replaced+ DPCT1010: SYCL uses exceptions to report errors and does not use+ the error codes. The cudaGetLastError function call was replacedwith 0. You need to rewrite this code.*/(void)0;@@ -3654,11 +3662,10 @@ int main(int argc, char **argv) try {} else {for (int64_t c = 0; c < g.hc; ++c)/*- DPCT1124: cudaMemcpyAsync is migrated to asynchronous- memcpy API. While the origin API might be synchronous, it- depends on the type of operand memory, so you may need to call- wait() on event return by memcpy API to ensure synchronization- behavior.+ DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy+ API. While the origin API might be synchronous, it depends on+ the type of operand memory, so you may need to call wait() on+ event return by memcpy API to ensure synchronization behavior.*/if (DPCT_CHECK_ERROR(strata::q_of(token_stream)->memcpy(ss.R + (size_t)c * g.n_embd, d_emb,@@ -3950,8 +3957,8 @@ int main(int argc, char **argv) try {real error-handling function.*//*- DPCT1010: SYCL uses exceptions to report errors and does not- use the error codes. The cudaGetLastError function call was replaced+ DPCT1010: SYCL uses exceptions to report errors and does not use+ the error codes. The cudaGetLastError function call was replacedwith 0. You need to rewrite this code.*/std::fprintf(stderr,@@ -3998,9 +4005,9 @@ int main(int argc, char **argv) try {function.*//*- DPCT1010: SYCL uses exceptions to report errors and- does not use the error codes. The cudaGetLastError function- call was replaced with 0. You need to rewrite this code.+ DPCT1010: SYCL uses exceptions to report errors and does+ not use the error codes. The cudaGetLastError function call+ was replaced with 0. You need to rewrite this code.*/dpct::get_error_string_dummy(0));return 1;@@ -4020,9 +4027,9 @@ int main(int argc, char **argv) try {function.*//*- DPCT1010: SYCL uses exceptions to report errors and- does not use the error codes. The cudaGetLastError function- call was replaced with 0. You need to rewrite this code.+ DPCT1010: SYCL uses exceptions to report errors and does+ not use the error codes. The cudaGetLastError function call+ was replaced with 0. You need to rewrite this code.*/dpct::get_error_string_dummy(0));return 1;@@ -4110,10 +4117,10 @@ int main(int argc, char **argv) try {st->d_res = sycl::malloc_device<int32_t>(host_res.size(), dpct::get_in_order_queue())) != 0 ||/*- DPCT1114: cudaMemcpy is migrated to asynchronization- memcpy, assuming in the original code the source host memory is- pageable memory. If the memory is not pageable, call wait() on- event return by memcpy API to ensure synchronization behavior.+ DPCT1114: cudaMemcpy is migrated to asynchronization memcpy,+ assuming in the original code the source host memory is pageable+ memory. If the memory is not pageable, call wait() on event+ return by memcpy API to ensure synchronization behavior.*/DPCT_CHECK_ERROR(dpct::get_in_order_queue().memcpy(st->d_res, host_res.data(),@@ -4261,8 +4268,26 @@ int main(int argc, char **argv) try {const int64_t k = plan_lend(chunk);if (k > 0) lend_from = xcache.slots() - k;}- if (src.pin_cache_complement(xcache, err, o.resident_pin, {}, lend_from, o.resident_headroom,- o.resident_budget, &profile)) {+ bool resident_ok = src.pin_cache_complement(xcache, err, o.resident_pin, {}, lend_from, o.resident_headroom,+ o.resident_budget, &profile);+ std::string whole_err;+ if (!resident_ok && o.resident_soft) {+ // #467: the whole complement does not fit - keep what does, the hottest by the profile, through the #403+ // budget path (sized by the RAM alone) instead of none: the misses outside it read the same file bytes+ // the mmap fallback reads, so the answers are unchanged. Nothing pinned: the old fallback below.+ whole_err = err;+ resident_ok = src.pin_cache_complement(xcache, err, o.resident_pin, {}, -1, o.resident_headroom,+ strata::core::FileExpertSource::kResidentWhatFits, &profile);+ if (resident_ok)+ std::fprintf(stderr, "strata generate: WARNING: the whole resident RAM mode does not fit (%s); %.2f "+ "GiB of the experts the GPU does not hold, the hottest by the expert profile, are "+ "kept in RAM and the rest are read from the model folder through the OS file "+ "cache\n",+ whole_err.c_str(), (double) src.resident_bytes() / 1073741824.0);+ else+ err = whole_err + "; " + err;+ }+ if (resident_ok) {if (o.adapt_every > 0 && o.adapt_swaps > 0 &&!src.reserve_exchanges(std::min<int64_t>(o.adapt_swaps, 96), err)) {std::fprintf(stderr, "strata generate: CPU expert residency: %s\n", err.c_str());@@ -4368,24 +4393,76 @@ int main(int argc, char **argv) try {// 128-slot floor. The percentage cap is an AUTO-chunk rule and only the auto scan applies it - an// explicit --prefill is the operator's number, and a loan of it only has to fit. With one participant// (no split) this reduces to plan_lend exactly, so the single-GPU loan is unchanged from main.- auto fits = [&](int64_t c, bool cap) -> bool {- for (const PfPart& p : pf_parts) {- const int64_t k = part_slots(p, c);- if (k <= 0 || k + 128 > p.cache->slots()) return false;- if (cap && k * 100 > kAutoLendPct * p.cache->slots()) return false;- }+ auto fits_one = [&](const PfPart& p, int64_t c, bool cap) -> bool {+ const int64_t k = part_slots(p, c);+ if (k <= 0 || k + 128 > p.cache->slots()) return false;+ return !(cap && k * 100 > kAutoLendPct * p.cache->slots());+ };+ // `only`: CUDA0's cache alone (#448: what one GPU would choose, for the log below); null: every one+ auto fits = [&](int64_t c, bool cap, const PfPart* only = nullptr) -> bool {+ if (only != nullptr) return fits_one(*only, c, cap);+ for (const PfPart& p : pf_parts)+ if (!fits_one(p, c, cap)) return false;return true;};static constexpr int64_t kAutoChunks[] = {32768, 16384, 8192, 6144, 4096, 3072, 2048, 1024, 512, 256};- int64_t chunk = 0;- if (o.prefill_auto) {- for (const int64_t c : kAutoChunks) {- if (c > 8192 && (c > o.prefill_auto_max || c > o.max_context)) continue; // #282, as plan_lend- if (fits(c, true)) { chunk = c; break; }+ auto pick = [&](const PfPart* only) -> int64_t {+ if (o.prefill_auto) {+ for (const int64_t c : kAutoChunks) {+ if (c > 8192 && (c > o.prefill_auto_max || c > o.max_context)) continue; // #282, as plan_lend+ if (fits(c, true, only)) return c;+ }+ } else {+ for (int64_t c = o.prefill_chunk; c >= 256; c /= 2)+ if (fits(c, false, only)) return c;+ }+ return 0;+ };+ const int64_t chunk = pick(nullptr);+ // #448: a small card in a layer split caps every stage's chunk (an RTX 3080's 512-slot cache held a+ // 32 GB card's split to 512 tokens: prompts 6.2x slower, decode the same). Named when it bites, so the+ // regression is one log line: each stage that cannot fund the chunk CUDA0 alone would read in.+ if (pf_parts.size() > 1) {+ const int64_t alone = pick(&pf_parts[0]);+ if (alone > chunk) {+ for (size_t i = 1; i < pf_parts.size(); ++i) {+ const PfPart& p = pf_parts[i];+ if (fits_one(p, alone, o.prefill_auto)) continue;+ const int dev = p.dev < 0 ? 0 : p.dev;+ dpct::device_info prop{};+ if (DPCT_CHECK_ERROR(+ dpct::get_device(dev).get_device_info(prop)) !=+ 0) {+ /*+ DPCT1010: SYCL uses exceptions to report errors+ and does not use the error codes. The+ cudaGetLastError function call was replaced with 0.+ You need to rewrite this code.+ */+ (void)0;+ prop.get_name()[0] = 0;+ }+ const std::string pct =+ o.prefill_auto ? ", and lend at most " + std::to_string(kAutoLendPct) + "%" : "";+ std::fprintf(+ stderr,+ "strata serve: WARNING: prompt chunk %lld tokens, "+ "not %lld: CUDA%d (%s) "+ "has %lld expert-cache slots, and a %lld-token "+ "chunk borrows %lld of them "+ "(it must keep 128%s) - prompts read slower than "+ "on CUDA0 alone (#448)\n",+ (long long)chunk, (long long)alone, dev,+ prop.get_name(), (long long)p.cache->slots(),+ (long long)alone, (long long)part_slots(p, alone),+ pct.c_str());+ // the helper tiers start at CUDA1 without a split (and are enabled in order)+ std::fprintf(stderr, "strata serve: a card this small can serve as a helper expert cache "+ "instead of a split stage: without --layer-split, with %s "+ "(docs/SECOND_GPU.md)\n",+ dev == 1 ? "--expert-cache-device1 N" : "--expert-cache-device1..3 N, in order");+ }}- } else {- for (int64_t c = o.prefill_chunk; c >= 256; c /= 2)- if (fits(c, false)) { chunk = c; break; }}if (chunk > 0) {if (o.prefill_auto)@@ -4569,16 +4646,16 @@ int main(int argc, char **argv) try {const strata::core::OnDevice on(stp->dev);stp->sp.reset();/*- DPCT1010: SYCL uses exceptions to report errors and- does not use the error codes. The cudaGetLastError function- call was replaced with 0. You need to rewrite this code.+ DPCT1010: SYCL uses exceptions to report errors and does+ not use the error codes. The cudaGetLastError function call+ was replaced with 0. You need to rewrite this code.*/(void)0;}sp.reset();/*- DPCT1010: SYCL uses exceptions to report errors and does- not use the error codes. The cudaGetLastError function call was+ DPCT1010: SYCL uses exceptions to report errors and does not+ use the error codes. The cudaGetLastError function call wasreplaced with 0. You need to rewrite this code.*/(void)0;@@ -5004,10 +5081,10 @@ int main(int argc, char **argv) try {try {if (d_res != nullptr)/*- DPCT1114: cudaMemcpy is migrated to asynchronization- memcpy, assuming in the original code the source host memory is- pageable memory. If the memory is not pageable, call wait() on- event return by memcpy API to ensure synchronization behavior.+ DPCT1114: cudaMemcpy is migrated to asynchronization memcpy,+ assuming in the original code the source host memory is pageable+ memory. If the memory is not pageable, call wait() on event+ return by memcpy API to ensure synchronization behavior.*/dpct::get_in_order_queue().memcpy(d_res, host_res.data(), host_res.size() * sizeof(int32_t)).wait();@@ -6557,8 +6634,8 @@ int main(int argc, char **argv) try {function.*//*- DPCT1010: SYCL uses exceptions to report errors and does- not use the error codes. The cudaGetLastError function call was+ DPCT1010: SYCL uses exceptions to report errors and does not+ use the error codes. The cudaGetLastError function call wasreplaced with 0. You need to rewrite this code.*/(long long)pos, dpct::get_error_string_dummy(0));@@ -6633,8 +6710,8 @@ int main(int argc, char **argv) try {function.*//*- DPCT1010: SYCL uses exceptions to report errors and does- not use the error codes. The cudaGetLastError function call was+ DPCT1010: SYCL uses exceptions to report errors and does not+ use the error codes. The cudaGetLastError function call wasreplaced with 0. You need to rewrite this code.*/dpct::get_error_string_dummy(0));@@ -6779,10 +6856,10 @@ int main(int argc, char **argv) try {pending.clear();if (d_res != nullptr)/*- DPCT1114: cudaMemcpy is migrated to asynchronization- memcpy, assuming in the original code the source host memory is- pageable memory. If the memory is not pageable, call wait() on- event return by memcpy API to ensure synchronization behavior.+ DPCT1114: cudaMemcpy is migrated to asynchronization memcpy,+ assuming in the original code the source host memory is pageable+ memory. If the memory is not pageable, call wait() on event+ return by memcpy API to ensure synchronization behavior.*/dpct::get_in_order_queue().memcpy(d_res, host_res.data(), host_res.size() * sizeof(int32_t)).wait();diff --git a/sycl/tools/merge_upstream.py b/sycl/tools/merge_upstream.pynew file mode 100644index 000000000..3306ed2d6--- /dev/null+++ b/sycl/tools/merge_upstream.py@@ -0,0 +1,37 @@+# merge_sel.py BASE_OUT NEW_OUT OLD_REV NEW_REV: 3-way merge into sycl/ of the files upstream changed OLD_REV..NEW_REV+import re, subprocess, sys, os, shutil+B, N, old, new = sys.argv[1:5]+pat = re.compile(r"\b([A-Za-z0-9_]+)_([0-9a-f]{6})\b")+H = lambda t: pat.sub(lambda m: m.group(1) + "_HASH", t)+def hashes(t):+ m = {}+ for a, h in pat.findall(t): m.setdefault(a, set()).add(h)+ return {a: next(iter(v)) for a, v in m.items() if len(v) == 1}+changed = subprocess.check_output(["git", "diff", "--name-only", old, new, "--", "src", "include"], text=True).split()+HAND = {"src/core/mtp.cpp", "src/core/verify.cpp", "src/ngram/ple_reader.cpp", "src/kernels/native_expert_parity.cpp"}+for f in changed:+ rel = f[:-3] + ".dp.cpp" if f.endswith(".cu") else f+ pf = "sycl/" + rel+ if f in HAND:+ if not os.path.exists(pf): print("HAND-MISSING", f); continue+ open("/tmp/_b", "w").write(subprocess.check_output(["git", "show", f"{old}:{f}"], text=True))+ open("/tmp/_n", "w").write(subprocess.check_output(["git", "show", f"{new}:{f}"], text=True))+ r = subprocess.run(["git", "merge-file", "-L", "port", "-L", "base", "-L", "new", pf, "/tmp/_b", "/tmp/_n"]).returncode+ print("HAND", "MERGED" if r == 0 else f"CONFLICT {r}", rel); continue+ bf, nf = f"{B}/{rel}", f"{N}/{rel}"+ if not os.path.exists(nf):+ print("NOT-MIGRATED (original used)" if not os.path.exists(pf) else "PORT-HAS-NO-DPCT?", rel); continue+ nt = open(nf).read()+ if not os.path.exists(pf):+ shutil.copy(nf, pf); print("NEWCOPY", rel); continue+ if not os.path.exists(bf):+ print("NO-BASE (new to dpct output)", rel); continue+ bt = open(bf).read()+ if H(bt) == H(nt): print("NOCHANGE-after-dpct", rel); continue+ pt = open(pf).read(); ph = hashes(pt); bh = hashes(bt)+ nt = pat.sub(lambda m: f"{m.group(1)}_{bh[m.group(1)]}" if m.group(1) in bh else m.group(0), nt)+ canon = lambda t: pat.sub(lambda m: f"{m.group(1)}_{ph[m.group(1)]}" if m.group(1) in ph else m.group(0), t)+ bt, nt = canon(bt), canon(nt)+ open("/tmp/_b", "w").write(bt); open("/tmp/_n", "w").write(nt)+ r = subprocess.run(["git", "merge-file", "-L", "port", "-L", "base", "-L", "new", pf, "/tmp/_b", "/tmp/_n"]).returncode+ print("MERGED" if r == 0 else f"CONFLICT {r}", rel)