Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/models/inkling.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ only part of the experts was not measured. Three runs each, 32 tokens written af
On an RTX 20 card (Turing) the engine multiplies the experts as halves while it reads a prompt. With `--prompt-int8`
it multiplies them on the int8 tensor cores, as it does on RTX 30 and newer, with the prompt's numbers rounded to 8
bits with a scale for every 32 (`STRATA_PF_I8MMA=0` turns the int8 products off on every card). It is not the
default because it moves the answers more: measured on a Quadro RTX 4000 (8 GB),
default on RTX 20 because it moves the answers more: measured on a Quadro RTX 4000 (8 GB),
which holds a third to two thirds of the experts, written after the halves' greedy answers to three prompts of 302
to 8,192 tokens, 64 tokens each, with three files (the two below and an IQ3_S), it gives the same most likely token
at 560 of the 576 steps (97.2%). Prompt speed on that card, three runs each:
at 560 of the 576 steps (97.2%). On an AMD RDNA3 or RDNA4 card (HIP) the same kernel is the default, and
`--no-prompt-int8` turns it off. Prompt speed on the RTX 20 card, three runs each:

| Size | Prompt | Halves (the default on RTX 20) | int8 (`--prompt-int8`) |
| --- | ---: | ---: | ---: |
Expand Down
3 changes: 2 additions & 1 deletion engine/include/strata/hip_compat/intrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ __device__ __forceinline__ int dp4a(int a, int b, int c) {
// both packed operands signed to preserve CUDA __dp4a semantics; keep the
// portable path for other HIP compilers/targets.
return __builtin_amdgcn_sudot4(true, a, true, b, c, false);
#elif (defined(__gfx1030__) || defined(__gfx1031__) || defined(__gfx1032__)) && __has_builtin(__builtin_amdgcn_sdot4)
#elif (defined(__gfx1030__) || defined(__gfx1031__) || defined(__gfx1032__) || defined(__gfx1033__) || defined(__gfx1034__) || \
defined(__gfx1035__) || defined(__gfx1036__)) && __has_builtin(__builtin_amdgcn_sdot4)
// RDNA2 has no sudot4 (that is gfx11+), but it has the plain signed v_dot4_i32_i8 (dot1-insts): the same
// signed x signed byte products accumulated modulo 2^32, no clamp.
return __builtin_amdgcn_sdot4(a, b, c, false);
Expand Down
7 changes: 7 additions & 0 deletions engine/include/strata/kernels/gfx_arch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ inline bool gfx_arch_is_gfx11_wmma(const char* gcn) {
/// defined(__gfx1201__)`): the R9700 / 9070 (XT) are gfx1201, the 9060 (XT) gfx1200.
inline bool gfx_arch_is_gfx12_wmma(const char* gcn) { return gfx_arch_is(gcn, "gfx1200") || gfx_arch_is(gcn, "gfx1201"); }

/// RDNA2 (RX 6000: gfx1030 RX 6800 / 6900, gfx1031 RX 6700, gfx1032 RX 6600, gfx1033-gfx1036 the APUs and the
/// smallest parts): the signed dot4 (v_dot4_i32_i8), no matrix cores.
inline bool gfx_arch_is_rdna2(const char* gcn) {
return gfx_arch_is(gcn, "gfx1030") || gfx_arch_is(gcn, "gfx1031") || gfx_arch_is(gcn, "gfx1032") || gfx_arch_is(gcn, "gfx1033") ||
gfx_arch_is(gcn, "gfx1034") || gfx_arch_is(gcn, "gfx1035") || gfx_arch_is(gcn, "gfx1036");
}

/// Strix Halo (Ryzen AI Max, RDNA3.5): the part the gfx1151 defaults (docs/STRIX_HALO.md) are measured on.
inline bool gfx_arch_is_gfx1151(const char* gcn) { return gfx_arch_is(gcn, "gfx1151"); }

Expand Down
9 changes: 5 additions & 4 deletions engine/include/strata/kernels/iq_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,17 @@ bool gemm_iq_f16_grouped(int ty, const void* W, size_t expert_bytes, int n_out,
const int32_t* bounds, int n_experts, int max_rows, float* Y, int ldy, void* stream);
/// The same products on the int8 tensor cores, for matrices of any number of rows (src/kernels/cuda/i8_mma.cuh):
/// the weights decoded to int8 a tile at a time, the activations int8 with a scale per 32 values, FP32 sums.
/// CUDA, Ampere and newer (Turing with gemm_iq_i8_turing()). gemm_iq_i8_takes: the current card runs it for K columns of type ty (K a multiple of 256,
/// CUDA, Ampere and newer (Turing with gemm_iq_i8_turing()); HIP, RDNA3 and RDNA4 (gfx11 / gfx12 WMMA) and RDNA2 (gfx103x
/// dot4), the same sums and so the same bits; on by default there, off with gemm_iq_i8_turing(false)). gemm_iq_i8_takes: the current card runs it for K columns of type ty (K a multiple of 256,
/// or of 32 for a type of 32-value blocks, MXFP4's too, of 64 for NVFP4; STRATA_PF_I8MMA=0 turns it off). gemm_iq_i8_quantize: row i of xq = row ids[i] of x (row i without ids), ld
/// floats a row; xq holds rows * K * 5 / 4 bytes, 16-byte aligned. gemm_iq_i8_grouped: matrix e (n_out rows,
/// mat_bytes apart) times rows bounds[e]..bounds[e+1] of an xq of total_rows rows; row i's products go to row ids[i]
/// of Y (row i without ids). With `from`, row i is row from[i] of xq. With `at` (n_mats values on the device,
/// multiples of 16), matrix e is at W + at[e] in place of W + e * mat_bytes. false: not launched.
bool gemm_iq_i8_takes(int ty, int K);
/// The int8 kernel on Turing (sm_75) too, from now on in this process, by m8n8k16 MMAs: the same sums as on Ampere.
/// Off by default, where Turing's products are the halves' (mmq_own.cu); a model's engine turns it on (Inkling 2
/// with --prompt-int8).
/// The int8 kernel on Turing (sm_75) by m8n8k16 MMAs, or not on HIP's RDNA3 / RDNA4, from now on in this process: the
/// same sums as on Ampere. Off by default on Turing, where the products are the halves' (mmq_own.cu), and on by
/// default on HIP; a model's engine says (Inkling 2: --prompt-int8 on Turing, --no-prompt-int8 on HIP).
void gemm_iq_i8_turing(bool on);
/// The int8 kernel also takes type ty, from now on in this process (on false: no longer), for a type it takes only when
/// asked: IQ1_S (19) and MXFP4 (39). A model's engine asks for them at load (Inkling 2: IQ1_S with
Expand Down
8 changes: 6 additions & 2 deletions engine/src/kernels/cuda/i8_mma.cu
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
// include/strata/kernels/iq_kernels.hpp; the kernel is i8_mma.cuh). A file of their own so that a change to them
// builds without iq_kernels.cu. The weight sub-blocks are decoded by i8_expert.cuh, which this file includes as
// iq_kernels.cu does, in an anonymous namespace (only what i8_mma.cuh instantiates of it is compiled here).
// CUDA only: a HIP build compiles this file empty and takes iq_kernels.cu's stubs.
#if !defined(__HIPCC__)
// HIP: RDNA3 and RDNA4 (i8_mma.cuh's i8m_wmma); a gfx906 build (wave64) compiles this file empty and takes
// iq_kernels.cu's stubs.
#if !defined(STRATA_HIP_GFX906)
#include "strata/kernels/iq_kernels.hpp"
#include "strata/kernels/dp4a.hpp"
#if defined(__HIPCC__)
#include "strata/kernels/gfx_arch.hpp"
#endif

#include <cuda_fp16.h>
#include <cuda_runtime.h>
Expand Down
Loading
Loading