Skip to content
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

[RTTI] Assert virtual dtor for dynamic cast #28616

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class KernelExecutor : public KernelExecutorBase {
void update_by_config(const GenericConfig& new_config) override final { // NOLINT
if (m_config.hash() == new_config.hash())
return;
static_assert(std::has_virtual_destructor_v<Conf>);
const auto& new_ptr = dynamic_cast<const Conf*>(&new_config);
OPENVINO_ASSERT(new_config.is_completed() && new_ptr, "Failed to update kernel config in get_config");
m_config = *new_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class MemoryAccess {
explicit MemoryAccess(const std::set<size_t>& input_ports, const std::set<size_t>& output_ports);
explicit MemoryAccess(const PortMap& input_ports, const PortMap& output_ports);
MemoryAccess() = default;
virtual ~MemoryAccess() = default;

// This method can be called only in ctors
void ctor_initialize(const std::set<size_t>& input_ports, const std::set<size_t>& output_ports);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ shared_ptr<T> check_all_inputs(const shared_ptr<ov::op::v0::Concat>& concat) {
const auto concat_in_values = concat->input_values();
size_t idx = 0;
for (const auto& in_to_concat : concat_in_values) {
static_assert(std::has_virtual_destructor_v<T>);
const auto& cast_to_split = dynamic_pointer_cast<T>(in_to_concat.get_node_shared_ptr());
// There is a special case with (GRU/RNN/LSTM)Sequence ops:
//
Expand Down
1 change: 1 addition & 0 deletions src/inference/dev_api/openvino/runtime/so_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct SoPtr {
template <typename U>
SoPtr(const SoPtr<U>& that) : _ptr{std::dynamic_pointer_cast<T>(that._ptr)},
_so{that._so} {
static_assert(std::has_virtual_destructor_v<T>);
OPENVINO_ASSERT(_ptr != nullptr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ struct RepackedInput {
template <class T = RepackedInputKernel,
typename std::enable_if<std::is_base_of<RepackedInputKernel, T>::value, bool>::type = true>
std::shared_ptr<const T> kernel() const {
static_assert(std::has_virtual_destructor_v<T>);
const auto ker = std::dynamic_pointer_cast<const T>(m_kernel);
OPENVINO_ASSERT(ker, "Kernel is empty!");
return ker;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BlockedMemoryDesc : public virtual MemoryDesc {
virtual bool isCompatible(const BlockedMemoryDesc& rhs, CmpMask cmpMask) const = 0;
using MemoryDesc::isCompatible;

~BlockedMemoryDesc() override = default;
virtual ~BlockedMemoryDesc() override = default;

std::string serializeFormat() const override;

Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_cpu/src/memory_desc/cpu_memory_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class MemoryDesc {
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<MemoryDesc, T>::value, int>::type = 0>
T* as() {
static_assert(std::has_virtual_destructor_v<T>);
T* casted = dynamic_cast<T*>(this);
if (!casted)
OPENVINO_THROW("Cannot dynamically cast MemoryDesc");
Expand Down
1 change: 1 addition & 0 deletions src/plugins/intel_cpu/src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class NodeDesc {
typename std::enable_if<!std::is_pointer<T>::value && !std::is_reference<T>::value, int>::type = 0,
typename std::enable_if<std::is_base_of<ExecutorFactoryLegacy, T>::value, int>::type = 0>
std::shared_ptr<T> getExecutorFactoryAs() {
static_assert(std::has_virtual_destructor_v<T>);
auto casted = std::dynamic_pointer_cast<T>(executorFactory);
if (!casted)
OPENVINO_THROW("Cannot dynamically cast ExecutorFactory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
template <class Conv>
ov::matcher_pass_callback ov::intel_cpu::ConvertConv1DBase::convert_conv1d_to_conv2d() {
return [&](ov::pass::pattern::Matcher& m) {
static_assert(std::has_virtual_destructor_v<Conv>);
auto conv = std::dynamic_pointer_cast<Conv>(m.get_match_root());
if (!conv) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
template <class T>
ov::matcher_pass_callback ov::intel_cpu::ConvertReduceMultiAxisBase::convert_reduce() {
return [&](ov::pass::pattern::Matcher& m) {
static_assert(std::has_virtual_destructor_v<T>);
auto reduce = std::dynamic_pointer_cast<T>(m.get_match_root());
if (!reduce) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
template <class T>
ov::matcher_pass_callback ov::intel_cpu::ConvertReduceNoKeepDimsBase::convert_reduce() {
return [&](ov::pass::pattern::Matcher& m) {
static_assert(std::has_virtual_destructor_v<T>);
auto reduce = std::dynamic_pointer_cast<T>(m.get_match_root());
if (!reduce || reduce->get_keep_dims()) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct fused_primitive_desc {

template<typename T>
std::shared_ptr<T> get_typed_fuse_params() const {
static_assert(std::has_virtual_destructor_v<T>);
auto p = std::dynamic_pointer_cast<T>(f_param);
if (!p)
throw std::runtime_error("Invalid dynamic cast of fused parameters!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ enum class reduce_mode : uint16_t;
enum class eltwise_mode : int32_t;
} // namespace cldnn

#define REGISTER_FACTORY_IMPL(op_version, op_name) \
void __register ## _ ## op_name ## _ ## op_version(); \
void __register ## _ ## op_name ## _ ## op_version() { \
ProgramBuilder::RegisterFactory<ov::op::op_version::op_name>( \
[](ProgramBuilder& p, const std::shared_ptr<ov::Node>& op) { \
auto op_casted = std::dynamic_pointer_cast<ov::op::op_version::op_name>(op); \
OPENVINO_ASSERT(op_casted, "[GPU] Invalid ov Node type passed into ", __PRETTY_FUNCTION__); \
Create##op_name##Op(p, op_casted); \
}); \
}
#define REGISTER_FACTORY_IMPL(op_version, op_name) \
void __register##_##op_name##_##op_version(); \
void __register##_##op_name##_##op_version() { \
ProgramBuilder::RegisterFactory<ov::op::op_version::op_name>( \
[](ProgramBuilder& p, const std::shared_ptr<ov::Node>& op) { \
static_assert(std::has_virtual_destructor_v<ov::op::op_version::op_name>); \
auto op_casted = std::dynamic_pointer_cast<ov::op::op_version::op_name>(op); \
OPENVINO_ASSERT(op_casted, "[GPU] Invalid ov Node type passed into ", __PRETTY_FUNCTION__); \
Create##op_name##Op(p, op_casted); \
}); \
}

namespace ov {
namespace intel_gpu {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct typed_primitive_impl_ocl : public typed_primitive_impl<PType> {
template<typename ImplType, typename KernelParamsType>
static std::unique_ptr<primitive_impl> make_deep_copy(const ImplType& impl_ocl) {
auto prim_impl = make_unique<ImplType>(impl_ocl);
static_assert(std::has_virtual_destructor_v<KernelParamsType>);
KernelParamsType* params_ptr = dynamic_cast<KernelParamsType*>((*prim_impl)._kernel_data.params.get());
if (params_ptr != nullptr) {
(*prim_impl)._kernel_data.params = make_unique<KernelParamsType>(*params_ptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ struct fused_operation_desc {
KernelType GetType() const { return op_params->GetType(); }
template<typename T>
std::shared_ptr<T> GetOpParams() const {
static_assert(std::has_virtual_destructor_v<T>);
auto p = std::dynamic_pointer_cast<T>(op_params);
if (!p)
throw std::runtime_error("Invalid dynamic cast of fused operation parameters");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
namespace {
template<typename T>
static bool disable_reduce_decomposition(const std::shared_ptr<const ov::Node> node) {
static_assert(std::has_virtual_destructor_v<T>);
if (auto op = std::dynamic_pointer_cast<const T>(node)) {
if (op->input(0).get_partial_shape()[0].is_static()) {
bool fp16_batch_not_1 = op->get_element_type() == ov::element::f16 && op->input(0).get_partial_shape()[0] != 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void check_impl() {
size_t actual_impls_count = 0;
for (size_t i = 0; i < all_impls.size(); i++) {
ASSERT_NE(all_impls[i], nullptr) << " Implementation " << i << " of " << PType().type_string();
static_assert(std::has_virtual_destructor_v<PType>);
if (std::dynamic_pointer_cast<ImplementationManagerLegacy<PType>>(all_impls[i]) != nullptr)
actual_impls_count++;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/template/src/remote_tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class VectorImpl : public ov::IRemoteTensor {

template <class T>
operator std::vector<T>&() const {
static_assert(std::has_virtual_destructor_v<T>);
auto impl = std::dynamic_pointer_cast<VectorTensorImpl<T>>(m_tensor);
OPENVINO_ASSERT(impl, "Cannot get vector. Type is incorrect!");
return impl->get();
Expand Down
Loading