Skip to content

Commit 7b8adc1

Browse files
committed
fix: dynamically calculate canny preprocessing context sizes
Tested from 64x64 to 2048x2048. Fixes #253 Fixes #642
1 parent 52cd4a2 commit 7b8adc1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

preprocessing.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
void convolve(struct ggml_tensor* input, struct ggml_tensor* output, struct ggml_tensor* kernel, int padding) {
88
struct ggml_init_params params;
9-
params.mem_size = 20 * 1024 * 1024; // 10
9+
params.mem_size = 80 * input->ne[0] * input->ne[1]; // 20M for 512x512
1010
params.mem_buffer = NULL;
1111
params.no_alloc = false;
1212
struct ggml_context* ctx0 = ggml_init(params);
@@ -164,7 +164,7 @@ void threshold_hystersis(struct ggml_tensor* img, float high_threshold, float lo
164164

165165
bool preprocess_canny(sd_image_t img, float high_threshold, float low_threshold, float weak, float strong, bool inverse) {
166166
struct ggml_init_params params;
167-
params.mem_size = static_cast<size_t>(10 * 1024 * 1024); // 10MB
167+
params.mem_size = static_cast<size_t>(40 * img.width * img.height); // 10MB for 512x512
168168
params.mem_buffer = NULL;
169169
params.no_alloc = false;
170170
struct ggml_context* work_ctx = ggml_init(params);

0 commit comments

Comments
 (0)