Skip to content

Commit 8d33e93

Browse files
committed
[ET-VK][runtime] Inline resize update checks
Pull Request resolved: pytorch#22498 Inline direct generation-stamp lookup while keeping rare nested ValueList traversal out of line. Authored with Codex. ghstack-source-id: 423933067 @exported-using-ghexport Differential Revision: [D118543873](https://our.internmc.facebook.com/intern/diff/D118543873/)
1 parent cb0db9e commit 8d33e93

2 files changed

Lines changed: 22 additions & 19 deletions

File tree

‎backends/vulkan/runtime/graph/ComputeGraph.cpp‎

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,26 +242,13 @@ utils::StorageType ComputeGraph::suggested_storage_type() {
242242
return utils::kTexture3D;
243243
}
244244

245-
bool ComputeGraph::was_value_updated(const ValueRef idx) const noexcept {
246-
if (!is_valid_value_idx(idx)) {
247-
return false;
248-
}
249-
250-
const size_t value_idx = static_cast<size_t>(idx);
251-
if (value_idx < value_update_generations_.size() &&
252-
value_update_generations_[value_idx] == current_update_generation_) {
253-
return true;
254-
}
255-
256-
if (val_is_value_list(idx)) {
257-
const auto& value_list = values_.at(idx).toConstValueList();
258-
for (const auto& nested_idx : value_list) {
259-
if (was_value_updated(nested_idx)) {
260-
return true;
261-
}
245+
bool ComputeGraph::was_value_list_updated(const ValueRef idx) const noexcept {
246+
const auto& value_list = values_[static_cast<size_t>(idx)].toConstValueList();
247+
for (const auto nested_idx : value_list) {
248+
if (was_value_updated(nested_idx)) {
249+
return true;
262250
}
263251
}
264-
265252
return false;
266253
}
267254

‎backends/vulkan/runtime/graph/ComputeGraph.h‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ class ComputeGraph final {
712712

713713
private:
714714
void check_no_active_value_ptrs();
715+
bool was_value_list_updated(const ValueRef idx) const noexcept;
715716

716717
public:
717718
/*
@@ -1174,7 +1175,22 @@ class ComputeGraph final {
11741175

11751176
// Check if a specific ValueRef (or ValueList) was updated, with recursive
11761177
// handling
1177-
bool was_value_updated(const ValueRef idx) const noexcept;
1178+
inline bool was_value_updated(const ValueRef idx) const noexcept {
1179+
if (idx < 0) {
1180+
return false;
1181+
}
1182+
1183+
const size_t value_idx = static_cast<size_t>(idx);
1184+
if (value_idx >= values_.size()) {
1185+
return false;
1186+
}
1187+
if (value_idx < value_update_generations_.size() &&
1188+
value_update_generations_[value_idx] == current_update_generation_) {
1189+
return true;
1190+
}
1191+
1192+
return values_[value_idx].isValueList() && was_value_list_updated(idx);
1193+
}
11781194

11791195
// Set the flag to indicate that re-encoding is required
11801196
inline void set_requires_reencode() noexcept {

0 commit comments

Comments
 (0)