Skip to content

Commit

Permalink
removed object_type
Browse files Browse the repository at this point in the history
  • Loading branch information
e-ddykim committed Nov 15, 2022
1 parent 8187e6d commit abc9275
Show file tree
Hide file tree
Showing 104 changed files with 127 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class Serializer<BinaryInputBuffer, Data<T>> {

} // namespace cldnn

#define BIND_BINARY_BUFFER_WITH_TYPE(cls_name, obj_type) \
#define BIND_BINARY_BUFFER_WITH_TYPE(cls_name) \
namespace cldnn { \
const object_type cls_name::type = obj_type; \
const std::string cls_name::type = #cls_name; \
BIND_TO_BUFFER(BinaryOutputBuffer, cls_name) \
BIND_TO_BUFFER(BinaryInputBuffer, cls_name) \
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#include <functional>
#include "buffer.hpp"
#include "static_instance.hpp"
#include "object_types.hpp"

#define DECLARE_OBJECT_TYPE_SERIALIZATION \
static const object_type type; \
object_type get_type() const override { return type; }
static const std::string type; \
std::string get_type() const override { return type; }

#define BIND_TO_BUFFER(buffer, type) \
template <> \
Expand All @@ -25,26 +24,19 @@
const instance_creator<buffer, type>& bind_creator<buffer, type>::creator = \
static_instance<instance_creator<buffer, type>>::get_instance().instantiate();

// It's a defect, and was fixed in C++14
// https://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148
struct enum_class_hash {
template <typename T>
std::size_t operator()(T t) const { return static_cast<std::size_t>(t); }
};

namespace cldnn {

template <typename BufferType>
struct saver_storage {
using save_function = std::function<void(BufferType&, const void*)>;
using value_type = typename std::unordered_map<object_type, save_function, enum_class_hash>::value_type;
using value_type = typename std::unordered_map<std::string, save_function>::value_type;

static saver_storage<BufferType>& instance() {
static saver_storage<BufferType> instance;
return instance;
}

const save_function& get_save_function(const object_type& type) const {
const save_function& get_save_function(const std::string& type) const {
return map.at(type);
}

Expand All @@ -57,7 +49,7 @@ struct saver_storage {
saver_storage(const saver_storage&) = delete;
void operator=(const saver_storage&) = delete;

std::unordered_map<object_type, save_function, enum_class_hash> map;
std::unordered_map<std::string, save_function> map;
};

template <typename T>
Expand All @@ -67,14 +59,14 @@ struct void_deleter {

template <typename BufferType, typename FuncT>
struct loader_storage {
using value_type = typename std::unordered_map<object_type, FuncT, enum_class_hash>::value_type;
using value_type = typename std::unordered_map<std::string, FuncT>::value_type;

static loader_storage& instance() {
static loader_storage instance;
return instance;
}

const FuncT& get_load_function(const object_type& type) {
const FuncT& get_load_function(const std::string& type) {
return map.at(type);
}

Expand All @@ -87,7 +79,7 @@ struct loader_storage {
loader_storage(const loader_storage&) = delete;
void operator=(const loader_storage&) = delete;

std::unordered_map<object_type, FuncT, enum_class_hash> map;
std::unordered_map<std::string, FuncT> map;
};

template <typename BufferType>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "buffer.hpp"
#include "bind.hpp"
#include "helpers.hpp"
#include "object_types.hpp"

namespace cldnn {

Expand All @@ -21,7 +20,7 @@ class Serializer<BufferType, std::unique_ptr<T>, typename std::enable_if<std::is
public:
static void save(BufferType& buffer, const std::unique_ptr<T>& ptr) {
const auto& type = ptr->get_type();
buffer << cldnn::make_data(&type, sizeof(object_type));
buffer << type;
const auto save_func = saver_storage<BufferType>::instance().get_save_function(type);
save_func(buffer, ptr.get());
}
Expand All @@ -31,17 +30,17 @@ template <typename BufferType, typename T>
class Serializer<BufferType, std::unique_ptr<T>, typename std::enable_if<std::is_base_of<InputBuffer<BufferType>, BufferType>::value>::type> {
public:
static void load(BufferType& buffer, std::unique_ptr<T>& ptr, engine& engine) {
object_type type;
buffer >> cldnn::make_data(&type, sizeof(object_type));
std::string type;
buffer >> type;
const auto load_func = dif<BufferType>::instance().get_load_function(type);
std::unique_ptr<void, void_deleter<void>> result;
load_func(buffer, result, engine);
ptr.reset(static_cast<T*>(result.release()));
}

static void load(BufferType& buffer, std::unique_ptr<T>& ptr) {
object_type type;
buffer >> cldnn::make_data(&type, sizeof(object_type));
std::string type;
buffer >> type;
const auto load_func = def<BufferType>::instance().get_load_function(type);
std::unique_ptr<void, void_deleter<void>> result;
load_func(buffer, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ attach_prior_box_common::attach_prior_box_common() {
} // namespace common
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::common::wait_for_events_impl, cldnn::object_type::WAIT_FOR_EVENTS_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::common::wait_for_events_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/cpu/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ attach_assign_impl::attach_assign_impl() {
} // namespace cpu
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::assign_impl, cldnn::object_type::ASSIGN_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::assign_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -874,4 +874,4 @@ attach_detection_output_impl::attach_detection_output_impl() {
} // namespace cpu
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::detection_output_impl, cldnn::object_type::DETECTION_OUTPUT_IMPL_CPU)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::detection_output_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,4 @@ attach_non_max_suppression_impl::attach_non_max_suppression_impl() {
} // namespace cpu
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::non_max_suppression_impl, cldnn::object_type::NON_MAX_SUPPRESSION_IMPL_CPU)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::non_max_suppression_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/cpu/proposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,4 @@ attach_proposal_impl::attach_proposal_impl() {
} // namespace cpu
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::proposal_impl, cldnn::object_type::PROPOSAL_IMPL_CPU)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::proposal_impl)
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 @@ -56,4 +56,4 @@ attach_read_value_impl::attach_read_value_impl() {
} // namespace cpu
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::read_value_impl, cldnn::object_type::READ_VALUE_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::cpu::read_value_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ attach_activation_impl::attach_activation_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::activation_impl, cldnn::object_type::ACTIVATION_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::activation_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ attach_adaptive_pooling_impl::attach_adaptive_pooling_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::adaptive_pooling_impl, cldnn::object_type::ADAPTIVE_POOLING_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::adaptive_pooling_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/arg_max_min.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ attach_arg_max_min_impl::attach_arg_max_min_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::arg_max_min_impl, cldnn::object_type::ARG_MAX_MIN_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::arg_max_min_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ attach_average_unpooling_impl::attach_average_unpooling_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::average_unpooling_impl, cldnn::object_type::AVERAGE_UNPOOLING_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::average_unpooling_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ attach_batch_to_space_impl::attach_batch_to_space_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::batch_to_space_impl, cldnn::object_type::BATCH_TO_SPACE_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::batch_to_space_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ attach_binary_convolution_impl::attach_binary_convolution_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::binary_convolution_impl, cldnn::object_type::BINARY_CONVOLUTION_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::binary_convolution_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/border.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ attach_border_impl::attach_border_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::border_impl, cldnn::object_type::BORDER_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::border_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ attach_broadcast_impl::attach_broadcast_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::broadcast_impl, cldnn::object_type::BROADCAST_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::broadcast_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/bucketize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ attach_bucketize_impl::attach_bucketize_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::bucketize_impl, cldnn::object_type::BUCKETIZE_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::bucketize_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@ attach_concatenation_impl::attach_concatenation_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::concatenation_impl, cldnn::object_type::CONCATENATION_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::concatenation_impl)
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ attach_convert_color_impl::attach_convert_color_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::convert_color_impl, cldnn::object_type::CONVERT_COLOR_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::convert_color_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,4 @@ attach_convolution_impl::attach_convolution_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::convolution_impl, cldnn::object_type::CONVOLUTION_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::convolution_impl)
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/crop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ attach_crop_impl::attach_crop_impl() {
} // namespace ocl
} // namespace cldnn

BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::crop_impl, cldnn::object_type::CROP_IMPL)
BIND_BINARY_BUFFER_WITH_TYPE(cldnn::ocl::crop_impl)
Loading

0 comments on commit abc9275

Please sign in to comment.