ggml : update ggml_prec specification (#26675)

* ggml : update ggml_prec specification

[no ci]

* cont : add GGML_PREC_BF16

* cont : rework API

* cont : use new API

* cont : swap arg order

* cont : support for MUL_MAT_ID

* cont : fix accidental remove of "break;"

* cont : return bools, add doc TAG_GGML_PREC, clean-up

* cont : add search tag

* cont : ws
This commit is contained in:
Georgi Gerganov
2026-09-08 09:06:24 +03:00
committed by GitHub
parent 9dcf84e5ae
commit 5a6caa05fc
10 changed files with 134 additions and 22 deletions
+12
View File
@@ -160,6 +160,18 @@ static float ggml_get_op_params_f32(const struct ggml_tensor * tensor, uint32_t
return ((const float *)(tensor->op_params))[i];
}
// [TAG_GGML_PREC]
// - GGML_OP_MUL_MAT
// 0 - acc
// 1 - hint
// 2 - src0 precision
// 3 - src1 precision
//
// - GGML_OP_MUL_MAT_ID
// 0 - acc
// 1 - hint
// 2 - src0 precision
// 3 - src1 precision
static void ggml_set_op_params_i32(struct ggml_tensor * tensor, uint32_t i, int32_t value) {
assert(i < GGML_MAX_OP_PARAMS / sizeof(int32_t));
((int32_t *)(tensor->op_params))[i] = value;
+51
View File
@@ -3277,6 +3277,57 @@ struct ggml_tensor * ggml_l2_norm_inplace(
return ggml_l2_norm_impl(ctx, a, eps, true);
}
// ggml_prec
bool ggml_prec_set_acc(
struct ggml_tensor * a,
enum ggml_prec prec) {
switch (a->op) {
case GGML_OP_MUL_MAT:
case GGML_OP_MUL_MAT_ID:
{
const int32_t prec_i32 = (int32_t) prec;
ggml_set_op_params_i32(a, 0, prec_i32);
}
break;
case GGML_OP_FLASH_ATTN_EXT:
{
const int32_t prec_i32 = (int32_t) prec;
ggml_set_op_params_i32(a, 3, prec_i32);
}
break;
default:
return false;
};
return true;
}
bool ggml_prec_set_src(
struct ggml_tensor * a,
enum ggml_prec prec,
int idx) {
GGML_ASSERT(idx >= 0 && idx < GGML_MAX_SRC);
switch (a->op) {
case GGML_OP_MUL_MAT:
case GGML_OP_MUL_MAT_ID:
{
if (idx != 1) {
return false;
}
const int32_t prec_i32 = (int32_t) prec;
ggml_set_op_params_i32(a, 2 + idx, prec_i32);
}
break;
default:
return false;
};
return true;
}
// ggml_mul_mat
static inline bool ggml_can_mul_mat(const struct ggml_tensor * t0, const struct ggml_tensor * t1) {