Skip to content
Closed
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
19 changes: 17 additions & 2 deletions backends/vulkan/runtime/graph/ops/ExecuteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,37 @@ bool ExecuteNode::trigger_resize(ComputeGraph* graph) {
}

bool ExecuteNode::was_any_arg_updated(const ComputeGraph* const graph) const {
// Check all ValueRefs in ArgGroups
// Check input args.
for (const auto& arg_group : args_) {
if (!(arg_group.access & vkapi::kRead)) {
continue;
}
for (const auto& value_ref : arg_group.refs) {
if (graph->was_value_updated(value_ref)) {
return true;
}
}
}

// Check all ValueRefs in resize_args
// Check resize args.
for (const auto& value_ref : resize_args_) {
if (graph->was_value_updated(value_ref)) {
return true;
}
}

// Check output args.
for (const auto& arg_group : args_) {
if (arg_group.access & vkapi::kRead) {
continue;
}
for (const auto& value_ref : arg_group.refs) {
if (graph->was_value_updated(value_ref)) {
return true;
}
}
}

return false;
}

Expand Down
131 changes: 131 additions & 0 deletions backends/vulkan/test/vulkan_compute_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,137 @@ TEST(VulkanComputeGraphTest, was_value_updated_checks_nested_value_lists) {
EXPECT_TRUE(graph.was_value_updated(outer_list));
}

TEST(VulkanComputeGraphTest, execute_node_resize_tracks_read_arg_updates) {
GraphConfig config;
ComputeGraph graph(config);

const ValueRef output = graph.add_symint(1);
const ValueRef input = graph.add_symint(2);
size_t resize_count = 0;
ExecuteNode node(
[&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
},
{},
{{output, vkapi::kWrite}, {input, vkapi::kRead}});

graph.set_symint(input, 3);

EXPECT_TRUE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 1);
}

TEST(VulkanComputeGraphTest, execute_node_resize_tracks_write_arg_updates) {
GraphConfig config;
ComputeGraph graph(config);

const ValueRef output = graph.add_symint(1);
const ValueRef input = graph.add_symint(2);
size_t resize_count = 0;
ExecuteNode node(
[&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
},
{},
{{output, vkapi::kWrite}, {input, vkapi::kRead}});

graph.set_symint(output, 3);

EXPECT_TRUE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 1);
}

TEST(VulkanComputeGraphTest, execute_node_resize_tracks_read_write_updates) {
GraphConfig config;
ComputeGraph graph(config);

const ValueRef value = graph.add_symint(1);
size_t resize_count = 0;
ExecuteNode node(
[&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
},
{},
{{value, vkapi::kReadWrite}});

graph.set_symint(value, 2);

EXPECT_TRUE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 1);
}

TEST(VulkanComputeGraphTest, execute_node_resize_tracks_nested_resize_args) {
GraphConfig config;
ComputeGraph graph(config);

const ValueRef value = graph.add_symint(1);
const ValueRef inner_list = graph.add_value_list({value});
const ValueRef outer_list = graph.add_value_list({inner_list});
size_t resize_count = 0;
ExecuteNode node(
[&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
},
{outer_list});

graph.set_symint(value, 2);

EXPECT_TRUE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 1);
}

TEST(VulkanComputeGraphTest, execute_node_resize_skips_unchanged_args) {
GraphConfig config;
ComputeGraph graph(config);

const ValueRef output = graph.add_symint(1);
const ValueRef input = graph.add_symint(2);
size_t resize_count = 0;
ExecuteNode node(
[&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
},
{},
{{output, vkapi::kWrite}, {input, vkapi::kRead}});

EXPECT_FALSE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 0);
}

TEST(VulkanComputeGraphTest, execute_node_force_resize_ignores_arg_updates) {
GraphConfig config;
config.force_resize = true;
ComputeGraph graph(config);

size_t resize_count = 0;
ExecuteNode node([&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
});

EXPECT_TRUE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 1);
}

TEST(
VulkanComputeGraphTest,
execute_node_data_dependent_resize_is_unconditional) {
GraphConfig config;
ComputeGraph graph(config);

size_t resize_count = 0;
ExecuteNode node(
[&resize_count](ComputeGraph*, const auto&, const auto&) {
++resize_count;
},
{},
{},
"data_dependent_node",
true);

EXPECT_TRUE(node.trigger_resize(&graph));
EXPECT_EQ(resize_count, 1);
}

TEST(VulkanComputeGraphTest, resize_input_marks_staging_value_updated) {
GraphConfig config;
ComputeGraph graph(config);
Expand Down
Loading