Skip to content
Closed
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 ggml/src/ggml-cpu/ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <cfloat>
#include <cmath>

extern "C" void ggml_set_turbo3_wht_group_size(int gs);

// ggml_compute_forward_dup

static void ggml_compute_forward_dup_same_cont(
Expand Down Expand Up @@ -4928,10 +4930,9 @@ static void ggml_compute_forward_set_rows_f32(

// For turbo types: communicate WHT group size to the quantize function via global
if (dst->type == GGML_TYPE_TURBO3_0 || dst->type == GGML_TYPE_TURBO4_0 || dst->type == GGML_TYPE_TURBO2_0) {
extern int turbo3_cpu_wht_group_size;
int gs = 0;
memcpy(&gs, dst->op_params, sizeof(int));
turbo3_cpu_wht_group_size = (gs == 64 || gs == 128) ? gs : 0;
ggml_set_turbo3_wht_group_size((gs == 64 || gs == 128) ? gs : 0);
}

for (int64_t i03 = 0; i03 < ne03; ++i03) {
Expand Down
32 changes: 17 additions & 15 deletions ggml/src/ggml-cuda/turbo-innerq.cuh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#pragma once

// TurboQuant InnerQ per-channel equalization — cross-TU shared state
// The host-side state lives in turbo-innerq.cu; device-side state is per-TU
// in turbo-quant.cuh (only set-rows.cu needs device access).
// TurboQuant InnerQ per-channel equalization - cross-TU shared state

#define INNERQ_MAX_CHANNELS 128

// Host-side shared state (defined in turbo-innerq.cu)
extern bool g_innerq_finalized;
extern float g_innerq_scale_inv_host[INNERQ_MAX_CHANNELS];

// Called from set-rows.cu after InnerQ finalization to publish scale_inv
void turbo_innerq_publish(const float * scale_inv, int group_size);
// DLL export/import macro
#if defined(_WIN32)
# if defined(GGML_BACKEND_BUILD)
# define TURBO_INNERQ_API __declspec(dllexport)
# else
# define TURBO_INNERQ_API __declspec(dllimport)
# endif
#else
# define TURBO_INNERQ_API
#endif

// Called from llama-kv-cache.cpp (or equivalent) to check if tensor needs update
// Returns true if there are new scale_inv values to upload
bool turbo_innerq_needs_tensor_update(void);
// Host-side shared state (defined in turbo-innerq.cu)
extern TURBO_INNERQ_API bool g_innerq_finalized;
extern TURBO_INNERQ_API float g_innerq_scale_inv_host[INNERQ_MAX_CHANNELS];

// Called after tensor update to clear the flag
void turbo_innerq_mark_tensor_updated(void);
TURBO_INNERQ_API void turbo_innerq_publish(const float * scale_inv, int group_size);
TURBO_INNERQ_API bool turbo_innerq_needs_tensor_update(void);
TURBO_INNERQ_API void turbo_innerq_mark_tensor_updated(void);
8 changes: 8 additions & 0 deletions ggml/src/ggml-turbo-quant.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include "ggml-common.h"
#include "ggml-impl.h"

#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#include <string.h>
#include <assert.h>
Expand All @@ -18,6 +21,11 @@
/* Global: WHT group size for CPU quantize path (set by CPU SET_ROWS handler) */
int turbo3_cpu_wht_group_size = 0;

/* Setter called from CPU backend (DLL boundary safe) */
GGML_API void ggml_set_turbo3_wht_group_size(int gs) {
turbo3_cpu_wht_group_size = gs;
}

/* ---------- constants ---------- */

#define TURBO_SEED_ROTATION 42
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ target_include_directories(llama PUBLIC ../include)
target_compile_features (llama PRIVATE cxx_std_17) # don't bump

target_link_libraries(llama PUBLIC ggml)
if (GGML_CUDA)
target_link_libraries(llama PRIVATE ggml-cuda)
target_compile_definitions(llama PRIVATE GGML_USE_CUDA)
endif()

if (BUILD_SHARED_LIBS)
set_target_properties(llama PROPERTIES POSITION_INDEPENDENT_CODE ON)
Expand Down
6 changes: 1 addition & 5 deletions src/llama-kv-cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
#endif

#ifdef GGML_USE_CUDA
extern bool g_innerq_finalized;
extern float g_innerq_scale_inv_host[INNERQ_MAX_CHANNELS];
extern bool turbo_innerq_needs_tensor_update(void);
extern void turbo_innerq_mark_tensor_updated(void);
#include "../ggml/src/ggml-cuda/turbo-innerq.cuh"
#else
static bool g_innerq_finalized = false;
static float g_innerq_scale_inv_host[INNERQ_MAX_CHANNELS] = {};
static bool turbo_innerq_needs_tensor_update(void) { return false; }
static void turbo_innerq_mark_tensor_updated(void) {}
#endif

//
// llama_kv_cache
//
Expand Down