diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/validation/CL/UNIT/DynamicTensor.cpp | 31 | ||||
-rw-r--r-- | tests/validation/GLES_COMPUTE/UNIT/DynamicTensor.cpp | 3 | ||||
-rw-r--r-- | tests/validation/NEON/UNIT/DynamicTensor.cpp | 35 | ||||
-rw-r--r-- | tests/validation/fixtures/UNIT/DynamicTensorFixture.h | 157 |
4 files changed, 211 insertions, 15 deletions
diff --git a/tests/validation/CL/UNIT/DynamicTensor.cpp b/tests/validation/CL/UNIT/DynamicTensor.cpp index 38acbd5c3a..06670478b2 100644 --- a/tests/validation/CL/UNIT/DynamicTensor.cpp +++ b/tests/validation/CL/UNIT/DynamicTensor.cpp @@ -23,6 +23,7 @@ */ #include "arm_compute/runtime/BlobLifetimeManager.h" #include "arm_compute/runtime/CL/CLBufferAllocator.h" +#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h" #include "arm_compute/runtime/CL/functions/CLL2NormalizeLayer.h" #include "arm_compute/runtime/MemoryGroup.h" #include "arm_compute/runtime/MemoryManagerOnDemand.h" @@ -35,6 +36,7 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" #include "tests/validation/fixtures/UNIT/DynamicTensorFixture.h" namespace arm_compute @@ -45,6 +47,10 @@ namespace validation { namespace { +constexpr AbsoluteTolerance<float> absolute_tolerance_float(0.0001f); /**< Absolute Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ +RelativeTolerance<float> tolerance_f32(0.1f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ +constexpr float tolerance_num = 0.07f; /**< Tolerance number */ + using CLL2NormLayerWrapper = SimpleFunctionWrapper<MemoryManagerOnDemand, CLL2NormalizeLayer, ICLTensor>; template <> void CLL2NormLayerWrapper::configure(ICLTensor *src, ICLTensor *dst) @@ -56,7 +62,8 @@ TEST_SUITE(CL) TEST_SUITE(UNIT) TEST_SUITE(DynamicTensor) -using CLDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<CLTensor, CLAccessor, CLBufferAllocator, BlobLifetimeManager, PoolManager, MemoryManagerOnDemand, CLL2NormLayerWrapper>; +using BlobMemoryManagementService = MemoryManagementService<CLBufferAllocator, BlobLifetimeManager, PoolManager, MemoryManagerOnDemand>; +using CLDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<CLTensor, CLAccessor, BlobMemoryManagementService, CLL2NormLayerWrapper>; /** Tests the memory manager with dynamic input and output tensors. * @@ -97,6 +104,28 @@ FIXTURE_DATA_TEST_CASE(DynamicTensorType3Single, CLDynamicTensorType3SingleFunct } } +using CLDynamicTensorType3ComplexFunction = DynamicTensorType3ComplexFunction<CLTensor, CLAccessor, BlobMemoryManagementService, CLConvolutionLayer>; +/** Tests the memory manager with dynamic input and output tensors. + * + * Create and manage the tensors needed to run a complex function. After the function is executed, + * change the input and output size requesting more memory and go through the manage/allocate process. + * The memory manager should be able to update the inner structures and allocate the requested memory + * */ +FIXTURE_DATA_TEST_CASE(DynamicTensorType3Complex, CLDynamicTensorType3ComplexFunction, framework::DatasetMode::ALL, + framework::dataset::zip(framework::dataset::zip(framework::dataset::zip(framework::dataset::zip( + framework::dataset::make("InputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 16U), TensorShape(64U, 64U, 16U) } }), + framework::dataset::make("WeightsManager", { TensorShape(3U, 3U, 16U, 5U) })), + framework::dataset::make("BiasShape", { TensorShape(5U) })), + framework::dataset::make("OutputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 5U), TensorShape(64U, 64U, 5U) } })), + framework::dataset::make("PadStrideInfo", { PadStrideInfo(1U, 1U, 1U, 1U) }))) +{ + for(unsigned int i = 0; i < num_iterations; ++i) + { + run_iteration(i); + validate(CLAccessor(dst_target), dst_ref, tolerance_f32, tolerance_num, absolute_tolerance_float); + } +} + TEST_SUITE_END() // DynamicTensor TEST_SUITE_END() // UNIT TEST_SUITE_END() // CL diff --git a/tests/validation/GLES_COMPUTE/UNIT/DynamicTensor.cpp b/tests/validation/GLES_COMPUTE/UNIT/DynamicTensor.cpp index 2b972843b8..cab854424e 100644 --- a/tests/validation/GLES_COMPUTE/UNIT/DynamicTensor.cpp +++ b/tests/validation/GLES_COMPUTE/UNIT/DynamicTensor.cpp @@ -56,7 +56,8 @@ TEST_SUITE(GC) TEST_SUITE(UNIT) TEST_SUITE(DynamicTensor) -using GCDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<GCTensor, GCAccessor, GCBufferAllocator, BlobLifetimeManager, PoolManager, MemoryManagerOnDemand, GCNormLayerWrapper>; +using BlobMemoryManagementService = MemoryManagementService<GCBufferAllocator, BlobLifetimeManager, PoolManager, MemoryManagerOnDemand>; +using GCDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<GCTensor, GCAccessor, BlobMemoryManagementService, GCNormLayerWrapper>; /** Tests the memory manager with dynamic input and output tensors. * diff --git a/tests/validation/NEON/UNIT/DynamicTensor.cpp b/tests/validation/NEON/UNIT/DynamicTensor.cpp index 319aa6a8ee..dde67b06a6 100644 --- a/tests/validation/NEON/UNIT/DynamicTensor.cpp +++ b/tests/validation/NEON/UNIT/DynamicTensor.cpp @@ -22,19 +22,18 @@ * SOFTWARE. */ #include "arm_compute/runtime/Allocator.h" -#include "arm_compute/runtime/MemoryGroup.h" #include "arm_compute/runtime/MemoryManagerOnDemand.h" +#include "arm_compute/runtime/NEON/functions/NEConvolutionLayer.h" #include "arm_compute/runtime/NEON/functions/NENormalizationLayer.h" #include "arm_compute/runtime/OffsetLifetimeManager.h" #include "arm_compute/runtime/PoolManager.h" #include "support/ToolchainSupport.h" #include "tests/AssetsLibrary.h" -#include "tests/Globals.h" #include "tests/NEON/Accessor.h" -#include "tests/Utils.h" #include "tests/framework/Asserts.h" #include "tests/framework/Macros.h" #include "tests/framework/datasets/Datasets.h" +#include "tests/validation/Validation.h" #include "tests/validation/fixtures/UNIT/DynamicTensorFixture.h" namespace arm_compute @@ -45,6 +44,10 @@ namespace validation { namespace { +constexpr AbsoluteTolerance<float> absolute_tolerance_float(0.0001f); /**< Absolute Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ +RelativeTolerance<float> tolerance_f32(0.1f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ +constexpr float tolerance_num = 0.07f; /**< Tolerance number */ + using NENormLayerWrapper = SimpleFunctionWrapper<MemoryManagerOnDemand, NENormalizationLayer, ITensor>; template <> void NENormLayerWrapper::configure(arm_compute::ITensor *src, arm_compute::ITensor *dst) @@ -55,7 +58,9 @@ void NENormLayerWrapper::configure(arm_compute::ITensor *src, arm_compute::ITens TEST_SUITE(NEON) TEST_SUITE(UNIT) TEST_SUITE(DynamicTensor) -using NEDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<Tensor, Accessor, Allocator, OffsetLifetimeManager, PoolManager, MemoryManagerOnDemand, NENormLayerWrapper>; + +using OffsetMemoryManagementService = MemoryManagementService<Allocator, OffsetLifetimeManager, PoolManager, MemoryManagerOnDemand>; +using NEDynamicTensorType3SingleFunction = DynamicTensorType3SingleFunction<Tensor, Accessor, OffsetMemoryManagementService, NENormLayerWrapper>; /** Tests the memory manager with dynamic input and output tensors. * @@ -79,6 +84,28 @@ FIXTURE_DATA_TEST_CASE(DynamicTensorType3Single, NEDynamicTensorType3SingleFunct } } +using NEDynamicTensorType3ComplexFunction = DynamicTensorType3ComplexFunction<Tensor, Accessor, OffsetMemoryManagementService, NEConvolutionLayer>; +/** Tests the memory manager with dynamic input and output tensors. + * + * Create and manage the tensors needed to run a complex function. After the function is executed, + * change the input and output size requesting more memory and go through the manage/allocate process. + * The memory manager should be able to update the inner structures and allocate the requested memory + * */ +FIXTURE_DATA_TEST_CASE(DynamicTensorType3Complex, NEDynamicTensorType3ComplexFunction, framework::DatasetMode::ALL, + framework::dataset::zip(framework::dataset::zip(framework::dataset::zip(framework::dataset::zip( + framework::dataset::make("InputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 6U), TensorShape(128U, 128U, 6U) } }), + framework::dataset::make("WeightsManager", { TensorShape(3U, 3U, 6U, 3U) })), + framework::dataset::make("BiasShape", { TensorShape(3U) })), + framework::dataset::make("OutputShape", { std::vector<TensorShape>{ TensorShape(12U, 12U, 3U), TensorShape(128U, 128U, 3U) } })), + framework::dataset::make("PadStrideInfo", { PadStrideInfo(1U, 1U, 1U, 1U) }))) +{ + for(unsigned int i = 0; i < num_iterations; ++i) + { + run_iteration(i); + validate(Accessor(dst_target), dst_ref, tolerance_f32, tolerance_num, absolute_tolerance_float); + } +} + TEST_SUITE_END() // DynamicTensor TEST_SUITE_END() // UNIT TEST_SUITE_END() // NEON diff --git a/tests/validation/fixtures/UNIT/DynamicTensorFixture.h b/tests/validation/fixtures/UNIT/DynamicTensorFixture.h index 66ef6c4aff..b2600f13f0 100644 --- a/tests/validation/fixtures/UNIT/DynamicTensorFixture.h +++ b/tests/validation/fixtures/UNIT/DynamicTensorFixture.h @@ -32,6 +32,7 @@ #include "tests/framework/Asserts.h" #include "tests/framework/Fixture.h" #include "tests/validation/Helpers.h" +#include "tests/validation/reference/ConvolutionLayer.h" #include "tests/validation/reference/NormalizationLayer.h" namespace arm_compute @@ -49,6 +50,9 @@ template <typename AllocatorType, struct MemoryManagementService { public: + using LftMgrType = LifetimeMgrType; + +public: MemoryManagementService() : allocator(), lifetime_mgr(nullptr), pool_mgr(nullptr), mm(nullptr), mg(), num_pools(0) { @@ -118,15 +122,11 @@ private: */ template <typename TensorType, typename AccessorType, - typename AllocatorType, - typename LifetimeMgrType, - typename PoolMgrType, - typename MemoryManagerType, + typename MemoryManagementServiceType, typename SimpleFunctionWrapperType> class DynamicTensorType3SingleFunction : public framework::Fixture { - using T = float; - using MemoryManagementServiceType = MemoryManagementService<AllocatorType, LifetimeMgrType, PoolMgrType, MemoryManagerType>; + using T = float; public: template <typename...> @@ -234,9 +234,148 @@ protected: } public: - TensorShape input_l0{}, input_l1{}; - typename LifetimeMgrType::info_type internal_l0{}, internal_l1{}; - typename LifetimeMgrType::info_type cross_l0{}, cross_l1{}; + TensorShape input_l0{}, input_l1{}; + typename MemoryManagementServiceType::LftMgrType::info_type internal_l0{}, internal_l1{}; + typename MemoryManagementServiceType::LftMgrType::info_type cross_l0{}, cross_l1{}; +}; + +/** Simple test case to run a single function with different shapes twice. + * + * Runs a specified function twice, where the second time the size of the input/output is different + * Internal memory of the function and input/output are managed by different services + */ +template <typename TensorType, + typename AccessorType, + typename MemoryManagementServiceType, + typename ComplexFunctionType> +class DynamicTensorType3ComplexFunction : public framework::Fixture +{ + using T = float; + +public: + template <typename...> + void setup(std::vector<TensorShape> input_shapes, TensorShape weights_shape, TensorShape bias_shape, std::vector<TensorShape> output_shapes, PadStrideInfo info) + { + num_iterations = input_shapes.size(); + _data_type = DataType::F32; + _data_layout = DataLayout::NHWC; + _input_shapes = input_shapes; + _output_shapes = output_shapes; + _weights_shape = weights_shape; + _bias_shape = bias_shape; + _info = info; + + // Create function + _f_target = support::cpp14::make_unique<ComplexFunctionType>(_ms.mm); + } + + void run_iteration(unsigned int idx) + { + auto input_shape = _input_shapes[idx]; + auto output_shape = _output_shapes[idx]; + + dst_ref = run_reference(input_shape, _weights_shape, _bias_shape, output_shape, _info); + dst_target = run_target(input_shape, _weights_shape, _bias_shape, output_shape, _info, WeightsInfo()); + } + +protected: + template <typename U> + void fill(U &&tensor, int i) + { + switch(tensor.data_type()) + { + case DataType::F32: + { + std::uniform_real_distribution<> distribution(-1.0f, 1.0f); + library->fill(tensor, distribution, i); + break; + } + default: + library->fill_tensor_uniform(tensor, i); + } + } + + TensorType run_target(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, + PadStrideInfo info, WeightsInfo weights_info) + { + if(_data_layout == DataLayout::NHWC) + { + permute(input_shape, PermutationVector(2U, 0U, 1U)); + permute(weights_shape, PermutationVector(2U, 0U, 1U)); + permute(output_shape, PermutationVector(2U, 0U, 1U)); + } + + _weights_target = create_tensor<TensorType>(weights_shape, _data_type, 1, QuantizationInfo(), _data_layout); + _bias_target = create_tensor<TensorType>(bias_shape, _data_type, 1); + + // Create tensors + TensorType src = create_tensor<TensorType>(input_shape, _data_type, 1, QuantizationInfo(), _data_layout); + TensorType dst = create_tensor<TensorType>(output_shape, _data_type, 1, QuantizationInfo(), _data_layout); + + // Create and configure function + _f_target->configure(&src, &_weights_target, &_bias_target, &dst, info, weights_info); + + ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Allocate tensors + src.allocator()->allocate(); + dst.allocator()->allocate(); + _weights_target.allocator()->allocate(); + _bias_target.allocator()->allocate(); + + ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); + ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); + + // Fill tensors + fill(AccessorType(src), 0); + fill(AccessorType(_weights_target), 1); + fill(AccessorType(_bias_target), 2); + + // Populate and validate memory manager + _ms.clear(); + _ms.populate(1); + _ms.mg.acquire(); + + // Compute NEConvolutionLayer function + _f_target->run(); + _ms.mg.release(); + + return dst; + } + + SimpleTensor<T> run_reference(TensorShape input_shape, TensorShape weights_shape, TensorShape bias_shape, TensorShape output_shape, PadStrideInfo info) + { + // Create reference + SimpleTensor<T> src{ input_shape, _data_type, 1 }; + SimpleTensor<T> weights{ weights_shape, _data_type, 1 }; + SimpleTensor<T> bias{ bias_shape, _data_type, 1 }; + + // Fill reference + fill(src, 0); + fill(weights, 1); + fill(bias, 2); + + return reference::convolution_layer<T>(src, weights, bias, output_shape, info); + } + +public: + unsigned int num_iterations{ 0 }; + SimpleTensor<T> dst_ref{}; + TensorType dst_target{}; + +private: + DataType _data_type{ DataType::UNKNOWN }; + DataLayout _data_layout{ DataLayout::UNKNOWN }; + PadStrideInfo _info{}; + std::vector<TensorShape> _input_shapes{}; + std::vector<TensorShape> _output_shapes{}; + TensorShape _weights_shape{}; + TensorShape _bias_shape{}; + MemoryManagementServiceType _ms{}; + TensorType _weights_target{}; + TensorType _bias_target{}; + std::unique_ptr<ComplexFunctionType> _f_target{}; }; } // namespace validation } // namespace test |