Skip to content

Commit 8f4fb4b

Browse files
authored
[ET-VK] Adding get or create int function to read int value. (#12507)
This diff adds a new function `get_or_create_int` to the `ComputeGraph` class, which allows reading an integer value from a `ValueRef` index. The function returns the extracted integer value if the value at the index is an integer, otherwise it throws an error. Additionally, an overload of the function is added to return a default value if the value at the index is `None`. Differential Revision: [D78094858](https://our.internmc.facebook.com/intern/diff/D78094858/)
1 parent b6663ef commit 8f4fb4b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

backends/vulkan/runtime/graph/ComputeGraph.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,12 @@ class ComputeGraph final {
424424
// Scalar Value Extraction
425425
//
426426

427+
bool is_scalar_or_none(const ValueRef idx) const {
428+
const Value& value = values_.at(idx);
429+
return value.isInt() || value.isDouble() || value.isBool() ||
430+
value.isNone();
431+
}
432+
427433
template <typename T>
428434
T extract_scalar(const ValueRef idx) {
429435
Value& value = values_.at(idx);
@@ -439,6 +445,15 @@ class ComputeGraph final {
439445
VK_THROW("Cannot extract scalar from Value with type ", value.type());
440446
}
441447

448+
template <typename T>
449+
T extract_scalar_or(const ValueRef idx, const T default_value) {
450+
Value& value = values_.at(idx);
451+
if (value.isNone()) {
452+
return default_value;
453+
}
454+
return extract_scalar<T>(idx);
455+
}
456+
442457
template <typename T>
443458
std::optional<T> extract_optional_scalar(const ValueRef idx) {
444459
if (val_is_none(idx)) {

0 commit comments

Comments
 (0)