Skip to content

Commit

Permalink
code refactoring based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
e-ddykim committed Nov 8, 2022
1 parent d0c2e87 commit fd32d54
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 26 deletions.
87 changes: 85 additions & 2 deletions src/plugins/intel_gpu/src/graph/kernel_selector_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,46 @@ void kernel_impl_params::save(BinaryOutputBuffer& ob) const {
ob << unique_id;
ob << input_layouts;
ob << output_layout;
ob << primary_input_idx;
ob << input_offsets.size();
for (size_t i = 0; i < input_offsets.size(); i++) {
ob << input_offsets[i].sizes();
}

if (weights_layout.has_value()) {
ob << true;
ob << weights_layout.value();
} else {
ob << false;
}

if (bias_layout.has_value()) {
ob << true;
ob << bias_layout.value();
} else {
ob << false;
}

if (weights_zero_points_layout.has_value()) {
ob << true;
ob << weights_zero_points_layout.value();
} else {
ob << false;
}

if (activations_zero_points_layout.has_value()) {
ob << true;
ob << activations_zero_points_layout.value();
} else {
ob << false;
}

if (compensation_layout.has_value()) {
ob << true;
ob << compensation_layout.value();
} else {
ob << false;
}

ob << fused_desc.size();
#ifdef ENABLE_ONEDNN_FOR_GPU
size_t num_fused_prims = fused_desc_onednn.size();
Expand All @@ -1056,14 +1095,57 @@ void kernel_impl_params::save(BinaryOutputBuffer& ob) const {
ob << make_data(&fused_prim, sizeof(fused_primitive_desc_onednn));
}
#endif // ENABLE_ONEDNN_FOR_GPU
ob << primary_input_idx;
}

void kernel_impl_params::load(BinaryInputBuffer& ib) {
ib >> has_runtime_layouts;
ib >> unique_id;
ib >> input_layouts;
ib >> output_layout;
ib >> primary_input_idx;
{
size_t num_input_offsets;
ib >> num_input_offsets;
input_offsets.resize(num_input_offsets);
for (size_t i = 0; i < num_input_offsets; i++) {
std::vector<cldnn::tensor::value_type> sizes;
ib >> sizes;
input_offsets[i] = cldnn::tensor(sizes);
}
}
bool has_value = false;
layout layout_buf;

ib >> has_value;
if (has_value) {
ib >> layout_buf;
weights_layout = layout_buf;
}

ib >> has_value;
if (has_value) {
ib >> layout_buf;
bias_layout = layout_buf;
}

ib >> has_value;
if (has_value) {
ib >> layout_buf;
weights_zero_points_layout = layout_buf;
}

ib >> has_value;
if (has_value) {
ib >> layout_buf;
activations_zero_points_layout = layout_buf;
}

ib >> has_value;
if (has_value) {
ib >> layout_buf;
compensation_layout = layout_buf;
}

{
// Fake fused_desc just for has_fused_primitives()
size_t num_fused_desc;
Expand All @@ -1080,4 +1162,5 @@ void kernel_impl_params::load(BinaryInputBuffer& ib) {
ib >> make_data(&fused_desc_onednn[idx], sizeof(fused_primitive_desc_onednn));
}
#endif // ENABLE_ONEDNN_FOR_GPU
ib >> primary_input_idx;
}
16 changes: 4 additions & 12 deletions src/plugins/intel_gpu/src/graph/primitive_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,8 @@ void primitive_inst::rebuild_deps(

_deps.resize(_dep_ids.size());
for (size_t i = 0; i < _dep_ids.size(); i++) {
if (primitives.count(_dep_ids[i]) > 0) {
_deps[i] = primitives.at(_dep_ids[i]);
} else {
std::cout << _dep_ids[i] << " is not found in _primitives" << std::endl;
}
OPENVINO_ASSERT((primitives.count(_dep_ids[i]) > 0), _dep_ids[i], "is not found in _primitives");
_deps[i] = primitives.at(_dep_ids[i]);
}
}

Expand All @@ -459,9 +456,7 @@ void primitive_inst::rebuild_exec_deps(
break;
}
}
if (found == false) {
std::cout << "not found in _exec_order" << std::endl;
}
OPENVINO_ASSERT(found, _exec_dep_ids[i], "not found in _exec_order");
}
}

