aboutsummaryrefslogtreecommitdiff
path: root/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp')
-rw-r--r--src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp103
1 files changed, 85 insertions, 18 deletions
diff --git a/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp b/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp
index 4a585b70fd..ba5ca78955 100644
--- a/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp
+++ b/src/core/NEON/kernels/NEGenerateProposalsLayerKernel.cpp
@@ -30,6 +30,8 @@
#include "arm_compute/core/Utils.h"
#include "arm_compute/core/Window.h"
+#include <arm_neon.h>
+
namespace arm_compute
{
namespace
@@ -39,7 +41,7 @@ Status validate_arguments(const ITensorInfo *anchors, const ITensorInfo *all_anc
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(anchors, all_anchors);
ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(anchors);
ARM_COMPUTE_RETURN_ERROR_ON(anchors->dimension(0) != info.values_per_roi());
- ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(anchors, DataType::F16, DataType::F32);
+ ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(anchors, DataType::QSYMM16, DataType::F16, DataType::F32);
ARM_COMPUTE_RETURN_ERROR_ON(anchors->num_dimensions() > 2);
if(all_anchors->total_size() > 0)
{
@@ -50,6 +52,11 @@ Status validate_arguments(const ITensorInfo *anchors, const ITensorInfo *all_anc
ARM_COMPUTE_RETURN_ERROR_ON(all_anchors->num_dimensions() > 2);
ARM_COMPUTE_RETURN_ERROR_ON(all_anchors->dimension(0) != info.values_per_roi());
ARM_COMPUTE_RETURN_ERROR_ON(all_anchors->dimension(1) != feature_height * feature_width * num_anchors);
+
+ if(is_data_type_quantized(anchors->data_type()))
+ {
+ ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(anchors, all_anchors);
+ }
}
return Status{};
}
@@ -74,7 +81,7 @@ void NEComputeAllAnchorsKernel::configure(const ITensor *anchors, ITensor *all_a
// Initialize the output if empty
const TensorShape output_shape(info.values_per_roi(), width * height * num_anchors);
- auto_init_if_empty(*all_anchors->info(), output_shape, 1, data_type);
+ auto_init_if_empty(*all_anchors->info(), TensorInfo(output_shape, 1, data_type, anchors->info()->quantization_info()));
// Set instance variables
_anchors = anchors;
@@ -92,12 +99,9 @@ Status NEComputeAllAnchorsKernel::validate(const ITensorInfo *anchors, const ITe
return Status{};
}
-void NEComputeAllAnchorsKernel::run(const Window &window, const ThreadInfo &info)
+template <>
+void NEComputeAllAnchorsKernel::internal_run<int16_t>(const Window &window, const ThreadInfo &info)
{
- ARM_COMPUTE_UNUSED(info);
- ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
- ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
-
Iterator all_anchors_it(_all_anchors, window);
Iterator anchors_it(_all_anchors, window);
@@ -105,27 +109,90 @@ void NEComputeAllAnchorsKernel::run(const Window &window, const ThreadInfo &info
const float stride = 1.f / _anchors_info.spatial_scale();
const size_t feat_width = _anchors_info.feat_width();
+ const UniformQuantizationInfo qinfo = _anchors->info()->quantization_info().uniform();
+
execute_window_loop(window, [&](const Coordinates & id)
{
const size_t anchor_offset = id.y() % num_anchors;
- const auto out_anchor_ptr = reinterpret_cast<float *>(all_anchors_it.ptr());
- const auto anchor_ptr = reinterpret_cast<float *>(_anchors->ptr_to_element(Coordinates(0, anchor_offset)));
-
- *out_anchor_ptr = *anchor_ptr;
- *(1 + out_anchor_ptr) = *(1 + anchor_ptr);
- *(2 + out_anchor_ptr) = *(2 + anchor_ptr);
- *(3 + out_anchor_ptr) = *(3 + anchor_ptr);
+ const auto out_anchor_ptr = reinterpret_cast<int16_t *>(all_anchors_it.ptr());
+ const auto anchor_ptr = reinterpret_cast<int16_t *>(_anchors->ptr_to_element(Coordinates(0, anchor_offset)));
const size_t shift_idy = id.y() / num_anchors;
const float shiftx = (shift_idy % feat_width) * stride;
const float shifty = (shift_idy / feat_width) * stride;
- *out_anchor_ptr += shiftx;
- *(out_anchor_ptr + 1) += shifty;
- *(out_anchor_ptr + 2) += shiftx;
- *(out_anchor_ptr + 3) += shifty;
+ const float new_anchor_x1 = dequantize_qsymm16(*anchor_ptr, qinfo.scale) + shiftx;
+ const float new_anchor_y1 = dequantize_qsymm16(*(1 + anchor_ptr), qinfo.scale) + shifty;
+ const float new_anchor_x2 = dequantize_qsymm16(*(2 + anchor_ptr), qinfo.scale) + shiftx;
+ const float new_anchor_y2 = dequantize_qsymm16(*(3 + anchor_ptr), qinfo.scale) + shifty;
+
+ *out_anchor_ptr = quantize_qsymm16(new_anchor_x1, qinfo.scale);
+ *(out_anchor_ptr + 1) = quantize_qsymm16(new_anchor_y1, qinfo.scale);
+ *(out_anchor_ptr + 2) = quantize_qsymm16(new_anchor_x2, qinfo.scale);
+ *(out_anchor_ptr + 3) = quantize_qsymm16(new_anchor_y2, qinfo.scale);
+ },
+ all_anchors_it);
+}
+
+template <typename T>
+void NEComputeAllAnchorsKernel::internal_run(const Window &window, const ThreadInfo &info)
+{
+ Iterator all_anchors_it(_all_anchors, window);
+ Iterator anchors_it(_all_anchors, window);
+
+ const size_t num_anchors = _anchors->info()->dimension(1);
+ const T stride = 1.f / _anchors_info.spatial_scale();
+ const size_t feat_width = _anchors_info.feat_width();
+
+ execute_window_loop(window, [&](const Coordinates & id)
+ {
+ const size_t anchor_offset = id.y() % num_anchors;
+
+ const auto out_anchor_ptr = reinterpret_cast<T *>(all_anchors_it.ptr());
+ const auto anchor_ptr = reinterpret_cast<T *>(_anchors->ptr_to_element(Coordinates(0, anchor_offset)));
+
+ const size_t shift_idy = id.y() / num_anchors;
+ const T shiftx = (shift_idy % feat_width) * stride;
+ const T shifty = (shift_idy / feat_width) * stride;
+
+ *out_anchor_ptr = *anchor_ptr + shiftx;
+ *(out_anchor_ptr + 1) = *(1 + anchor_ptr) + shifty;
+ *(out_anchor_ptr + 2) = *(2 + anchor_ptr) + shiftx;
+ *(out_anchor_ptr + 3) = *(3 + anchor_ptr) + shifty;
},
all_anchors_it);
}
+
+void NEComputeAllAnchorsKernel::run(const Window &window, const ThreadInfo &info)
+{
+ ARM_COMPUTE_UNUSED(info);
+ ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
+ ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
+
+ switch(_anchors->info()->data_type())
+ {
+ case DataType::QSYMM16:
+ {
+ internal_run<int16_t>(window, info);
+ break;
+ }
+#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+ case DataType::F16:
+ {
+ internal_run<float16_t>(window, info);
+ break;
+ }
+#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
+ case DataType::F32:
+ {
+ internal_run<float>(window, info);
+ break;
+ }
+ default:
+ {
+ ARM_COMPUTE_ERROR("Data type not supported");
+ }
+ }
+}
} // namespace arm_compute