aboutsummaryrefslogtreecommitdiff
path: root/tests/PaddingCalculator.h
diff options
context:
space:
mode:
authorMoritz Pflanzer <moritz.pflanzer@arm.com>2017-06-21 15:54:07 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-09-17 13:03:43 +0100
commit5b51229fad2fcf639051abb6eabfffe98eaadd06 (patch)
treeedea3bbc56e91a7a4569d7ab50df1e8414ac136e /tests/PaddingCalculator.h
parent9746fd824efe1d1d9933c59376e81dcf9c7a0eca (diff)
downloadComputeLibrary-5b51229fad2fcf639051abb6eabfffe98eaadd06.tar.gz
COMPMID-250: Add PaddingCalculator class
Change-Id: I0e3771f82eaf6a578f19e2602d7dcf1cb6210a2b Reviewed-on: http://mpd-gerrit.cambridge.arm.com/78426 Reviewed-by: SiCong Li <sicong.li@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com>
Diffstat (limited to 'tests/PaddingCalculator.h')
-rw-r--r--tests/PaddingCalculator.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/PaddingCalculator.h b/tests/PaddingCalculator.h
new file mode 100644
index 0000000000..029312b73b
--- /dev/null
+++ b/tests/PaddingCalculator.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2017 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_TEST_PADDING_CALCULATOR_H__
+#define __ARM_COMPUTE_TEST_PADDING_CALCULATOR_H__
+
+#include "arm_compute/core/Types.h"
+
+namespace arm_compute
+{
+namespace test
+{
+/** Calculate required padding. */
+class PaddingCalculator final
+{
+public:
+ /** Construct calculator with size of tensor's dimension and step size.
+ *
+ * @param[in] size Number of elements available.
+ * @param[in] processed_elements Number of elements processed per iteration.
+ */
+ PaddingCalculator(int size, int processed_elements)
+ : _size{ size }, _num_processed_elements{ processed_elements }, _num_accessed_elements{ processed_elements }
+ {
+ }
+
+ /** Set border mode.
+ *
+ * @param[in] mode Border mode.
+ */
+ void set_border_mode(BorderMode mode);
+
+ /** Set border size.
+ *
+ * @param[in] size Border size in elements.
+ */
+ void set_border_size(int size);
+
+ /** Set offset of the access relative to the current position.
+ *
+ * @param[in] offset Offset of the access.
+ */
+ void set_access_offset(int offset);
+
+ /** Set number of accessed elements.
+ *
+ * @param[in] elements Number of accessed elements per iteration.
+ */
+ void set_accessed_elements(int elements);
+
+ /** Compute the required padding.
+ *
+ * @return Required padding in number of elements.
+ */
+ int required_padding() const;
+
+private:
+ int _size;
+ int _num_processed_elements;
+ int _num_accessed_elements;
+ BorderMode _mode{ BorderMode::UNDEFINED };
+ int _border_size{ 0 };
+ int _offset{ 0 };
+};
+
+inline void PaddingCalculator::set_border_mode(BorderMode mode)
+{
+ _mode = mode;
+}
+
+inline void PaddingCalculator::set_border_size(int size)
+{
+ _border_size = size;
+}
+
+inline void PaddingCalculator::set_access_offset(int offset)
+{
+ _offset = offset;
+}
+
+inline void PaddingCalculator::set_accessed_elements(int elements)
+{
+ _num_accessed_elements = elements;
+}
+
+inline int PaddingCalculator::required_padding() const
+{
+ if(_mode == BorderMode::UNDEFINED)
+ {
+ return (((_size - _border_size + _num_processed_elements - 1) / _num_processed_elements) - 1) * _num_processed_elements + _num_accessed_elements - _size + _border_size + _offset;
+ }
+ else
+ {
+ return (((_size + _num_processed_elements - 1) / _num_processed_elements) - 1) * _num_processed_elements + _num_accessed_elements - _size + _offset;
+ }
+}
+} // namespace test
+} // namespace arm_compute
+#endif