From ebf858dbdc2afd2248562db573cfeee1ac117b08 Mon Sep 17 00:00:00 2001 From: Stephen Jia Date: Mon, 14 Jul 2025 08:33:15 -0700 Subject: [PATCH] [ET-VK][ez] Rename `run_prepack()` to `prepack()` and replace `encode_prepack()` + `prepack()` with just `prepack()` Title says it all! See below diff for more context on why this new API exists. Differential Revision: [D78275583](https://our.internmc.facebook.com/intern/diff/D78275583/) [ghstack-poisoned] --- backends/vulkan/runtime/VulkanBackend.cpp | 2 +- backends/vulkan/runtime/graph/ComputeGraph.cpp | 18 +----------------- backends/vulkan/runtime/graph/ComputeGraph.h | 5 +---- .../test/op_tests/choose_qparams_test.cpp | 4 ++-- .../vulkan/test/op_tests/dequantize_test.cpp | 4 ++-- .../vulkan/test/op_tests/quantize_test.cpp | 4 ++-- .../test/op_tests/quantized_linear_test.cpp | 6 +++--- .../test/op_tests/rotary_embedding_test.cpp | 2 +- backends/vulkan/test/op_tests/sdpa_test.cpp | 2 +- .../vulkan/test/vulkan_compute_api_test.cpp | 17 ++++++++--------- 10 files changed, 22 insertions(+), 42 deletions(-) diff --git a/backends/vulkan/runtime/VulkanBackend.cpp b/backends/vulkan/runtime/VulkanBackend.cpp index f25a020a60f..a974aa256b9 100644 --- a/backends/vulkan/runtime/VulkanBackend.cpp +++ b/backends/vulkan/runtime/VulkanBackend.cpp @@ -503,7 +503,7 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface { compute_graph->prepare(); compute_graph->prepare_pipelines(); - compute_graph->run_prepack(); + compute_graph->prepack(); // If dynamic shapes are not expected, then the command buffer only needs to // be encoded once. Otherwise, wait until the first inference to encode the diff --git a/backends/vulkan/runtime/graph/ComputeGraph.cpp b/backends/vulkan/runtime/graph/ComputeGraph.cpp index c25fa28be6f..c8c5b14686e 100644 --- a/backends/vulkan/runtime/graph/ComputeGraph.cpp +++ b/backends/vulkan/runtime/graph/ComputeGraph.cpp @@ -765,23 +765,7 @@ void ComputeGraph::submit_current_cmd_and_wait(const bool final_use) { context_->flush(); } -void ComputeGraph::encode_prepack() { - for (std::unique_ptr& node : prepack_nodes_) { - node->encode(this); - } -} - -void ComputeGraph::prepack() const { - // Submit and execute the command buffer - vkapi::VulkanFence fence = context_->fences().get_fence(); - context_->submit_cmd_to_gpu(fence.get_submit_handle(), /*final_use = */ true); - fence.wait(); - context_->fences().return_fence(fence); - - context_->flush(); -} - -void ComputeGraph::run_prepack() { +void ComputeGraph::prepack() { int i = 0; bool submitted = false; for (std::unique_ptr& node : prepack_nodes_) { diff --git a/backends/vulkan/runtime/graph/ComputeGraph.h b/backends/vulkan/runtime/graph/ComputeGraph.h index b78c1b3218d..ae17f60b9c3 100644 --- a/backends/vulkan/runtime/graph/ComputeGraph.h +++ b/backends/vulkan/runtime/graph/ComputeGraph.h @@ -838,14 +838,11 @@ class ComputeGraph final { staging_nbytes_in_cmd_ += staging_bytes; } - void encode_prepack(); - void prepack() const; - /* * Executes prepacking operations to transfer model weight data from the CPU * to GPU. */ - void run_prepack(); + void prepack(); // // Graph Execution diff --git a/backends/vulkan/test/op_tests/choose_qparams_test.cpp b/backends/vulkan/test/op_tests/choose_qparams_test.cpp index 55e96151387..5bc91ea37a6 100644 --- a/backends/vulkan/test/op_tests/choose_qparams_test.cpp +++ b/backends/vulkan/test/op_tests/choose_qparams_test.cpp @@ -447,7 +447,7 @@ void test_vulkan_choose_qparams_tensor_impl( ValueRef staging_zero_point = graph.set_output_tensor(r_zero_point); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -659,7 +659,7 @@ void test_vulkan_choose_qparams_per_token_asymmetric_impl( ValueRef staging_zero_point = graph.set_output_tensor(r_zero_point); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); diff --git a/backends/vulkan/test/op_tests/dequantize_test.cpp b/backends/vulkan/test/op_tests/dequantize_test.cpp index 6c604076c41..79f640c36d1 100644 --- a/backends/vulkan/test/op_tests/dequantize_test.cpp +++ b/backends/vulkan/test/op_tests/dequantize_test.cpp @@ -599,7 +599,7 @@ void test_vulkan_dequantize_per_tensor_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -1060,7 +1060,7 @@ void test_vulkan_dequantize_per_token_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); diff --git a/backends/vulkan/test/op_tests/quantize_test.cpp b/backends/vulkan/test/op_tests/quantize_test.cpp index 150bda6989e..6064382f073 100644 --- a/backends/vulkan/test/op_tests/quantize_test.cpp +++ b/backends/vulkan/test/op_tests/quantize_test.cpp @@ -490,7 +490,7 @@ void test_vulkan_quantize_per_tensor_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -849,7 +849,7 @@ void test_vulkan_quantize_per_token_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); diff --git a/backends/vulkan/test/op_tests/quantized_linear_test.cpp b/backends/vulkan/test/op_tests/quantized_linear_test.cpp index 0cd27ea07f3..26316344b0e 100644 --- a/backends/vulkan/test/op_tests/quantized_linear_test.cpp +++ b/backends/vulkan/test/op_tests/quantized_linear_test.cpp @@ -454,7 +454,7 @@ void test_vulkan_linear_qga4w_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -549,7 +549,7 @@ void test_vulkan_linear_qcs4w_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -683,7 +683,7 @@ void test_vulkan_linear_qta8a_qga4w_impl( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); diff --git a/backends/vulkan/test/op_tests/rotary_embedding_test.cpp b/backends/vulkan/test/op_tests/rotary_embedding_test.cpp index eebbb89ab40..2955a54e5f3 100644 --- a/backends/vulkan/test/op_tests/rotary_embedding_test.cpp +++ b/backends/vulkan/test/op_tests/rotary_embedding_test.cpp @@ -112,7 +112,7 @@ void test_reference( ValueRef staging_xk_out = graph.set_output_tensor(r_xk_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); diff --git a/backends/vulkan/test/op_tests/sdpa_test.cpp b/backends/vulkan/test/op_tests/sdpa_test.cpp index 79b679674a5..9a3da49ddad 100644 --- a/backends/vulkan/test/op_tests/sdpa_test.cpp +++ b/backends/vulkan/test/op_tests/sdpa_test.cpp @@ -350,7 +350,7 @@ void test_vulkan_sdpa( ValueRef staging_out = graph.set_output_tensor(r_out); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); diff --git a/backends/vulkan/test/vulkan_compute_api_test.cpp b/backends/vulkan/test/vulkan_compute_api_test.cpp index 17f197dfdeb..f3fed8b6622 100644 --- a/backends/vulkan/test/vulkan_compute_api_test.cpp +++ b/backends/vulkan/test/vulkan_compute_api_test.cpp @@ -1435,7 +1435,6 @@ TEST(VulkanComputeGraphTest, test_simple_prepacked_graph) { graph.prepare(); - graph.encode_prepack(); graph.prepack(); graph.encode_execute(); @@ -2568,7 +2567,7 @@ void test_binary_op( out.staging = graph.set_output_tensor(out.value); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -2641,7 +2640,7 @@ void test_mm( B, M, K, N, dtype, storage_type, memory_layout, mat2_data, prepack); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); for (int i = 1; i < 4; i++) { @@ -2722,7 +2721,7 @@ void test_mm_with_resize_reencode( B, M, K, N, dtype, storage_type, memory_layout, mat2_data, false); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -2800,7 +2799,7 @@ void test_max_pool2d( idx_ioval.staging = graph.set_output_tensor(idx_ioval.value); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -2879,7 +2878,7 @@ void test_grid_priors( out.staging = graph.set_output_tensor(out.value); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); @@ -2983,7 +2982,7 @@ void test_transpose_view_mm( out.staging = graph.set_output_tensor(out.value); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); for (int i = 1; i < 4; i++) { @@ -3049,7 +3048,7 @@ void test_to_copy() { out.staging = graph.set_output_tensor(out.value); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute(); graph.propagate_resize(); @@ -3236,7 +3235,7 @@ void test_dynamic_dispatch(int M, int N) { ComputeGraph graph = build_dynamic_dispatch_test_graph(M, N); graph.prepare(); - graph.encode_prepack(); + graph.prepack(); graph.encode_execute();