Skip to content

Commit 57e2d0a

Browse files
committed
binbcast: add try catch sycl::exception
1 parent 7d8a4d9 commit 57e2d0a

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

ggml/src/ggml-sycl/binbcast.cpp

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,58 +226,73 @@ inline void ggml_sycl_op_bin_bcast(const ggml_tensor * src0, const ggml_tensor *
226226
} else if (src0->type == GGML_TYPE_I16 && dst->type == GGML_TYPE_I16) {
227227
op()(src0, src1, dst, (const int16_t *) src0_dd, (const int16_t *) src1_dd, (int16_t *) dst_dd, main_stream);
228228
} else {
229-
fprintf(stderr, "%s: unsupported types: dst: %s, src0: %s, src1: %s\n", __func__, ggml_type_name(dst->type),
229+
GGML_LOG_ERROR("%s: unsupported types: dst: %s, src0: %s, src1: %s\n", __func__, ggml_type_name(dst->type),
230230
ggml_type_name(src0->type), ggml_type_name(src1->type));
231231
GGML_ABORT("fatal error");
232232
}
233233
}
234234

235-
inline void ggml_sycl_op_add(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
235+
inline void ggml_sycl_op_add(ggml_backend_sycl_context & ctx, ggml_tensor * dst) try {
236236
const void * src0_dd = static_cast<void *>(dst->src[0]->data);
237237
const void * src1_dd = static_cast<void *>(dst->src[1]->data);
238238
void * dst_dd = static_cast<void *>(dst->data);
239239
const dpct::queue_ptr main_stream = ctx.stream();
240240

241241
ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_add>>(dst->src[0], dst->src[1], dst, src0_dd, src1_dd, dst_dd,
242242
main_stream);
243+
} catch (const sycl::exception & exc) {
244+
std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl;
245+
std::exit(1);
243246
}
244247

245-
inline void ggml_sycl_op_sub(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
248+
inline void ggml_sycl_op_sub(ggml_backend_sycl_context & ctx, ggml_tensor * dst) try {
246249
const void * src0_dd = static_cast<void *>(dst->src[0]->data);
247250
const void * src1_dd = static_cast<void *>(dst->src[1]->data);
248251
void * dst_dd = static_cast<void *>(dst->data);
249252
const dpct::queue_ptr main_stream = ctx.stream();
250253

251254
ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_sub>>(dst->src[0], dst->src[1], dst, src0_dd, src1_dd, dst_dd,
252255
main_stream);
256+
} catch (const sycl::exception & exc) {
257+
std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl;
258+
std::exit(1);
253259
}
254260

255-
inline void ggml_sycl_op_mul(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
261+
inline void ggml_sycl_op_mul(ggml_backend_sycl_context & ctx, ggml_tensor * dst) try {
256262
const void * src0_dd = static_cast<void *>(dst->src[0]->data);
257263
const void * src1_dd = static_cast<void *>(dst->src[1]->data);
258264
void * dst_dd = static_cast<void *>(dst->data);
259265
const dpct::queue_ptr main_stream = ctx.stream();
260266

261267
ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_mul>>(dst->src[0], dst->src[1], dst, src0_dd, src1_dd, dst_dd,
262268
main_stream);
269+
} catch (const sycl::exception & exc) {
270+
std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl;
271+
std::exit(1);
263272
}
264273

265-
inline void ggml_sycl_op_div(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
274+
inline void ggml_sycl_op_div(ggml_backend_sycl_context & ctx, ggml_tensor * dst) try {
266275
const void * src0_dd = static_cast<void *>(dst->src[0]->data);
267276
const void * src1_dd = static_cast<void *>(dst->src[1]->data);
268277
void * dst_dd = static_cast<void *>(dst->data);
269278
const dpct::queue_ptr main_stream = ctx.stream();
270279

271280
ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_div>>(dst->src[0], dst->src[1], dst, src0_dd, src1_dd, dst_dd,
272281
main_stream);
282+
} catch (const sycl::exception & exc) {
283+
std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl;
284+
std::exit(1);
273285
}
274286

275-
inline void ggml_sycl_op_repeat(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
287+
inline void ggml_sycl_op_repeat(ggml_backend_sycl_context & ctx, ggml_tensor * dst) try {
276288
const void * src0_d = static_cast<void *>(dst->src[0]->data);
277289
void * dst_d = static_cast<void *>(dst->data);
278290
dpct::queue_ptr main_stream = ctx.stream();
279291

280292
ggml_sycl_op_bin_bcast<bin_bcast_sycl<op_repeat>>(dst, dst->src[0], dst, nullptr, src0_d, dst_d, main_stream);
293+
} catch (const sycl::exception & exc) {
294+
std::cerr << exc.what() << "Exception caught at file:" << __FILE__ << ", line:" << __LINE__ << std::endl;
295+
std::exit(1);
281296
}
282297

283298
void ggml_sycl_add(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {

ggml/src/ggml-sycl/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#pragma clang diagnostic ignored "-Wnested-anon-types"
3232
#include "ggml-common.h"
3333
#pragma clang diagnostic pop
34+
#include "ggml-impl.h"
3435

3536
void* ggml_sycl_host_malloc(size_t size);
3637
void ggml_sycl_host_free(void* ptr);

0 commit comments

Comments
 (0)