@@ -1445,6 +1445,49 @@ static bool ggml_vk_matmul_shmem_support(const vk_device& device, const std::vec
14451445 return supported;
14461446}
14471447
1448+ struct GpuPipelineConfig {
1449+ // List of all aliases for a given GPU.
1450+ // For example, this can include names like "NAVI10", "RX 5700", etc.
1451+ std::vector<std::string> device_names;
1452+
1453+ // Mapping of pipeline names to their specific subgroup sizes.
1454+ // Example: {"soft_max_f32", 64}.
1455+ std::unordered_map<std::string, uint32_t > pipelines;
1456+
1457+ // Default subgroup size for this GPU.
1458+ // Defaults to 0 if not explicitly provided.
1459+ uint32_t default_subgroup_size = 0 ;
1460+ };
1461+
1462+ // Define configurations for different GPUs.
1463+ static std::vector<GpuPipelineConfig> gpu_pipeline_configs = {
1464+ {
1465+ {" NAVI10" , " NAVI14" , " RX 5700" , " RX 5600" , " RX 5500" },
1466+ {
1467+ {" soft_max_f32" , 64 }, {" soft_max_f32_wg512" , 64 },
1468+ {" soft_max_f32_f16" , 64 }, {" soft_max_f32_f16_wg512" , 64 },
1469+ {" im2col_f32" , 64 }, {" im2col_f32_f16" , 64 },
1470+ },
1471+ 32
1472+ },
1473+ };
1474+
1475+ static uint32_t get_subgroup_size (const std::string &pipeline_name, const std::string &device_name) {
1476+ for (const auto &config : gpu_pipeline_configs) {
1477+ for (const auto &alias : config.device_names ) {
1478+ if (device_name.find (alias) != std::string::npos) {
1479+ auto pipIt = config.pipelines .find (pipeline_name);
1480+ if (pipIt != config.pipelines .end () && pipIt->second != 0 ) {
1481+ return pipIt->second ;
1482+ }
1483+ return config.default_subgroup_size ;
1484+ }
1485+ }
1486+ }
1487+ // If no matching configuration is found, return 0.
1488+ return 0 ;
1489+ }
1490+
14481491static void ggml_vk_load_shaders (vk_device& device) {
14491492 VK_LOG_DEBUG (" ggml_vk_load_shaders(" << device->name << " )" );
14501493
@@ -1566,11 +1609,17 @@ static void ggml_vk_load_shaders(vk_device& device) {
15661609 device->pipeline_matmul_id_f32 = std::make_shared<vk_matmul_pipeline_struct>();
15671610 }
15681611
1612+ vk::PhysicalDeviceProperties2 props2;
1613+ device->physical_device .getProperties2 (&props2);
1614+ std::string device_name = props2.properties .deviceName .data ();
1615+
15691616 std::vector<std::future<void >> compiles;
15701617 auto const &ggml_vk_create_pipeline = [&](vk_device& device, vk_pipeline& pipeline, const std::string &name, size_t spv_size, const void * spv_data, const std::string &entrypoint,
15711618 uint32_t parameter_count, uint32_t push_constant_size, std::array<uint32_t , 3 > wg_denoms, const std::vector<uint32_t >& specialization_constants,
15721619 uint32_t align, bool disable_robustness = false , bool require_full_subgroups = false , uint32_t required_subgroup_size = 0 ) {
15731620
1621+ required_subgroup_size = get_subgroup_size (name, device_name);
1622+
15741623 if (!pipeline) {
15751624 pipeline = std::make_shared<vk_pipeline_struct>();
15761625 pipeline->name = name;
@@ -2779,7 +2828,9 @@ static void ggml_vk_print_gpu_info(size_t idx) {
27792828 subgroup_props.pNext = &driver_props;
27802829 physical_device.getProperties2 (&props2);
27812830
2782- const size_t subgroup_size = subgroup_props.subgroupSize ;
2831+ uint32_t default_subgroup_size = get_subgroup_size (" " , props2.properties .deviceName .data ());
2832+ const size_t subgroup_size = (default_subgroup_size != 0 ) ? default_subgroup_size : subgroup_props.subgroupSize ;
2833+
27832834 const bool uma = props2.properties .deviceType == vk::PhysicalDeviceType::eIntegratedGpu;
27842835
27852836 bool fp16_storage = false ;
0 commit comments