diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.cpp b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.cpp index 41c75c0ecc3423..8b038009762bbb 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.cpp +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.cpp @@ -218,7 +218,7 @@ struct jit_uni_roi_pooling_kernel_f32 : public jit_uni_roi_pooling_kernel, publi for (int i = 0; i < c_blocks; i++) { int src_c_off = i * jpp_.ih * jpp_.iw * jpp_.c_block * jpp_.src_data_size; - auto load_context = std::make_shared(jpp_.src_prc, Precision::FP32, step, false, "zero", src_c_off); + const auto load_context = std::make_shared(jpp_.src_prc, Precision::FP32, step, false, "zero", src_c_off); mov(aux_reg_input, reg_input); @@ -555,7 +555,7 @@ void MKLDNNROIPoolingNode::execute() { } else { for (int h = hstart; h < hend; ++h) { for (int w = wstart; w < wend; ++w) { - T batch_data = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + + float batch_data = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + h * src_strides[2] + w * src_strides[3] + c]; if (batch_data > dst[pool_index]) { @@ -567,17 +567,17 @@ void MKLDNNROIPoolingNode::execute() { } } } else { - T roi_start_w_ = src_roi_ptr[1]; - T roi_start_h_ = src_roi_ptr[2]; - T roi_end_w_ = src_roi_ptr[3]; - T roi_end_h_ = src_roi_ptr[4]; + float roi_start_w_ = src_roi_ptr[1]; + float roi_start_h_ = src_roi_ptr[2]; + float roi_end_w_ = src_roi_ptr[3]; + float roi_end_h_ = src_roi_ptr[4]; - T height_scale = (jpp.pooled_h > 1 ? ((roi_end_h_ - roi_start_h_) * (jpp.ih - 1)) / (jpp.pooled_h - 1) : 0); - T width_scale = (jpp.pooled_w > 1 ? ((roi_end_w_ - roi_start_w_) * (jpp.iw - 1)) / (jpp.pooled_w - 1) : 0); + float height_scale = (jpp.pooled_h > 1 ? ((roi_end_h_ - roi_start_h_) * (jpp.ih - 1)) / (jpp.pooled_h - 1) : 0); + float width_scale = (jpp.pooled_w > 1 ? ((roi_end_w_ - roi_start_w_) * (jpp.iw - 1)) / (jpp.pooled_w - 1) : 0); - T in_y = (jpp.pooled_h > 1 ? (oh * height_scale + roi_start_h_ * (jpp.ih - 1)) : + float in_y = (jpp.pooled_h > 1 ? (oh * height_scale + roi_start_h_ * (jpp.ih - 1)) : 0.5 * (roi_start_h_ + roi_end_h_) * (jpp.ih - 1)); - T in_x = (jpp.pooled_w > 1 ? (ow * width_scale + roi_start_w_ * (jpp.iw - 1)) : + float in_x = (jpp.pooled_w > 1 ? (ow * width_scale + roi_start_w_ * (jpp.iw - 1)) : 0.5 * (roi_start_w_ + roi_end_w_) * (jpp.iw - 1)); if (in_y < 0 || in_y > jpp.ih - 1 || in_x < 0 || in_x > jpp.iw - 1) { @@ -616,20 +616,20 @@ void MKLDNNROIPoolingNode::execute() { arg.bin_area = 1; } else { for (int c = 0; c < 1; c++) { - const T top_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + + const float top_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + top_y_index * src_strides[2] + left_x_index * src_strides[3] + c]; - const T top_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + + const float top_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + top_y_index * src_strides[2] + right_x_index * src_strides[3] + c]; - const T bottom_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + + const float bottom_left = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + bottom_y_index * src_strides[2] + left_x_index * src_strides[3] + c]; - const T bottom_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + + const float bottom_right = src_data[roi_batch_ind * src_strides[0] + cb * src_strides[1] + bottom_y_index * src_strides[2] + right_x_index * src_strides[3] + c]; - const T top = top_left + (top_right - top_left) * (in_x - left_x_index); - const T bottom = bottom_left + (bottom_right - bottom_left) * (in_x - left_x_index); + const float top = top_left + (top_right - top_left) * (in_x - left_x_index); + const float bottom = bottom_left + (bottom_right - bottom_left) * (in_x - left_x_index); dst[n * dst_strides[0] + cb * dst_strides[1] + oh * dst_strides[2] + ow * dst_strides[3] + c] = - top + (bottom - top) * (in_y - top_y_index); + top + (bottom - top) * (in_y - top_y_index); } } } @@ -650,8 +650,6 @@ struct ROIPoolingContext { template struct MKLDNNROIPoolingNode::ROIPoolingExecute { - // using dataT = typename T::type; - void operator()(ROIPoolingContext & ctx) { ctx.node.execute(); } diff --git a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.h b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.h index 5be21ce6b851d1..9ff53c3747dc49 100644 --- a/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.h +++ b/inference-engine/src/mkldnn_plugin/nodes/mkldnn_roi_pooling_node.h @@ -78,22 +78,22 @@ class MKLDNNROIPoolingNode : public MKLDNNNode { void createPrimitive() override; void execute(mkldnn::stream strm) override; bool created() const override; + +private: template void execute(); template struct ROIPoolingExecute; -private: + InferenceEngine::Precision runtimePrecision; + size_t src_data_size; size_t dst_data_size; - InferenceEngine::Precision runtimePrecision; - int pooled_h = 0; int pooled_w = 0; float spatial_scale = 0; ROIPoolingOpType opType = Max; jit_roi_pooling_params jpp = {}; - std::shared_ptr roi_pooling_kernel = nullptr; }; diff --git a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/roi_pooling.cpp b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/roi_pooling.cpp index 3eda478b871faf..c8f90290f998e0 100644 --- a/inference-engine/tests/functional/plugin/cpu/single_layer_tests/roi_pooling.cpp +++ b/inference-engine/tests/functional/plugin/cpu/single_layer_tests/roi_pooling.cpp @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 // #include +#include "ie_common.h" #include "test_utils/cpu_test_utils.hpp" +#include "utils/bfloat16.hpp" using namespace InferenceEngine; using namespace CPUTestUtils; @@ -67,7 +69,21 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterfacegetTensorDesc()); blob->allocate(); - CommonTestUtils::fill_data_roi(blob->buffer(), blob->size(), feat_map_shape[0] - 1, height, width, 1.0f, is_roi_max_mode); + switch (inPrc) { + case Precision::FP32: { + CommonTestUtils::fill_data_roi + (blob->buffer(), blob->size(), feat_map_shape[0] - 1, height, width, 1.0f, is_roi_max_mode); + break; + } + case Precision::BF16: { + CommonTestUtils::fill_data_roi + (blob->buffer(), blob->size(), feat_map_shape[0] - 1, height, width, 1.0f, is_roi_max_mode); + break; + } + default: + IE_THROW() << "roi_pooling. Unsupported precision"; + break; + } } else { blob = GenerateInput(*info); } @@ -86,8 +102,6 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterfaceGetParam(); std::tie(inFmts, outFmts, priority, selectedType) = cpuParams; std::tie(inputShape, coordsShape, poolShape, spatial_scale, pool_method, netPrecision, targetDevice) = basicParamsSet; @@ -106,7 +120,8 @@ class ROIPoolingCPULayerTest : public testing::WithParamInterface filterCPUInfoForDevice() { return resCPUParams; } -const std::vector> inShapes = {{1, 3, 8, 8}, {3, 4, 50, 50}}; +const std::vector> inShapes = {{1, 3, 8, 8}, + {3, 4, 50, 50}}; -const std::vector> pooledShapes_max = {{1, 1}, {2, 2}, {3, 3}, {6, 6}}; +const std::vector> pooledShapes_max = {{1, 1}, + {2, 2}, + {3, 3}, + {6, 6}}; -const std::vector> pooledShapes_bilinear = {{1, 1}, {2, 2}, {3, 3}, {6, 6}}; +const std::vector> pooledShapes_bilinear = {{1, 1}, + {2, 2}, + {3, 3}, + {6, 6}}; -const std::vector> coordShapes = {{1, 5}}; - // {3, 5}, - // {5, 5}}; +const std::vector> coordShapes = {{1, 5}, + {3, 5}, + {5, 5}}; -const std::vector netPRCs = {InferenceEngine::Precision::BF16, InferenceEngine::Precision::FP32}; +const std::vector netPRCs = {InferenceEngine::Precision::FP32, InferenceEngine::Precision::BF16}; const std::vector spatial_scales = {0.625f, 1.f}; diff --git a/inference-engine/tests/functional/shared_test_classes/src/read_ir/generate_inputs.cpp b/inference-engine/tests/functional/shared_test_classes/src/read_ir/generate_inputs.cpp index c4fc81dd7b7b12..dfe3b0b62cf715 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/read_ir/generate_inputs.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/read_ir/generate_inputs.cpp @@ -273,13 +273,13 @@ InferenceEngine::Blob::Ptr generate(const std::shared_ptrallocate(); - CommonTestUtils::fill_data_roi(blob->buffer(), - blob->size(), - node->get_input_shape(0).front() - 1, - inputShape[2], - inputShape[3], - 1.0f, - node->get_method() == "max"); + CommonTestUtils::fill_data_roi(blob->buffer(), + blob->size(), + node->get_input_shape(0).front() - 1, + inputShape[2], + inputShape[3], + 1.0f, + node->get_method() == "max"); return blob; } return FuncTestUtils::createAndFillBlob(info.getTensorDesc()); @@ -582,4 +582,4 @@ InputsMap getInputMap() { return inputsMap; } -} // namespace LayerTestsDefinitions \ No newline at end of file +} // namespace LayerTestsDefinitions diff --git a/inference-engine/tests/functional/shared_test_classes/src/single_layer/roi_pooling.cpp b/inference-engine/tests/functional/shared_test_classes/src/single_layer/roi_pooling.cpp index f8d3ba8569306d..c4e4ec2245670f 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/single_layer/roi_pooling.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/single_layer/roi_pooling.cpp @@ -51,8 +51,8 @@ namespace LayerTestsDefinitions { if (it == 1) { blob = make_blob_with_precision(info->getTensorDesc()); blob->allocate(); - CommonTestUtils::fill_data_roi(blob->buffer(), blob->size(), feat_map_shape[0] - 1, - height, width, 1.0f, is_roi_max_mode); + CommonTestUtils::fill_data_roi(blob->buffer(), blob->size(), feat_map_shape[0] - 1, + height, width, 1.0f, is_roi_max_mode); } else { blob = GenerateInput(*info); } diff --git a/inference-engine/tests/ie_test_utils/common_test_utils/data_utils.hpp b/inference-engine/tests/ie_test_utils/common_test_utils/data_utils.hpp index 50e2eb37e99fc2..3c6762cf64fe83 100644 --- a/inference-engine/tests/ie_test_utils/common_test_utils/data_utils.hpp +++ b/inference-engine/tests/ie_test_utils/common_test_utils/data_utils.hpp @@ -139,8 +139,9 @@ inline void fill_data_bbox(float *data, size_t size, int height, int width, floa } } +template inline void -fill_data_roi(float *data, size_t size, const uint32_t range, const int height, const int width, const float omega, +fill_data_roi(T *data, size_t size, const uint32_t range, const int height, const int width, const float omega, const bool is_roi_max_mode, const int seed = 1) { std::default_random_engine random(seed); std::uniform_int_distribution distribution(0, range);