Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/visp/ml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ struct tensor_converter {
dst_type = src_type;
}

backend.reset(ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr));
if (!backend && whcn_to_cwhn) {
// cpu instruction set not supported, but we must do layout conversion
throw except("Cannot use CPU for tensor conversion: hardware not supported");
} else if (!backend) {
// don't convert, hope the backend can deal with the model as-is (might be slow)
dst_type = GGML_TYPE_COUNT;
return;
}

ggml_init_params ctx_params{
.mem_size = ggml_tensor_overhead() + ggml_graph_overhead(),
.mem_buffer = nullptr,
Expand All @@ -380,8 +390,6 @@ struct tensor_converter {

gallocr.reset(ggml_gallocr_new(ggml_backend_cpu_buffer_type()));
ggml_gallocr_reserve(gallocr.get(), graph);

backend.reset(ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr));
}

ggml_type target_type(ggml_tensor const* t) const {
Expand Down