Expand Down Expand Up @@ -1083,7 +1078,7 @@ void primitive_inst::load(cldnn::BinaryInputBuffer& ib) {
allocation_type _allocation_type;
ib >> make_data(&_allocation_type, sizeof(_allocation_type));

size_t data_size; // = _output->size();
size_t data_size;
ib >> cldnn::make_data(&data_size, sizeof(size_t));
_outputs[0] = get_network().get_memory_pool().get_memory(output_layout, _allocation_type, false);

Expand All @@ -1096,7 +1091,6 @@ void primitive_inst::load(cldnn::BinaryInputBuffer& ib) {
delete[] _buf;
}
} else if (_object_type == object_type::EXECUTABLE_INST) {
// primitive_impl
_impl_params.release();
_impl_params = make_unique<kernel_impl_params>();
_impl_params->load(ib);
Expand All @@ -1123,7 +1117,6 @@ void primitive_inst::load(cldnn::BinaryInputBuffer& ib) {
ib >> _can_share_buffer;
ib >> _is_constant;

// output memory
layout output_layout = layout(cldnn::data_types::bin, cldnn::format::any, cldnn::tensor());
ib >> output_layout;

Expand Down Expand Up @@ -1160,5 +1153,4 @@ void primitive_inst::load(cldnn::BinaryInputBuffer& ib) {
_output_changed = false;
}
}

} // namespace cldnn
4 changes: 3 additions & 1 deletion src/plugins/intel_gpu/src/graph/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,9 @@ void program::cleanup() {
}
}
}
// _kernels_cache->reset();

if (_engine.configuration().kernels_cache_path.empty())
_kernels_cache->reset();
}

void program::add_split_outputs() {
Expand Down
9 changes: 2 additions & 7 deletions src/plugins/intel_gpu/src/plugin/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ CompiledModel::CompiledModel(InferenceEngine::CNNNetwork &network, std::shared_p
m_waitExecutor(executorManager()->getIdleCPUStreamsExecutor({ "GPUWaitExecutor" })) {
auto casted_context = std::dynamic_pointer_cast<gpu::ClContext>(context);

if (nullptr == casted_context) {
IE_THROW() << "Invalid remote context";
}
OPENVINO_ASSERT((casted_context != nullptr), "Invalid remote context");

m_context = casted_context;

Expand Down Expand Up @@ -107,9 +105,7 @@ CompiledModel::CompiledModel(std::istream& networkModel, std::shared_ptr<Inferen
m_waitExecutor(executorManager()->getIdleCPUStreamsExecutor({ "GPUWaitExecutor" })) {
auto casted_context = std::dynamic_pointer_cast<gpu::ClContext>(context);

if (nullptr == casted_context) {
IE_THROW() << "Invalid remote context";
}
OPENVINO_ASSERT((casted_context != nullptr), "Invalid remote context");

m_context = casted_context;

Expand Down Expand Up @@ -195,7 +191,6 @@ CompiledModel::CompiledModel(std::istream& networkModel, std::shared_ptr<Inferen
new_param->set_friendly_name(param_name);
new_param->set_element_type(param_element_type);
new_param->set_layout(param_layout);
// hoho->output(0).get_rt_info() = param_rt_info;
new_param->output(0).get_tensor().set_names(param_names);
new_param->validate_and_infer_types();
new_params.emplace_back(new_param);
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/intel_gpu/src/plugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ Plugin::Plugin() : m_defaultContexts({}) {
CustomLayer::LoadFromFile(config_path, config.second.customLayers, true);
}

isModelCachingEnabled = false;
if (const char* env_p = std::getenv("OV_GPU_MODEL_CACHING")) {
if (env_p[0] == '1') {
isModelCachingEnabled = true;
Expand Down Expand Up @@ -279,9 +278,6 @@ IExecutableNetworkInternal::Ptr Plugin::LoadExeNetworkImpl(const InferenceEngine
OV_ITT_SCOPED_TASK(itt::domains::intel_gpu_plugin, "Plugin::LoadExeNetworkImpl::CreateContext");
std::lock_guard<std::mutex> lock(engine_mutex);
if (!canReuseDefaultContext()) {
// if (m_defaultContexts.find(conf.device_id) != m_defaultContexts.end()) {
// statistics_map.erase(m_defaultContexts[conf.device_id]);
// }
m_defaultContexts[conf.device_id] = std::make_shared<RemoteCLContext>(shared_from_this(), AnyMap(), conf);
} else {
m_defaultContexts[conf.device_id]->GetConfig().kernels_cache_dir = conf.kernels_cache_dir;
Expand Down

0 comments on commit fd32d54

Please sign in to comment.