Skip to content

Commit df40507

Browse files
committed
Update on "[ET-VK][Op Redesign][4/n] Merge ArithmeticNode into ExecuteNode"
This diff moves the logic of `ArithmeticNode` into its corresponding OpFunction `add_arithmetic_node()` and the `ExecuteNode` class. Our aim is to remove all derived classes of `ExecuteNode`, i.e., to make `ExecuteNode` a final class. All operator-specific logic will be handled in the OpFunction. Note the next change will move `StagingNode` into its OpFunction + this new ExecuteNode implementation. Until then, we can't tidy up the `ExecuteNode` class fully. Finally, we leave a few task TODOs. Differential Revision: [D53982441](https://our.internmc.facebook.com/intern/diff/D53982441/) [ghstack-poisoned]
1 parent 9cb7646 commit df40507

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

backends/vulkan/runtime/graph/ops/ExecuteNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class ExecuteNode {
4141
const api::utils::uvec3& local_workgroup_size,
4242
const std::vector<ValueRef>& outputs,
4343
const std::vector<ValueRef>& inputs,
44-
const api::UniformParamsBuffer& params)
44+
api::UniformParamsBuffer&& params)
4545
: shader_(shader),
4646
global_workgroup_size_(global_workgroup_size),
4747
local_workgroup_size_(local_workgroup_size),
4848
outputs_(outputs),
4949
inputs_(inputs),
50-
params_(params) {}
50+
params_(std::move(params)) {}
5151

5252
virtual ~ExecuteNode() = default;
5353

backends/vulkan/runtime/graph/ops/impl/Arithmetic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void add_arithmetic_node(
8282
api::UniformParamsBuffer params(graph.context(), block);
8383

8484
graph.execute_nodes().emplace_back(new ExecuteNode(
85-
shader, global_size, local_size, {out}, {arg1, arg2}, params));
85+
shader, global_size, local_size, {out}, {arg1, arg2}, std::move(params)));
8686
}
8787

8888
ArithmeticPrepack::ArithmeticPrepack(const ValueRef tref, const ValueRef packed)

backends/vulkan/test/vulkan_compute_api_test.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ TEST(VulkanComputeGraphTest, test_simple_shared_objects) {
526526
api::kFloat,
527527
/*shared_object_idx = */ 4);
528528

529-
// Allocation count will be 2 (1 staging buffer for each input tensor)
529+
// Allocation count will be 2:
530+
// 1 staging buffer for each input tensor
530531
EXPECT_TRUE(get_vma_allocation_count() == 2);
531532

532533
ValueRef c = add_arithmetic_node(
@@ -542,8 +543,10 @@ TEST(VulkanComputeGraphTest, test_simple_shared_objects) {
542543
api::kFloat,
543544
/*shared_object_idx = */ 2);
544545

545-
// Allocation count will be 3 (1 staging buffer for each input tensor)
546-
EXPECT_TRUE(get_vma_allocation_count() == 3);
546+
// Allocation count will be 4, two are new:
547+
// 1 uniform buffer for arithmetic shader params
548+
// 1 staging buffer for the input tensor
549+
EXPECT_TRUE(get_vma_allocation_count() == 4);
547550

548551
ValueRef e = add_arithmetic_node(
549552
graph,
@@ -557,14 +560,16 @@ TEST(VulkanComputeGraphTest, test_simple_shared_objects) {
557560
out.value = e;
558561
out.staging = graph.set_output_tensor(out.value);
559562

560-
// Allocation count will be 4 (1 staging buffer for each I/O tensor)
561-
EXPECT_TRUE(get_vma_allocation_count() == 4);
563+
// Allocation count will be 6, three are new:
564+
// 1 uniform buffer for arithmetic shader params
565+
// 1 staging buffer for the input tensor
566+
EXPECT_TRUE(get_vma_allocation_count() == 6);
562567

563568
graph.encode_execute();
564569

565570
// Allocation count will be 13:
566571
// 4 staging buffers for each I/O tensor
567-
// 6 uniform buffers to store args for each shader dispatch
572+
// 6 uniform buffers to store params for each shader dispatch
568573
// 3 shared objects to back tensor memory
569574
EXPECT_TRUE(get_vma_allocation_count() == 13);
570575

0 commit comments

Comments
 (0)