Skip to content

Commit 51f9bc5

Browse files
committed
ggml : prefix lookup tables with ggml_
1 parent 6022bf4 commit 51f9bc5

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

Diff for: ggml-impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static inline ggml_fp16_t ggml_compute_fp32_to_fp16(float f) {
208208

209209
// precomputed f32 table for f16 (256 KB)
210210
// defined in ggml.c, initialized in ggml_init()
211-
extern float table_f32_f16[1 << 16];
211+
extern float ggml_table_f32_f16[1 << 16];
212212

213213
// On ARM NEON, it's quicker to directly convert x -> x instead of calling into ggml_lookup_fp16_to_fp32,
214214
// so we define GGML_FP16_TO_FP32 and GGML_FP32_TO_FP16 elsewhere for NEON.
@@ -218,7 +218,7 @@ extern float table_f32_f16[1 << 16];
218218
inline static float ggml_lookup_fp16_to_fp32(ggml_fp16_t f) {
219219
uint16_t s;
220220
memcpy(&s, &f, sizeof(uint16_t));
221-
return table_f32_f16[s];
221+
return ggml_table_f32_f16[s];
222222
}
223223

224224
#define GGML_FP16_TO_FP32(x) ggml_lookup_fp16_to_fp32(x)

Diff for: ggml.c

+22-22
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,19 @@ typedef double ggml_float;
232232
//
233233

234234
// precomputed gelu table for f16 (128 KB)
235-
static ggml_fp16_t table_gelu_f16[1 << 16];
235+
static ggml_fp16_t ggml_tablegelu_f16[1 << 16];
236236

237237
// precomputed quick gelu table for f16 (128 KB)
238-
static ggml_fp16_t table_gelu_quick_f16[1 << 16];
238+
static ggml_fp16_t ggml_tablegelu_quick_f16[1 << 16];
239239

240240
// precomputed silu table for f16 (128 KB)
241-
static ggml_fp16_t table_silu_f16[1 << 16];
241+
static ggml_fp16_t ggml_tablesilu_f16[1 << 16];
242242

243243
// precomputed exp table for f16 (128 KB)
244-
static ggml_fp16_t table_exp_f16[1 << 16];
244+
static ggml_fp16_t ggml_tableexp_f16[1 << 16];
245245

246246
// precomputed f32 table for f16 (256 KB) (ggml-impl.h)
247-
float table_f32_f16[1 << 16];
247+
float ggml_tablef32_f16[1 << 16];
248248

249249
// note: do not use these inside ggml.c
250250
// these are meant to be used via the ggml.h API
@@ -1363,7 +1363,7 @@ inline static float ggml_gelu_f32(float x) {
13631363
inline static void ggml_vec_gelu_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
13641364
const uint16_t * i16 = (const uint16_t *) x;
13651365
for (int i = 0; i < n; ++i) {
1366-
y[i] = table_gelu_f16[i16[i]];
1366+
y[i] = ggml_tablegelu_f16[i16[i]];
13671367
}
13681368
}
13691369

@@ -1373,7 +1373,7 @@ inline static void ggml_vec_gelu_f32(const int n, float * y, const float * x) {
13731373
for (int i = 0; i < n; ++i) {
13741374
ggml_fp16_t fp16 = GGML_FP32_TO_FP16(x[i]);
13751375
memcpy(&t, &fp16, sizeof(uint16_t));
1376-
y[i] = GGML_FP16_TO_FP32(table_gelu_f16[t]);
1376+
y[i] = GGML_FP16_TO_FP32(ggml_tablegelu_f16[t]);
13771377
}
13781378
}
13791379
#else
@@ -1391,7 +1391,7 @@ inline static float ggml_gelu_quick_f32(float x) {
13911391
//inline static void ggml_vec_gelu_quick_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
13921392
// const uint16_t * i16 = (const uint16_t *) x;
13931393
// for (int i = 0; i < n; ++i) {
1394-
// y[i] = table_gelu_quick_f16[i16[i]];
1394+
// y[i] = ggml_tablegelu_quick_f16[i16[i]];
13951395
// }
13961396
//}
13971397

@@ -1401,7 +1401,7 @@ inline static void ggml_vec_gelu_quick_f32(const int n, float * y, const float *
14011401
for (int i = 0; i < n; ++i) {
14021402
ggml_fp16_t fp16 = GGML_FP32_TO_FP16(x[i]);
14031403
memcpy(&t, &fp16, sizeof(uint16_t));
1404-
y[i] = GGML_FP16_TO_FP32(table_gelu_quick_f16[t]);
1404+
y[i] = GGML_FP16_TO_FP32(ggml_tablegelu_quick_f16[t]);
14051405
}
14061406
}
14071407
#else
@@ -1420,7 +1420,7 @@ inline static float ggml_silu_f32(float x) {
14201420
//inline static void ggml_vec_silu_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
14211421
// const uint16_t * i16 = (const uint16_t *) x;
14221422
// for (int i = 0; i < n; ++i) {
1423-
// y[i] = table_silu_f16[i16[i]];
1423+
// y[i] = ggml_tablesilu_f16[i16[i]];
14241424
// }
14251425
//}
14261426

@@ -1430,7 +1430,7 @@ inline static void ggml_vec_silu_f32(const int n, float * y, const float * x) {
14301430
for (int i = 0; i < n; ++i) {
14311431
ggml_fp16_t fp16 = GGML_FP32_TO_FP16(x[i]);
14321432
memcpy(&t, &fp16, sizeof(uint16_t));
1433-
y[i] = GGML_FP16_TO_FP32(table_silu_f16[t]);
1433+
y[i] = GGML_FP16_TO_FP32(ggml_tablesilu_f16[t]);
14341434
}
14351435
}
14361436
#else
@@ -2146,11 +2146,11 @@ struct ggml_context * ggml_init(struct ggml_init_params params) {
21462146
for (int i = 0; i < (1 << 16); ++i) {
21472147
uint16_t ui = i;
21482148
memcpy(&ii, &ui, sizeof(ii));
2149-
const float f = table_f32_f16[i] = GGML_COMPUTE_FP16_TO_FP32(ii);
2150-
table_gelu_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_f32(f));
2151-
table_gelu_quick_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_quick_f32(f));
2152-
table_silu_f16[i] = GGML_FP32_TO_FP16(ggml_silu_f32(f));
2153-
table_exp_f16[i] = GGML_FP32_TO_FP16(expf(f));
2149+
const float f = ggml_tablef32_f16[i] = GGML_COMPUTE_FP16_TO_FP32(ii);
2150+
ggml_tablegelu_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_f32(f));
2151+
ggml_tablegelu_quick_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_quick_f32(f));
2152+
ggml_tablesilu_f16[i] = GGML_FP32_TO_FP16(ggml_silu_f32(f));
2153+
ggml_tableexp_f16[i] = GGML_FP32_TO_FP16(expf(f));
21542154
}
21552155

