Skip to content

[ET-VK] Adding get or create int function to read int value. #12356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: gh/trivedivivek/115/base
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions backends/vulkan/runtime/graph/ComputeGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,22 @@ vkapi::BufferBindInfo ComputeGraph::get_or_create_int_param_buffer(
}
}

int32_t ComputeGraph::get_or_create_int(const ValueRef idx) {
if (values_.at(idx).isInt()) {
return extract_scalar<int32_t>(idx);
}
VK_THROW("Cannot create a int param buffer for the given value");
}

int32_t ComputeGraph::get_or_create_int(
const ValueRef idx,
const int32_t default_val) {
if (values_.at(idx).isNone()) {
return default_val;
}
return get_or_create_int(idx);
}

void ComputeGraph::set_symint(const ValueRef idx, const int32_t val) {
get_symint(idx)->set(val);
}
Expand Down
10 changes: 10 additions & 0 deletions backends/vulkan/runtime/graph/ComputeGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ class ComputeGraph final {
// Scalar Value Extraction
//

bool is_scalar(const ValueRef idx) const {
const Value& value = values_.at(idx);
return value.isInt() || value.isDouble() || value.isBool() ||
value.isNone();
}

template <typename T>
T extract_scalar(const ValueRef idx) {
Value& value = values_.at(idx);
Expand Down Expand Up @@ -679,6 +685,10 @@ class ComputeGraph final {
const ValueRef idx,
const int32_t default_value);

int32_t get_or_create_int(const ValueRef idx);

int32_t get_or_create_int(const ValueRef idx, const int32_t default_value);

void set_symint(const ValueRef idx, const int32_t val);

int32_t read_symint(const ValueRef idx);
Expand Down
Loading