mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-03-01 03:26:12 +00:00
vulkan: Make Vulkan optional at runtime (ggml/11493). (llama/11494)
Co-authored-by: Jeff Bolz <jbolz@nvidia.com>
This commit is contained in:
parent
b4b063a5c9
commit
db6e19188a
@ -10,8 +10,6 @@ extern "C" {
|
|||||||
#define GGML_VK_NAME "Vulkan"
|
#define GGML_VK_NAME "Vulkan"
|
||||||
#define GGML_VK_MAX_DEVICES 16
|
#define GGML_VK_MAX_DEVICES 16
|
||||||
|
|
||||||
GGML_BACKEND_API void ggml_vk_instance_init(void);
|
|
||||||
|
|
||||||
// backend API
|
// backend API
|
||||||
GGML_BACKEND_API ggml_backend_t ggml_backend_vk_init(size_t dev_num);
|
GGML_BACKEND_API ggml_backend_t ggml_backend_vk_init(size_t dev_num);
|
||||||
|
|
||||||
|
@ -2793,14 +2793,12 @@ static void ggml_vk_print_gpu_info(size_t idx) {
|
|||||||
static bool ggml_vk_instance_validation_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
|
static bool ggml_vk_instance_validation_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
|
||||||
static bool ggml_vk_instance_portability_enumeration_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
|
static bool ggml_vk_instance_portability_enumeration_ext_available(const std::vector<vk::ExtensionProperties>& instance_extensions);
|
||||||
|
|
||||||
void ggml_vk_instance_init() {
|
static void ggml_vk_instance_init() {
|
||||||
if (vk_instance_initialized) {
|
if (vk_instance_initialized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VK_LOG_DEBUG("ggml_vk_instance_init()");
|
VK_LOG_DEBUG("ggml_vk_instance_init()");
|
||||||
|
|
||||||
vk_instance_initialized = true;
|
|
||||||
|
|
||||||
uint32_t api_version = vk::enumerateInstanceVersion();
|
uint32_t api_version = vk::enumerateInstanceVersion();
|
||||||
|
|
||||||
if (api_version < VK_API_VERSION_1_2) {
|
if (api_version < VK_API_VERSION_1_2) {
|
||||||
@ -2851,6 +2849,7 @@ void ggml_vk_instance_init() {
|
|||||||
GGML_LOG_DEBUG("ggml_vulkan: Validation layers enabled\n");
|
GGML_LOG_DEBUG("ggml_vulkan: Validation layers enabled\n");
|
||||||
}
|
}
|
||||||
vk_instance.instance = vk::createInstance(instance_create_info);
|
vk_instance.instance = vk::createInstance(instance_create_info);
|
||||||
|
vk_instance_initialized = true;
|
||||||
|
|
||||||
size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
|
size_t num_available_devices = vk_instance.instance.enumeratePhysicalDevices().size();
|
||||||
|
|
||||||
@ -2875,7 +2874,7 @@ void ggml_vk_instance_init() {
|
|||||||
// Make sure at least one device exists
|
// Make sure at least one device exists
|
||||||
if (devices.empty()) {
|
if (devices.empty()) {
|
||||||
std::cerr << "ggml_vulkan: Error: No devices found." << std::endl;
|
std::cerr << "ggml_vulkan: Error: No devices found." << std::endl;
|
||||||
GGML_ABORT("fatal error");
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default to using all dedicated GPUs
|
// Default to using all dedicated GPUs
|
||||||
@ -8350,8 +8349,13 @@ ggml_backend_reg_t ggml_backend_vk_reg() {
|
|||||||
/* .iface = */ ggml_backend_vk_reg_i,
|
/* .iface = */ ggml_backend_vk_reg_i,
|
||||||
/* .context = */ nullptr,
|
/* .context = */ nullptr,
|
||||||
};
|
};
|
||||||
|
try {
|
||||||
return ®
|
ggml_vk_instance_init();
|
||||||
|
return ®
|
||||||
|
} catch (const vk::SystemError& e) {
|
||||||
|
VK_LOG_DEBUG("ggml_backend_vk_reg() -> Error: System error: " << e.what());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extension availability
|
// Extension availability
|
||||||
|
Loading…
x
Reference in New Issue
Block a user