-
Notifications
You must be signed in to change notification settings - Fork 4.5k
If backends fail it is possible to try using a null pointer #3313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1326,6 +1326,10 @@ static ggml_backend_t whisper_backend_init_gpu(const whisper_context_params & pa | |
if (params.use_gpu) { | ||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) { | ||
ggml_backend_dev_t dev_cur = ggml_backend_dev_get(i); | ||
// Prevent null pointer being used in following code | ||
if(dev_cur == nullptr) { | ||
continue; | ||
} | ||
if (ggml_backend_dev_type(dev_cur) == GGML_BACKEND_DEVICE_TYPE_GPU) { | ||
if (cnt == 0 || cnt == params.gpu_device) { | ||
dev = dev_cur; | ||
|
@@ -1364,6 +1368,10 @@ static std::vector<ggml_backend_t> whisper_backend_init(const whisper_context_pa | |
// ACCEL backends | ||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) { | ||
ggml_backend_dev_t dev = ggml_backend_dev_get(i); | ||
// Prevent null pointer being used in following code | ||
if(dev == nullptr) { | ||
continue; | ||
} | ||
if (ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_ACCEL) { | ||
WHISPER_LOG_INFO("%s: using %s backend\n", __func__, ggml_backend_dev_name(dev)); | ||
ggml_backend_t backend = ggml_backend_dev_init(dev, nullptr); | ||
|
@@ -1395,6 +1403,10 @@ static buft_list_t make_buft_list(whisper_context_params & params) { | |
int cnt = 0; | ||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) { | ||
ggml_backend_dev_t dev = ggml_backend_dev_get(i); | ||
// Prevent null pointer being used in following code | ||
if(dev == nullptr) { | ||
continue; | ||
} | ||
if (ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_GPU) { | ||
if (cnt == 0 || cnt == params.gpu_device) { | ||
auto * buft = ggml_backend_dev_buffer_type(dev); | ||
|
@@ -1412,20 +1424,23 @@ static buft_list_t make_buft_list(whisper_context_params & params) { | |
|
||
// CPU Extra | ||
auto * cpu_dev = ggml_backend_dev_by_type(GGML_BACKEND_DEVICE_TYPE_CPU); | ||
auto * cpu_reg = ggml_backend_dev_backend_reg(cpu_dev); | ||
auto get_extra_bufts_fn = (ggml_backend_dev_get_extra_bufts_t) | ||
ggml_backend_reg_get_proc_address(cpu_reg, "ggml_backend_dev_get_extra_bufts"); | ||
if (get_extra_bufts_fn) { | ||
ggml_backend_buffer_type_t * extra_bufts = get_extra_bufts_fn(cpu_dev); | ||
while (extra_bufts && *extra_bufts) { | ||
buft_list.emplace_back(cpu_dev, *extra_bufts); | ||
++extra_bufts; | ||
// Prevent null pointer being used in following code | ||
if(cpu_dev != nullptr) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can you add a space after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added space after if *4 to fix nit The most easiest way to trigger the state this avoids is by commenting out the ggml_backend_load_all() in whisper-bench and build shared all_cpu_variants. OK that error would be pretty stupid but at least with this it'll tell you there are no backends. The alternative is a core-dump which tells you less than zero I know most perople will build static for the build-box but if you want to pass something around as a release shared all_cpu_variants is a must Also if you pass a static release around you run into the issue of it not loading the right CPU on older kit (probably same result - not tested - yet, only just though of it) |
||
auto * cpu_reg = ggml_backend_dev_backend_reg(cpu_dev); | ||
auto get_extra_bufts_fn = (ggml_backend_dev_get_extra_bufts_t) | ||
ggml_backend_reg_get_proc_address(cpu_reg, "ggml_backend_dev_get_extra_bufts"); | ||
if (get_extra_bufts_fn) { | ||
ggml_backend_buffer_type_t * extra_bufts = get_extra_bufts_fn(cpu_dev); | ||
while (extra_bufts && *extra_bufts) { | ||
buft_list.emplace_back(cpu_dev, *extra_bufts); | ||
++extra_bufts; | ||
} | ||
} | ||
} | ||
|
||
// CPU | ||
buft_list.emplace_back(cpu_dev, ggml_backend_cpu_buffer_type()); | ||
|
||
// CPU | ||
buft_list.emplace_back(cpu_dev, ggml_backend_cpu_buffer_type()); | ||
} | ||
|
||
return buft_list; | ||
} | ||
|
||
|
@@ -1728,6 +1743,12 @@ static bool whisper_model_load(struct whisper_model_loader * loader, whisper_con | |
|
||
// Create a list of available bufts, in priority order | ||
buft_list_t buft_list = make_buft_list(wctx.params); | ||
// Under rare circumstances it may not be possible to build a buft_list | ||
// This can occur, for example, is all backends fail | ||
if (buft_list.empty()) { | ||
WHISPER_LOG_ERROR("%s: Failed to find a create a list of available bufts - possibly all backends failed\n", __func__); | ||
return false; | ||
} | ||
|
||
auto create_tensor = [&](asr_tensor type, asr_system system, ggml_tensor * meta, int layer = 0) -> ggml_tensor * { | ||
ggml_op op = ASR_TENSOR_INFO.at(type); | ||
|
Uh oh!
There was an error while loading. Please reload this page.