From 883d0000a7c8edde617dcbf86a100493fb096c3f Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 23 Oct 2026 18:35:00 +0200 Subject: [PATCH] metal: the dsv41 engine links and runs on the Mac Two things made this possible: * the launch syntax. 146 kernel launches (119 in the sources, 27 in the vendor tree) are now strata_ds4_launch(kernel, grid, block, shared, stream, args...), a call a C++ compiler can parse, with a macro that forces the global name past argument-dependent lookup and a body that stops the run naming the kernel until a Metal dispatch exists. Every source then compiles as C++ through include/metal_compat - .cu files included, since the Metal project has no CUDA language and was silently skipping them. * the last CUDA names the kernel files needed: __grid_constant__, cudaDataType, __umulhi/__mulhi, the bitwise atomics, __halves2half2 / __half2half2 / __low2half / __high2half / __low2float / __high2float / __hadd2 / __hmul2 / __hfma2 / __hneg2, the occupancy query and the stream-capture status. The EXL3 legacy path (v1.1.8's kernels, NVIDIA before sm_80) is defined in metal/src/engine/exl3_legacy_stub.cpp: four of its seven entry points abort with their name, three answer as the declarations require. The 2.25bpw text model does not use EXL3. Result: build rc=0, 0 undefined symbols, strata_ds4 = 1,410,552 bytes, Mach-O arm64, and it runs (its own usage text). Next is the run-time loop: a pack reports the first kernel it needs, implement it in MSL, repeat. --- metal/CMakeLists.txt | 21 ++- metal/include/metal_compat/cublas_v2.h | 1 + .../metal_compat/cuda_device_builtins.h | 30 ++++- metal/include/metal_compat/cuda_fp16.h | 12 ++ metal/include/metal_compat/cuda_launch.h | 23 ++++ metal/include/metal_compat/cuda_runtime.h | 15 +++ metal/include/metal_compat/mma.h | 8 +- metal/src/engine/exl3_legacy_stub.cpp | 29 +++++ src/dsv41/ds4_attn_split.cuh | 4 +- src/dsv41/ds4_gguf.cu | 44 +++---- src/dsv41/ds4_iq.cu | 26 ++-- src/dsv41/ds4_kernels.cu | 122 +++++++++--------- src/dsv41/ds4_tq.cu | 10 +- src/dsv41/ds4_vision.cu | 26 ++-- src/dsv41/vendor/exl3.cu | 30 ++--- src/dsv41/vendor/exl3_cpu.cpp | 4 + src/dsv41/vendor/exl3_legacy.cu | 16 +-- src/dsv41/vendor/moe_win.cu | 2 +- src/dsv41/vendor/sampler.cu | 8 +- 19 files changed, 269 insertions(+), 162 deletions(-) create mode 100644 metal/include/metal_compat/cuda_launch.h create mode 100644 metal/src/engine/exl3_legacy_stub.cpp diff --git a/metal/CMakeLists.txt b/metal/CMakeLists.txt index 91b7e032..f585cb4a 100644 --- a/metal/CMakeLists.txt +++ b/metal/CMakeLists.txt @@ -99,7 +99,8 @@ set(STRATA_METAL_HOST_SOURCES ${S}/spec/suffix_drafter.cpp ${S}/spec/controller.cpp ${S}/spec/draft_policy.cpp ${S}/spec/draft_source.cpp ${S}/kernels/cpu/pool.cpp ${S}/kernels/cpu/expert_layout.cpp ${S}/kernels/cpu/native_expert.cpp ${S}/kernels/cpu/hadamard.cpp ${S}/kernels/cpu/tq_cpu.cpp) # Gyro: the Hadamard rotation, the scalar trellis rows -set_source_files_properties(${S}/core/device.cu ${S}/core/pinned.cu PROPERTIES LANGUAGE CXX) +set_source_files_properties(${S}/core/device.cu ${S}/core/pinned.cu ${DS4}/ds4_vision.cu ${DS4}/vendor/exl3.cu ${DS4}${DS4}/vendor/moe_win.cu ${DS4}/vendor/sampler.cu + PROPERTIES LANGUAGE CXX) # The kernel library: Metal implementations (src/engine/*.cpp) and, for every entry point not ported yet, a stub # that stops the engine with the entry point's name (src/engine/stubs.cpp, generated by tools/gen_stubs.py). @@ -127,16 +128,22 @@ target_link_libraries(strata PRIVATE strata_metal_kernels strata_metal_host stra # through include/metal_compat, which gives them CUDA's names over the Metal runtime; the kernel entry points they call are # the Metal implementations in src/engine/* or the stubs from tools/gen_stubs.py that stop the engine with the name. set(DS4 ${STRATA_ROOT}/src/dsv41) +# The DeepSeek engine's sources. Every .cu compiles as C++ through include/metal_compat; the EXL3 legacy path is left out +# (the 2.25bpw text model never calls it) and the vision tower is included because ds4_model.cu references it. set(STRATA_DS4_SOURCES - ${DS4}/ds4_main.cpp - ${DS4}/ds4_model.cu ${DS4}/ds4_gguf.cu ${DS4}/ds4_iq.cu ${DS4}/ds4_kernels.cu ${DS4}/ds4_tq.cu + ${DS4}/ds4_main.cpp ${DS4}/ds4_model.cu ${DS4}/ds4_gguf.cu ${DS4}/ds4_iq.cu ${DS4}/ds4_kernels.cu ${DS4}/ds4_tq.cu + ${DS4}/ds4_vision.cu + ${DS4}/vendor/exl3.cu ${DS4}/vendor/exl3_cpu.cpp ${DS4}/vendor/moe_win.cu ${DS4}/vendor/sampler.cu ${DS4}/ds4_gg_cpu.cpp ${DS4}/ds4_gguf_cpu.cpp ${DS4}/ds4_iq_cpu.cpp ${DS4}/ds4_tq_cpu.cpp ${DS4}/ds4_packinfo.cpp) -set_source_files_properties(${DS4}/ds4_model.cu ${DS4}/ds4_gguf.cu ${DS4}/ds4_iq.cu ${DS4}/ds4_kernels.cu ${DS4}/ds4_tq.cu - PROPERTIES LANGUAGE CXX) +set_source_files_properties( + ${DS4}/ds4_model.cu ${DS4}/ds4_gguf.cu ${DS4}/ds4_iq.cu ${DS4}/ds4_kernels.cu ${DS4}/ds4_tq.cu ${DS4}/ds4_vision.cu + ${DS4}/vendor/exl3.cu ${DS4}/vendor/moe_win.cu ${DS4}/vendor/sampler.cu + PROPERTIES LANGUAGE CXX) +list(APPEND STRATA_DS4_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/engine/exl3_legacy_stub.cpp) # v1.1.8 EXL3: absent on Metal add_executable(strata_ds4 ${STRATA_DS4_SOURCES}) target_include_directories(strata_ds4 PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include/metal_compat ${STRATA_ROOT}/include ${DS4} - ${STRATA_ROOT}/third_party/ggml ${STRATA_GGML_DIR}/ggml/include ${STRATA_GGML_DIR}/ggml/src) + ${CMAKE_CURRENT_SOURCE_DIR}/include/metal_compat ${STRATA_ROOT}/include ${DS4} ${CMAKE_CURRENT_SOURCE_DIR}/src + ${STRATA_ROOT}/third_party/ggml ${STRATA_GGML_DIR}/ggml/include ${STRATA_GGML_DIR}/ggml/src ${STRATA_GGML_DIR}/ggml/src/ggml-cpu) target_compile_definitions(strata_ds4 PRIVATE STRATA_METAL=1) target_compile_options(strata_ds4 PRIVATE -Wno-unused-parameter -Wno-deprecated-declarations -Wno-implicit-function-declaration) target_link_libraries(strata_ds4 PRIVATE strata_metal_kernels strata_metal_host) diff --git a/metal/include/metal_compat/cublas_v2.h b/metal/include/metal_compat/cublas_v2.h index 50a966fd..8df80513 100644 --- a/metal/include/metal_compat/cublas_v2.h +++ b/metal/include/metal_compat/cublas_v2.h @@ -21,6 +21,7 @@ enum cublasOperation_t { CUBLAS_OP_N = 0, CUBLAS_OP_T = 1, CUBLAS_OP_C = 2 }; enum cublasComputeType_t { CUBLAS_COMPUTE_16F = 64, CUBLAS_COMPUTE_32F = 68, CUBLAS_COMPUTE_32F_FAST_16F = 74 }; enum cublasGemmAlgo_t { CUBLAS_GEMM_DEFAULT = -1, CUBLAS_GEMM_DEFAULT_TENSOR_OP = 99 }; enum cudaDataType_t { CUDA_R_32F = 0, CUDA_R_16F = 2, CUDA_R_16BF = 14, CUDA_R_8F_E4M3 = 28 }; +using cudaDataType = cudaDataType_t; // the engine names it both ways static inline cublasStatus_t cublasCreate(cublasHandle_t* h) { *h = (void*) 1; // the Metal runtime is a singleton: the handle carries no state diff --git a/metal/include/metal_compat/cuda_device_builtins.h b/metal/include/metal_compat/cuda_device_builtins.h index 95c9b9fd..4c990455 100644 --- a/metal/include/metal_compat/cuda_device_builtins.h +++ b/metal/include/metal_compat/cuda_device_builtins.h @@ -1,3 +1,10 @@ +#ifndef __grid_constant__ +#define __grid_constant__ +#endif +#ifndef __device_builtin__ +#define __device_builtin__ +#endif + // cuda_device_builtins.h - the CUDA device built-ins, declared for the HOST compile only. // // The DeepSeek kernels are compiled twice in this port: as C++ here, to enumerate exactly which API the device code uses, @@ -16,10 +23,6 @@ static strata_dim3 threadIdx{0, 0, 0}, blockIdx{0, 0, 0}, blockDim{1, 1, 1}, gri static inline void __syncthreads() {} static inline void __syncwarp(unsigned = 0xffffffffu) {} -static inline unsigned __shfl_down_sync(unsigned, unsigned v, int) { return v; } -static inline unsigned __shfl_xor_sync(unsigned, unsigned v, int) { return v; } -static inline float __shfl_down_sync(unsigned, float v, int) { return v; } -static inline float __shfl_xor_sync(unsigned, float v, int) { return v; } static inline unsigned __ballot_sync(unsigned, int) { return 0; } static inline int __popc(unsigned v) { return __builtin_popcount(v); } static inline int __ffs(unsigned v) { return __builtin_ffs((int) v); } @@ -144,6 +147,19 @@ static inline int __float2int_rd(float a) { return (int) __builtin_floorf(a); } static inline int __float2int_ru(float a) { return (int) __builtin_ceilf(a); } template static inline T __ldg(const T* p) { return *p; } template static inline T __ldcv(const T* p) { return *p; } -static inline unsigned __shfl_up_sync(unsigned, unsigned v, int) { return v; } -static inline float __shfl_up_sync(unsigned, float v, int) { return v; } -static inline unsigned __shfl_sync(unsigned, unsigned v, int) { return v; } + +// shuffles: one template each, so int/unsigned/float/short all bind (CUDA has overloads; a template is the same thing here) +template static inline T __shfl_xor_sync(unsigned, T v, int) { return v; } +template static inline T __shfl_down_sync(unsigned, T v, int) { return v; } +template static inline T __shfl_up_sync(unsigned, T v, int) { return v; } +template static inline T __shfl_sync(unsigned, T v, int) { return v; } + +// the integer multiply-high and the bitwise atomics the sampler uses +static inline unsigned __umulhi(unsigned a, unsigned b) { return (unsigned) (((unsigned long long) a * b) >> 32); } +static inline int __mulhi(int a, int b) { return (int) (((long long) a * b) >> 32); } +static inline unsigned atomicOr(unsigned* p, unsigned v) { const unsigned o = *p; *p = o | v; return o; } +static inline unsigned atomicAnd(unsigned* p, unsigned v) { const unsigned o = *p; *p = o & v; return o; } +static inline unsigned atomicXor(unsigned* p, unsigned v) { const unsigned o = *p; *p = o ^ v; return o; } +static inline unsigned atomicExch(unsigned* p, unsigned v) { const unsigned o = *p; *p = v; return o; } +static inline unsigned atomicInc(unsigned* p, unsigned v) { const unsigned o = *p; *p = (o >= v ? 0 : o + 1); return o; } +static inline unsigned atomicDec(unsigned* p, unsigned v) { const unsigned o = *p; *p = (o == 0 || o > v ? v : o - 1); return o; } diff --git a/metal/include/metal_compat/cuda_fp16.h b/metal/include/metal_compat/cuda_fp16.h index 9ee80d53..1f88d298 100644 --- a/metal/include/metal_compat/cuda_fp16.h +++ b/metal/include/metal_compat/cuda_fp16.h @@ -85,3 +85,15 @@ static inline float __fadd_rn(float a, float b) { return a + b; } static inline float __fmaf_rn(float a, float b, float c) { return a * b + c; } static inline float __frcp_rn(float a) { return 1.0f / a; } static inline float __fsqrt_rn(float a) { return __builtin_sqrtf(a); } + +// the half2 pack/unpack and arithmetic helpers the trellis and vision paths use +static inline __half2 __halves2half2(__half lo, __half hi) { __half2 h; h.x = lo.x; h.y = hi.x; return h; } +static inline __half2 __half2half2(__half v) { __half2 h; h.x = v.x; h.y = v.x; return h; } +static inline __half __low2half(__half2 h) { __half o; o.x = h.x; return o; } +static inline __half __high2half(__half2 h) { __half o; o.x = h.y; return o; } +static inline float __low2float(__half2 h) { return strata_f16_bits_to_f32(h.x); } +static inline float __high2float(__half2 h) { return strata_f16_bits_to_f32(h.y); } +static inline __half2 __hadd2(__half2 a, __half2 b) { return __floats2half2_rn(__half2float(__low2half(a)) + __half2float(__low2half(b)), __half2float(__high2half(a)) + __half2float(__high2half(b))); } +static inline __half2 __hmul2(__half2 a, __half2 b) { return __floats2half2_rn(__half2float(__low2half(a)) * __half2float(__low2half(b)), __half2float(__high2half(a)) * __half2float(__high2half(b))); } +static inline __half2 __hfma2(__half2 a, __half2 b, __half2 c) { return __floats2half2_rn(__half2float(__low2half(a)) * __half2float(__low2half(b)) + __half2float(__low2half(c)), __half2float(__high2half(a)) * __half2float(__high2half(b)) + __half2float(__high2half(c))); } +static inline __half2 __hneg2(__half2 a) { __half2 h; h.x = a.x ^ 0x8000u; h.y = a.y ^ 0x8000u; return h; } diff --git a/metal/include/metal_compat/cuda_launch.h b/metal/include/metal_compat/cuda_launch.h new file mode 100644 index 00000000..25627621 --- /dev/null +++ b/metal/include/metal_compat/cuda_launch.h @@ -0,0 +1,23 @@ +// cuda_launch.h - the <<>> launch syntax, as a call. +// +// A C++ compiler cannot parse CUDA's launch syntax, and the Metal port replaces every launch with a dispatch anyway (the grid +// becomes a threadgroup count, the block a threadgroup size). strata_ds4_launch() is that call: the kernel first, then the +// launch shape, then the kernel's own arguments - every parameter generic, because the shapes vary (dim3, plain ints, sizes, +// and the stream type), and the point of this header is to make the sources parse, not to type-check the port. +// +// Until a kernel has a Metal implementation the call stops the run naming the kernel, so the engine reports the first one it +// needs and the port proceeds one kernel at a time. +#pragma once + +#include +#include + +template +static inline void strata_ds4_launch(K kernel, A&&...) { + static_assert(sizeof(K) > 0, "kernel"); + std::fprintf(stderr, "strata metal: a dsv41 kernel launch has no Metal dispatch yet\n"); + std::abort(); +} + +// the call sites sit inside namespaces whose first argument would win argument-dependent lookup: force the global one +#define strata_ds4_launch(...) ::strata_ds4_launch(__VA_ARGS__) diff --git a/metal/include/metal_compat/cuda_runtime.h b/metal/include/metal_compat/cuda_runtime.h index fd7cb93c..aedad00a 100644 --- a/metal/include/metal_compat/cuda_runtime.h +++ b/metal/include/metal_compat/cuda_runtime.h @@ -1,4 +1,5 @@ // The CUDA function-space qualifiers and the few launch/kernel spellings the shared sources use. On Metal they say +#include "cuda_launch.h" // nothing: a "kernel" here is an MSL function compiled at run time and dispatched by the host runtime, so the qualifiers // are empty and __forceinline__ is plain inline. Part of the metal_compat layer (M5 Max, 2026-10-23). #ifndef __host__ @@ -42,6 +43,7 @@ #endif #include "cuda_device_builtins.h" + #include using std::fmaxf; @@ -93,6 +95,12 @@ inline constexpr unsigned cudaEventDefault = strata::gpu::kEventDefault; inline constexpr unsigned cudaEventDisableTiming = strata::gpu::kEventDisableTiming; inline constexpr unsigned cudaEventBlockingSync = strata::gpu::kEventBlockingSync; inline constexpr unsigned cudaStreamNonBlocking = strata::gpu::kStreamNonBlocking; +enum cudaStreamCaptureStatus { cudaStreamCaptureStatusNone = 0, cudaStreamCaptureStatusActive = 1, cudaStreamCaptureStatusInvalidated = 2 }; +static inline strata::gpu::Error cudaStreamIsCapturing(strata::gpu::Stream, cudaStreamCaptureStatus* st) { + if (st) *st = cudaStreamCaptureStatusNone; + return strata::gpu::kSuccess; +} + enum cudaStreamCaptureMode { cudaStreamCaptureModeGlobal = 0, cudaStreamCaptureModeThreadLocal = 1, cudaStreamCaptureModeRelaxed = 2 }; // (the compute capability is asked by the 0.1.45 Turing defaults in verify.cpp: no answer here, which reads as "not a Turing card") enum cudaDeviceAttr { @@ -196,3 +204,10 @@ inline cudaError_t cudaGraphExecDestroy(cudaGraphExec_t x) { return strata::gpu: inline strata::gpu::Error cudaMemcpy2D(void*, size_t, const void*, size_t, size_t, size_t, strata::gpu::CopyKind) { return strata::gpu::kErrorUnsupported; // cudaMemcpy2D_unimplemented_marker } + +// occupancy query: the Metal runtime decides its own threadgroup limits, so answer "one block" and let the caller size grids +template +static inline strata::gpu::Error cudaOccupancyMaxActiveBlocksPerMultiprocessor(int* n, K&&, int, A&&...) { + if (n) *n = 1; + return strata::gpu::kSuccess; +} diff --git a/metal/include/metal_compat/mma.h b/metal/include/metal_compat/mma.h index 6a4fe461..511071f0 100644 --- a/metal/include/metal_compat/mma.h +++ b/metal/include/metal_compat/mma.h @@ -29,10 +29,10 @@ template std::abort(); } -template inline void fill_fragment(F&, T) { strata_metal_wmma_missing("fill_fragment"); } -template inline void load_matrix_sync(F&, const P*, unsigned, unsigned = 0) { strata_metal_wmma_missing("load_matrix_sync"); } -template inline void mma_sync(F&, const F&, const F&, const F&) { strata_metal_wmma_missing("mma_sync"); } -template inline void store_matrix_sync(P*, const F&, unsigned, layout_t) { strata_metal_wmma_missing("store_matrix_sync"); } +template inline void fill_fragment(A&&...) { strata_metal_wmma_missing("fill_fragment"); } +template inline void load_matrix_sync(A&&...) { strata_metal_wmma_missing("load_matrix_sync"); } +template inline void mma_sync(A&&...) { strata_metal_wmma_missing("mma_sync"); } // variadic: the engine passes four fragments of different types +template inline void store_matrix_sync(A&&...) { strata_metal_wmma_missing("store_matrix_sync"); } } // namespace wmma } // namespace nvcuda diff --git a/metal/src/engine/exl3_legacy_stub.cpp b/metal/src/engine/exl3_legacy_stub.cpp new file mode 100644 index 00000000..7d2cd4ce --- /dev/null +++ b/metal/src/engine/exl3_legacy_stub.cpp @@ -0,0 +1,29 @@ +// metal/src/engine/exl3_legacy_stub.cpp - v1.1.8's EXL3 decode kernels, absent on Metal. +// +// exl3_legacy.cu exists for NVIDIA GPUs before sm_80, which pick it over the newer tiles; nothing on a Mac can select it +// (use_legacy() is false without CUDA), and the 2.25bpw text model does not use EXL3 at all. Leaving the file out of the +// target would break the link for these seven entry points, so they are defined here and stop the run naming themselves - +// the same contract as the stub generator, and a loud failure rather than a silent wrong decode. +#include +#include + +#include // MvJob, MoeArgs, WinArgs + +namespace strata::dsv41k::exl3::legacy { + +[[noreturn]] static void missing(const char* what) { + std::fprintf(stderr, + "strata metal: exl3::legacy::%s has no Metal implementation (v1.1.8's EXL3 kernels; the 2.25bpw text model " + "does not use EXL3)\n", what); + std::abort(); +} + +int launch_errors() { return 0; } +bool prepare(cudaStream_t) { missing("prepare"); } +bool several_ok() { return false; } +bool mv(const MvJob*, int, cudaStream_t) { missing("mv"); } +void moe_gate_up(const MoeArgs&, const float*, float*, cudaStream_t) { missing("moe_gate_up"); } +void moe_down(const MoeArgs&, const float*, const float*, float*, cudaStream_t) { missing("moe_down"); } +bool win_experts(const WinArgs&, cudaStream_t) { missing("win_experts"); } + +} // namespace strata::dsv41k::exl3::legacy diff --git a/src/dsv41/ds4_attn_split.cuh b/src/dsv41/ds4_attn_split.cuh index 959830b0..9def53b8 100644 --- a/src/dsv41/ds4_attn_split.cuh +++ b/src/dsv41/ds4_attn_split.cuh @@ -198,8 +198,8 @@ void sparse_attn_split(const float* q, const uint16_t* win, const uint8_t* ckv, const AttnRows& ar, const float* sink, int heads, int T, float scale, float* out, const AttnSplitScratch& sc, int total_max, cudaStream_t s) { const int nsplit = (total_max + R - 1) / R; - attn_part<<>>(q, win, ckv, ckv_row_bytes, sel, sel_stride, ar, heads, scale, sc.part, sc.ml, sc.nsplit); - attn_merge<<>>(sc.part, sc.ml, sink, heads, sc.nsplit, R, ar, out); + strata_ds4_launch(attn_part, dim3(heads / G, nsplit, T), 256, 0, s, q, win, ckv, ckv_row_bytes, sel, sel_stride, ar, heads, scale, sc.part, sc.ml, sc.nsplit); + strata_ds4_launch(attn_merge, dim3(heads, T), 256, 0, s, sc.part, sc.ml, sink, heads, sc.nsplit, R, ar, out); } } // namespace attnsplit diff --git a/src/dsv41/ds4_gguf.cu b/src/dsv41/ds4_gguf.cu index 5bee5880..a72bcf7c 100644 --- a/src/dsv41/ds4_gguf.cu +++ b/src/dsv41/ds4_gguf.cu @@ -198,7 +198,7 @@ __global__ void __launch_bounds__(kThreads) q8_quant_kernel(const float* __restr } void q8_quant(const float* x, size_t ldx, int rows, int k, int8_t* q, float* d, cudaStream_t s) { const dim3 grid((unsigned) ((k / 32 + kWarps - 1) / kWarps), (unsigned) rows); - q8_quant_kernel<<>>(x, ldx, k, q, d); + strata_ds4_launch(q8_quant_kernel, grid, kThreads, 0, s, x, ldx, k, q, d); } // 8 E2M1 codes (a word of 4 code bytes) -> their values as int8: .x the low nibbles' (values 0..3 of the word's bytes), @@ -1040,14 +1040,14 @@ template void mv_launch(int f, const BfJobs& J, int nj, int max_n, bool vec, cudaStream_t s) { const dim3 grid((unsigned) ((max_n + kWarps - 1) / kWarps), (unsigned) nj); if (f == 1) { - if (vec) mx_mv_kernel<<>>(J); - else mx_mv_kernel<<>>(J); + if (vec) strata_ds4_launch(mx_mv_kernel, grid, kThreads, 0, s, J); + else strata_ds4_launch(mx_mv_kernel, grid, kThreads, 0, s, J); } else if (f == 2) { // (vec here: every row 4-byte aligned, so staged) - if (vec) q8_mv_kernel<<>>(J); - else q8_mv_kernel<<>>(J); + if (vec) strata_ds4_launch(q8_mv_kernel, grid, kThreads, 0, s, J); + else strata_ds4_launch(q8_mv_kernel, grid, kThreads, 0, s, J); } else { - if (vec) bf16_mv_kernel<<>>(J); - else bf16_mv_kernel<<>>(J); + if (vec) strata_ds4_launch(bf16_mv_kernel, grid, kThreads, 0, s, J); + else strata_ds4_launch(bf16_mv_kernel, grid, kThreads, 0, s, J); } } void mv_set(int f, const BfJobs& J, int nj, int max_n, int max_c, bool vec, cudaStream_t s) { @@ -1165,8 +1165,8 @@ void rows(const x3::Mat& m, uint16_t* dst, bool bf16, cudaStream_t s) { const size_t ld = row_stride(m); const size_t total = (size_t) m.n * (size_t) m.k; const unsigned blocks = (unsigned) std::min((total + 255) / 256, 65535); - if (m.fmt == kFmtQ8_0) q8_rows_kernel<<>>((const uint8_t*) m.raw, ld, m.k, m.n, dst, bf16); - else bf16_rows_kernel<<>>((const uint16_t*) m.raw, ld, m.k, m.n, dst, bf16); + if (m.fmt == kFmtQ8_0) strata_ds4_launch(q8_rows_kernel, blocks, 256, 0, s, (const uint8_t*) m.raw, ld, m.k, m.n, dst, bf16); + else strata_ds4_launch(bf16_rows_kernel, blocks, 256, 0, s, (const uint16_t*) m.raw, ld, m.k, m.n, dst, bf16); check("rows"); } @@ -1175,15 +1175,15 @@ namespace { template struct GateUpK { static void run(const MxArgs& m, dim3 grid, cudaStream_t s) { - if (mx_row_bytes(m.n_embd) % 4 == 0) mx_gate_up_kernel<<>>(m); - else mx_gate_up_kernel<<>>(m); + if (mx_row_bytes(m.n_embd) % 4 == 0) strata_ds4_launch(mx_gate_up_kernel, grid, kThreads, 0, s, m); + else strata_ds4_launch(mx_gate_up_kernel, grid, kThreads, 0, s, m); } }; template struct DownK { static void run(const MxArgs& m, dim3 grid, cudaStream_t s) { - if (mx_row_bytes(m.n_ff) % 4 == 0) mx_down_kernel<<>>(m); - else mx_down_kernel<<>>(m); + if (mx_row_bytes(m.n_ff) % 4 == 0) strata_ds4_launch(mx_down_kernel, grid, kThreads, 0, s, m); + else strata_ds4_launch(mx_down_kernel, grid, kThreads, 0, s, m); } }; template