Skip to content

Commit ec0fbeb

Browse files
hexagon: error checks in the buffer allocator
1 parent 693a13d commit ec0fbeb

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

ggml/src/ggml-hexagon/ggml-hexagon.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,28 +1388,36 @@ static const char * ggml_backend_hexagon_buffer_type_name(ggml_backend_buffer_ty
13881388
return static_cast<ggml_backend_hexagon_buffer_type_context *>(buffer_type->context)->name.c_str();
13891389
}
13901390

1391-
static ggml_backend_buffer_t ggml_backend_hexagon_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buffer_type,
1392-
size_t size) {
1391+
static ggml_backend_buffer_t ggml_backend_hexagon_buffer_type_alloc_buffer(
1392+
ggml_backend_buffer_type_t buffer_type, size_t size) {
13931393
auto sess = static_cast<ggml_backend_hexagon_buffer_type_context *>(buffer_type->context)->sess;
1394-
ggml_backend_hexagon_buffer_context * ctx = new ggml_backend_hexagon_buffer_context(sess, size, false /*repack*/);
1395-
return ggml_backend_buffer_init(buffer_type, ggml_backend_hexagon_buffer_interface, ctx, size);
1394+
try {
1395+
ggml_backend_hexagon_buffer_context * ctx = new ggml_backend_hexagon_buffer_context(sess, size, false /*repack*/);
1396+
return ggml_backend_buffer_init(buffer_type, ggml_backend_hexagon_buffer_interface, ctx, size);
1397+
} catch (std::exception const &exc) {
1398+
GGML_LOG_ERROR("ggml-hex: %s failed to allocate buffer context: %s\n", sess->name.c_str(), exc.what());
1399+
return nullptr;
1400+
}
13961401
}
13971402

13981403
static ggml_backend_buffer_t ggml_backend_hexagon_repack_buffer_type_alloc_buffer(
1399-
ggml_backend_buffer_type_t buffer_type,
1400-
size_t size) {
1404+
ggml_backend_buffer_type_t buffer_type, size_t size) {
14011405
auto sess = static_cast<ggml_backend_hexagon_buffer_type_context *>(buffer_type->context)->sess;
1402-
ggml_backend_hexagon_buffer_context * ctx = new ggml_backend_hexagon_buffer_context(sess, size, true /*repack*/);
1403-
return ggml_backend_buffer_init(buffer_type, ggml_backend_hexagon_buffer_interface, ctx, size);
1406+
try {
1407+
ggml_backend_hexagon_buffer_context * ctx = new ggml_backend_hexagon_buffer_context(sess, size, true /*repack*/);
1408+
return ggml_backend_buffer_init(buffer_type, ggml_backend_hexagon_buffer_interface, ctx, size);
1409+
} catch (std::exception const &exc) {
1410+
GGML_LOG_ERROR("ggml-hex: %s failed to allocate buffer context: %s\n", sess->name.c_str(), exc.what());
1411+
return nullptr;
1412+
}
14041413
}
14051414

14061415
static size_t ggml_backend_hexagon_buffer_type_get_alignment(ggml_backend_buffer_type_t buffer_type) {
14071416
return 128; // HVX alignment
14081417
GGML_UNUSED(buffer_type);
14091418
}
14101419

1411-
static size_t ggml_backend_hexagon_buffer_type_get_alloc_size(ggml_backend_buffer_type_t buft,
1412-
const struct ggml_tensor * t) {
1420+
static size_t ggml_backend_hexagon_buffer_type_get_alloc_size(ggml_backend_buffer_type_t buft, const struct ggml_tensor * t) {
14131421
return ggml_nbytes(t);
14141422
}
14151423

0 commit comments

Comments
 (0)