Skip to content

Commit 3bf1665

Browse files
committed
chore: clear the msvc compilation warning
1 parent 3001c23 commit 3bf1665

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

rng.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ class STDDefaultRNG : public RNG {
1616

1717
public:
1818
void manual_seed(uint64_t seed) {
19-
generator.seed(seed);
19+
generator.seed((unsigned int)seed);
2020
}
2121

2222
std::vector<float> randn(uint32_t n) {
2323
std::vector<float> result;
2424
float mean = 0.0;
2525
float stddev = 1.0;
2626
std::normal_distribution<float> distribution(mean, stddev);
27-
for (int i = 0; i < n; i++) {
27+
for (uint32_t i = 0; i < n; i++) {
2828
float random_number = distribution(generator);
2929
result.push_back(random_number);
3030
}

rng_philox.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class PhiloxRNG : public RNG {
1616
private:
1717
std::vector<uint32_t> philox_m = {0xD2511F53, 0xCD9E8D57};
1818
std::vector<uint32_t> philox_w = {0x9E3779B9, 0xBB67AE85};
19-
float two_pow32_inv = 2.3283064e-10;
20-
float two_pow32_inv_2pi = 2.3283064e-10 * 6.2831855;
19+
float two_pow32_inv = 2.3283064e-10f;
20+
float two_pow32_inv_2pi = 2.3283064e-10f * 6.2831855f;
2121

2222
std::vector<uint32_t> uint32(uint64_t x) {
2323
std::vector<uint32_t> result(2);
@@ -27,10 +27,10 @@ class PhiloxRNG : public RNG {
2727
}
2828

2929
std::vector<std::vector<uint32_t>> uint32(const std::vector<uint64_t>& x) {
30-
int N = x.size();
30+
uint32_t N = (uint32_t)x.size();
3131
std::vector<std::vector<uint32_t>> result(2, std::vector<uint32_t>(N));
3232

33-
for (int i = 0; i < N; ++i) {
33+
for (uint32_t i = 0; i < N; ++i) {
3434
result[0][i] = static_cast<uint32_t>(x[i] & 0xFFFFFFFF);
3535
result[1][i] = static_cast<uint32_t>(x[i] >> 32);
3636
}
@@ -41,7 +41,7 @@ class PhiloxRNG : public RNG {
4141
// A single round of the Philox 4x32 random number generator.
4242
void philox4_round(std::vector<std::vector<uint32_t>>& counter,
4343
const std::vector<std::vector<uint32_t>>& key) {
44-
uint32_t N = counter[0].size();
44+
uint32_t N = (uint32_t)counter[0].size();
4545
for (uint32_t i = 0; i < N; i++) {
4646
std::vector<uint32_t> v1 = uint32(static_cast<uint64_t>(counter[0][i]) * static_cast<uint64_t>(philox_m[0]));
4747
std::vector<uint32_t> v2 = uint32(static_cast<uint64_t>(counter[2][i]) * static_cast<uint64_t>(philox_m[1]));
@@ -63,7 +63,7 @@ class PhiloxRNG : public RNG {
6363
std::vector<std::vector<uint32_t>> philox4_32(std::vector<std::vector<uint32_t>>& counter,
6464
std::vector<std::vector<uint32_t>>& key,
6565
int rounds = 10) {
66-
uint32_t N = counter[0].size();
66+
uint32_t N = (uint32_t)counter[0].size();
6767
for (int i = 0; i < rounds - 1; ++i) {
6868
philox4_round(counter, key);
6969

@@ -81,7 +81,7 @@ class PhiloxRNG : public RNG {
8181
float u = x * two_pow32_inv + two_pow32_inv / 2;
8282
float v = y * two_pow32_inv_2pi + two_pow32_inv_2pi / 2;
8383

84-
float s = sqrt(-2.0 * log(u));
84+
float s = sqrt(-2.0f * log(u));
8585

8686
float r1 = s * sin(v);
8787
return r1;
@@ -115,8 +115,8 @@ class PhiloxRNG : public RNG {
115115
std::vector<std::vector<uint32_t>> g = philox4_32(counter, key_uint32);
116116

117117
std::vector<float> result;
118-
for (int i = 0; i < n; ++i) {
119-
result.push_back(box_muller(g[0][i], g[1][i]));
118+
for (uint32_t i = 0; i < n; ++i) {
119+
result.push_back(box_muller((float)g[0][i], (float)g[1][i]));
120120
}
121121
return result;
122122
}

stable-diffusion.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "rng_philox.h"
1919
#include "stable-diffusion.h"
2020

21-
#define EPS 1e-05
21+
#define EPS 1e-05f
2222

2323
static SDLogLevel log_level = SDLogLevel::INFO;
2424

@@ -122,9 +122,9 @@ ggml_tensor* load_tensor_from_file(ggml_context* ctx, const std::string& file_pa
122122
}
123123

124124
void ggml_tensor_set_f32_randn(struct ggml_tensor* tensor, std::shared_ptr<RNG> rng) {
125-
uint32_t n = ggml_nelements(tensor);
125+
uint32_t n = (uint32_t)ggml_nelements(tensor);
126126
std::vector<float> random_numbers = rng->randn(n);
127-
for (int i = 0; i < n; i++) {
127+
for (uint32_t i = 0; i < n; i++) {
128128
ggml_set_f32_1d(tensor, i, random_numbers[i]);
129129
}
130130
}
@@ -438,12 +438,12 @@ std::vector<std::pair<std::string, float>> parse_prompt_attention(const std::str
438438
std::string weight = m[1];
439439

440440
if (text == "(") {
441-
round_brackets.push_back(res.size());
441+
round_brackets.push_back((int)res.size());
442442
} else if (text == "[") {
443-
square_brackets.push_back(res.size());
443+
square_brackets.push_back((int)res.size());
444444
} else if (!weight.empty()) {
445445
if (!round_brackets.empty()) {
446-
multiply_range(round_brackets.back(), std::stod(weight));
446+
multiply_range(round_brackets.back(), std::stof(weight));
447447
round_brackets.pop_back();
448448
}
449449
} else if (text == ")" && !round_brackets.empty()) {
@@ -2707,13 +2707,13 @@ struct DiscreteSchedule : SigmaSchedule {
27072707
if (n == 0) {
27082708
return result;
27092709
} else if (n == 1) {
2710-
result.push_back(t_to_sigma(t_max));
2710+
result.push_back(t_to_sigma((float)t_max));
27112711
result.push_back(0);
27122712
return result;
27132713
}
27142714

27152715
float step = static_cast<float>(t_max) / static_cast<float>(n - 1);
2716-
for (int i = 0; i < n; ++i) {
2716+
for (uint32_t i = 0; i < n; ++i) {
27172717
float t = t_max - step * i;
27182718
result.push_back(t_to_sigma(t));
27192719
}
@@ -2726,17 +2726,17 @@ struct KarrasSchedule : SigmaSchedule {
27262726
std::vector<float> get_sigmas(uint32_t n) {
27272727
// These *COULD* be function arguments here,
27282728
// but does anybody ever bother to touch them?
2729-
float sigma_min = 0.1;
2730-
float sigma_max = 10.;
2731-
float rho = 7.;
2729+
float sigma_min = 0.1f;
2730+
float sigma_max = 10.f;
2731+
float rho = 7.f;
27322732

27332733
std::vector<float> result(n + 1);
27342734

2735-
float min_inv_rho = pow(sigma_min, (1. / rho));
2736-
float max_inv_rho = pow(sigma_max, (1. / rho));
2737-
for (int i = 0; i < n; i++) {
2735+
float min_inv_rho = pow(sigma_min, (1.f / rho));
2736+
float max_inv_rho = pow(sigma_max, (1.f / rho));
2737+
for (uint32_t i = 0; i < n; i++) {
27382738
// Eq. (5) from Karras et al 2022
2739-
result[i] = pow(max_inv_rho + (float)i / ((float)n - 1.) * (min_inv_rho - max_inv_rho), rho);
2739+
result[i] = pow(max_inv_rho + (float)i / ((float)n - 1.f) * (min_inv_rho - max_inv_rho), rho);
27402740
}
27412741
result[n] = 0.;
27422742
return result;
@@ -3748,7 +3748,7 @@ class StableDiffusionGGML {
37483748
}
37493749
} else {
37503750
// DPM-Solver-2
3751-
float sigma_mid = exp(0.5 * (log(sigmas[i]) + log(sigmas[i + 1])));
3751+
float sigma_mid = exp(0.5f * (log(sigmas[i]) + log(sigmas[i + 1])));
37523752
float dt_1 = sigma_mid - sigmas[i];
37533753
float dt_2 = sigmas[i + 1] - sigmas[i];
37543754

@@ -3811,7 +3811,7 @@ class StableDiffusionGGML {
38113811
float t = t_fn(sigmas[i]);
38123812
float t_next = t_fn(sigma_down);
38133813
float h = t_next - t;
3814-
float s = t + 0.5 * h;
3814+
float s = t + 0.5f * h;
38153815

38163816
float* vec_d = (float*)d->data;
38173817
float* vec_x = (float*)x->data;
@@ -3820,7 +3820,7 @@ class StableDiffusionGGML {
38203820

38213821
// First half-step
38223822
for (int j = 0; j < ggml_nelements(x); j++) {
3823-
vec_x2[j] = (sigma_fn(s) / sigma_fn(t)) * vec_x[j] - (exp(-h * 0.5) - 1) * vec_denoised[j];
3823+
vec_x2[j] = (sigma_fn(s) / sigma_fn(t)) * vec_x[j] - (exp(-h * 0.5f) - 1) * vec_denoised[j];
38243824
}
38253825

38263826
denoise(x2, sigmas[i + 1], i + 1);
@@ -3862,7 +3862,7 @@ class StableDiffusionGGML {
38623862
float t_next = t_fn(sigmas[i + 1]);
38633863
float h = t_next - t;
38643864
float a = sigmas[i + 1] / sigmas[i];
3865-
float b = exp(-h) - 1.;
3865+
float b = exp(-h) - 1.f;
38663866
float* vec_x = (float*)x->data;
38673867
float* vec_denoised = (float*)denoised->data;
38683868
float* vec_old_denoised = (float*)old_denoised->data;
@@ -3876,7 +3876,7 @@ class StableDiffusionGGML {
38763876
float h_last = t - t_fn(sigmas[i - 1]);
38773877
float r = h_last / h;
38783878
for (int j = 0; j < ggml_nelements(x); j++) {
3879-
float denoised_d = (1. + 1. / (2. * r)) * vec_denoised[j] - (1. / (2. * r)) * vec_old_denoised[j];
3879+
float denoised_d = (1.f + 1.f / (2.f * r)) * vec_denoised[j] - (1.f / (2.f * r)) * vec_old_denoised[j];
38803880
vec_x[j] = a * vec_x[j] - b * denoised_d;
38813881
}
38823882
}
@@ -3910,7 +3910,7 @@ class StableDiffusionGGML {
39103910

39113911
if (i == 0 || sigmas[i + 1] == 0) {
39123912
// Simpler step for the edge cases
3913-
float b = exp(-h) - 1.;
3913+
float b = exp(-h) - 1.f;
39143914
for (int j = 0; j < ggml_nelements(x); j++) {
39153915
vec_x[j] = a * vec_x[j] - b * vec_denoised[j];
39163916
}
@@ -3919,10 +3919,10 @@ class StableDiffusionGGML {
39193919
float h_min = std::min(h_last, h);
39203920
float h_max = std::max(h_last, h);
39213921
float r = h_max / h_min;
3922-
float h_d = (h_max + h_min) / 2.;
3923-
float b = exp(-h_d) - 1.;
3922+
float h_d = (h_max + h_min) / 2.f;
3923+
float b = exp(-h_d) - 1.f;
39243924
for (int j = 0; j < ggml_nelements(x); j++) {
3925-
float denoised_d = (1. + 1. / (2. * r)) * vec_denoised[j] - (1. / (2. * r)) * vec_old_denoised[j];
3925+
float denoised_d = (1.f + 1.f / (2.f * r)) * vec_denoised[j] - (1.f / (2.f * r)) * vec_old_denoised[j];
39263926
vec_x[j] = a * vec_x[j] - b * denoised_d;
39273927
}
39283928
}

0 commit comments

Comments
 (0)