Skip to content

Commit cb0db9e

Browse files
committed
[ET-VK][runtime] Check resize inputs before outputs
Pull Request resolved: pytorch#22497 Prioritize read dependencies before write-only outputs so active nodes short-circuit without changing resize semantics. Authored with Codex. ghstack-source-id: 423933065 @exported-using-ghexport Differential Revision: [D118543866](https://our.internmc.facebook.com/intern/diff/D118543866/)
1 parent d3e5f1b commit cb0db9e

2 files changed

Lines changed: 148 additions & 2 deletions

File tree

‎backends/vulkan/runtime/graph/ops/ExecuteNode.cpp‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,37 @@ bool ExecuteNode::trigger_resize(ComputeGraph* graph) {
3939
}
4040

4141
bool ExecuteNode::was_any_arg_updated(const ComputeGraph* const graph) const {
42-
// Check all ValueRefs in ArgGroups
42+
// Check input args.
4343
for (const auto& arg_group : args_) {
44+
if (!(arg_group.access & vkapi::kRead)) {
45+
continue;
46+
}
4447
for (const auto& value_ref : arg_group.refs) {
4548
if (graph->was_value_updated(value_ref)) {
4649
return true;
4750
}
4851
}
4952
}
5053

51-
// Check all ValueRefs in resize_args
54+
// Check resize args.
5255
for (const auto& value_ref : resize_args_) {
5356
if (graph->was_value_updated(value_ref)) {
5457
return true;
5558
}
5659
}
5760

61+
// Check output args.
62+
for (const auto& arg_group : args_) {
63+
if (arg_group.access & vkapi::kRead) {
64+
continue;
65+
}
66+
for (const auto& value_ref : arg_group.refs) {
67+
if (graph->was_value_updated(value_ref)) {
68+
return true;
69+
}
70+
}
71+
}
72+
5873
return false;
5974
}
6075

‎backends/vulkan/test/vulkan_compute_api_test.cpp‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,137 @@ TEST(VulkanComputeGraphTest, was_value_updated_checks_nested_value_lists) {
22042204
EXPECT_TRUE(graph.was_value_updated(outer_list));
22052205
}
22062206

2207+
TEST(VulkanComputeGraphTest, execute_node_resize_tracks_read_arg_updates) {
2208+
GraphConfig config;
2209+
ComputeGraph graph(config);
2210+
2211+
const ValueRef output = graph.add_symint(1);
2212+
const ValueRef input = graph.add_symint(2);
2213+
size_t resize_count = 0;
2214+
ExecuteNode node(
2215+
[&resize_count](ComputeGraph*, const auto&, const auto&) {
2216+
++resize_count;
2217+
},
2218+
{},
2219+
{{output, vkapi::kWrite}, {input, vkapi::kRead}});
2220+
2221+
graph.set_symint(input, 3);
2222+
2223+
EXPECT_TRUE(node.trigger_resize(&graph));
2224+
EXPECT_EQ(resize_count, 1);
2225+
}
2226+
2227+
TEST(VulkanComputeGraphTest, execute_node_resize_tracks_write_arg_updates) {
2228+
GraphConfig config;
2229+
ComputeGraph graph(config);
2230+
2231+
const ValueRef output = graph.add_symint(1);
2232+
const ValueRef input = graph.add_symint(2);
2233+
size_t resize_count = 0;
2234+
ExecuteNode node(
2235+
[&resize_count](ComputeGraph*, const auto&, const auto&) {
2236+
++resize_count;
2237+
},
2238+
{},
2239+
{{output, vkapi::kWrite}, {input, vkapi::kRead}});
2240+
2241+
graph.set_symint(output, 3);
2242+
2243+
EXPECT_TRUE(node.trigger_resize(&graph));
2244+
EXPECT_EQ(resize_count, 1);
2245+
}
2246+
2247+
TEST(VulkanComputeGraphTest, execute_node_resize_tracks_read_write_updates) {
2248+
GraphConfig config;
2249+
ComputeGraph graph(config);
2250+
2251+
const ValueRef value = graph.add_symint(1);
2252+
size_t resize_count = 0;
2253+
ExecuteNode node(
2254+
[&resize_count](ComputeGraph*, const auto&, const auto&) {
2255+
++resize_count;
2256+
},
2257+
{},
2258+
{{value, vkapi::kReadWrite}});
2259+
2260+
graph.set_symint(value, 2);
2261+
2262+
EXPECT_TRUE(node.trigger_resize(&graph));
2263+
EXPECT_EQ(resize_count, 1);
2264+
}
2265+
2266+
TEST(VulkanComputeGraphTest, execute_node_resize_tracks_nested_resize_args) {
2267+
GraphConfig config;
2268+
ComputeGraph graph(config);
2269+
2270+
const ValueRef value = graph.add_symint(1);
2271+
const ValueRef inner_list = graph.add_value_list({value});
2272+
const ValueRef outer_list = graph.add_value_list({inner_list});
2273+
size_t resize_count = 0;
2274+
ExecuteNode node(
2275+
[&resize_count](ComputeGraph*, const auto&, const auto&) {
2276+
++resize_count;
2277+
},
2278+
{outer_list});
2279+
2280+
graph.set_symint(value, 2);
2281+
2282+
EXPECT_TRUE(node.trigger_resize(&graph));
2283+
EXPECT_EQ(resize_count, 1);
2284+
}
2285+
2286+
TEST(VulkanComputeGraphTest, execute_node_resize_skips_unchanged_args) {
2287+
GraphConfig config;
2288+
ComputeGraph graph(config);
2289+
2290+
const ValueRef output = graph.add_symint(1);
2291+
const ValueRef input = graph.add_symint(2);
2292+
size_t resize_count = 0;
2293+
ExecuteNode node(
2294+
[&resize_count](ComputeGraph*, const auto&, const auto&) {
2295+
++resize_count;
2296+
},
2297+
{},
2298+
{{output, vkapi::kWrite}, {input, vkapi::kRead}});
2299+
2300+
EXPECT_FALSE(node.trigger_resize(&graph));
2301+
EXPECT_EQ(resize_count, 0);
2302+
}
2303+
2304+
TEST(VulkanComputeGraphTest, execute_node_force_resize_ignores_arg_updates) {
2305+
GraphConfig config;
2306+
config.force_resize = true;
2307+
ComputeGraph graph(config);
2308+
2309+
size_t resize_count = 0;
2310+
ExecuteNode node([&resize_count](ComputeGraph*, const auto&, const auto&) {
2311+
++resize_count;
2312+
});
2313+
2314+
EXPECT_TRUE(node.trigger_resize(&graph));
2315+
EXPECT_EQ(resize_count, 1);
2316+
}
2317+
2318+
TEST(
2319+
VulkanComputeGraphTest,
2320+
execute_node_data_dependent_resize_is_unconditional) {
2321+
GraphConfig config;
2322+
ComputeGraph graph(config);
2323+
2324+
size_t resize_count = 0;
2325+
ExecuteNode node(
2326+
[&resize_count](ComputeGraph*, const auto&, const auto&) {
2327+
++resize_count;
2328+
},
2329+
{},
2330+
{},
2331+
"data_dependent_node",
2332+
true);
2333+
2334+
EXPECT_TRUE(node.trigger_resize(&graph));
2335+
EXPECT_EQ(resize_count, 1);
2336+
}
2337+
22072338
TEST(VulkanComputeGraphTest, resize_input_marks_staging_value_updated) {
22082339
GraphConfig config;
22092340
ComputeGraph graph(config);

0 commit comments

Comments
 (0)