Skip to content

Commit

Permalink
Add cpu_impl and gpu_impl selection condition and pass func test
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinchoi-intel committed Dec 24, 2024
1 parent 6f4b86e commit 0f00606
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 50 deletions.
40 changes: 36 additions & 4 deletions src/plugins/intel_gpu/src/graph/impls/cpu/resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,51 @@ struct resample_impl : public typed_primitive_impl<resample> {
namespace detail {

attach_resample_impl::attach_resample_impl() {
auto formats = {
// 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,
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);
// }
// }

auto types = {
data_types::f32,
};
// 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);
}

} // namespace detail


} // namespace cpu
} // namespace cldnn

Expand Down
2 changes: 1 addition & 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,7 @@ void register_implementations() {
REGISTER_OCL(swiglu);
REGISTER_OCL(tile);
REGISTER_OCL(gather_tree);
REGISTER_OCL(resample);
//REGISTER_OCL(resample);
REGISTER_OCL(grn);
REGISTER_OCL(ctc_greedy_decoder);
REGISTER_OCL(ctc_loss);
Expand Down
2 changes: 1 addition & 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,7 @@
#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/resample.hpp"
#include "intel_gpu/primitives/reshape.hpp"
#include "intel_gpu/primitives/reverse_sequence.hpp"
#include "intel_gpu/primitives/rms.hpp"
Expand Down
74 changes: 40 additions & 34 deletions src/plugins/intel_gpu/src/graph/impls/ocl/resample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "primitive_base.hpp"

#include "resample.hpp"
#include "resample_inst.h"
#include "kernel_selector/kernels/resample/resample_kernel_selector.h"
#include "kernel_selector/kernels/resample/resample_kernel_base.h"
Expand Down Expand Up @@ -174,42 +175,47 @@ 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 {

// 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);
}

} // namespace detail
} // namespace ocl
} // namespace cldnn

Expand Down
33 changes: 33 additions & 0 deletions src/plugins/intel_gpu/src/graph/impls/ocl/resample.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

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

#include <memory>
namespace cldnn {
namespace ocl {

struct ResampleImplementationManager : public ImplementationManager {
OV_GPU_PRIMITIVE_IMPL("ocl::resample")
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;
}
};

} // namespace ocl
} // namespace cldnn
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/graph/impls/registry/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ REGISTER_IMPLS(reshape);
REGISTER_IMPLS(non_max_suppression);
REGISTER_IMPLS(softmax);
REGISTER_IMPLS(range);
//REGISTER_IMPLS(resample);
REGISTER_IMPLS(resample);
REGISTER_IMPLS(select);
REGISTER_IMPLS(scatter_update);
REGISTER_IMPLS(scatter_elements_update);
Expand Down Expand Up @@ -201,7 +201,7 @@ 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(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
55 changes: 55 additions & 0 deletions src/plugins/intel_gpu/src/graph/impls/registry/resample_impls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (C) 2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include "predicates.hpp"
#include "registry.hpp"
#include "intel_gpu/primitives/resample.hpp"
#include "primitive_inst.h"

#if OV_GPU_WITH_OCL
#include "impls/ocl/resample.hpp"
#endif


namespace ov {
namespace intel_gpu {

using namespace cldnn;

const std::vector<std::shared_ptr<cldnn::ImplementationManager>>& Registry<resample>::get_implementations() {
static const std::vector<std::shared_ptr<ImplementationManager>> impls = {
OV_GPU_CREATE_INSTANCE_OCL(ocl::ResampleImplementationManager, shape_types::static_shape,
[](const cldnn::program_node& node){
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;
})
// 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;
}

} // namespace intel_gpu
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,14 @@ const std::vector<ShapeParams> shapeParams4D_LargeShape = {
{{1.f, 1.f, 2.f, 2.f}},
defaultAxes4D.front()
},
// ShapeParams{
// ov::op::v4::Interpolate::ShapeCalcMode::SIZES,
// InputShape{{-1, -1, -1, -1}, {{1, 3, 48, 48}}},
// ov::test::utils::InputLayerType::CONSTANT,
// ov::test::utils::InputLayerType::CONSTANT,
// {{1, 3, 144, 144}},
// defaultAxes4D.front()
// },
ShapeParams{
ov::op::v4::Interpolate::ShapeCalcMode::SIZES,
InputShape{{-1, -1, -1, -1}, {{1, 3, 48, 48}}},
ov::test::utils::InputLayerType::CONSTANT,
ov::test::utils::InputLayerType::CONSTANT,
{{1, 3, 144, 144}},
defaultAxes4D.front()
},
};

const auto interpolateCasesLinearOnnx_AlignCorners_Floor = ::testing::Combine(
Expand Down

0 comments on commit 0f00606

Please sign in to comment.