Skip to content

Commit

Permalink
Complete to run benchmark_app f32 for resample cpu impl
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinchoi-intel committed Dec 26, 2024
1 parent 0f00606 commit 931097e
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 93 deletions.
42 changes: 10 additions & 32 deletions src/plugins/intel_gpu/src/graph/impls/cpu/resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,34 +106,32 @@ struct resample_impl : public typed_primitive_impl<resample> {
auto input_mem_ptr = instance.input_memory_ptr();
cldnn::mem_lock<uint8_t, mem_lock_type::read> input_lock(input_mem_ptr, stream);

auto input_rank = params->input_layouts[0].get_rank();
for (size_t i = 0; i < params->input_layouts.size(); i++) {
auto input_tensor = make_tensor(params->input_layouts[0], input_lock.data());
input_host_tensors.push_back(input_tensor);
}

if (scales.size() < input_rank)
scales.insert(scales.begin(), input_rank - scales.size(), 1.f);

for(size_t i = (input_rank - axes.size()); i > 0; i--)
axes.insert(axes.begin(), 1, (i - 1));

if (input_host_tensors.size() == 1) {
auto target_shape_sizes = params->output_layouts[0].get_tensor().sizes();
std::vector<int64_t> target_shape_ps;
for (size_t i = 0; i < axes.size(); i++)
for (size_t i = 0; i < input_rank; i++)
target_shape_ps.push_back(target_shape_sizes[i]);

auto target_shape_tensor = ov::Tensor(ov::element::i32, {target_shape_ps.size()}, target_shape_ps.data());
input_host_tensors.push_back(target_shape_tensor);

if (shape_calc_mode == ov::op::util::InterpolateBase::ShapeCalcMode::SIZES) {
auto new_scales = scales;
auto input_shape_sizes = params->input_layouts[0].get_tensor().sizes();
for (size_t i = 0; i < sizes.size(); i++)
new_scales[i] = sizes[i] / input_shape_sizes[i];

auto scales_tensor = ov::Tensor(ov::element::f32, {new_scales.size()}, new_scales.data());
input_host_tensors.push_back(scales_tensor);
shape_calc_mode = ov::op::util::InterpolateBase::ShapeCalcMode::SCALES;
} else if (shape_calc_mode == ov::op::util::InterpolateBase::ShapeCalcMode::SCALES) {
if (shape_calc_mode == ov::op::util::InterpolateBase::ShapeCalcMode::SCALES) {
auto scales_tensor = ov::Tensor(ov::element::f32, {scales.size()}, scales.data());
input_host_tensors.push_back(scales_tensor);
} else {
OPENVINO_ASSERT(false, "[GPU] Not supported Interpolate ShapeCalcMode", instance.id());
OPENVINO_ASSERT(false, "[GPU] Not supported Interpolate ShapeCalcMode of CPU impl", instance.id());
}

auto axes_tensor = ov::Tensor(ov::element::i64, {axes.size()}, axes.data());
Expand Down Expand Up @@ -189,19 +187,6 @@ struct resample_impl : public typed_primitive_impl<resample> {
namespace detail {

attach_resample_impl::attach_resample_impl() {
// auto formats = {
// format::bfyx,
// };

// auto types = {
// data_types::f32,
// };

// implementation_map<resample>::add(impl_types::cpu, shape_types::static_shape, resample_impl::create, types, formats);
// implementation_map<resample>::add(impl_types::cpu, shape_types::dynamic_shape, resample_impl::create, types, formats);

//std::set<implementation_map<resample>::key_type> keys;

const auto types = {data_types::f32, data_types::i32};
const auto formats = {
format::bfyx,
Expand All @@ -219,13 +204,6 @@ attach_resample_impl::attach_resample_impl() {
format::bs_fs_zyx_bsv32_fsv32,
format::bs_fs_zyx_bsv32_fsv16,
};
// for (const auto type : types) {
// for (const auto format : formats) {
// keys.emplace(type, format);
// }
// }

// keys.emplace(data_types::f32, format::yxfb);

implementation_map<resample>::add(impl_types::cpu, shape_types::static_shape, resample_impl::create, types, formats);
implementation_map<resample>::add(impl_types::cpu, shape_types::dynamic_shape, resample_impl::create, types, formats);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ void register_implementations() {
REGISTER_OCL(swiglu);
REGISTER_OCL(tile);
REGISTER_OCL(gather_tree);
//REGISTER_OCL(resample);
REGISTER_OCL(grn);
REGISTER_OCL(ctc_greedy_decoder);
REGISTER_OCL(ctc_loss);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_gpu/src/graph/impls/ocl/register.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include "intel_gpu/primitives/reduce.hpp"
#include "intel_gpu/primitives/region_yolo.hpp"
#include "intel_gpu/primitives/reorg_yolo.hpp"
//#include "intel_gpu/primitives/resample.hpp"
#include "intel_gpu/primitives/reshape.hpp"
#include "intel_gpu/primitives/reverse_sequence.hpp"
#include "intel_gpu/primitives/rms.hpp"
Expand Down
36 changes: 0 additions & 36 deletions src/plugins/intel_gpu/src/graph/impls/ocl/resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,42 +175,6 @@ struct resample_impl : typed_primitive_impl_ocl<resample> {
}
};

// namespace detail {

// attach_resample_impl::attach_resample_impl() {
// std::set<implementation_map<resample>::key_type> keys;

// const auto types = {data_types::f16, data_types::f32, data_types::i8, data_types::u8, data_types::i32};
// const auto formats = {
// format::bfyx,
// format::b_fs_yx_fsv16,
// format::b_fs_yx_fsv32,
// format::bs_fs_yx_bsv16_fsv16,
// format::bs_fs_yx_bsv32_fsv16,
// format::bs_fs_yx_bsv32_fsv32,

// format::bfzyx,
// format::b_fs_zyx_fsv16,
// format::b_fs_zyx_fsv32,
// format::bs_fs_zyx_bsv16_fsv32,
// format::bs_fs_zyx_bsv16_fsv16,
// format::bs_fs_zyx_bsv32_fsv32,
// format::bs_fs_zyx_bsv32_fsv16,
// };
// for (const auto type : types) {
// for (const auto format : formats) {
// keys.emplace(type, format);
// }
// }

// keys.emplace(data_types::f32, format::yxfb);
// keys.emplace(data_types::f16, format::yxfb);
// keys.emplace(data_types::f16, format::fs_b_yx_fsv32);

// implementation_map<resample>::add(impl_types::ocl, typed_primitive_impl_ocl<resample>::create<resample_impl>, keys);
// }

// } // namespace detail
std::unique_ptr<primitive_impl> ResampleImplementationManager::create_impl(const program_node& node, const kernel_impl_params& params) const {
assert(node.is_type<resample>());
return typed_primitive_impl_ocl<resample>::create<resample_impl>(static_cast<const resample_node&>(node), params);
Expand Down
12 changes: 1 addition & 11 deletions src/plugins/intel_gpu/src/graph/impls/ocl/resample.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "impls/registry/implementation_manager.hpp"
#include "program_node.h"
//#include "intel_gpu/primitives/resample.hpp"
#include "resample_inst.h"

#include <memory>
namespace cldnn {
Expand All @@ -15,16 +15,6 @@ struct ResampleImplementationManager : public ImplementationManager {
ResampleImplementationManager(shape_types shape_type, ValidateFunc vf = nullptr) : ImplementationManager(impl_types::ocl, shape_type, vf) {}
std::unique_ptr<primitive_impl> create_impl(const program_node& node, const kernel_impl_params& params) const override;
bool validate_impl(const program_node& node) const override {
// auto prim = node.as<resample>().get_primitive();
// const auto& in0_layout = node.get_input_layout(0);

// if (in0_layout.data_type == ov::element::f32 &&
// prim->operation_type == ov::op::util::InterpolateBase::InterpolateMode::LINEAR_ONNX &&
// prim->coord_trans_mode == ov::op::util::InterpolateBase::CoordinateTransformMode::ALIGN_CORNERS &&
// prim->shape_calc_mode == ov::op::util::InterpolateBase::ShapeCalcMode::SCALES) {
// return false;
// }

return true;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ REGISTER_DEFAULT_IMPLS(space_to_batch, OCL_S);
REGISTER_DEFAULT_IMPLS(space_to_depth, OCL_S);
REGISTER_DEFAULT_IMPLS(swiglu, OCL_S, OCL_D);
REGISTER_DEFAULT_IMPLS(gather_tree, OCL_S);
//REGISTER_DEFAULT_IMPLS(resample, CPU_S, OCL_S);
REGISTER_DEFAULT_IMPLS(grn, OCL_S);
REGISTER_DEFAULT_IMPLS(ctc_greedy_decoder, OCL_S);
REGISTER_DEFAULT_IMPLS(ctc_loss, OCL_S);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,10 @@ const std::vector<std::shared_ptr<cldnn::ImplementationManager>>& Registry<resam

return true;
})
// OV_GPU_CREATE_INSTANCE_OCL(ocl::ResampleImplementationManager, shape_types::dynamic_shape,
// [](const cldnn::program_node& node){
// return false;
// })

OV_GPU_GET_INSTANCE_CPU(resample, shape_types::static_shape,
[](const cldnn::program_node& node){
return true;
})
// OV_GPU_GET_INSTANCE_CPU(resample, shape_types::dynamic_shape,
// [](const cldnn::program_node& node){
// return false;
// })
};

return impls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,20 @@ INSTANTIATE_TEST_SUITE_P(InterpolateLinear_Layout_Test, InterpolateLayerGPUTest,
const std::vector<ShapeParams> shapeParams4D_LargeShape = {
ShapeParams{
ov::op::v4::Interpolate::ShapeCalcMode::SCALES,
//InputShape{{-1, {2, 100}, -1, -1}, {{1, 64, 148, 148}}},
InputShape{{-1, -1, -1, -1}, {{1, 3, 48, 48}}}, // min shape for failure
InputShape{{-1, {2, 100}, -1, -1}, {{1, 64, 148, 148}}},
ov::test::utils::InputLayerType::CONSTANT,
ov::test::utils::InputLayerType::CONSTANT,
{{1.f, 1.f, 2.f, 2.f}},
defaultAxes4D.front()
},
ShapeParams{
ov::op::v4::Interpolate::ShapeCalcMode::SCALES,
InputShape{{-1, -1, -1, -1}, {{1, 3, 48, 48}}},
ov::test::utils::InputLayerType::CONSTANT,
ov::test::utils::InputLayerType::CONSTANT,
{{2.f, 2.f}},
reducedAxes4D.front()
},
ShapeParams{
ov::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, -1, -1, -1}, {{1, 3, 48, 48}}},
Expand Down

0 comments on commit 931097e

Please sign in to comment.