Skip to content

Commit

Permalink
Replace std dynamic casts with ov defined
Browse files Browse the repository at this point in the history
std::dynamic_pointer_cast -> ov::as_type_ptr
std::dynamic_cast -> ov::as_type
Signed-off-by: Tomasz Jankowski <tomasz1.jankowski@intel.com>
  • Loading branch information
t-jankowski committed Jan 13, 2025
1 parent 588f93d commit 4590922
Show file tree
Hide file tree
Showing 66 changed files with 206 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ struct weightless_cache_manager {
return ov::op::util::is_constant(node);
});
OPENVINO_ASSERT(it != ops.end());
mem_obj->transformed_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(*it);
mem_obj->transformed_constant = ov::as_type_ptr<ov::op::v0::Constant>(*it);
OPENVINO_ASSERT(mem_obj->transformed_constant->get_element_type() == curr_dtype);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/plugin/ops/batch_to_space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void CreateBatchToSpaceOp(ProgramBuilder& p, const std::shared_ptr<ov::op

bool non_constant_input = false;
for (size_t i = 1; i < 4; ++i) {
auto inConst = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));
auto inConst = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));

bool is_const_input = (inConst != nullptr);
OPENVINO_ASSERT((i == 1) || (i >= 2 && non_constant_input != is_const_input),
Expand All @@ -45,7 +45,7 @@ static void CreateBatchToSpaceOp(ProgramBuilder& p, const std::shared_ptr<ov::op
p.add_primitive(*op, batchToSpacePrim);
} else {
for (size_t i = 1; i < 4; ++i) {
auto inConst = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));
auto inConst = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(i));

std::vector<int32_t> sizes = inConst->cast_vector<int32_t>();
int32_t default_size = i == 1 ? 1 : 0;
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_gpu/src/plugin/ops/broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ static void CreateCommonBroadcastOp(ProgramBuilder& p, const std::shared_ptr<ov:
}

