@@ -4497,7 +4497,7 @@ static void ggml_vk_instance_init() {
4497
4497
new_driver.pNext = &new_id;
4498
4498
devices[i].getProperties2(&new_props);
4499
4499
4500
- if (new_props.properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu) {
4500
+ if (new_props.properties.deviceType == vk::PhysicalDeviceType::eDiscreteGpu || new_props.properties.deviceType == vk::PhysicalDeviceType::eIntegratedGpu ) {
4501
4501
// Check if there are two physical devices corresponding to the same GPU
4502
4502
auto old_device = std::find_if(
4503
4503
vk_instance.device_indices.begin(),
@@ -4567,7 +4567,7 @@ static void ggml_vk_instance_init() {
4567
4567
}
4568
4568
}
4569
4569
4570
- // If no dedicated GPUs found, fall back to the first non-CPU device.
4570
+ // If no GPUs found, fall back to the first non-CPU device.
4571
4571
// If only CPU devices are available, return without devices.
4572
4572
if (vk_instance.device_indices.empty()) {
4573
4573
for (size_t i = 0; i < devices.size(); i++) {
@@ -12078,12 +12078,63 @@ void ggml_backend_vk_get_device_memory(int device, size_t * free, size_t * total
12078
12078
}
12079
12079
}
12080
12080
12081
+ static vk::PhysicalDeviceType ggml_backend_vk_get_device_type(int device_idx) {
12082
+ GGML_ASSERT(device_idx >= 0 && device_idx < (int) vk_instance.device_indices.size());
12083
+
12084
+ vk::PhysicalDevice device = vk_instance.instance.enumeratePhysicalDevices()[vk_instance.device_indices[device_idx]];
12085
+
12086
+ vk::PhysicalDeviceProperties2 props = {};
12087
+ device.getProperties2(&props);
12088
+
12089
+ return props.properties.deviceType;
12090
+ }
12091
+
12092
+ static std::string ggml_backend_vk_get_device_pci_id(int device_idx) {
12093
+ GGML_ASSERT(device_idx >= 0 && device_idx < (int) vk_instance.device_indices.size());
12094
+
12095
+ vk::PhysicalDevice device = vk_instance.instance.enumeratePhysicalDevices()[vk_instance.device_indices[device_idx]];
12096
+
12097
+ const std::vector<vk::ExtensionProperties> ext_props = device.enumerateDeviceExtensionProperties();
12098
+
12099
+ bool ext_support = false;
12100
+
12101
+ for (const auto& properties : ext_props) {
12102
+ if (strcmp("VK_EXT_pci_bus_info", properties.extensionName) == 0) {
12103
+ ext_support = true;
12104
+ break;
12105
+ }
12106
+ }
12107
+
12108
+ if (!ext_support) {
12109
+ return "";
12110
+ }
12111
+
12112
+ vk::PhysicalDeviceProperties2 props = {};
12113
+ vk::PhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info = {};
12114
+
12115
+ props.pNext = &pci_bus_info;
12116
+
12117
+ device.getProperties2(&props);
12118
+
12119
+ const uint32_t pci_domain = pci_bus_info.pciDomain;
12120
+ const uint32_t pci_bus = pci_bus_info.pciBus;
12121
+ const uint32_t pci_device = pci_bus_info.pciDevice;
12122
+ const uint8_t pci_function = (uint8_t) pci_bus_info.pciFunction; // pci function is between 0 and 7, prevent printf overflow warning
12123
+
12124
+ char pci_bus_id[16] = {};
12125
+ snprintf(pci_bus_id, sizeof(pci_bus_id), "%04x:%02x:%02x.%x", pci_domain, pci_bus, pci_device, pci_function);
12126
+
12127
+ return std::string(pci_bus_id);
12128
+ }
12129
+
12081
12130
//////////////////////////
12082
12131
12083
12132
struct ggml_backend_vk_device_context {
12084
12133
size_t device;
12085
12134
std::string name;
12086
12135
std::string description;
12136
+ bool is_integrated_gpu;
12137
+ std::string pci_bus_id;
12087
12138
};
12088
12139
12089
12140
static const char * ggml_backend_vk_device_get_name(ggml_backend_dev_t dev) {
@@ -12112,16 +12163,18 @@ static ggml_backend_buffer_type_t ggml_backend_vk_device_get_host_buffer_type(gg
12112
12163
}
12113
12164
12114
12165
static enum ggml_backend_dev_type ggml_backend_vk_device_get_type(ggml_backend_dev_t dev) {
12115
- UNUSED(dev) ;
12116
- // TODO: return GGML_BACKEND_DEVICE_TYPE_IGPU for integrated GPUs
12117
- return GGML_BACKEND_DEVICE_TYPE_GPU;
12166
+ ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context ;
12167
+
12168
+ return ctx->is_integrated_gpu ? GGML_BACKEND_DEVICE_TYPE_IGPU : GGML_BACKEND_DEVICE_TYPE_GPU;
12118
12169
}
12119
12170
12120
12171
static void ggml_backend_vk_device_get_props(ggml_backend_dev_t dev, struct ggml_backend_dev_props * props) {
12172
+ ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;
12173
+
12121
12174
props->name = ggml_backend_vk_device_get_name(dev);
12122
12175
props->description = ggml_backend_vk_device_get_description(dev);
12123
12176
props->type = ggml_backend_vk_device_get_type(dev);
12124
- // TODO: set props->device_id to PCI bus id
12177
+ props->device_id = ctx->pci_bus_id.empty() ? nullptr : ctx->pci_bus_id.c_str();
12125
12178
ggml_backend_vk_device_get_memory(dev, &props->memory_free, &props->memory_total);
12126
12179
props->caps = {
12127
12180
/* .async = */ false,
@@ -12388,8 +12441,8 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
12388
12441
}
12389
12442
12390
12443
if (
12391
- src0_type == GGML_TYPE_F32 && src1_type == GGML_TYPE_I32 ||
12392
- src0_type == GGML_TYPE_I32 && src1_type == GGML_TYPE_F32
12444
+ ( src0_type == GGML_TYPE_F32 && src1_type == GGML_TYPE_I32) ||
12445
+ ( src0_type == GGML_TYPE_I32 && src1_type == GGML_TYPE_F32)
12393
12446
) {
12394
12447
return true;
12395
12448
}
@@ -12554,6 +12607,8 @@ static ggml_backend_dev_t ggml_backend_vk_reg_get_device(ggml_backend_reg_t reg,
12554
12607
ctx->device = i;
12555
12608
ctx->name = GGML_VK_NAME + std::to_string(i);
12556
12609
ctx->description = desc;
12610
+ ctx->is_integrated_gpu = ggml_backend_vk_get_device_type(i) == vk::PhysicalDeviceType::eIntegratedGpu;
12611
+ ctx->pci_bus_id = ggml_backend_vk_get_device_pci_id(i);
12557
12612
devices.push_back(new ggml_backend_device {
12558
12613
/* .iface = */ ggml_backend_vk_device_i,
12559
12614
/* .reg = */ reg,
0 commit comments