Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

1.6 KB
Raw Blame
// SPDX-License-Identifier: MIT
// Adapted from Gufo (github.com/gufo-org/gufo, 07e1191, MIT, Copyright (c) 2026 Gufo contributors), path
// src/models/qwen38_flash_next/kernels/rocm/mmq/quantize.hpp, itself adapted from llama.cpp 5c0e946 ggml/src/ggml-cuda
// (github.com/ggml-org/llama.cpp, MIT, Copyright (c) 2023-2026 The ggml authors). See THIRD_PARTY_NOTICES.md.
// Changes: none.
#pragma once

#include "common.hpp"
#include "mmq.hpp"

#include <cstdint>

#define HIP_QUANTIZE_BLOCK_SIZE     256
#define HIP_QUANTIZE_BLOCK_SIZE_MMQ 128

static_assert(MATRIX_ROW_PADDING %    HIP_QUANTIZE_BLOCK_SIZE      == 0, "Risk of out-of-bounds access.");
static_assert(MATRIX_ROW_PADDING % (4*HIP_QUANTIZE_BLOCK_SIZE_MMQ) == 0, "Risk of out-of-bounds access.");

void quantize_row_q8_1_hip(
        const float * x, const int32_t * ids, void * vy,
        ggml_type type_src0, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
        int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3, hipStream_t stream);

// quantize_row_q8_1_hip for `slots` one-expert rows, written in expert
// order: row r of vy is slot slot_of_rank[r], whose expert is sorted_ids[r].
void quantize_row_q8_1_by_expert_hip(
        const float * x, const int32_t * ids, void * vy, int32_t * sorted_ids,
        int32_t * slot_of_rank, int64_t ne00, int64_t s01, int64_t ne0,
        int slots, hipStream_t stream);

void quantize_mmq_q8_1_hip(
        const float * x, const int32_t * ids, void * vy,
        ggml_type type_src0, int64_t ne00, int64_t s01, int64_t s02, int64_t s03,
        int64_t ne0, int64_t ne1, int64_t ne2, int64_t ne3, hipStream_t stream);