Skip to content

[ET-VK][ez] Rename run_prepack() to prepack() and replace encode_prepack() + prepack() with just prepack() #12534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/VulkanBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,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
Expand Down
18 changes: 1 addition & 17 deletions backends/vulkan/runtime/graph/ComputeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,23 +769,7 @@ void ComputeGraph::submit_current_cmd_and_wait(const bool final_use) {
context_->flush();
}

void ComputeGraph::encode_prepack() {
for (std::unique_ptr<PrepackNode>& 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;
const bool reduce_peak_memory = total_constant_nbytes_ > 500 * MB;
Expand Down
5 changes: 1 addition & 4 deletions backends/vulkan/runtime/graph/ComputeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,14 +861,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
Expand Down
4 changes: 2 additions & 2 deletions backends/vulkan/test/op_tests/choose_qparams_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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();

Expand Down Expand Up @@ -676,7 +676,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();

Expand Down
4 changes: 1 addition & 3 deletions backends/vulkan/test/op_tests/dequantize_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,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();

Expand Down Expand Up @@ -1670,7 +1670,6 @@ void test_vulkan_dequantize_per_channel_impl(
ValueRef staging_out = graph.set_output_tensor(r_out);

graph.prepare();
graph.encode_prepack();
graph.prepack();
graph.encode_execute();

Expand Down Expand Up @@ -2345,7 +2344,6 @@ void test_vulkan_dequantize_per_tensor_tensor_impl(
ValueRef staging_out = graph.set_output_tensor(r_out);

graph.prepare();
graph.encode_prepack();
graph.prepack();
graph.encode_execute();

Expand Down
4 changes: 1 addition & 3 deletions backends/vulkan/test/op_tests/quantize_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,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();

Expand Down Expand Up @@ -1412,7 +1412,6 @@ void test_vulkan_quantize_per_channel_impl(
ValueRef staging_out = graph.set_output_tensor(r_out);

graph.prepare();
graph.encode_prepack();
graph.prepack();
graph.encode_execute();

Expand Down Expand Up @@ -2042,7 +2041,6 @@ void test_vulkan_quantize_per_tensor_tensor_impl(
ValueRef staging_out = graph.set_output_tensor(r_out);

graph.prepare();
graph.encode_prepack();
graph.prepack();
graph.encode_execute();

Expand Down
6 changes: 3 additions & 3 deletions backends/vulkan/test/op_tests/quantized_linear_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion backends/vulkan/test/op_tests/rotary_embedding_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion backends/vulkan/test/op_tests/sdpa_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion backends/vulkan/test/op_tests/utils/gen_computegraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ def gen_graph_build_code(self, include_declarations: bool = True) -> str:
graph_build += self.set_output(self.refs["out"], include_declarations)

graph_build += f"{self.graph}{self.dot}prepare();\n"
graph_build += f"{self.graph}{self.dot}encode_prepack();\n"
graph_build += f"{self.graph}{self.dot}prepack();\n"
graph_build += f"{self.graph}{self.dot}encode_execute();\n"

Expand Down
17 changes: 8 additions & 9 deletions backends/vulkan/test/vulkan_compute_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,6 @@ TEST(VulkanComputeGraphTest, test_simple_prepacked_graph) {

graph.prepare();

graph.encode_prepack();
graph.prepack();

graph.encode_execute();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down
Loading