ov::op::BroadcastModeSpec mode = ov::op::BroadcastType::NONE;
if (auto broadcast_v3 = std::dynamic_pointer_cast<ov::op::v3::Broadcast>(op)) {
if (auto broadcast_v3 = ov::as_type_ptr<ov::op::v3::Broadcast>(op)) {
mode = broadcast_v3->get_broadcast_spec();
} else if (auto broadcast_v1 = std::dynamic_pointer_cast<ov::op::v1::Broadcast>(op)) {
} else if (auto broadcast_v1 = ov::as_type_ptr<ov::op::v1::Broadcast>(op)) {
switch (broadcast_v1->get_broadcast_spec().m_type) {
case ov::op::AutoBroadcastType::NONE: mode = ov::op::BroadcastType::NONE; break;
case ov::op::AutoBroadcastType::NUMPY: mode = ov::op::BroadcastType::NUMPY; break;
Expand Down Expand Up @@ -98,7 +98,7 @@ static void CreateCommonBroadcastOp(ProgramBuilder& p, const std::shared_ptr<ov:
static void CreateBroadcastOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v1::Broadcast>& op) {
validate_inputs_count(op, {2, 3});
if (op->get_broadcast_spec().m_type == ov::op::AutoBroadcastType::NONE && op->get_input_size() == 3) {
auto axis_mapping_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto axis_mapping_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
OPENVINO_ASSERT(axis_mapping_node != nullptr, "[GPU] Unsupported parameter nodes type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");

auto axis_mapping = axis_mapping_node->get_axis_set_val();
Expand All @@ -113,7 +113,7 @@ static void CreateBroadcastOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v
validate_inputs_count(op, {2, 3});
ov::AxisSet axis_mapping;
if (op->get_input_size() == 3) {
auto axis_mapping_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto axis_mapping_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
OPENVINO_ASSERT(axis_mapping_node != nullptr, "[GPU] Unsupported parameter nodes type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");

axis_mapping = axis_mapping_node->get_axis_set_val();
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/plugin/ops/constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void create_data(ProgramBuilder& p, const ov::Shape& const_shape, const s
}

static bool is_btiwise(Node* node) {
return dynamic_cast<const ov::op::util::BinaryElementwiseBitwise*>(node) != nullptr;
return ov::as_type<const ov::op::util::BinaryElementwiseBitwise>(node) != nullptr;
}

static void CreateConstantOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v0::Constant>& op) {
Expand Down Expand Up @@ -185,7 +185,7 @@ static void CreateConstantOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v0
// Also check if constant users is a backprop convolution - in that case O and I need to be swapped.
for (auto& node : constUsers) {
auto outOp = node.get_node();
if (auto castedOp = dynamic_cast<ov::op::v0::Concat*>(outOp)) {
if (auto castedOp = ov::as_type<ov::op::v0::Concat>(outOp)) {
if (castedOp->get_axis() == 0) {
consts[op].needsBatchInterpretation = constDims.size() == 1;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/plugin/ops/convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static void CreateConvolutionBackpropDataOp(ProgramBuilder& p, const std::shared
output_padding,
weights_have_group_dim);
if (op->get_input_size() == 3) {
auto output_shape_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto output_shape_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
if (output_shape_constant) {
auto output_shape = output_shape_constant->cast_vector<int64_t>();
ov::Shape shape(output_shape.begin(), output_shape.end());
Expand Down Expand Up @@ -253,7 +253,7 @@ static void CreateGroupConvolutionBackpropDataOp(ProgramBuilder& p, const std::s
output_padding,
weights_have_group_dim);
if (op->get_input_size() == 3) {
auto output_shape_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto output_shape_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
if (output_shape_constant) {
auto output_shape = output_shape_constant->cast_vector<int64_t>();
ov::Shape shape(output_shape.begin(), output_shape.end());
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/plugin/ops/ctc_greedy_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void CreateCommonCTCGreedyDecoderOp(ProgramBuilder& p, const std::shared_
if (p.use_new_shape_infer()) {
uint32_t blank_index = UINT32_MAX;
if (reordered_inputs.size() == 3) {
auto blank_index_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto blank_index_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
if (!blank_index_node) {
OPENVINO_THROW("Unsupported blank_index node type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");
}
Expand All @@ -70,7 +70,7 @@ static void CreateCommonCTCGreedyDecoderOp(ProgramBuilder& p, const std::shared_
} else {
uint32_t blank_index = static_cast<uint32_t>(op->get_input_shape(0).back() - 1);
if (reordered_inputs.size() == 3) {
auto blank_index_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto blank_index_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
if (!blank_index_node) {
OPENVINO_THROW("Unsupported blank_index node type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/plugin/ops/cum_sum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void CreateCumSumOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v0::

int64_t axis = 0;
if (op->get_input_size() == 2) {
auto axes_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
auto axes_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
OPENVINO_ASSERT(axes_constant != nullptr, "[GPU] Unsupported parameter nodes type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");
axis = axes_constant->cast_vector<int64_t>()[0];
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_gpu/src/plugin/ops/dft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void createDft(ProgramBuilder& p,

if (op->is_dynamic() && p.use_new_shape_infer()) {
std::vector<int64_t> axes;
auto axes_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
auto axes_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
if (axes_constant != nullptr) {
axes = axes_constant->cast_vector<int64_t>();
uint8_t axis_correction = static_cast<uint8_t>(op->get_input_partial_shape(0).size());
Expand All @@ -42,7 +42,7 @@ void createDft(ProgramBuilder& p,

if (op->get_input_size() == 3) {
std::vector<int64_t> signal_size;
auto signal_size_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto signal_size_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
if (signal_size_constant != nullptr) {
signal_size = signal_size_constant->cast_vector<int64_t>();
}
Expand All @@ -56,7 +56,7 @@ void createDft(ProgramBuilder& p,
} else {
const auto& out_shape = op->get_output_shape(0);

auto axes_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
auto axes_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
OPENVINO_ASSERT(axes_constant != nullptr, "[GPU] Unsupported parameter nodes type in ", friendly_name, " (", op->get_type_name(), ")");
auto axes = axes_constant->cast_vector<int64_t>();
uint8_t axis_correction = static_cast<uint8_t>(op->get_input_shape(0).size());
Expand All @@ -67,7 +67,7 @@ void createDft(ProgramBuilder& p,

std::vector<int64_t> signal_size;
if (op->get_input_size() == 3) {
auto signal_size_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
auto signal_size_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(2));
OPENVINO_ASSERT(signal_size_constant != nullptr, "[GPU] Unsupported parameter nodes type in ", friendly_name, " (", op->get_type_name(), ")");
signal_size = signal_size_constant->cast_vector<int64_t>();
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/plugin/ops/eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static void CreateLogicalXorOp(ProgramBuilder& p, const std::shared_ptr<ov::op::

static void CreatePowerOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v1::Power>& op) {
validate_inputs_count(op, {2});
auto power_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
auto power_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(1));
if (power_node) {
if (ov::shape_size(power_node->get_output_shape(0)) == 1) {
float pow;
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/plugin/ops/embedding_bag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void CreateEmbeddingBagOffsetsSumOp(ProgramBuilder& p, const std::shared_

int32_t defaultIndex = -1;
if (inputs.size() > 3) {
auto index_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(3));
auto index_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(3));
OPENVINO_ASSERT(index_node != nullptr, "[GPU] Unsupported parameter nodes type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");

float val;
Expand Down Expand Up @@ -110,7 +110,7 @@ static void CreateEmbeddingSegmentsSumOp(ProgramBuilder& p, const std::shared_pt
int32_t defaultIndex = -1;
// port of default_index is 4 by default, but we removed "num_segments" above, so now it's equal to 3
if (inputs.size() > 3) {
auto index_node = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(4));
auto index_node = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(4));
OPENVINO_ASSERT(index_node != nullptr, "[GPU] Unsupported parameter nodes type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");

float val;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/plugin/ops/eye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static void CreateEyeOp(ProgramBuilder& p, const std::shared_ptr<ov::op::v9::Eye
for (size_t i = dim_size, j = os_sz; i > 0 && j > 0; --i, --j) {
dims[i - 1] = output_shapes[j - 1];
}
const ov::op::v0::Constant* constant = dynamic_cast<ov::op::v0::Constant*>(op->get_input_node_ptr(2));
const ov::op::v0::Constant* constant = ov::as_type<ov::op::v0::Constant>(op->get_input_node_ptr(2));
OPENVINO_ASSERT(constant != nullptr, "Unsupported parameter nodes type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");

int32_t shift{};
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_gpu/src/plugin/ops/fully_connected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void CreateFullyConnectedCompressedOp(ProgramBuilder& p, const std::share
float zp_value = 0.0f;
bool has_scalar_zp = false;
if (zp_name.size() > 0) {
auto zp_const = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(W_ZP_IDX));
auto zp_const = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(W_ZP_IDX));
if (zp_const && ov::shape_size(zp_const->get_output_shape(0)) == 1) {
has_scalar_zp = true;
zp_value = zp_const->cast_vector<float>()[0];
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/plugin/ops/gather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void CreateGatherOpBase(ProgramBuilder& p, const std::shared_ptr<T>& op, const i
const auto input_rank = input_shape.rank().get_length();
const auto& indices = op->input_value(1);
const auto& indices_node = indices.get_node_shared_ptr();
auto indices_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(indices_node);
auto indices_constant = ov::as_type_ptr<ov::op::v0::Constant>(indices_node);
bool is_indices_constant = (indices_constant) ? true : false;

if (is_static && axis == 0 && input_rank > 1 && indices.get_partial_shape().rank().get_length() == 0 &&
Expand Down Expand Up @@ -149,7 +149,7 @@ void CreateGatherOpBase(ProgramBuilder& p, const std::shared_ptr<T>& op, const i
float zp_value = 0.0f;
bool has_scalar_zp = false;
if (op->get_input_size() == 5) {
std::shared_ptr<ov::op::v0::Constant> zp_const = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(4));
std::shared_ptr<ov::op::v0::Constant> zp_const = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(4));
if (zp_const && ov::shape_size(zp_const->get_output_shape(0)) == 1) {
has_scalar_zp = true;
zp_value = zp_const->cast_vector<float>()[0];
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/intel_gpu/src/plugin/ops/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static std::vector<int64_t> ExtractAxes(const std::shared_ptr<ov::op::util::Inte
std::vector<int64_t> axes;
auto inputRank = op->get_input_partial_shape(0).size();
if (op->get_input_size() == axes_index + 1) {
auto axes_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(axes_index));
auto axes_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(axes_index));
OPENVINO_ASSERT(axes_constant, "Unsupported parameter node type in ", op->get_friendly_name(), " (", op->get_type_name(), ")");

axes = axes_constant->cast_vector<int64_t>();
Expand Down Expand Up @@ -76,10 +76,10 @@ static void CreateInterpolateOp(ProgramBuilder& p, const std::shared_ptr<ov::op:

auto attrs = op->get_attrs();

auto sizes_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(SIZES_INDEX));
auto sizes_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(SIZES_INDEX));
std::vector<int64_t> sizes = sizes_constant ? sizes_constant->cast_vector<int64_t>() : std::vector<int64_t>{};

auto scales_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(SCALES_INDEX));
auto scales_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(SCALES_INDEX));
std::vector<float> scales = scales_constant ? scales_constant->cast_vector<float>() : std::vector<float>{};

std::vector<int64_t> axes = ExtractAxes(op, AXES_INDEX);
Expand Down Expand Up @@ -156,7 +156,7 @@ static void CreateInterpolateOp(ProgramBuilder& p, const std::shared_ptr<ov::op:

auto attrs = op->get_attrs();

auto scales_or_sizes_constant = std::dynamic_pointer_cast<ov::op::v0::Constant>(op->get_input_node_shared_ptr(eScalesOrSizesIndex));
auto scales_or_sizes_constant = ov::as_type_ptr<ov::op::v0::Constant>(op->get_input_node_shared_ptr(eScalesOrSizesIndex));
std::vector<float> scales = scales_or_sizes_constant && attrs.shape_calculation_mode == ov::op::v11::Interpolate::ShapeCalcMode::SCALES ?
scales_or_sizes_constant->cast_vector<float>() : std::vector<float>{};
std::vector<int64_t> sizes = scales_or_sizes_constant && attrs.shape_calculation_mode == ov::op::v11::Interpolate::ShapeCalcMode::SIZES ?
Expand Down
Loading

0 comments on commit 4590922

Please sign in to comment.