Skip to content

Commit be17235

Browse files
committed
Merge remote-tracking branch 'llama.cpp/master' into crokeso
2 parents eada78d + d7f5f4e commit be17235

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

ggml/include/ggml.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@
320320
extern "C" {
321321
#endif
322322

323+
// Function type used in fatal error callbacks
324+
typedef void (*ggml_abort_callback_t)(const char * error_message);
325+
326+
// Set the abort callback (passing null will restore original abort functionality: printing a message to stdout)
327+
// Returns the old callback for chaining
328+
GGML_API ggml_abort_callback_t ggml_set_abort_callback(ggml_abort_callback_t callback);
329+
323330
GGML_NORETURN GGML_ATTRIBUTE_FORMAT(3, 4)
324331
GGML_API void ggml_abort(const char * file, int line, const char * fmt, ...);
325332

ggml/src/ggml-opencl/kernels/upscale.cl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ kernel void kernel_upscale_bilinear(
6060
float sf0,
6161
float sf1,
6262
float sf2,
63-
float sf3
63+
float sf3,
64+
float pixel_offset
6465
) {
6566
global const char * src_base = (global const char *)p_src0 + off_src0;
6667
global float * dst_base = (global float *)((global char *)p_dst + off_dst);
@@ -80,8 +81,6 @@ kernel void kernel_upscale_bilinear(
8081
int i02_src = (int)(i12_dst / sf2);
8182
int i03_src = (int)(i13_dst / sf3);
8283

83-
const float pixel_offset = 0.5f;
84-
8584
float y_src_f = ((float)i11_dst + pixel_offset) / sf1 - pixel_offset;
8685
long y0_src = (long)floor(y_src_f);
8786
long y1_src = y0_src + 1;

ggml/src/ggml.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,34 @@ void ggml_print_backtrace(void) {
231231
}
232232
#endif
233233

234+
static ggml_abort_callback_t g_abort_callback = NULL;
235+
236+
// Set the abort callback (passing null will restore original abort functionality: printing a message to stdout)
237+
GGML_API ggml_abort_callback_t ggml_set_abort_callback(ggml_abort_callback_t callback) {
238+
ggml_abort_callback_t ret_val = g_abort_callback;
239+
g_abort_callback = callback;
240+
return ret_val;
241+
}
242+
234243
void ggml_abort(const char * file, int line, const char * fmt, ...) {
235244
fflush(stdout);
236245

237-
fprintf(stderr, "%s:%d: ", file, line);
246+
char message[2048];
247+
int offset = snprintf(message, sizeof(message), "%s:%d: ", file, line);
238248

239249
va_list args;
240250
va_start(args, fmt);
241-
vfprintf(stderr, fmt, args);
251+
vsnprintf(message + offset, sizeof(message) - offset, fmt, args);
242252
va_end(args);
243253

244-
fprintf(stderr, "\n");
254+
if (g_abort_callback) {
255+
g_abort_callback(message);
256+
} else {
257+
// default: print error and backtrace to stderr
258+
fprintf(stderr, "%s\n", message);
259+
ggml_print_backtrace();
260+
}
245261

246-
ggml_print_backtrace();
247262
abort();
248263
}
249264

0 commit comments

Comments
 (0)