21562156
const uint64_t t_end = ggml_time_us(); UNUSED(t_end);
@@ -10513,7 +10513,7 @@ static void ggml_compute_forward_soft_max_f32(
1051310513
// const float val = (sp[i] == -INFINITY) ? 0.0 : exp(sp[i] - max);
1051410514
ggml_fp16_t s = GGML_FP32_TO_FP16(sp[i] - max);
1051510515
memcpy(&scvt, &s, sizeof(scvt));
10516-
const float val = GGML_FP16_TO_FP32(table_exp_f16[scvt]);
10516+
const float val = GGML_FP16_TO_FP32(ggml_tableexp_f16[scvt]);
1051710517
sum += (ggml_float)val;
1051810518
dp[i] = val;
1051910519
}
@@ -12802,7 +12802,7 @@ static void ggml_compute_forward_flash_attn_f32(
1280212802
#else
1280312803
ggml_fp16_t s = GGML_FP32_TO_FP16(SS[j] - max);
1280412804
memcpy(&scvt[j], &s, sizeof(uint16_t));
12805-
const float val = GGML_FP16_TO_FP32(table_exp_f16[scvt[j]]);
12805+
const float val = GGML_FP16_TO_FP32(ggml_tableexp_f16[scvt[j]]);
1280612806
#endif
1280712807
sump[j] += (ggml_float)val;
1280812808
SS[j] = val;
@@ -13004,7 +13004,7 @@ static void ggml_compute_forward_flash_attn_f16(
1300413004
} else {
1300513005
ggml_fp16_t s = GGML_FP32_TO_FP16(SS[j] - max);
1300613006
memcpy(&scvt[j], &s, sizeof(uint16_t));
13007-
const float val = GGML_FP16_TO_FP32(table_exp_f16[scvt[j]]);
13007+
const float val = GGML_FP16_TO_FP32(ggml_tableexp_f16[scvt[j]]);
1300813008
sump[j] += (ggml_float)val;
1300913009
SS[j] = val;
1301013010
}
@@ -13455,7 +13455,7 @@ static void ggml_compute_forward_flash_attn_back_f32(
1345513455
#else
1345613456
ggml_fp16_t s = GGML_FP32_TO_FP16(SR[j] - max);
1345713457
memcpy(&scvt[j], &s, sizeof(uint16_t));
13458-
const float val = GGML_FP16_TO_FP32(table_exp_f16[scvt[j]]);
13458+
const float val = GGML_FP16_TO_FP32(ggml_tableexp_f16[scvt[j]]);
1345913459
#endif
1346013460
sump[j] += (ggml_float)val;
1346113461
SW[j] = val;
@@ -14205,7 +14205,7 @@ static void ggml_compute_forward_cross_entropy_loss_f32(
1420514205
#else
1420614206
ggml_fp16_t s = GGML_FP32_TO_FP16(s0[i] - max);
1420714207
memcpy(&scvt, &s, sizeof(scvt));
14208-
const float val = GGML_FP16_TO_FP32(table_exp_f16[scvt]);
14208+
const float val = GGML_FP16_TO_FP32(ggml_tableexp_f16[scvt]);
1420914209
#endif
1421014210
sum += (ggml_float)val;
1421114211
st[i] = val;
@@ -14319,7 +14319,7 @@ static void ggml_compute_forward_cross_entropy_loss_back_f32(
1431914319
#else
1432014320
ggml_fp16_t s = GGML_FP32_TO_FP16(s0[i] - max);
1432114321
memcpy(&scvt, &s, sizeof(scvt));
14322-
const float val = GGML_FP16_TO_FP32(table_exp_f16[scvt]);
14322+
const float val = GGML_FP16_TO_FP32(ggml_tableexp_f16[scvt]);
1432314323
#endif
1432414324
sum += (ggml_float)val;
1432514325
ds0[i] = val;

0 commit comments

Comments
 (0)