| @@ -266,6 +266,8 @@ public: | |||
| void query_extension_properties(); | |||
| public: | |||
| int device_index; | |||
| // physical device | |||
| VkPhysicalDevice physicalDevice; | |||
| @@ -1141,11 +1143,21 @@ GpuInfo& GpuInfo::operator=(const GpuInfo&) | |||
| return *this; | |||
| } | |||
| int GpuInfo::device_index() const | |||
| { | |||
| return d->device_index; | |||
| } | |||
| VkPhysicalDevice GpuInfo::physicalDevice() const | |||
| { | |||
| return d->physicalDevice; | |||
| } | |||
| VkPhysicalDevice GpuInfo::physical_device() const | |||
| { | |||
| return d->physicalDevice; | |||
| } | |||
| const VkPhysicalDeviceFeatures& GpuInfo::physicalDevicefeatures() const | |||
| { | |||
| return d->physicalDevicefeatures; | |||
| @@ -1161,6 +1173,11 @@ const VkPhysicalDeviceMemoryProperties& GpuInfo::physicalDeviceMemoryProperties( | |||
| return d->physicalDeviceMemoryProperties; | |||
| } | |||
| const VkPhysicalDeviceMemoryProperties& GpuInfo::physical_device_memory_properties() const | |||
| { | |||
| return d->physicalDeviceMemoryProperties; | |||
| } | |||
| const std::vector<VkExtensionProperties>& GpuInfo::deviceExtensionProperties() const | |||
| { | |||
| return d->deviceExtensionProperties; | |||
| @@ -2209,10 +2226,11 @@ int create_gpu_instance(const char* driver_path) | |||
| const VkPhysicalDevice& physicalDevice = physicalDevices[i]; | |||
| delete g_gpu_infos[gpu_info_index]; | |||
| g_gpu_infos[gpu_info_index] = new GpuInfo; | |||
| // GpuInfoPrivate& gpu_info = *(g_gpu_infos[gpu_info_index]->d); | |||
| GpuInfo& gpu_info = *g_gpu_infos[gpu_info_index]; | |||
| gpu_info.d->device_index = gpu_info_index; | |||
| gpu_info.d->physicalDevice = physicalDevice; | |||
| gpu_info.d->query_features(); | |||
| @@ -2591,12 +2609,11 @@ const ncnn::Packing_vulkan* VulkanDevicePrivate::get_utility_operator(int storag | |||
| opt.use_vulkan_compute = true; | |||
| opt.blob_vkallocator = opt.workspace_vkallocator = vkdev->acquire_blob_allocator(); | |||
| opt.staging_vkallocator = vkdev->acquire_staging_allocator(); | |||
| // cache uop pipeline as device member explicitly | |||
| opt.pipeline_cache = 0; | |||
| opt.vulkan_device_index = vkdev->info.device_index(); | |||
| ncnn::Packing_vulkan* uop = new ncnn::Packing_vulkan; | |||
| uop->vkdev = vkdev; | |||
| @@ -2613,9 +2630,6 @@ const ncnn::Packing_vulkan* VulkanDevicePrivate::get_utility_operator(int storag | |||
| uop_packing[storage_type_from][storage_type_to][cast_type_from_index][cast_type_to_index][packing_type_to_index] = uop; | |||
| vkdev->reclaim_blob_allocator(opt.blob_vkallocator); | |||
| vkdev->reclaim_staging_allocator(opt.staging_vkallocator); | |||
| return uop; | |||
| } | |||
| @@ -2627,6 +2641,7 @@ void VulkanDevicePrivate::destroy_utility_operator() | |||
| opt.use_int8_arithmetic = false; | |||
| opt.use_cooperative_matrix = false; | |||
| opt.pipeline_cache = 0; | |||
| opt.vulkan_device_index = vkdev->info.device_index(); | |||
| // from buffer | image | |||
| // to buffer | image | |||
| @@ -4576,11 +4591,13 @@ int compile_spirv_module(const char* comp_data, int comp_data_size, const Option | |||
| bool support_shader_int64 = false; | |||
| if (opt.blob_vkallocator) | |||
| // fill device macros | |||
| { | |||
| const VulkanDevice* vkdev = opt.blob_vkallocator->vkdev; | |||
| int device_index = opt.vulkan_device_index; | |||
| if (device_index < 0 || device_index >= get_gpu_count()) | |||
| device_index = get_default_gpu_index(); | |||
| const GpuInfo& info = vkdev->info; | |||
| const GpuInfo& info = get_gpu_info(device_index); | |||
| support_shader_int64 = info.physicalDevicefeatures().shaderInt64; | |||
| @@ -4935,10 +4952,6 @@ int compile_spirv_module(const char* comp_data, int comp_data_size, const Option | |||
| #undef DD_APPEND_PROPERTY | |||
| } | |||
| else | |||
| { | |||
| NCNN_LOGE("opt.blob_vkallocator is null"); | |||
| } | |||
| std::string define_macro_data; | |||
| @@ -193,8 +193,11 @@ public: | |||
| explicit GpuInfo(); | |||
| virtual ~GpuInfo(); | |||
| int device_index() const; | |||
| // vulkan physical device | |||
| VkPhysicalDevice physicalDevice() const; | |||
| VkPhysicalDevice physical_device() const; // api compatibility | |||
| // features | |||
| const VkPhysicalDeviceFeatures& physicalDevicefeatures() const; | |||
| @@ -204,6 +207,7 @@ public: | |||
| // memory properties | |||
| const VkPhysicalDeviceMemoryProperties& physicalDeviceMemoryProperties() const; | |||
| const VkPhysicalDeviceMemoryProperties& physical_device_memory_properties() const; // api compatibility | |||
| // extension properties | |||
| const std::vector<VkExtensionProperties>& deviceExtensionProperties() const; | |||
| @@ -1380,7 +1380,14 @@ int Net::load_param(const DataReader& dr) | |||
| if (opt.use_vulkan_compute) | |||
| { | |||
| if (!d->vkdev) d->vkdev = get_gpu_device(); | |||
| if (!d->vkdev) | |||
| { | |||
| int device_index = opt.vulkan_device_index; | |||
| if (device_index < 0 || device_index >= get_gpu_count()) | |||
| device_index = get_default_gpu_index(); | |||
| d->vkdev = get_gpu_device(device_index); | |||
| } | |||
| if (!d->vkdev || !d->vkdev->is_valid()) opt.use_vulkan_compute = false; // no valid vulkan device, fallback to cpu | |||
| } | |||
| if (opt.use_vulkan_compute) | |||
| @@ -1683,7 +1690,14 @@ int Net::load_param_bin(const DataReader& dr) | |||
| if (opt.use_vulkan_compute) | |||
| { | |||
| if (!d->vkdev) d->vkdev = get_gpu_device(); | |||
| if (!d->vkdev) | |||
| { | |||
| int device_index = opt.vulkan_device_index; | |||
| if (device_index < 0 || device_index >= get_gpu_count()) | |||
| device_index = get_default_gpu_index(); | |||
| d->vkdev = get_gpu_device(device_index); | |||
| } | |||
| if (!d->vkdev || !d->vkdev->is_valid()) opt.use_vulkan_compute = false; // no valid vulkan device, fallback to cpu | |||
| } | |||
| if (opt.use_vulkan_compute) | |||
| @@ -2305,11 +2319,13 @@ std::vector<Layer*>& Net::mutable_layers() | |||
| #if NCNN_VULKAN | |||
| void Net::set_vulkan_device(int device_index) | |||
| { | |||
| opt.vulkan_device_index = device_index; | |||
| d->vkdev = get_gpu_device(device_index); | |||
| } | |||
| void Net::set_vulkan_device(const VulkanDevice* _vkdev) | |||
| { | |||
| opt.vulkan_device_index = _vkdev->info.device_index(); | |||
| d->vkdev = _vkdev; | |||
| } | |||
| @@ -21,6 +21,10 @@ namespace ncnn { | |||
| Option::Option() | |||
| { | |||
| lightmode = true; | |||
| use_shader_pack8 = false; | |||
| use_subgroup_ops = false; | |||
| use_reserved_0 = false; | |||
| num_threads = get_physical_big_cpu_count(); | |||
| blob_allocator = 0; | |||
| workspace_allocator = 0; | |||
| @@ -50,18 +54,13 @@ Option::Option() | |||
| use_packing_layout = true; | |||
| use_shader_pack8 = false; | |||
| use_subgroup_ops = false; | |||
| use_subgroup_reserved_1 = false; | |||
| use_subgroup_reserved_2 = false; | |||
| use_subgroup_reserved_3 = false; | |||
| vulkan_device_index = -1; | |||
| use_reserved_1 = false; | |||
| use_image_storage = false; | |||
| use_tensor_storage = false; | |||
| use_reserved_0 = false; | |||
| use_reserved_2 = false; | |||
| flush_denormals = 3; | |||
| @@ -78,6 +77,10 @@ Option::Option() | |||
| use_fp16_uniform = true; | |||
| use_int8_uniform = true; | |||
| use_reserved_9 = false; | |||
| use_reserved_10 = false; | |||
| use_reserved_11 = false; | |||
| } | |||
| } // namespace ncnn | |||
| @@ -37,6 +37,14 @@ public: | |||
| // enabled by default | |||
| bool lightmode; | |||
| // use pack8 shader | |||
| bool use_shader_pack8; | |||
| // enable subgroup in shader | |||
| bool use_subgroup_ops; | |||
| bool use_reserved_0; | |||
| // thread count | |||
| // default value is the one returned by get_cpu_count() | |||
| int num_threads; | |||
| @@ -105,20 +113,16 @@ public: | |||
| // enabled by default | |||
| bool use_packing_layout; | |||
| bool use_shader_pack8; | |||
| // the vulkan device | |||
| int vulkan_device_index; | |||
| // subgroup option | |||
| bool use_subgroup_ops; | |||
| bool use_subgroup_reserved_1; | |||
| bool use_subgroup_reserved_2; | |||
| bool use_subgroup_reserved_3; | |||
| bool use_reserved_1; | |||
| // turn on for adreno | |||
| bool use_image_storage; | |||
| bool use_tensor_storage; | |||
| bool use_reserved_0; | |||
| bool use_reserved_2; | |||
| // enable DAZ(Denormals-Are-Zero) and FTZ(Flush-To-Zero) | |||
| // default value is 3 | |||