Skip to content

Commit

Permalink
Apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-k-park committed Dec 23, 2024
1 parent abddffc commit 1c7c4e3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 42 deletions.
1 change: 0 additions & 1 deletion src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ struct network {

ov::intel_gpu::VariablesMap _variables_states;
ov::intel_gpu::VariablesInfoMap _variables_state_info;
std::vector<std::shared_ptr<primitive_inst>> _read_values;

program::primitives_info _prims_info;
size_t _weights_cache_capacity = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,33 @@ void mark_state_init_subgraphs::mark_node(program_node* node) {
return;

const auto& variable_id = node->as<read_value>().get_primitive()->variable_id;
node->set_state_init_subgraph_id(variable_id);
node->set_state_variable_id_of_init_subgraph(variable_id);

// Create a queue for BFS
std::queue<program_node*> q;
// Enqueue the source node (read_value)
q.push(node);

auto can_be_marked = [&](const program_node* dep_node, const program_node* cur_node) {
for (auto& u : dep_node->get_users()) {
if (u == cur_node)
continue;
if (u->get_state_init_subgraph_id().compare(variable_id) != 0) {
if (u->get_state_variable_id_of_init_subgraph().compare(variable_id) != 0) {
return false;
}
}
GPU_DEBUG_TRACE_DETAIL << "marked " << dep_node->id() << " as node in a init_subgraph for " << node->id() << std::endl;
return true;
};

// Iterate over the queue
while (!q.empty()) {
auto cur_size = q.size();
for (size_t i = 0; i < cur_size; ++i) {
// Dequeue the node from queue
auto& cur_node = q.front();
q.pop();
for (auto& dep : cur_node->get_dependencies()) {
if (can_be_marked(dep.first, cur_node)) {
dep.first->set_state_init_subgraph_id(variable_id);
dep.first->set_state_variable_id_of_init_subgraph(variable_id);
if (!dep.first->is_constant())
node->add_dependant_initializer_pid(dep.first->id());
// Enqueue visited dependant node
node->add_state_initializer(dep.first->id());
q.push(dep.first);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/cpu/read_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct read_value_impl : public typed_primitive_impl<read_value> {
if (!instance.get_user_insts().empty()) {
auto user_inst = instance.get_user_insts().front();
if (!(user_inst->get_node().is_type<assign>() || user_inst->get_node().is_type<kv_cache>()) &&
!instance.get_dependant_initializer_insts().empty()) {
!instance.get_state_initializers().empty()) {
variable.set();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/intel_gpu/src/graph/include/primitive_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class primitive_inst {
uint32_t get_network_id() const;
virtual event::ptr set_output_memory(memory::ptr mem, bool check = true, size_t idx = 0);
void check_memory_to_set(const memory& mem, const layout& layout) const;
const std::vector<primitive_inst*>& get_dependant_initializer_insts() const { return dependant_initializer_insts; }
const std::vector<primitive_inst*>& get_state_initializers() const { return state_initializers; }
const std::list<const cldnn::program_node *>& get_users() const { return _node->get_users(); }
const std::vector<primitive_inst*>& get_user_insts() const { return _users; }
void init_users() {
Expand Down Expand Up @@ -270,7 +270,7 @@ class primitive_inst {
void do_runtime_in_place_crop();
void do_runtime_skip_scatter_update();
void configure_shape_of_dependencies();
void configure_initializer_dependencies();
void configure_state_initializers();

memory::ptr fused_memory(size_t dep_id) const {
return dep_memory_ptr(get_fused_mem_offset() + dep_id);
Expand Down Expand Up @@ -358,7 +358,7 @@ class primitive_inst {
std::vector<primitive_inst*> dependant_shape_of_insts;

// List of dependant primitives for state initializer subgraphs
std::vector<primitive_inst*> dependant_initializer_insts;
std::vector<primitive_inst*> state_initializers;

std::vector<primitive_inst*> _users;
// this is a set of dependencies in terms of execution
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/intel_gpu/src/graph/include/program_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ struct program_node {
void set_in_shape_of_subgraph(bool val = true) { in_shape_of_subgraph = val; }
bool is_in_shape_of_subgraph() const { return in_shape_of_subgraph; }

void set_state_init_subgraph_id(std::string id) { state_init_subgraph_id = id; }
bool is_in_state_init_subgraph() const { return !state_init_subgraph_id.empty(); }
std::string get_state_init_subgraph_id() const { return state_init_subgraph_id; }
void set_state_variable_id_of_init_subgraph(std::string id) { state_id_of_init_subgraph = id; }
bool is_in_state_init_subgraph() const { return !state_id_of_init_subgraph.empty(); }
std::string get_state_variable_id_of_init_subgraph() const { return state_id_of_init_subgraph; }

// check/set if the node can be optimized out (removed from the network)
bool can_be_optimized() const { return optimized; }
Expand Down Expand Up @@ -372,10 +372,10 @@ struct program_node {
return dependant_shape_of_nodes;
}

void add_dependant_initializer_pid(const primitive_id& id);
void add_state_initializer(const primitive_id& id);

const std::vector<primitive_id>& get_dependant_initializer_pids() const {
return dependant_initializer_pids;
const std::vector<primitive_id>& get_state_initializers() const {
return state_initializers;
}

void set_reused_memory_color(uint32_t color) const {
Expand Down Expand Up @@ -517,8 +517,8 @@ struct program_node {

std::set<const program_node*> dependant_shape_of_nodes;

std::string state_init_subgraph_id;
std::vector<primitive_id> dependant_initializer_pids;
std::string state_id_of_init_subgraph;
std::vector<primitive_id> state_initializers;

bool output = false;
uint8_t user_mark = 0;
Expand Down
11 changes: 4 additions & 7 deletions src/plugins/intel_gpu/src/graph/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void network::build_insts_deps() {
inst.second->build_deps();
inst.second->init_users();
inst.second->configure_shape_of_dependencies();
inst.second->configure_initializer_dependencies();
inst.second->configure_state_initializers();
}
}

Expand Down Expand Up @@ -699,12 +699,12 @@ std::map<primitive_id, network_output> network::execute(const std::vector<event:
}
}

for (auto& inst : _read_values) {
if (!inst->get_dependant_initializer_insts().empty()) {
for (auto& inst : _exec_order) {
if (inst->get_node().is_type<read_value>() && !inst->get_state_initializers().empty()) {
auto prim = inst->get_node().as<read_value>().get_primitive();
const auto& variable = get_variable(prim->variable_id);
if (variable.is_set()) {
for (auto& init_inst : inst->get_dependant_initializer_insts()) {
for (auto& init_inst : inst->get_state_initializers()) {
init_inst->set_flag(ExecutionFlags::SKIP);
}
}
Expand Down Expand Up @@ -926,9 +926,6 @@ void network::allocate_primitive_instance(program_node const& node) {
if (node.is_type<data>())
_data_outputs.push_back(inst);
}
if (node.is_type<read_value>()) {
_read_values.push_back(inst);
}
if (auto state_prim = std::dynamic_pointer_cast<memory_state::variable>(inst)) {
auto prim = inst->get_node().get_primitive();
set_variables_state_info(state_prim->variable_id(), node.get_output_layout(0), state_prim->get_user_specified_type(), prim.get());
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/intel_gpu/src/graph/primitive_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,14 +2015,14 @@ void primitive_inst::configure_shape_of_dependencies() {
}
}

void primitive_inst::configure_initializer_dependencies() {
if (!dependant_initializer_insts.empty())
void primitive_inst::configure_state_initializers() {
if (!state_initializers.empty())
return;

OPENVINO_ASSERT(_node != nullptr, "_node should not be nullptr for configure_initializer_dependencies.");
OPENVINO_ASSERT(_node != nullptr, "_node should not be nullptr for configure_state_initializers.");

if (dependant_initializer_insts.empty() && !_node->get_dependant_initializer_pids().empty()) {
dependant_initializer_insts = _network.get_primitives(_node->get_dependant_initializer_pids());
if (state_initializers.empty() && !_node->get_state_initializers().empty()) {
state_initializers = _network.get_primitives(_node->get_state_initializers());
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/plugins/intel_gpu/src/graph/program_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ std::unique_ptr<json_composite> program_node::desc_to_json() const {
node_info->add("dependant_shape_of_nodes_ids", dependant_shape_of_nodes_ids);
node_info->add("in_shape_of_subgraph", in_shape_of_subgraph);

node_info->add("state_init_subgraph_id", state_init_subgraph_id);
node_info->add("dependant_initializer_pids", dependant_initializer_pids);
node_info->add("state_id_of_init_subgraph", state_id_of_init_subgraph);
node_info->add("state_initializers", state_initializers);
return node_info;
}

Expand Down Expand Up @@ -665,8 +665,8 @@ void program_node::add_dependant_shape_of_node(const program_node* node) {
dependant_shape_of_nodes.insert(node);
}

void program_node::add_dependant_initializer_pid(const primitive_id& id) {
dependant_initializer_pids.push_back(id);
void program_node::add_state_initializer(const primitive_id& id) {
state_initializers.push_back(id);
}

void program_node::save(cldnn::BinaryOutputBuffer& ob) const {
Expand Down Expand Up @@ -705,8 +705,8 @@ void program_node::save(cldnn::BinaryOutputBuffer& ob) const {
ob << in_shape_of_subgraph;
ob << runtime_skippable;

ob << state_init_subgraph_id;
ob << dependant_initializer_pids;
ob << state_id_of_init_subgraph;
ob << state_initializers;

ob << output;
ob << user_mark;
Expand Down Expand Up @@ -883,8 +883,8 @@ void program_node::load(cldnn::BinaryInputBuffer& ib) {
ib >> in_shape_of_subgraph;
ib >> runtime_skippable;

ib >> state_init_subgraph_id;
ib >> dependant_initializer_pids;
ib >> state_id_of_init_subgraph;
ib >> state_initializers;

ib >> output;
ib >> user_mark;
Expand Down

0 comments on commit 1c7c4e3

Please sign in to comment.