Skip to content

Commit 970c4a3

Browse files
authored
chore: replace some NULL with nullptr + use "%zu" for printing some size_t data (#1457)
1 parent b8bdffc commit 970c4a3

6 files changed

Lines changed: 22 additions & 22 deletions

File tree

src/ggml_extend.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,16 +2758,16 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_lokr_forward(
27582758
bool is_conv,
27592759
WeightAdapter::ForwardParams::conv2d_params_t conv_params,
27602760
float scale) {
2761-
GGML_ASSERT((w1 != NULL || (w1a != NULL && w1b != NULL)));
2762-
GGML_ASSERT((w2 != NULL || (w2a != NULL && w2b != NULL)));
2761+
GGML_ASSERT((w1 != nullptr || (w1a != nullptr && w1b != nullptr)));
2762+
GGML_ASSERT((w2 != nullptr || (w2a != nullptr && w2b != nullptr)));
27632763

2764-
int uq = (w1 != NULL) ? (int)w1->ne[0] : (int)w1a->ne[0];
2765-
int up = (w1 != NULL) ? (int)w1->ne[1] : (int)w1b->ne[1];
2764+
int uq = (w1 != nullptr) ? (int)w1->ne[0] : (int)w1a->ne[0];
2765+
int up = (w1 != nullptr) ? (int)w1->ne[1] : (int)w1b->ne[1];
27662766

27672767
int q_actual = is_conv ? (int)h->ne[2] : (int)h->ne[0];
27682768
int vq = q_actual / uq;
27692769

2770-
int vp = (w2 != NULL) ? (is_conv ? (int)w2->ne[3] : (int)w2->ne[1])
2770+
int vp = (w2 != nullptr) ? (is_conv ? (int)w2->ne[3] : (int)w2->ne[1])
27712771
: (int)w2a->ne[1];
27722772
GGML_ASSERT(q_actual == (uq * vq) && "Input dimension mismatch for LoKR split");
27732773

@@ -2803,7 +2803,7 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_lokr_forward(
28032803
#endif
28042804

28052805
ggml_tensor* h_split = ggml_reshape_3d(ctx, h, vq, uq * merge_batch_uq, batch / merge_batch_uq);
2806-
if (w2 != NULL) {
2806+
if (w2 != nullptr) {
28072807
hb = ggml_mul_mat(ctx, w2, h_split);
28082808
} else {
28092809
hb = ggml_mul_mat(ctx, w2b, ggml_mul_mat(ctx, w2a, h_split));
@@ -2816,7 +2816,7 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_lokr_forward(
28162816
hb_t = ggml_reshape_3d(ctx, hb_t, uq, vp * merge_batch_vp, batch / merge_batch_vp);
28172817

28182818
ggml_tensor* hc_t;
2819-
if (w1 != NULL) {
2819+
if (w1 != nullptr) {
28202820
hc_t = ggml_mul_mat(ctx, w1, hb_t);
28212821
} else {
28222822
hc_t = ggml_mul_mat(ctx, w1b, ggml_mul_mat(ctx, w1a, hb_t));
@@ -2834,7 +2834,7 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_lokr_forward(
28342834
// 1. Reshape input: [W, H, vq*uq, batch] -> [W, H, vq, uq * batch]
28352835
ggml_tensor* h_split = ggml_reshape_4d(ctx, h, h->ne[0], h->ne[1], vq, uq * batch);
28362836

2837-
if (w2 != NULL) {
2837+
if (w2 != nullptr) {
28382838
hb = ggml_ext_conv_2d(ctx, h_split, w2, nullptr,
28392839
conv_params.s0,
28402840
conv_params.s1,
@@ -2902,7 +2902,7 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_lokr_forward(
29022902
ggml_tensor* hb_merged = ggml_reshape_2d(ctx, hb, w_out * h_out * vp, uq * batch);
29032903
ggml_tensor* hc_t;
29042904
ggml_tensor* hb_merged_t = ggml_cont(ctx, ggml_transpose(ctx, hb_merged));
2905-
if (w1 != NULL) {
2905+
if (w1 != nullptr) {
29062906
// Would be great to be able to transpose w1 instead to avoid transposing both hb and hc
29072907
hc_t = ggml_mul_mat(ctx, w1, hb_merged_t);
29082908
} else {

src/stable-diffusion.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ class StableDiffusionGGML {
198198
device = 0;
199199
}
200200
if (device >= device_count) {
201-
LOG_WARN("Cannot find targeted vulkan device (%llu). Falling back to device 0.", device);
201+
LOG_WARN("Cannot find targeted vulkan device (%zu). Falling back to device 0.", device);
202202
device = 0;
203203
}
204204
}
205-
LOG_INFO("Vulkan: Using device %llu", device);
205+
LOG_INFO("Vulkan: Using device %zu", device);
206206
backend = ggml_backend_vk_init(device);
207207
}
208208
if (!backend) {
@@ -3233,7 +3233,7 @@ static sd_image_t* decode_image_outputs(sd_ctx_t* sd_ctx,
32333233
}
32343234
decoded_images.push_back(std::move(image));
32353235
int64_t t2 = ggml_time_ms();
3236-
LOG_INFO("latent %" PRId64 " decoded, taking %.2fs", i + 1, (t2 - t1) * 1.0f / 1000);
3236+
LOG_INFO("latent %zu decoded, taking %.2fs", i + 1, (t2 - t1) * 1.0f / 1000);
32373237
}
32383238

32393239
int64_t t4 = ggml_time_ms();
@@ -3475,7 +3475,7 @@ SD_API sd_image_t* generate_image(sd_ctx_t* sd_ctx, const sd_img_gen_params_t* s
34753475
sd_ctx->sd->diffusion_model->free_params_buffer();
34763476
}
34773477
int64_t denoise_end = ggml_time_ms();
3478-
LOG_INFO("generating %" PRId64 " latent images completed, taking %.2fs",
3478+
LOG_INFO("generating %zu latent images completed, taking %.2fs",
34793479
final_latents.size(),
34803480
(denoise_end - denoise_start) * 1.0f / 1000);
34813481

src/tokenizers/clip_tokenizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void CLIPTokenizer::load_from_merges(const std::string& merges_utf8_str) {
6262
}
6363
vocab.push_back(utf8_to_utf32("<|startoftext|>"));
6464
vocab.push_back(utf8_to_utf32("<|endoftext|>"));
65-
LOG_DEBUG("vocab size: %llu", vocab.size());
65+
LOG_DEBUG("vocab size: %zu", vocab.size());
6666
int i = 0;
6767
for (const auto& token : vocab) {
6868
encoder[token] = i;

src/tokenizers/mistral_tokenizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void MistralTokenizer::load_from_merges(const std::string& merges_utf8_str, cons
2828
byte_decoder[pair.second] = pair.first;
2929
}
3030
std::vector<std::u32string> merges = split_utf32(merges_utf8_str);
31-
LOG_DEBUG("merges size %llu", merges.size());
31+
LOG_DEBUG("merges size %zu", merges.size());
3232
std::vector<std::pair<std::u32string, std::u32string>> merge_pairs;
3333
for (const auto& merge : merges) {
3434
size_t space_pos = merge.find(' ');

src/tokenizers/qwen2_tokenizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void Qwen2Tokenizer::load_from_merges(const std::string& merges_utf8_str) {
1111
}
1212

1313
std::vector<std::u32string> merges = split_utf32(merges_utf8_str);
14-
LOG_DEBUG("merges size %llu", merges.size());
14+
LOG_DEBUG("merges size %zu", merges.size());
1515
std::vector<std::pair<std::u32string, std::u32string>> merge_pairs;
1616
for (const auto& merge : merges) {
1717
size_t space_pos = merge.find(' ');

src/util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ std::unique_ptr<MmapWrapper> MmapWrapper::create(const std::string& filename) {
119119
filename.c_str(),
120120
GENERIC_READ,
121121
FILE_SHARE_READ,
122-
NULL,
122+
nullptr,
123123
OPEN_EXISTING,
124124
FILE_ATTRIBUTE_NORMAL,
125-
NULL);
125+
nullptr);
126126

127127
if (file_handle == INVALID_HANDLE_VALUE) {
128128
return nullptr;
@@ -136,16 +136,16 @@ std::unique_ptr<MmapWrapper> MmapWrapper::create(const std::string& filename) {
136136

137137
file_size = static_cast<size_t>(size.QuadPart);
138138

139-
HANDLE mapping_handle = CreateFileMapping(file_handle, NULL, PAGE_READONLY, 0, 0, NULL);
139+
HANDLE mapping_handle = CreateFileMapping(file_handle, nullptr, PAGE_READONLY, 0, 0, nullptr);
140140

141-
if (mapping_handle == NULL) {
141+
if (mapping_handle == nullptr) {
142142
CloseHandle(file_handle);
143143
return nullptr;
144144
}
145145

146146
mapped_data = MapViewOfFile(mapping_handle, FILE_MAP_READ, 0, 0, file_size);
147147

148-
if (mapped_data == NULL) {
148+
if (mapped_data == nullptr) {
149149
CloseHandle(mapping_handle);
150150
CloseHandle(file_handle);
151151
return nullptr;
@@ -203,7 +203,7 @@ std::unique_ptr<MmapWrapper> MmapWrapper::create(const std::string& filename) {
203203

204204
size_t file_size = sb.st_size;
205205

206-
void* mapped_data = mmap(NULL, file_size, PROT_READ, mmap_flags, file_descriptor, 0);
206+
void* mapped_data = mmap(nullptr, file_size, PROT_READ, mmap_flags, file_descriptor, 0);
207207

208208
close(file_descriptor);
209209

0 commit comments

Comments
 (0)