Skip to content

Commit 3afbe43

Browse files
committed
More explicit casts to fix clang warnings (incomplete)
1 parent ac2056b commit 3afbe43

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

ggml.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ static void quantize_row_q4_0_reference(const float * restrict x, void * restric
479479
const float v0 = x[i*QK + l + 0]*id;
480480
const float v1 = x[i*QK + l + 1]*id;
481481

482-
const uint8_t vi0 = ((int8_t) (round(v0))) + 8;
483-
const uint8_t vi1 = ((int8_t) (round(v1))) + 8;
482+
const uint8_t vi0 = (int8_t)roundf(v0) + 8;
483+
const uint8_t vi1 = (int8_t)roundf(v1) + 8;
484484

485485
assert(vi0 >= 0 && vi0 < 16);
486486
assert(vi1 >= 0 && vi1 < 16);
@@ -747,8 +747,8 @@ void quantize_row_q4_1(const float * restrict x, void * restrict y, int k) {
747747
const float v0 = (x[i*QK + l + 0] - min)*id;
748748
const float v1 = (x[i*QK + l + 1] - min)*id;
749749

750-
const uint8_t vi0 = round(v0);
751-
const uint8_t vi1 = round(v1);
750+
const uint8_t vi0 = roundf(v0);
751+
const uint8_t vi1 = roundf(v1);
752752

753753
assert(vi0 >= 0 && vi0 < 16);
754754
assert(vi1 >= 0 && vi1 < 16);
@@ -2173,16 +2173,16 @@ inline static void ggml_vec_scale_f32(const int n, float * y, const float v) {
21732173
#endif
21742174
}
21752175

2176-
inline static void ggml_vec_norm_f32 (const int n, float * s, const float * x) { ggml_vec_dot_f32(n, s, x, x); *s = sqrt(*s); }
2176+
inline static void ggml_vec_norm_f32 (const int n, float * s, const float * x) { ggml_vec_dot_f32(n, s, x, x); *s = sqrtf(*s); }
21772177
inline static void ggml_vec_sqr_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = x[i]*x[i]; }
2178-
inline static void ggml_vec_sqrt_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = sqrt(x[i]); }
2178+
inline static void ggml_vec_sqrt_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = sqrtf(x[i]); }
21792179
inline static void ggml_vec_abs_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = fabsf(x[i]); }
21802180
inline static void ggml_vec_sgn_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? 1.f : ((x[i] < 0.f) ? -1.f : 0.f); }
21812181
inline static void ggml_vec_step_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? 1.f : 0.f; }
21822182
inline static void ggml_vec_relu_f32 (const int n, float * y, const float * x) { for (int i = 0; i < n; ++i) y[i] = (x[i] > 0.f) ? x[i] : 0.f; }
21832183

2184-
static const float GELU_COEF_A = 0.044715;
2185-
static const float SQRT_2_OVER_PI = 0.79788456080286535587989211986876;
2184+
static const float GELU_COEF_A = 0.044715f;
2185+
static const float SQRT_2_OVER_PI = 0.79788456080286535587989211986876f;
21862186

21872187
inline static float ggml_gelu_f32(float x) {
21882188
return 0.5f*x*(1.0f + tanhf(SQRT_2_OVER_PI*x*(1.0f + GELU_COEF_A*x*x)));
@@ -7565,8 +7565,8 @@ static void ggml_compute_forward_rope_f32(
75657565
const float * const src = (float *)((char *) src0->data + i3*nb3 + i2*nb2 + i1*nb1 + i0*nb0);
75667566
float * dst_data = (float *)((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 + i0*nb0);
75677567

7568-
double x0 = src[0];
7569-
double x1 = src[1];
7568+
double x0 = (double)src[0];
7569+
double x1 = (double)src[1];
75707570

75717571
dst_data[0] = x0*cos_theta - x1*sin_theta;
75727572
dst_data[1] = x0*sin_theta + x1*cos_theta;
@@ -7621,8 +7621,8 @@ static void ggml_compute_forward_rope_f16(
76217621
const ggml_fp16_t * const src = (ggml_fp16_t *)((char *) src0->data + i3*nb3 + i2*nb2 + i1*nb1 + i0*nb0);
76227622
ggml_fp16_t * dst_data = (ggml_fp16_t *)((char *) dst->data + i3*nb3 + i2*nb2 + i1*nb1 + i0*nb0);
76237623

7624-
double x0 = ggml_fp16_to_fp32(src[0]);
7625-
double x1 = ggml_fp16_to_fp32(src[1]);
7624+
double x0 = (double)ggml_fp16_to_fp32(src[0]);
7625+
double x1 = (double)ggml_fp16_to_fp32(src[1]);
76267626

76277627
dst_data[0] = ggml_fp32_to_fp16(x0*cos_theta - x1*sin_theta);
76287628
dst_data[1] = ggml_fp32_to_fp16(x0*sin_theta + x1*cos_theta);
@@ -8298,7 +8298,7 @@ static void ggml_compute_forward_flash_attn_f32(
82988298
const int ir0 = dr*ith;
82998299
const int ir1 = MIN(ir0 + dr, nr);
83008300

8301-
const float scale = 1.0/sqrt((double) D);
8301+
const float scale = 1.0f/sqrtf(D);
83028302

83038303
//printf("P=%d N=%d D=%d ir0=%d ir1=%d scale = %f\n", P, N, D, ir0, ir1, scale);
83048304

@@ -8507,7 +8507,7 @@ static void ggml_compute_forward_flash_attn_f16(
85078507
const int ir0 = dr*ith;
85088508
const int ir1 = MIN(ir0 + dr, nr);
85098509

8510-
const float scale = 1.0/sqrt((double) D);
8510+
const float scale = 1.0f/sqrtf(D);
85118511

85128512
//printf("P=%d N=%d D=%d ir0=%d ir1=%d scale = %f\n", P, N, D, ir0, ir1, scale);
85138513

main.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ std::vector<double> softmax(const std::vector<float>& logits) {
7373
for (size_t i = 0; i < logits.size(); i++) {
7474
// Subtract the maximum logit value from the current logit value for numerical stability
7575
float logit = logits[i] - max_logit;
76-
double exp_logit = std::exp(logit);
76+
double exp_logit = std::exp((double)logit);
7777
sum_exp += exp_logit;
7878
probs[i] = exp_logit;
7979
}
@@ -375,10 +375,10 @@ int main(int argc, char ** argv) {
375375

376376
if ((int) embd_inp.size() <= input_consumed && !is_interacting) {
377377
// out of user input, sample next token
378-
const float top_k = params.top_k;
379-
const float top_p = params.top_p;
380-
const float temp = params.temp;
381-
const float repeat_penalty = params.repeat_penalty;
378+
const int top_k = params.top_k;
379+
const double top_p = (double)params.top_p;
380+
const double temp = (double)params.temp;
381+
const double repeat_penalty = (double)params.repeat_penalty;
382382

383383
llama_token id = 0;
384384

0 commit comments

Comments
 (0)