From a7cb29ea7d16651ca30309c69b5b1bbf672d708c Mon Sep 17 00:00:00 2001 From: Jorge Pineda Date: Wed, 8 May 2024 09:36:09 -0700 Subject: [PATCH 1/2] [ET-VK][EZ] Stylize struct members with snake_case Because the current mix of camelCase and snake_case is inconsistent. Differential Revision: [D57080712](https://our.internmc.facebook.com/intern/diff/D57080712/) [ghstack-poisoned] --- backends/vulkan/runtime/VulkanBackend.cpp | 14 ++--- .../vulkan/runtime/VulkanDelegateHeader.cpp | 18 +++---- .../vulkan/runtime/VulkanDelegateHeader.h | 8 +-- backends/vulkan/runtime/api/Command.cpp | 4 +- backends/vulkan/runtime/api/Command.h | 4 +- backends/vulkan/runtime/api/Context.cpp | 16 +++--- backends/vulkan/runtime/api/Context.h | 12 ++--- backends/vulkan/runtime/api/Descriptor.cpp | 14 ++--- backends/vulkan/runtime/api/Descriptor.h | 12 ++--- backends/vulkan/runtime/api/QueryPool.cpp | 10 ++-- backends/vulkan/runtime/api/QueryPool.h | 4 +- backends/vulkan/runtime/api/Runtime.cpp | 24 ++++----- backends/vulkan/runtime/api/Runtime.h | 8 +-- .../vulkan/runtime/graph/ComputeGraph.cpp | 54 +++++++++---------- backends/vulkan/runtime/graph/GraphConfig.cpp | 53 +++++++++--------- backends/vulkan/runtime/graph/GraphConfig.h | 16 +++--- .../vulkan/test/op_tests/utils/codegen.py | 4 +- 17 files changed, 137 insertions(+), 138 deletions(-) diff --git a/backends/vulkan/runtime/VulkanBackend.cpp b/backends/vulkan/runtime/VulkanBackend.cpp index c1f3f06b440..1c754599678 100644 --- a/backends/vulkan/runtime/VulkanBackend.cpp +++ b/backends/vulkan/runtime/VulkanBackend.cpp @@ -48,7 +48,7 @@ using BytesVector = const flatbuffers::Vector>*; using UIntVector = const flatbuffers::Vector*; -const uint8_t* getConstantDataPtr( +const uint8_t* get_constant_data_ptr( VkGraphPtr flatbuffer_graph, const int32_t buffer_idx, const uint8_t* constant_data) { @@ -111,19 +111,19 @@ GraphConfig get_graph_config(ArrayRef& compile_specs) { const size_t value_size = spec.value.nbytes; if (strcmp(spec.key, "storage_type_override") == 0) { ET_CHECK_MSG(value_size == sizeof(int32_t), "Unexpected value size!"); - int value_as_int = static_cast(GetUInt32LE(value_data)); + int value_as_int = static_cast(getUInt32LE(value_data)); api::StorageType storage_type = static_cast(value_as_int); - config.setStorageTypeOverride(storage_type); + config.set_storage_type_override(storage_type); } if (strcmp(spec.key, "memory_layout_override") == 0) { ET_CHECK_MSG(value_size == sizeof(uint32_t), "Unexpected value size!"); - uint32_t value_as_int = GetUInt32LE(value_data); + uint32_t value_as_int = getUInt32LE(value_data); api::GPUMemoryLayout memory_layout = static_cast(value_as_int); - config.setMemoryLayoutOverride(memory_layout); + config.set_memory_layout_override(memory_layout); } } return config; @@ -181,7 +181,7 @@ class GraphBuilder { ValueRef ref; if (tensor_fb->constant_id() >= 0) { - const uint8_t* tensor_data = getConstantDataPtr( + const uint8_t* tensor_data = get_constant_data_ptr( flatbuffer_, tensor_fb->constant_id(), constant_data_); ref = compute_graph_->add_tensorref(dims_vector, dtype, tensor_data); @@ -399,7 +399,7 @@ class VulkanBackend final : public PyTorchBackendInterface { __ET_NODISCARD Error compileModel(const void* buffer_pointer, ComputeGraph* compute_graph) const { Result header = - VulkanDelegateHeader::Parse(buffer_pointer); + VulkanDelegateHeader::parse(buffer_pointer); const uint8_t* flatbuffer_data = nullptr; const uint8_t* constant_data = nullptr; diff --git a/backends/vulkan/runtime/VulkanDelegateHeader.cpp b/backends/vulkan/runtime/VulkanDelegateHeader.cpp index 4415996a648..a9a9fa849a7 100644 --- a/backends/vulkan/runtime/VulkanDelegateHeader.cpp +++ b/backends/vulkan/runtime/VulkanDelegateHeader.cpp @@ -39,7 +39,7 @@ constexpr ByteSlice kBytesSize = {22, 8}; } // namespace /// Interprets the 8 bytes at `data` as a little-endian uint64_t. -uint64_t GetUInt64LE(const uint8_t* data) { +uint64_t getUInt64LE(const uint8_t* data) { return (uint64_t)data[0] | ((uint64_t)data[1] << 8) | ((uint64_t)data[2] << 16) | ((uint64_t)data[3] << 24) | ((uint64_t)data[4] << 32) | ((uint64_t)data[5] << 40) | @@ -47,13 +47,13 @@ uint64_t GetUInt64LE(const uint8_t* data) { } /// Interprets the 4 bytes at `data` as a little-endian uint32_t. -uint32_t GetUInt32LE(const uint8_t* data) { +uint32_t getUInt32LE(const uint8_t* data) { return (uint32_t)data[0] | ((uint32_t)data[1] << 8) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 24); } /// Interprets the 2 bytes at `data` as a little-endian uint32_t. -uint32_t GetUInt16LE(const uint8_t* data) { +uint32_t getUInt16LE(const uint8_t* data) { return (uint32_t)data[0] | ((uint32_t)data[1] << 8); } @@ -77,7 +77,7 @@ bool VulkanDelegateHeader::is_valid() const { return true; } -Result VulkanDelegateHeader::Parse(const void* data) { +Result VulkanDelegateHeader::parse(const void* data) { const uint8_t* header_data = (const uint8_t*)data; const uint8_t* magic_start = header_data + kMagic.offset; @@ -86,11 +86,11 @@ Result VulkanDelegateHeader::Parse(const void* data) { } VulkanDelegateHeader header = VulkanDelegateHeader{ - GetUInt16LE(header_data + kHeaderSize.offset), - GetUInt32LE(header_data + kFlatbufferOffset.offset), - GetUInt32LE(header_data + kFlatbufferSize.offset), - GetUInt32LE(header_data + kBytesOffset.offset), - GetUInt64LE(header_data + kBytesSize.offset), + getUInt16LE(header_data + kHeaderSize.offset), + getUInt32LE(header_data + kFlatbufferOffset.offset), + getUInt32LE(header_data + kFlatbufferSize.offset), + getUInt32LE(header_data + kBytesOffset.offset), + getUInt64LE(header_data + kBytesSize.offset), }; if (!header.is_valid()) { diff --git a/backends/vulkan/runtime/VulkanDelegateHeader.h b/backends/vulkan/runtime/VulkanDelegateHeader.h index f9757ef4c2a..c5e8859743a 100644 --- a/backends/vulkan/runtime/VulkanDelegateHeader.h +++ b/backends/vulkan/runtime/VulkanDelegateHeader.h @@ -15,14 +15,14 @@ namespace executor { namespace vulkan { // Byte decoding utilities -uint64_t GetUInt64LE(const uint8_t* data); -uint32_t GetUInt32LE(const uint8_t* data); -uint32_t GetUInt16LE(const uint8_t* data); +uint64_t getUInt64LE(const uint8_t* data); +uint32_t getUInt32LE(const uint8_t* data); +uint32_t getUInt16LE(const uint8_t* data); struct VulkanDelegateHeader { bool is_valid() const; - static Result Parse(const void* data); + static Result parse(const void* data); uint32_t header_size; uint32_t flatbuffer_offset; diff --git a/backends/vulkan/runtime/api/Command.cpp b/backends/vulkan/runtime/api/Command.cpp index 2ddb4ab15aa..841c40e471a 100644 --- a/backends/vulkan/runtime/api/Command.cpp +++ b/backends/vulkan/runtime/api/Command.cpp @@ -392,7 +392,7 @@ CommandPool::CommandPool( VK_CHECK(vkCreateCommandPool(device_, &create_info, nullptr, &pool_)); // Pre-allocate some command buffers - allocate_new_batch(config_.cmdPoolInitialSize); + allocate_new_batch(config_.cmd_pool_initial_size); } CommandPool::~CommandPool() { @@ -406,7 +406,7 @@ CommandBuffer CommandPool::get_new_cmd(bool reusable) { std::lock_guard lock(mutex_); // No-ops if there are command buffers available - allocate_new_batch(config_.cmdPoolBatchSize); + allocate_new_batch(config_.cmd_pool_batch_size); VkCommandBuffer handle = buffers_[in_use_]; diff --git a/backends/vulkan/runtime/api/Command.h b/backends/vulkan/runtime/api/Command.h index 904631b2ac4..877f84d4cec 100644 --- a/backends/vulkan/runtime/api/Command.h +++ b/backends/vulkan/runtime/api/Command.h @@ -130,8 +130,8 @@ class CommandBuffer final { }; struct CommandPoolConfig final { - uint32_t cmdPoolInitialSize; - uint32_t cmdPoolBatchSize; + uint32_t cmd_pool_initial_size; + uint32_t cmd_pool_batch_size; }; class CommandPool final { diff --git a/backends/vulkan/runtime/api/Context.cpp b/backends/vulkan/runtime/api/Context.cpp index 9a43cf455d6..9f6cdabf396 100644 --- a/backends/vulkan/runtime/api/Context.cpp +++ b/backends/vulkan/runtime/api/Context.cpp @@ -30,12 +30,12 @@ Context::Context(size_t adapter_i, const ContextConfig& config) device_(adapter_p_->device_handle()), queue_(adapter_p_->request_queue()), // Resource pools - command_pool_(device_, queue_.family_index, config_.cmdPoolConfig), - descriptor_pool_(device_, config_.descriptorPoolConfig), + command_pool_(device_, queue_.family_index, config_.cmd_pool_config), + descriptor_pool_(device_, config_.descriptor_pool_config), fences_(device_), // Diagnostics #ifdef USE_VULKAN_GPU_DIAGNOSTICS - querypool_(config_.queryPoolConfig, adapter_p_), + querypool_(config_.query_pool_config, adapter_p_), #endif /* USE_VULKAN_GPU_DIAGNOSTICS */ // Command buffer submission cmd_mutex_{}, @@ -143,7 +143,7 @@ bool available() { Context* context() { static const std::unique_ptr context([]() -> Context* { try { - const uint32_t submit_frequency = 16u; + const uint32_t cmd_submit_frequency = 16u; const CommandPoolConfig cmd_config{ 32u, // cmdPoolInitialSize @@ -165,10 +165,10 @@ Context* context() { }; const ContextConfig config{ - submit_frequency, // cmdSubmitFrequency - cmd_config, // cmdPoolConfig - descriptor_pool_config, // descriptorPoolConfig - query_pool_config, // queryPoolConfig + cmd_submit_frequency, + cmd_config, + descriptor_pool_config, + query_pool_config, }; return new Context(runtime()->default_adapter_i(), config); diff --git a/backends/vulkan/runtime/api/Context.h b/backends/vulkan/runtime/api/Context.h index d79344dce8d..bddb9e1ae17 100644 --- a/backends/vulkan/runtime/api/Context.h +++ b/backends/vulkan/runtime/api/Context.h @@ -26,10 +26,10 @@ namespace vkcompute { namespace api { struct ContextConfig final { - uint32_t cmdSubmitFrequency; - CommandPoolConfig cmdPoolConfig; - DescriptorPoolConfig descriptorPoolConfig; - QueryPoolConfig queryPoolConfig; + uint32_t cmd_submit_frequency; + CommandPoolConfig cmd_pool_config; + DescriptorPoolConfig descriptor_pool_config; + QueryPoolConfig query_pool_config; }; // @@ -485,7 +485,7 @@ inline bool Context::submit_copy( submit_count_++; if (fence_handle != VK_NULL_HANDLE || - submit_count_ >= config_.cmdSubmitFrequency) { + submit_count_ >= config_.cmd_submit_frequency) { submit_cmd_to_gpu(fence_handle); return true; } @@ -568,7 +568,7 @@ inline bool Context::submit_compute_job( submit_count_++; if (fence_handle != VK_NULL_HANDLE || - submit_count_ >= config_.cmdSubmitFrequency) { + submit_count_ >= config_.cmd_submit_frequency) { submit_cmd_to_gpu(fence_handle); return true; } diff --git a/backends/vulkan/runtime/api/Descriptor.cpp b/backends/vulkan/runtime/api/Descriptor.cpp index 572cc674981..99ca6978594 100644 --- a/backends/vulkan/runtime/api/Descriptor.cpp +++ b/backends/vulkan/runtime/api/Descriptor.cpp @@ -235,7 +235,7 @@ DescriptorPool::DescriptorPool( config_(config), mutex_{}, piles_{} { - if (config.descriptorPoolMaxSets > 0) { + if (config.descriptor_pool_max_sets > 0) { init(config); } } @@ -257,19 +257,19 @@ void DescriptorPool::init(const DescriptorPoolConfig& config) { std::vector type_sizes{ { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - config_.descriptorUniformBufferCount, + config_.descriptor_uniform_buffer_count, }, { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, - config_.descriptorStorageBufferCount, + config_.descriptor_storage_buffer_count, }, { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - config_.descriptorCombinedSamplerCount, + config_.descriptor_combined_sampler_count, }, { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - config_.descriptorStorageBufferCount, + config_.descriptor_storage_buffer_count, }, }; @@ -277,7 +277,7 @@ void DescriptorPool::init(const DescriptorPoolConfig& config) { VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, // sType nullptr, // pNext 0u, // flags - config_.descriptorPoolMaxSets, // maxSets + config_.descriptor_pool_max_sets, // maxSets static_cast(type_sizes.size()), // poolSizeCounts type_sizes.data(), // pPoolSizes }; @@ -297,7 +297,7 @@ DescriptorSet DescriptorPool::get_descriptor_set( .insert({ set_layout, DescriptorSetPile( - config_.descriptorPileSizes, set_layout, device_, pool_), + config_.descriptor_pile_sizes, set_layout, device_, pool_), }) .first; } diff --git a/backends/vulkan/runtime/api/Descriptor.h b/backends/vulkan/runtime/api/Descriptor.h index 0b6b1cd885a..915a5b824c1 100644 --- a/backends/vulkan/runtime/api/Descriptor.h +++ b/backends/vulkan/runtime/api/Descriptor.h @@ -107,14 +107,14 @@ class DescriptorSetPile final { struct DescriptorPoolConfig final { // Overall Pool capacity - uint32_t descriptorPoolMaxSets; + uint32_t descriptor_pool_max_sets; // DescriptorCounts by type - uint32_t descriptorUniformBufferCount; - uint32_t descriptorStorageBufferCount; - uint32_t descriptorCombinedSamplerCount; - uint32_t descriptorStorageImageCount; + uint32_t descriptor_uniform_buffer_count; + uint32_t descriptor_storage_buffer_count; + uint32_t descriptor_combined_sampler_count; + uint32_t descriptor_storage_image_count; // Pile size for pre-allocating descriptor sets - uint32_t descriptorPileSizes; + uint32_t descriptor_pile_sizes; }; class DescriptorPool final { diff --git a/backends/vulkan/runtime/api/QueryPool.cpp b/backends/vulkan/runtime/api/QueryPool.cpp index b908c6e53b4..5deff1d4c4c 100644 --- a/backends/vulkan/runtime/api/QueryPool.cpp +++ b/backends/vulkan/runtime/api/QueryPool.cpp @@ -42,13 +42,13 @@ QueryPool::QueryPool(const QueryPoolConfig& config, const Adapter* adapter_p) nullptr, // pNext 0u, // flags VK_QUERY_TYPE_TIMESTAMP, // queryType - config_.maxQueryCount, // queryCount + config_.max_query_count, // queryCount 0u, // pipelineStatistics }; VK_CHECK(vkCreateQueryPool(device_, &info, nullptr, &querypool_)); - shader_log().reserve(config_.initialReserveSize); + shader_log().reserve(config_.initial_reserve_size); VK_CHECK_COND(adapter_p, "Valid GPU device must be created for QueryPool"); ns_per_tick_ = std::lround(adapter_p->timestamp_period()); @@ -79,16 +79,16 @@ void QueryPool::reset(const CommandBuffer& cmd) { previous_shader_count_ += shader_log().size(); in_use_ = 0u; shader_logs_.emplace_back(); - shader_log().reserve(config_.initialReserveSize); + shader_log().reserve(config_.initial_reserve_size); results_pending_ = false; } size_t QueryPool::write_timestamp(const CommandBuffer& cmd) { VK_CHECK_COND( - in_use_ < config_.maxQueryCount, + in_use_ < config_.max_query_count, "Vulkan QueryPool: Exceeded the maximum number of queries " "allowed by the queryPool (", - config_.maxQueryCount, + config_.max_query_count, ")!"); cmd.write_timestamp(querypool_, in_use_); diff --git a/backends/vulkan/runtime/api/QueryPool.h b/backends/vulkan/runtime/api/QueryPool.h index 9249942df08..a0c6d9b14f1 100644 --- a/backends/vulkan/runtime/api/QueryPool.h +++ b/backends/vulkan/runtime/api/QueryPool.h @@ -22,8 +22,8 @@ namespace vkcompute { namespace api { struct QueryPoolConfig final { - uint32_t maxQueryCount; - uint32_t initialReserveSize; + uint32_t max_query_count; + uint32_t initial_reserve_size; }; struct ShaderDuration final { diff --git a/backends/vulkan/runtime/api/Runtime.cpp b/backends/vulkan/runtime/api/Runtime.cpp index e113a4e3b4f..ebed34162f3 100644 --- a/backends/vulkan/runtime/api/Runtime.cpp +++ b/backends/vulkan/runtime/api/Runtime.cpp @@ -91,7 +91,7 @@ VkInstance create_instance(const RuntimeConfiguration& config) { std::vector enabled_layers; std::vector enabled_extensions; - if (config.enableValidationMessages) { + if (config.enable_validation_messages) { std::vector requested_layers{ // "VK_LAYER_LUNARG_api_dump", "VK_LAYER_KHRONOS_validation", @@ -175,7 +175,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL debug_report_callback_fn( VkDebugReportCallbackEXT create_debug_report_callback( VkInstance instance, const RuntimeConfiguration config) { - if (VK_NULL_HANDLE == instance || !config.enableValidationMessages) { + if (VK_NULL_HANDLE == instance || !config.enable_validation_messages) { return VkDebugReportCallbackEXT{}; } @@ -245,20 +245,20 @@ std::unique_ptr init_global_vulkan_runtime() { } #endif /* USE_VULKAN_VOLK, USE_VULKAN_WRAPPER */ - const bool enableValidationMessages = + const bool enable_validation_messages = #if defined(VULKAN_DEBUG) true; #else false; #endif /* VULKAN_DEBUG */ - const bool initDefaultDevice = true; - const uint32_t numRequestedQueues = 1; // TODO: raise this value + const bool init_default_device = true; + const uint32_t num_requested_queues = 1; // TODO: raise this value const RuntimeConfiguration default_config{ - enableValidationMessages, - initDefaultDevice, + enable_validation_messages, + init_default_device, AdapterSelector::First, - numRequestedQueues, + num_requested_queues, }; try { @@ -281,9 +281,9 @@ Runtime::Runtime(const RuntimeConfiguration config) // List of adapters will never exceed the number of physical devices adapters_.reserve(device_mappings_.size()); - if (config.initDefaultDevice) { + if (config.init_default_device) { try { - switch (config.defaultSelector) { + switch (config.default_selector) { case AdapterSelector::First: default_adapter_i_ = create_adapter(select_first); } @@ -350,8 +350,8 @@ uint32_t Runtime::create_adapter(const Selector& selector) { } // Otherwise, create an adapter for the selected physical device adapter_i = utils::safe_downcast(adapters_.size()); - adapters_.emplace_back( - new Adapter(instance_, device_mapping.first, config_.numRequestedQueues)); + adapters_.emplace_back(new Adapter( + instance_, device_mapping.first, config_.num_requested_queues)); device_mapping.second = adapter_i; return adapter_i; diff --git a/backends/vulkan/runtime/api/Runtime.h b/backends/vulkan/runtime/api/Runtime.h index f54bd7522ac..6cfcc0ca03a 100644 --- a/backends/vulkan/runtime/api/Runtime.h +++ b/backends/vulkan/runtime/api/Runtime.h @@ -35,10 +35,10 @@ enum AdapterSelector { }; struct RuntimeConfiguration final { - bool enableValidationMessages; - bool initDefaultDevice; - AdapterSelector defaultSelector; - uint32_t numRequestedQueues; + bool enable_validation_messages; + bool init_default_device; + AdapterSelector default_selector; + uint32_t num_requested_queues; }; class Runtime final { diff --git a/backends/vulkan/runtime/graph/ComputeGraph.cpp b/backends/vulkan/runtime/graph/ComputeGraph.cpp index 0c7941d6f52..2e8f4c007d0 100644 --- a/backends/vulkan/runtime/graph/ComputeGraph.cpp +++ b/backends/vulkan/runtime/graph/ComputeGraph.cpp @@ -56,7 +56,7 @@ ComputeGraph::ComputeGraph(GraphConfig config) execute_descriptor_counts_{}, context_{new api::Context( api::runtime()->default_adapter_i(), - config_.contextConfig)}, + config_.context_config)}, shared_objects_{}, values_{}, param_ubos_{}, @@ -65,17 +65,17 @@ ComputeGraph::ComputeGraph(GraphConfig config) inputs_{}, outputs_{} { // Ensure that descriptor counts are initialized to 0 - prepack_descriptor_counts_.descriptorPoolMaxSets = 0; - prepack_descriptor_counts_.descriptorUniformBufferCount = 0; - prepack_descriptor_counts_.descriptorStorageBufferCount = 0; - prepack_descriptor_counts_.descriptorCombinedSamplerCount = 0; - prepack_descriptor_counts_.descriptorStorageImageCount = 0; - - execute_descriptor_counts_.descriptorPoolMaxSets = 0; - execute_descriptor_counts_.descriptorUniformBufferCount = 0; - execute_descriptor_counts_.descriptorStorageBufferCount = 0; - execute_descriptor_counts_.descriptorCombinedSamplerCount = 0; - execute_descriptor_counts_.descriptorStorageImageCount = 0; + prepack_descriptor_counts_.descriptor_pool_max_sets = 0; + prepack_descriptor_counts_.descriptor_uniform_buffer_count = 0; + prepack_descriptor_counts_.descriptor_storage_buffer_count = 0; + prepack_descriptor_counts_.descriptor_combined_sampler_count = 0; + prepack_descriptor_counts_.descriptor_storage_image_count = 0; + + execute_descriptor_counts_.descriptor_pool_max_sets = 0; + execute_descriptor_counts_.descriptor_uniform_buffer_count = 0; + execute_descriptor_counts_.descriptor_storage_buffer_count = 0; + execute_descriptor_counts_.descriptor_combined_sampler_count = 0; + execute_descriptor_counts_.descriptor_storage_image_count = 0; context_->set_cmd(/*reusable = */ true); } @@ -95,20 +95,20 @@ void ComputeGraph::update_descriptor_counts( api::DescriptorPoolConfig* config = execute ? &execute_descriptor_counts_ : &prepack_descriptor_counts_; - config->descriptorPoolMaxSets += 1; + config->descriptor_pool_max_sets += 1; for (const VkDescriptorType arg_type : shader_info.kernel_layout) { switch (arg_type) { case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: - config->descriptorUniformBufferCount += 1; + config->descriptor_uniform_buffer_count += 1; break; case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: - config->descriptorStorageBufferCount += 1; + config->descriptor_storage_buffer_count += 1; break; case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: - config->descriptorCombinedSamplerCount += 1; + config->descriptor_combined_sampler_count += 1; break; case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: - config->descriptorStorageImageCount += 1; + config->descriptor_storage_image_count += 1; break; default: VK_THROW("Unsupported descriptor type!"); @@ -117,16 +117,16 @@ void ComputeGraph::update_descriptor_counts( } api::StorageType ComputeGraph::suggested_storage_type() { - if (config_.enableStorageTypeOverride) { - return config_.storageTypeOverride; + if (config_.enable_storage_type_override) { + return config_.storage_type_override; } return api::kTexture3D; } api::GPUMemoryLayout ComputeGraph::suggested_memory_layout( const std::vector& sizes) { - if (config_.enableMemoryLayoutOverride) { - return config_.memoryLayoutOverride; + if (config_.enable_memory_layout_override) { + return config_.memory_layout_override; } if (sizes.size() < 3) { return api::kWidthPacked; @@ -319,15 +319,15 @@ void ComputeGraph::prepare() { std::max( \ execute_descriptor_counts_.field, \ prepack_descriptor_counts_.field) * \ - config_.descriptorPoolSafetyFactor)) + config_.descriptor_pool_safety_factor)) - uint32_t max_sets = MERGE_FIELD(descriptorPoolMaxSets); + uint32_t max_sets = MERGE_FIELD(descriptor_pool_max_sets); api::DescriptorPoolConfig config{ max_sets, - std::max(MERGE_FIELD(descriptorUniformBufferCount), max_sets), - std::max(MERGE_FIELD(descriptorStorageBufferCount), max_sets), - std::max(MERGE_FIELD(descriptorCombinedSamplerCount), max_sets), - std::max(MERGE_FIELD(descriptorStorageImageCount), max_sets), + std::max(MERGE_FIELD(descriptor_uniform_buffer_count), max_sets), + std::max(MERGE_FIELD(descriptor_storage_buffer_count), max_sets), + std::max(MERGE_FIELD(descriptor_combined_sampler_count), max_sets), + std::max(MERGE_FIELD(descriptor_storage_image_count), max_sets), 1u, }; diff --git a/backends/vulkan/runtime/graph/GraphConfig.cpp b/backends/vulkan/runtime/graph/GraphConfig.cpp index 98b2d9a4263..29de4704395 100644 --- a/backends/vulkan/runtime/graph/GraphConfig.cpp +++ b/backends/vulkan/runtime/graph/GraphConfig.cpp @@ -12,12 +12,12 @@ namespace vkcompute { GraphConfig::GraphConfig() { // No automatic submissions - const uint32_t submit_frequency = UINT32_MAX; + const uint32_t cmd_submit_frequency = UINT32_MAX; // Only one command buffer will be encoded at a time const api::CommandPoolConfig cmd_config{ - 1u, // cmdPoolInitialSize - 1u, // cmdPoolBatchSize + 1u, // cmd_pool_initial_size + 1u, // cmd_pool_batch_size }; // Use lazy descriptor pool initialization by default; the graph runtime will @@ -25,49 +25,48 @@ GraphConfig::GraphConfig() { // trigger descriptor pool initialization with exact sizes before encoding the // command buffer. const api::DescriptorPoolConfig descriptor_pool_config{ - 0u, // descriptorPoolMaxSets - 0u, // descriptorUniformBufferCount - 0u, // descriptorStorageBufferCount - 0u, // descriptorCombinedSamplerCount - 0u, // descriptorStorageImageCount - 0u, // descriptorPileSizes + 0u, // descriptor_pool_max_sets + 0u, // descriptor_uniform_buffer_count + 0u, // descriptor_storage_buffer_count + 0u, // descriptor_combined_sampler_count + 0u, // descriptor_storage_image_count + 0u, // descriptor_pile_sizes }; const api::QueryPoolConfig query_pool_config{}; - const api::ContextConfig context_config{ - submit_frequency, // cmdSubmitFrequency - cmd_config, // cmdPoolConfig - descriptor_pool_config, // descriptorPoolConfig - query_pool_config, // queryPoolConfig + context_config = { + cmd_submit_frequency, + cmd_config, + descriptor_pool_config, + query_pool_config, }; - contextConfig = context_config; - // Empirically selected safety factor. If descriptor pools start running out // of memory, increase this safety factor. - descriptorPoolSafetyFactor = 1.25; + descriptor_pool_safety_factor = 1.25; // For now, force kTexture3D storage as we are still developing shader support // for buffer storage type. - enableStorageTypeOverride = true; - storageTypeOverride = api::kTexture3D; + enable_storage_type_override = true; + storage_type_override = api::kTexture3D; // For now, force kWidthPacked memory layout by default as we are still // developing support for other memory layouts. In the future memory layout // settings will be serialized as part of the graph. - enableMemoryLayoutOverride = true; - memoryLayoutOverride = api::kWidthPacked; + enable_memory_layout_override = true; + memory_layout_override = api::kWidthPacked; } -void GraphConfig::setStorageTypeOverride(api::StorageType storage_type) { - enableStorageTypeOverride = true; - storageTypeOverride = storage_type; +void GraphConfig::set_storage_type_override(api::StorageType storage_type) { + enable_storage_type_override = true; + storage_type_override = storage_type; } -void GraphConfig::setMemoryLayoutOverride(api::GPUMemoryLayout memory_layout) { - enableMemoryLayoutOverride = true; - memoryLayoutOverride = memory_layout; +void GraphConfig::set_memory_layout_override( + api::GPUMemoryLayout memory_layout) { + enable_memory_layout_override = true; + memory_layout_override = memory_layout; } } // namespace vkcompute diff --git a/backends/vulkan/runtime/graph/GraphConfig.h b/backends/vulkan/runtime/graph/GraphConfig.h index 7fb99f50407..f3e311daa22 100644 --- a/backends/vulkan/runtime/graph/GraphConfig.h +++ b/backends/vulkan/runtime/graph/GraphConfig.h @@ -13,26 +13,26 @@ namespace vkcompute { struct GraphConfig final { - api::ContextConfig contextConfig; + api::ContextConfig context_config; // Creating a descriptor pool with exactly the number of descriptors tallied // by iterating through the shader layouts of shaders used in the graph risks // the descriptor pool running out of memory, therefore apply a safety factor // to descriptor counts when creating the descriptor pool to mitigate this // risk. - float descriptorPoolSafetyFactor; + float descriptor_pool_safety_factor; - bool enableStorageTypeOverride; - api::StorageType storageTypeOverride; + bool enable_storage_type_override; + api::StorageType storage_type_override; - bool enableMemoryLayoutOverride; - api::GPUMemoryLayout memoryLayoutOverride; + bool enable_memory_layout_override; + api::GPUMemoryLayout memory_layout_override; // Generate a default graph config with pre-configured settings explicit GraphConfig(); - void setStorageTypeOverride(api::StorageType storage_type); - void setMemoryLayoutOverride(api::GPUMemoryLayout memory_layout); + void set_storage_type_override(api::StorageType storage_type); + void set_memory_layout_override(api::GPUMemoryLayout memory_layout); }; } // namespace vkcompute diff --git a/backends/vulkan/test/op_tests/utils/codegen.py b/backends/vulkan/test/op_tests/utils/codegen.py index a43998b47c9..7cfe71eee7f 100644 --- a/backends/vulkan/test/op_tests/utils/codegen.py +++ b/backends/vulkan/test/op_tests/utils/codegen.py @@ -582,8 +582,8 @@ class GeneratedOpsTest_{op_name} : public ::testing::TestWithParam< ::std::tuple api::StorageType default_storage_type; api::GPUMemoryLayout default_memory_layout; std::tie(test_dtype, default_storage_type, default_memory_layout) = GetParam(); - config.setStorageTypeOverride(default_storage_type); - config.setMemoryLayoutOverride(default_memory_layout); + config.set_storage_type_override(default_storage_type); + config.set_memory_layout_override(default_memory_layout); graph = new ComputeGraph(config); if (test_dtype == at::kHalf) {{ From d04f228b6d2c1c5c26f3bd3478eb88a17779da74 Mon Sep 17 00:00:00 2001 From: Jorge Pineda Date: Wed, 8 May 2024 09:38:01 -0700 Subject: [PATCH 2/2] Update on "[ET-VK][EZ] Stylize struct members with snake_case" Because the current mix of camelCase and snake_case is inconsistent. Differential Revision: [D57080712](https://our.internmc.facebook.com/intern/diff/D57080712/) [ghstack-poisoned]