whisper : add check for CPU backend initialization (#2918)

This commit adds a check for the CPU backend initialization in the
whisper library. If the initialization fails, an exception is thrown.

The motivation for this change is to make the library more robust and
handle the case when the CPU backend initialization fails.

Resolves: https://github.com/ggerganov/whisper.cpp/issues/2917
This commit is contained in:
Daniel Bevenius 2025-03-21 09:53:26 +01:00 committed by GitHub
parent 21fb513ef1
commit be9de81171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1355,7 +1355,11 @@ static std::vector<ggml_backend_t> whisper_backend_init(const whisper_context_pa
GGML_UNUSED(params); GGML_UNUSED(params);
result.push_back(ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr)); ggml_backend_t backend_cpu = ggml_backend_init_by_type(GGML_BACKEND_DEVICE_TYPE_CPU, nullptr);
if (backend_cpu == nullptr) {
throw std::runtime_error("failed to initialize CPU backend");
}
result.push_back(backend_cpu);
return result; return result;
} }