From 39c433ccc62ecb5258d7b5586f073a39ff5253f3 Mon Sep 17 00:00:00 2001 From: futz12 <56149058+futz12@users.noreply.github.com> Date: Thu, 31 Jul 2025 16:05:51 +0000 Subject: [PATCH] apply code-format changes --- src/gpu.cpp | 116 +++++++++++++++++++-------------------- src/pipelinecache.cpp | 4 +- src/pipelinecache.h | 2 +- tests/test_pipecache.cpp | 7 ++- 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/src/gpu.cpp b/src/gpu.cpp index 06fe089ac..c2f489544 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -477,16 +477,16 @@ void GpuInfoPrivate::query_properties() } if (physicalDeviceProperties.vendorID == 0x13b5 - && (physicalDeviceProperties.deviceID == 0x7500001 - || physicalDeviceProperties.deviceID == 0x7501000 - || physicalDeviceProperties.deviceID == 0x8602000 - || physicalDeviceProperties.deviceID == 0x8800020 - || physicalDeviceProperties.deviceID == 0x70930000 - || physicalDeviceProperties.deviceID == 0x70901010 - || physicalDeviceProperties.deviceID == 0x72120000 - || physicalDeviceProperties.deviceID == 0x74021000 - || physicalDeviceProperties.deviceID == 0x60a00002 - || physicalDeviceProperties.deviceID == 0x62210001)) + && (physicalDeviceProperties.deviceID == 0x7500001 + || physicalDeviceProperties.deviceID == 0x7501000 + || physicalDeviceProperties.deviceID == 0x8602000 + || physicalDeviceProperties.deviceID == 0x8800020 + || physicalDeviceProperties.deviceID == 0x70930000 + || physicalDeviceProperties.deviceID == 0x70901010 + || physicalDeviceProperties.deviceID == 0x72120000 + || physicalDeviceProperties.deviceID == 0x74021000 + || physicalDeviceProperties.deviceID == 0x60a00002 + || physicalDeviceProperties.deviceID == 0x62210001)) { // NOTE rk3288/rk3399/t880/g31/g51/g52/g71/g72 // however, g76/g77 has explicit fp16 arithmetic @@ -495,9 +495,9 @@ void GpuInfoPrivate::query_properties() } if (physicalDeviceProperties.vendorID == 0x5143 - && (physicalDeviceProperties.deviceID == 0x6030001 - || physicalDeviceProperties.deviceID == 0x6040001 - || physicalDeviceProperties.deviceID == 0x6050002)) + && (physicalDeviceProperties.deviceID == 0x6030001 + || physicalDeviceProperties.deviceID == 0x6040001 + || physicalDeviceProperties.deviceID == 0x6050002)) { // TODO enable devices other than qcom845/qcom855/qcom855plus/qcom865 // qcom adreno driver accept spirv with fp16 arithmetic @@ -513,7 +513,7 @@ static uint32_t find_device_compute_queue(const std::vectorqueryCooperativeMatrixSubProperties[i]; if (cmp.AType == type && cmp.BType == type - && cmp.CType == acctype && cmp.ResultType == acctype - && cmp.scope == scope) + && cmp.CType == acctype && cmp.ResultType == acctype + && cmp.scope == scope) { mnk_properties.push_back(cmp); } @@ -2046,8 +2046,8 @@ void GpuInfo::get_optimal_cooperative_matrix_mnk(int M, int N, int K, VkComponen const VkCooperativeMatrixPropertiesNV& cmp = d->queryCooperativeMatrixSubPropertiesNV[i]; if (cmp.AType == (VkComponentTypeNV)type && cmp.BType == (VkComponentTypeNV)type - && cmp.CType == (VkComponentTypeNV)acctype && cmp.DType == (VkComponentTypeNV)acctype - && cmp.scope == (VkScopeNV)scope) + && cmp.CType == (VkComponentTypeNV)acctype && cmp.DType == (VkComponentTypeNV)acctype + && cmp.scope == (VkScopeNV)scope) { VkCooperativeMatrixPropertiesKHR cmp_khr; cmp_khr.MSize = cmp.MSize; @@ -2460,7 +2460,7 @@ int create_gpu_instance(const char* driver_path) #endif // __ANDROID_API__ >= 26 uint32_t instance_api_version = VK_MAKE_VERSION(1, 0, 0); - typedef VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceVersion)(uint32_t* pApiVersion); + typedef VkResult(VKAPI_PTR * PFN_vkEnumerateInstanceVersion)(uint32_t * pApiVersion); PFN_vkEnumerateInstanceVersion vkEnumerateInstanceVersion = (PFN_vkEnumerateInstanceVersion)vkGetInstanceProcAddr(0, "vkEnumerateInstanceVersion"); if (vkEnumerateInstanceVersion) { @@ -2673,7 +2673,7 @@ int create_gpu_instance(const char* driver_path) fp16_matrix_properties.push_back(cmp); } if ((cmp.AType == VK_COMPONENT_TYPE_SINT8_KHR || cmp.AType == VK_COMPONENT_TYPE_SINT8_PACKED_NV) - && (cmp.BType == VK_COMPONENT_TYPE_SINT8_KHR || cmp.BType == VK_COMPONENT_TYPE_SINT8_PACKED_NV)) + && (cmp.BType == VK_COMPONENT_TYPE_SINT8_KHR || cmp.BType == VK_COMPONENT_TYPE_SINT8_PACKED_NV)) { bool mnk_hit = false; for (size_t k = 0; k < int8_matrix_properties.size(); k++) @@ -2704,9 +2704,9 @@ int create_gpu_instance(const char* driver_path) bf16_matrix_properties.push_back(cmp); } if ((cmp.AType == VK_COMPONENT_TYPE_FLOAT8_E4M3_EXT || cmp.AType == VK_COMPONENT_TYPE_FLOAT8_E5M2_EXT - || cmp.AType == VK_COMPONENT_TYPE_FLOAT_E4M3_NV || cmp.AType == VK_COMPONENT_TYPE_FLOAT_E5M2_NV) - && (cmp.BType == VK_COMPONENT_TYPE_FLOAT8_E4M3_EXT || cmp.BType == VK_COMPONENT_TYPE_FLOAT8_E5M2_EXT - || cmp.BType == VK_COMPONENT_TYPE_FLOAT_E4M3_NV || cmp.BType == VK_COMPONENT_TYPE_FLOAT_E5M2_NV)) + || cmp.AType == VK_COMPONENT_TYPE_FLOAT_E4M3_NV || cmp.AType == VK_COMPONENT_TYPE_FLOAT_E5M2_NV) + && (cmp.BType == VK_COMPONENT_TYPE_FLOAT8_E4M3_EXT || cmp.BType == VK_COMPONENT_TYPE_FLOAT8_E5M2_EXT + || cmp.BType == VK_COMPONENT_TYPE_FLOAT_E4M3_NV || cmp.BType == VK_COMPONENT_TYPE_FLOAT_E5M2_NV)) { bool mnk_hit = false; for (size_t k = 0; k < fp8_matrix_properties.size(); k++) @@ -3144,9 +3144,8 @@ const ncnn::Layer* VulkanDevicePrivate::get_utility_operator(int cast_type_from_ uop->vkdev = vkdev; ncnn::ParamDict pd; - pd.set(0, packing_type_to_index == 0 ? 1 : packing_type_to_index == 1 ? 4 - : 8); // out_elempack - pd.set(2, cast_type_from_index + 1); // 0=auto 1=fp32 2=fp16 3=int8 + pd.set(0, packing_type_to_index == 0 ? 1 : packing_type_to_index == 1 ? 4 : 8); // out_elempack + pd.set(2, cast_type_from_index + 1); // 0=auto 1=fp32 2=fp16 3=int8 pd.set(3, cast_type_to_index + 1); uop->load_param(pd); @@ -3897,8 +3896,8 @@ uint32_t VulkanDevice::find_memory_index(uint32_t memory_type_bits, VkFlags requ { const VkMemoryType& memoryType = memory_properties.memoryTypes[i]; if ((memoryType.propertyFlags & required) == required - && (preferred && (memoryType.propertyFlags & preferred)) - && (preferred_not && !(memoryType.propertyFlags & preferred_not))) + && (preferred && (memoryType.propertyFlags & preferred)) + && (preferred_not && !(memoryType.propertyFlags & preferred_not))) { return i; } @@ -3913,7 +3912,7 @@ uint32_t VulkanDevice::find_memory_index(uint32_t memory_type_bits, VkFlags requ { const VkMemoryType& memoryType = memory_properties.memoryTypes[i]; if ((memoryType.propertyFlags & required) == required - && (preferred && (memoryType.propertyFlags & preferred))) + && (preferred && (memoryType.propertyFlags & preferred))) { return i; } @@ -3928,7 +3927,7 @@ uint32_t VulkanDevice::find_memory_index(uint32_t memory_type_bits, VkFlags requ { const VkMemoryType& memoryType = memory_properties.memoryTypes[i]; if ((memoryType.propertyFlags & required) == required - && (preferred_not && !(memoryType.propertyFlags & preferred_not))) + && (preferred_not && !(memoryType.propertyFlags & preferred_not))) { return i; } @@ -4236,8 +4235,7 @@ void VulkanDevice::convert_packing(const VkMat& src, VkMat& dst, int dst_elempac void VulkanDevice::convert_packing(const VkMat& src, VkMat& dst, int dst_elempack, int cast_type_to, VkCompute& cmd, const Option& opt) const { - int packing_type_to_index = dst_elempack == 1 ? 0 : dst_elempack == 4 ? 1 - : 2; + int packing_type_to_index = dst_elempack == 1 ? 0 : dst_elempack == 4 ? 1 : 2; int cast_type_from_index; if (src.elembits() == 32) diff --git a/src/pipelinecache.cpp b/src/pipelinecache.cpp index cde9ee9ca..0fa9dd73a 100644 --- a/src/pipelinecache.cpp +++ b/src/pipelinecache.cpp @@ -145,7 +145,7 @@ public: }; PipelineCachePrivate::pipeline_cache_digest::pipeline_cache_digest(const uint32_t* spv_data, size_t spv_data_size, const std::vector& specializations, - uint32_t _local_size_x, uint32_t _local_size_y, uint32_t _local_size_z, uint32_t _subgroup_size) + uint32_t _local_size_x, uint32_t _local_size_y, uint32_t _local_size_z, uint32_t _subgroup_size) { spv_data_murmur3 = murmur3_32(spv_data, spv_data_size / 4); @@ -163,7 +163,7 @@ PipelineCachePrivate::pipeline_cache_digest::pipeline_cache_digest(const uint32_ } PipelineCachePrivate::pipeline_cache_digest::pipeline_cache_digest(int _shader_type_index, const Option& opt, const std::vector& specializations, - uint32_t _local_size_x, uint32_t _local_size_y, uint32_t _local_size_z, uint32_t _subgroup_size) + uint32_t _local_size_x, uint32_t _local_size_y, uint32_t _local_size_z, uint32_t _subgroup_size) { shader_type_index = _shader_type_index; diff --git a/src/pipelinecache.h b/src/pipelinecache.h index 15086e268..9962b645f 100644 --- a/src/pipelinecache.h +++ b/src/pipelinecache.h @@ -42,7 +42,7 @@ public: VkDescriptorUpdateTemplateKHR* descriptor_update_template, ShaderInfo& shader_info) const; - int save_cache(std::vector &buf) const; + int save_cache(std::vector& buf) const; int load_cache(const std::vector& buf) const; #ifdef NCNN_STDIO diff --git a/tests/test_pipecache.cpp b/tests/test_pipecache.cpp index acbcabe53..b63e29eea 100644 --- a/tests/test_pipecache.cpp +++ b/tests/test_pipecache.cpp @@ -298,7 +298,7 @@ static int test_gpu_pipecache_performance() net_no_cache.load_model(dr); auto end = std::chrono::high_resolution_clock::now(); - time_no_cache = std::chrono::duration_cast>(end - start).count(); + time_no_cache = std::chrono::duration_cast >(end - start).count(); std::cout << "Model loading time without cache: " << time_no_cache << " ms" << std::endl; // 推理以获得基准输出 @@ -347,7 +347,7 @@ static int test_gpu_pipecache_performance() net_with_cache.load_model(dr); auto end = std::chrono::high_resolution_clock::now(); - time_with_cache = std::chrono::duration_cast>(end - start).count(); + time_with_cache = std::chrono::duration_cast >(end - start).count(); std::cout << "Model loading time with cache: " << time_with_cache << " ms" << std::endl; // 推理 @@ -377,7 +377,8 @@ static int test_gpu_pipecache_performance() std::cout << " - Without Cache: " << time_no_cache << " ms" << std::endl; std::cout << " - With Cache: " << time_with_cache << " ms" << std::endl; - if (time_no_cache > 0) { + if (time_no_cache > 0) + { double speedup = (time_no_cache - time_with_cache) / time_no_cache * 100; std::cout << " - Speedup: " << speedup << "%" << std::endl; }