This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/libr4d/r4d_q8.h
T
Deadcode 1e968f6e1d radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves
  every shipped container
- Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime
- /v1/messages works with Claude Code as it ships (gearwave00001)
- a long agent conversation keeps its cached history when the client rewrites its last turn
  (manueloverride)
- a stream's first event goes out with the first token, so llama-benchy measures prefill right
- opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42)
- four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b)
- NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA
  adapters (baKon)
- many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool
  arguments and the CPU's vision and audio encoders
- plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
2026-10-16 18:25:18 +02:00

40 lines
1.9 KiB
C++

// r4d_q8.h -- the 8-bit activation codes the trunk GEMMs read, written by every quantising producer:
// E4M3 for the fp8a8 GEMMs, int8 for their int8 twins (gemm_i8a8_*). One scale per (row, 128
// columns); only the largest code and the conversion differ.
//
// E4M3: scale `amax * (1 / 448)`, clamp to +-448, two packed conversions. The clamp is required:
// v_cvt_pk_fp8_f32 returns NaN for out-of-range input instead of saturating, and
// `amax * (1 / scale)` can land an ulp above 448.
//
// Int8: as quant_act_i8g (r4d_quant_act_fp8.hip), scale `amax * (1 / 127)` and round-to-nearest-
// even into -127..127, so a fused producer writes the same codes as the standalone quantiser.
#pragma once
#include <hip/hip_runtime.h>
#include <cstdint>
template <bool I8>
__device__ __forceinline__ constexpr float q8_top() {
return I8 ? 127.0f : 448.0f;
}
// Four values times `inv` (the reciprocal of the scale), as four codes in one dword, value 0 in
// the low byte.
template <bool I8>
__device__ __forceinline__ uint32_t q8_pack4(float a, float b, float c, float d, float inv) {
if constexpr (I8) {
const int ia = (int)rintf(fminf(fmaxf(a * inv, -127.0f), 127.0f));
const int ib = (int)rintf(fminf(fmaxf(b * inv, -127.0f), 127.0f));
const int ic = (int)rintf(fminf(fmaxf(c * inv, -127.0f), 127.0f));
const int id = (int)rintf(fminf(fmaxf(d * inv, -127.0f), 127.0f));
return ((uint32_t)ia & 0xFFu) | (((uint32_t)ib & 0xFFu) << 8) |
(((uint32_t)ic & 0xFFu) << 16) | (((uint32_t)id & 0xFFu) << 24);
} else {
int pk = 0;
pk = __builtin_amdgcn_cvt_pk_fp8_f32(fminf(fmaxf(a * inv, -448.0f), 448.0f),
fminf(fmaxf(b * inv, -448.0f), 448.0f), pk, false);
pk = __builtin_amdgcn_cvt_pk_fp8_f32(fminf(fmaxf(c * inv, -448.0f), 448.0f),
fminf(fmaxf(d * inv, -448.0f), 448.0f), pk, true);
return (uint32_t)pk;
}
}