mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-09-19 01:05:09 +02:00
fix whisper device selection
This commit is contained in:
@@ -70,6 +70,27 @@ ggml_backend_dev_t kcpp_backend_get_device(int index)
|
||||
}
|
||||
}
|
||||
|
||||
ggml_backend_dev_t kcpp_backend_get_gpu_device(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
return get_ggml_main_device();
|
||||
}
|
||||
|
||||
size_t gpu_index = 0;
|
||||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
|
||||
ggml_backend_dev_t dev = ggml_backend_dev_get(i);
|
||||
const enum ggml_backend_dev_type type = ggml_backend_dev_type(dev);
|
||||
if (type == GGML_BACKEND_DEVICE_TYPE_GPU || type == GGML_BACKEND_DEVICE_TYPE_IGPU) {
|
||||
if (gpu_index == (size_t) index) {
|
||||
return dev;
|
||||
}
|
||||
++gpu_index;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// this is similar to sd_backend_is, except:
|
||||
// - if no backend is provided, checks the first ggml device (should be equivalent to a compile-time check)
|
||||
// - tests a |-separated list of backend/device name prefixes
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
int kcpp_backend_check(const char* name_list, ggml_backend_t backend = nullptr);
|
||||
|
||||
ggml_backend_dev_t kcpp_backend_get_device(int index);
|
||||
ggml_backend_dev_t kcpp_backend_get_gpu_device(int index);
|
||||
|
||||
// per-backend aux functions
|
||||
|
||||
|
||||
@@ -1216,9 +1216,9 @@ static ggml_backend_t whisper_backend_init(const whisper_context_params & params
|
||||
ggml_backend_t backend_gpu = NULL;
|
||||
|
||||
if (params.use_gpu) {
|
||||
auto device = kcpp_backend_get_device(params.gpu_device);
|
||||
auto device = kcpp_backend_get_gpu_device(params.gpu_device);
|
||||
if (!device) {
|
||||
WHISPER_LOG_ERROR("%s: couldn't get device %d\n", __func__, params.gpu_device);
|
||||
WHISPER_LOG_ERROR("%s: couldn't get GPU device %d\n", __func__, params.gpu_device);
|
||||
} else {
|
||||
WHISPER_LOG_INFO("%s: using backend %s\n", __func__, ggml_backend_dev_name(device));
|
||||
backend_gpu = ggml_backend_dev_init(device, nullptr);
|
||||
|
||||
Reference in New Issue
Block a user