Skip to content

Commit 4909c77

Browse files
committed
ggml : suppress double-promotion warning in GGML_F16x4_REDUCE
This commit adds a cast to `ggml_float` in the `GGML_F16x4_REDUCE` macro to suppress a double-promotion warning. Currently the following warning is generated when compiling the command.wasm example: ```console /whisper-work/ggml/src/ggml-cpu/ggml-cpu.c:1592:5: warning: implicit conversion increases floating-point precision: 'float' to 'ggml_float' (aka 'double') [-Wdouble-promotion] 1592 | GGML_F16_VEC_REDUCE(sumf, sum); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/danbev/work/ai/whisper-work/ggml/src/ggml-cpu/ggml-cpu.c:932:37: note: expanded from macro 'GGML_F16_VEC_REDUCE' 932 | #define GGML_F16_VEC_REDUCE GGML_F16x4_REDUCE | ^ /Users/danbev/work/ai/whisper-work/ggml/src/ggml-cpu/ggml-cpu.c:920:44: note: expanded from macro 'GGML_F16x4_REDUCE' 918 | res = wasm_f32x4_extract_lane(x[0], 0) + \ | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 919 | wasm_f32x4_extract_lane(x[0], 1) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 920 | wasm_f32x4_extract_lane(x[0], 2) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ 921 | wasm_f32x4_extract_lane(x[0], 3); \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /whisper-work/ggml/src/ggml-cpu/ggml-cpu.c:1640:9: warning: implicit conversion increases floating-point precision: 'float' to 'ggml_float' (aka 'double') [-Wdouble-promotion] 1640 | GGML_F16_VEC_REDUCE(sumf[k], sum[k]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Users/danbev/work/ai/whisper-work/ggml/src/ggml-cpu/ggml-cpu.c:932:37: note: expanded from macro 'GGML_F16_VEC_REDUCE' 932 | #define GGML_F16_VEC_REDUCE GGML_F16x4_REDUCE | ^ /Users/danbev/work/ai/whisper-work/ggml/src/ggml-cpu/ggml-cpu.c:920:44: note: expanded from macro 'GGML_F16x4_REDUCE' 918 | res = wasm_f32x4_extract_lane(x[0], 0) + \ | ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 919 | wasm_f32x4_extract_lane(x[0], 1) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 920 | wasm_f32x4_extract_lane(x[0], 2) + \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~ 921 | wasm_f32x4_extract_lane(x[0], 3); \ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated. ``` wasm_f32x4_extract_lane returns a 32-bit float and this is what the addition is performed on. But there is an implicit conversion from 32-bit float to 64-bit double when the result is assigned to `res`, which is of type `ggml_float`. My understanding here is that this is intentional and adding a cast to `ggml_float` should suppress the warning.
1 parent 6fb515d commit 4909c77

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -901,24 +901,24 @@ inline static void __wasm_f16x4_store(ggml_fp16_t * p, v128_t x) {
901901
#define GGML_F16x4_FMA GGML_F32x4_FMA
902902
#define GGML_F16x4_ADD wasm_f32x4_add
903903
#define GGML_F16x4_MUL wasm_f32x4_mul
904-
#define GGML_F16x4_REDUCE(res, x) \
905-
{ \
906-
int offset = GGML_F16_ARR >> 1; \
907-
for (int i = 0; i < offset; ++i) { \
908-
x[i] = wasm_f32x4_add(x[i], x[offset+i]); \
909-
} \
910-
offset >>= 1; \
911-
for (int i = 0; i < offset; ++i) { \
912-
x[i] = wasm_f32x4_add(x[i], x[offset+i]); \
913-
} \
914-
offset >>= 1; \
915-
for (int i = 0; i < offset; ++i) { \
916-
x[i] = wasm_f32x4_add(x[i], x[offset+i]); \
917-
} \
918-
res = wasm_f32x4_extract_lane(x[0], 0) + \
919-
wasm_f32x4_extract_lane(x[0], 1) + \
920-
wasm_f32x4_extract_lane(x[0], 2) + \
921-
wasm_f32x4_extract_lane(x[0], 3); \
904+
#define GGML_F16x4_REDUCE(res, x) \
905+
{ \
906+
int offset = GGML_F16_ARR >> 1; \
907+
for (int i = 0; i < offset; ++i) { \
908+
x[i] = wasm_f32x4_add(x[i], x[offset+i]); \
909+
} \
910+
offset >>= 1; \
911+
for (int i = 0; i < offset; ++i) { \
912+
x[i] = wasm_f32x4_add(x[i], x[offset+i]); \
913+
} \
914+
offset >>= 1; \
915+
for (int i = 0; i < offset; ++i) { \
916+
x[i] = wasm_f32x4_add(x[i], x[offset+i]); \
917+
} \
918+
res = (ggml_float) (wasm_f32x4_extract_lane(x[0], 0) + \
919+
wasm_f32x4_extract_lane(x[0], 1) + \
920+
wasm_f32x4_extract_lane(x[0], 2) + \
921+
wasm_f32x4_extract_lane(x[0], 3)); \
922922
}
923923

924924
#define GGML_F16_VEC GGML_F16x4

0 commit comments

Comments
 (0)