diff options
-rw-r--r-- | tests/AssetsLibrary.h | 8 | ||||
-rw-r--r-- | tests/RawTensor.cpp | 140 | ||||
-rw-r--r-- | tests/RawTensor.h | 90 | ||||
-rw-r--r-- | tests/SimpleTensor.h (renamed from tests/validation_new/SimpleTensor.h) | 7 | ||||
-rw-r--r-- | tests/validation/Validation.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/ActivationLayer.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/BitwiseAnd.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/BitwiseNot.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/BitwiseOr.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/BitwiseXor.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/ConvolutionLayer.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/DepthConcatenateLayer.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/Floor.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/GEMM.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/L2Normalize.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/NormalizationLayer.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/ReductionOperation.h | 2 | ||||
-rw-r--r-- | tests/validation_new/CPP/SoftmaxLayer.h | 2 |
18 files changed, 40 insertions, 233 deletions
diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index 18ffd773c8..2993662dc7 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -427,8 +427,8 @@ void AssetsLibrary::fill(T &&tensor, const std::string &name, Format format) con { const Coordinates id = index2coord(raw.shape(), offset / raw.element_size()); - const RawTensor::BufferType *const raw_ptr = raw.data() + offset; - const auto out_ptr = static_cast<RawTensor::BufferType *>(tensor(id)); + const RawTensor::value_type *const raw_ptr = raw.data() + offset; + const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id)); std::copy_n(raw_ptr, raw.element_size(), out_ptr); } } @@ -448,8 +448,8 @@ void AssetsLibrary::fill(T &&tensor, const std::string &name, Format format, Cha { const Coordinates id = index2coord(raw.shape(), offset / raw.element_size()); - const RawTensor::BufferType *const raw_ptr = raw.data() + offset; - const auto out_ptr = static_cast<RawTensor::BufferType *>(tensor(id)); + const RawTensor::value_type *const raw_ptr = raw.data() + offset; + const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id)); std::copy_n(raw_ptr, raw.element_size(), out_ptr); } } diff --git a/tests/RawTensor.cpp b/tests/RawTensor.cpp index e6b320fcb2..bc2747d2a1 100644 --- a/tests/RawTensor.cpp +++ b/tests/RawTensor.cpp @@ -23,48 +23,28 @@ */ #include "RawTensor.h" -#include "Utils.h" - -#include "arm_compute/core/Utils.h" -#include "support/ToolchainSupport.h" - -#include <algorithm> -#include <array> -#include <functional> -#include <stdexcept> -#include <utility> - namespace arm_compute { namespace test { RawTensor::RawTensor(TensorShape shape, Format format, int fixed_point_position) - : _buffer(nullptr), - _shape(shape), - _format(format), - _fixed_point_position(fixed_point_position) + : SimpleTensor(shape, format, fixed_point_position) { - _buffer = support::cpp14::make_unique<BufferType[]>(size()); + _buffer = support::cpp14::make_unique<uint8_t[]>(SimpleTensor::num_elements() * SimpleTensor::num_channels() * SimpleTensor::element_size()); } RawTensor::RawTensor(TensorShape shape, DataType data_type, int num_channels, int fixed_point_position) - : _buffer(nullptr), - _shape(shape), - _data_type(data_type), - _num_channels(num_channels), - _fixed_point_position(fixed_point_position) + : SimpleTensor(shape, data_type, num_channels, fixed_point_position) { - _buffer = support::cpp14::make_unique<BufferType[]>(size()); + _buffer = support::cpp14::make_unique<uint8_t[]>(SimpleTensor::num_elements() * SimpleTensor::num_channels() * SimpleTensor::element_size()); } RawTensor::RawTensor(const RawTensor &tensor) - : _buffer(nullptr), - _shape(tensor.shape()), - _format(tensor.format()), - _fixed_point_position(tensor.fixed_point_position()) + : SimpleTensor(tensor.shape(), tensor.data_type(), tensor.num_channels(), tensor.fixed_point_position()) { - _buffer = support::cpp14::make_unique<BufferType[]>(tensor.size()); - std::copy(tensor.data(), tensor.data() + size(), _buffer.get()); + _format = tensor.format(); + _buffer = support::cpp14::make_unique<uint8_t[]>(num_elements() * num_channels() * element_size()); + std::copy_n(tensor.data(), num_elements() * num_channels() * element_size(), _buffer.get()); } RawTensor &RawTensor::operator=(RawTensor tensor) @@ -74,114 +54,14 @@ RawTensor &RawTensor::operator=(RawTensor tensor) return *this; } -RawTensor::BufferType &RawTensor::operator[](size_t offset) -{ - return _buffer[offset]; -} - -const RawTensor::BufferType &RawTensor::operator[](size_t offset) const -{ - return _buffer[offset]; -} - -TensorShape RawTensor::shape() const -{ - return _shape; -} - -size_t RawTensor::element_size() const -{ - return num_channels() * element_size_from_data_type(data_type()); -} - -int RawTensor::fixed_point_position() const -{ - return _fixed_point_position; -} - -size_t RawTensor::size() const -{ - const size_t size = std::accumulate(_shape.cbegin(), _shape.cend(), 1, std::multiplies<size_t>()); - return size * element_size(); -} - -Format RawTensor::format() const -{ - return _format; -} - -DataType RawTensor::data_type() const -{ - if(_format != Format::UNKNOWN) - { - return data_type_from_format(_format); - } - else - { - return _data_type; - } -} - -int RawTensor::num_channels() const -{ - switch(_format) - { - case Format::U8: - case Format::S16: - case Format::U16: - case Format::S32: - case Format::U32: - case Format::F32: - return 1; - case Format::RGB888: - return 3; - case Format::UNKNOWN: - return _num_channels; - default: - ARM_COMPUTE_ERROR("NOT SUPPORTED!"); - } -} - -int RawTensor::num_elements() const -{ - return _shape.total_size(); -} - -PaddingSize RawTensor::padding() const -{ - return PaddingSize(0); -} - -const RawTensor::BufferType *RawTensor::data() const -{ - return _buffer.get(); -} - -RawTensor::BufferType *RawTensor::data() -{ - return _buffer.get(); -} - -const RawTensor::BufferType *RawTensor::operator()(const Coordinates &coord) const +const void *RawTensor::operator()(const Coordinates &coord) const { return _buffer.get() + coord2index(_shape, coord) * element_size(); } -RawTensor::BufferType *RawTensor::operator()(const Coordinates &coord) +void *RawTensor::operator()(const Coordinates &coord) { return _buffer.get() + coord2index(_shape, coord) * element_size(); } - -void swap(RawTensor &tensor1, RawTensor &tensor2) -{ - // Use unqualified call to swap to enable ADL. But make std::swap available - // as backup. - using std::swap; - swap(tensor1._shape, tensor2._shape); - swap(tensor1._format, tensor2._format); - swap(tensor1._data_type, tensor2._data_type); - swap(tensor1._num_channels, tensor2._num_channels); - swap(tensor1._buffer, tensor2._buffer); -} } // namespace test } // namespace arm_compute diff --git a/tests/RawTensor.h b/tests/RawTensor.h index 9d65e4f319..f1a9af37c9 100644 --- a/tests/RawTensor.h +++ b/tests/RawTensor.h @@ -24,27 +24,18 @@ #ifndef __ARM_COMPUTE_TEST_RAW_TENSOR_H__ #define __ARM_COMPUTE_TEST_RAW_TENSOR_H__ -#include "arm_compute/core/TensorShape.h" -#include "arm_compute/core/Types.h" - -#include <cstddef> -#include <cstdint> -#include <memory> +#include "SimpleTensor.h" namespace arm_compute { namespace test { -/** Simple tensor object that stores elements in a consecutive chunk of memory. - * - * It can be created by either loading an image from a file which also - * initialises the content of the tensor or by explcitly specifying the size. - * The latter leaves the content uninitialised. +/** Subclass of SimpleTensor using uint8_t as value type. * - * Furthermore, the class provides methods to convert the tensor's values into - * different image format. + * Access operations (except for operator[]) will be based on the data type to + * copy the right number of elements. */ -class RawTensor final +class RawTensor : public SimpleTensor<uint8_t> { public: /** Create an uninitialised tensor of the given @p shape and @p format. @@ -70,69 +61,17 @@ public: */ RawTensor(const RawTensor &tensor); - /** Create a deep copy of the given @p tensor. - * - * @param[in] tensor To be copied tensor. - */ RawTensor &operator =(RawTensor tensor); RawTensor(RawTensor &&) = default; ~RawTensor() = default; - using BufferType = uint8_t; - using Buffer = std::unique_ptr<BufferType[]>; - - /** Return value at @p offset in the buffer. - * - * @param[in] offset Offset within the buffer. - */ - BufferType &operator[](size_t offset); - - /** Return constant value at @p offset in the buffer. - * - * @param[in] offset Offset within the buffer. - */ - const BufferType &operator[](size_t offset) const; - - /** Shape of the tensor. */ - TensorShape shape() const; - - /** Size of each element in the tensor in bytes. */ - size_t element_size() const; - - /** Total size of the tensor in bytes. */ - size_t size() const; - - /** Image format of the tensor. */ - Format format() const; - - /** Data type of the tensor. */ - DataType data_type() const; - - /** Number of channels of the tensor. */ - int num_channels() const; - - /** Number of elements of the tensor. */ - int num_elements() const; - - /** Available padding around the tensor. */ - PaddingSize padding() const; - - /** The number of bits for the fractional part of the fixed point numbers. */ - int fixed_point_position() const; - - /** Constant pointer to the underlying buffer. */ - const BufferType *data() const; - - /** Pointer to the underlying buffer. */ - BufferType *data(); - /** Read only access to the specified element. * * @param[in] coord Coordinates of the desired element. * * @return A pointer to the desired element. */ - const BufferType *operator()(const Coordinates &coord) const; + const void *operator()(const Coordinates &coord) const override; /** Access to the specified element. * @@ -140,22 +79,7 @@ public: * * @return A pointer to the desired element. */ - BufferType *operator()(const Coordinates &coord); - - /** Swaps the content of the provided tensors. - * - * @param[in, out] tensor1 Tensor to be swapped. - * @param[in, out] tensor2 Tensor to be swapped. - */ - friend void swap(RawTensor &tensor1, RawTensor &tensor2); - -private: - Buffer _buffer{ nullptr }; - TensorShape _shape{}; - Format _format{ Format::UNKNOWN }; - DataType _data_type{ DataType::UNKNOWN }; - int _num_channels{ 0 }; - int _fixed_point_position{ 0 }; + void *operator()(const Coordinates &coord) override; }; } // namespace test } // namespace arm_compute diff --git a/tests/validation_new/SimpleTensor.h b/tests/SimpleTensor.h index 61d6f1cd04..ea955fa730 100644 --- a/tests/validation_new/SimpleTensor.h +++ b/tests/SimpleTensor.h @@ -54,7 +54,7 @@ namespace test * different image format. */ template <typename T> -class SimpleTensor final : public IAccessor +class SimpleTensor : public IAccessor { public: /** Create an uninitialised tensor. */ @@ -163,7 +163,7 @@ public: template <typename U> friend void swap(SimpleTensor<U> &tensor1, SimpleTensor<U> &tensor2); -private: +protected: Buffer _buffer{ nullptr }; TensorShape _shape{}; Format _format{ Format::UNKNOWN }; @@ -198,6 +198,8 @@ SimpleTensor<T>::SimpleTensor(const SimpleTensor &tensor) : _buffer(nullptr), _shape(tensor.shape()), _format(tensor.format()), + _data_type(tensor.data_type()), + _num_channels(tensor.num_channels()), _fixed_point_position(tensor.fixed_point_position()) { _buffer = support::cpp14::make_unique<T[]>(tensor.num_elements() * num_channels()); @@ -278,6 +280,7 @@ int SimpleTensor<T>::num_channels() const case Format::U16: case Format::S32: case Format::U32: + case Format::F32: return 1; case Format::RGB888: return 3; diff --git a/tests/validation/Validation.h b/tests/validation/Validation.h index 993a3c360e..f95859d029 100644 --- a/tests/validation/Validation.h +++ b/tests/validation/Validation.h @@ -26,6 +26,7 @@ #include "arm_compute/core/Types.h" #include "arm_compute/runtime/Array.h" +#include "tests/RawTensor.h" #include "boost_wrapper.h" @@ -37,7 +38,6 @@ class Tensor; namespace test { -class RawTensor; class IAccessor; namespace validation diff --git a/tests/validation_new/CPP/ActivationLayer.h b/tests/validation_new/CPP/ActivationLayer.h index 5f4ef46827..3f10a2f360 100644 --- a/tests/validation_new/CPP/ActivationLayer.h +++ b/tests/validation_new/CPP/ActivationLayer.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_ACTIVATION_LAYER_H__ #define __ARM_COMPUTE_TEST_ACTIVATION_LAYER_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/BitwiseAnd.h b/tests/validation_new/CPP/BitwiseAnd.h index 07fda90590..eba2fd695f 100644 --- a/tests/validation_new/CPP/BitwiseAnd.h +++ b/tests/validation_new/CPP/BitwiseAnd.h @@ -24,7 +24,7 @@ #ifndef __ARM_COMPUTE_TEST_BITWISE_AND_H__ #define __ARM_COMPUTE_TEST_BITWISE_AND_H__ -#include "tests/validation_new/SimpleTensor.h" +#include "tests/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/BitwiseNot.h b/tests/validation_new/CPP/BitwiseNot.h index 36aa50d75c..b4206f9388 100644 --- a/tests/validation_new/CPP/BitwiseNot.h +++ b/tests/validation_new/CPP/BitwiseNot.h @@ -24,7 +24,7 @@ #ifndef __ARM_COMPUTE_TEST_BITWISE_NOT_H__ #define __ARM_COMPUTE_TEST_BITWISE_NOT_H__ -#include "tests/validation_new/SimpleTensor.h" +#include "tests/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/BitwiseOr.h b/tests/validation_new/CPP/BitwiseOr.h index 727551132a..39158cb411 100644 --- a/tests/validation_new/CPP/BitwiseOr.h +++ b/tests/validation_new/CPP/BitwiseOr.h @@ -24,7 +24,7 @@ #ifndef __ARM_COMPUTE_TEST_BITWISE_OR_H__ #define __ARM_COMPUTE_TEST_BITWISE_OR_H__ -#include "tests/validation_new/SimpleTensor.h" +#include "tests/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/BitwiseXor.h b/tests/validation_new/CPP/BitwiseXor.h index 45a2e0323b..3e7721e843 100644 --- a/tests/validation_new/CPP/BitwiseXor.h +++ b/tests/validation_new/CPP/BitwiseXor.h @@ -24,7 +24,7 @@ #ifndef __ARM_COMPUTE_TEST_BITWISE_XOR_H__ #define __ARM_COMPUTE_TEST_BITWISE_XOR_H__ -#include "tests/validation_new/SimpleTensor.h" +#include "tests/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/ConvolutionLayer.h b/tests/validation_new/CPP/ConvolutionLayer.h index fd46567910..a7c9e086a4 100644 --- a/tests/validation_new/CPP/ConvolutionLayer.h +++ b/tests/validation_new/CPP/ConvolutionLayer.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_CONVOLUTION_LAYER_H__ #define __ARM_COMPUTE_TEST_CONVOLUTION_LAYER_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/DepthConcatenateLayer.h b/tests/validation_new/CPP/DepthConcatenateLayer.h index b67eb555eb..3c486a8015 100644 --- a/tests/validation_new/CPP/DepthConcatenateLayer.h +++ b/tests/validation_new/CPP/DepthConcatenateLayer.h @@ -24,7 +24,7 @@ #ifndef __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ #define __ARM_COMPUTE_TEST_DEPTHCONCATENATE_LAYER_H__ -#include "tests/validation_new/SimpleTensor.h" +#include "tests/SimpleTensor.h" #include <vector> diff --git a/tests/validation_new/CPP/Floor.h b/tests/validation_new/CPP/Floor.h index 8a6c3bcff6..30b8118622 100644 --- a/tests/validation_new/CPP/Floor.h +++ b/tests/validation_new/CPP/Floor.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_FLOOR_H__ #define __ARM_COMPUTE_TEST_FLOOR_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/GEMM.h b/tests/validation_new/CPP/GEMM.h index ff79c7b546..7fea2a9862 100644 --- a/tests/validation_new/CPP/GEMM.h +++ b/tests/validation_new/CPP/GEMM.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_GEMM_H__ #define __ARM_COMPUTE_TEST_GEMM_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/L2Normalize.h b/tests/validation_new/CPP/L2Normalize.h index 3e81b9a644..da36a73bba 100644 --- a/tests/validation_new/CPP/L2Normalize.h +++ b/tests/validation_new/CPP/L2Normalize.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_L2NORMALIZE_H__ #define __ARM_COMPUTE_TEST_L2NORMALIZE_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/NormalizationLayer.h b/tests/validation_new/CPP/NormalizationLayer.h index 54284b1d50..bdd87545ca 100644 --- a/tests/validation_new/CPP/NormalizationLayer.h +++ b/tests/validation_new/CPP/NormalizationLayer.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_NORMALIZATION_LAYER_H__ #define __ARM_COMPUTE_TEST_NORMALIZATION_LAYER_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/ReductionOperation.h b/tests/validation_new/CPP/ReductionOperation.h index 43a700d80a..500a8162fd 100644 --- a/tests/validation_new/CPP/ReductionOperation.h +++ b/tests/validation_new/CPP/ReductionOperation.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_REDUCTION_OPERATION_H__ #define __ARM_COMPUTE_TEST_REDUCTION_OPERATION_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { diff --git a/tests/validation_new/CPP/SoftmaxLayer.h b/tests/validation_new/CPP/SoftmaxLayer.h index 28a532ee96..cc52f3cf51 100644 --- a/tests/validation_new/CPP/SoftmaxLayer.h +++ b/tests/validation_new/CPP/SoftmaxLayer.h @@ -24,8 +24,8 @@ #ifndef __ARM_COMPUTE_TEST_SOFTMAX_LAYER_H__ #define __ARM_COMPUTE_TEST_SOFTMAX_LAYER_H__ +#include "tests/SimpleTensor.h" #include "tests/validation_new/Helpers.h" -#include "tests/validation_new/SimpleTensor.h" namespace arm_compute { |