Skip to content

Commit c69e69a

Browse files
authored
fix(runtime): allow integrated GPU backends (#3531)
Prefer matching discrete GPU devices while retaining a matching integrated GPU as fallback. Tested with the pinned llama.cpp revision in CPU and Vulkan builds; this addresses the iGPU selector bug without claiming to fix the separate RX 9070 XT backend crash.
1 parent ae5c4cc commit c69e69a

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

runtime/llama.cpp/sensevoice/funasr-sensevoice/funasr-sensevoice.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,22 @@ static std::string lower_copy(const char*s){
7676

7777
static ggml_backend_dev_t find_gpu_backend_device(const std::string&backend_name){
7878
ggml_backend_load_all();
79+
ggml_backend_dev_t integrated_fallback=nullptr;
7980
for(size_t i=0;i<ggml_backend_dev_count();i++){
8081
ggml_backend_dev_t dev=ggml_backend_dev_get(i);
81-
if(ggml_backend_dev_type(dev)!=GGML_BACKEND_DEVICE_TYPE_GPU) continue;
82+
enum ggml_backend_dev_type type=ggml_backend_dev_type(dev);
83+
if(type!=GGML_BACKEND_DEVICE_TYPE_GPU&&type!=GGML_BACKEND_DEVICE_TYPE_IGPU) continue;
8284
std::string reg=lower_copy(ggml_backend_reg_name(ggml_backend_dev_backend_reg(dev)));
8385
std::string dev_name=lower_copy(ggml_backend_dev_name(dev));
8486
std::string dev_desc=lower_copy(ggml_backend_dev_description(dev));
8587
if(reg.find(backend_name)!=std::string::npos||
8688
dev_name.find(backend_name)!=std::string::npos||
8789
dev_desc.find(backend_name)!=std::string::npos){
88-
return dev;
90+
if(type==GGML_BACKEND_DEVICE_TYPE_GPU) return dev;
91+
if(!integrated_fallback) integrated_fallback=dev;
8992
}
9093
}
91-
return nullptr;
94+
return integrated_fallback;
9295
}
9396

9497
static graph_backend make_graph_backend(const std::string&name){

runtime/llama.cpp/tests/test_backend_flags.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,22 @@ def test_sensevoice_vulkan_backend_has_dedicated_error_message():
2828
assert 'name=="vulkan"' in source
2929
assert "GGML_VULKAN=ON" in source
3030
assert "unsupported backend '%s' (expected cpu|cuda|vulkan)" in source
31+
32+
33+
def test_sensevoice_prefers_discrete_gpu_and_falls_back_to_matching_igpu():
34+
source = SENSEVOICE.read_text(encoding="utf-8")
35+
selector = source.split(
36+
"static ggml_backend_dev_t find_gpu_backend_device", maxsplit=1
37+
)[1].split("static graph_backend make_graph_backend", maxsplit=1)[0]
38+
39+
assert "GGML_BACKEND_DEVICE_TYPE_IGPU" in selector
40+
assert "integrated_fallback" in selector
41+
assert "return integrated_fallback" in selector
42+
discrete_return = "if(type==GGML_BACKEND_DEVICE_TYPE_GPU) return dev;"
43+
integrated_save = "if(!integrated_fallback) integrated_fallback=dev;"
44+
assert discrete_return in selector
45+
assert integrated_save in selector
46+
assert selector.index(discrete_return) < selector.index(integrated_save)
47+
assert selector.index(integrated_save) < selector.index(
48+
"return integrated_fallback"
49+
)

0 commit comments

Comments
 (0)