From d0c9cb808f674ce8bbfbdf0e66c5b8451f6af0f2 Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Thu, 11 Mar 2021 15:29:19 +0000 Subject: Add test case for memory managed softmax layer A test case for softmax layer with a given memory manager is added to test the scenario where the external caller owns the memory manager. Resolves: COMPMID-4298 Change-Id: If37ce72f7dad5901740bd32de9d70ea576caa2ae Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5258 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- tests/validation/CL/SoftmaxLayer.cpp | 49 +++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'tests/validation') diff --git a/tests/validation/CL/SoftmaxLayer.cpp b/tests/validation/CL/SoftmaxLayer.cpp index 396e274e0b..eb47b7f666 100644 --- a/tests/validation/CL/SoftmaxLayer.cpp +++ b/tests/validation/CL/SoftmaxLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2020 Arm Limited. + * Copyright (c) 2017-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -34,6 +34,12 @@ #include "tests/validation/Validation.h" #include "tests/validation/fixtures/SoftmaxLayerFixture.h" +#include "arm_compute/runtime/MemoryManagerOnDemand.h" +#include "arm_compute/runtime/PoolManager.h" +#include "arm_compute/runtime/BlobLifetimeManager.h" +#include "arm_compute/runtime/CL/CLBufferAllocator.h" +#include "arm_compute/runtime/BlobMemoryPool.h" + namespace arm_compute { namespace test @@ -62,6 +68,47 @@ const auto CNNDataTypes = framework::dataset::make("DataType", TEST_SUITE(CL) TEST_SUITE(SoftmaxLayer) +TEST_CASE(SimpleMemoryManaged, framework::DatasetMode::ALL) +{ + // The purpose of this test is to test if the function can + // run correctly even with the given memory manager from its caller + // (Similar scenario when the library is integrated into other software) + // especially when working with workspace() method of + // @ref arm_compute::opencl::ClSoftmax. + const auto shape = TensorShape{4,2}; // Random shape, not important + constexpr auto dt = DataType::F32; // Random data type, not important + + // Create a memory manager + auto lm = std::make_shared(); + auto pm = std::make_shared(); + auto alloc = std::make_unique(); + auto mm = std::make_shared(lm, pm); + + auto src = create_tensor(shape, dt); + auto dst = create_tensor(shape, dt); + src.allocator()->allocate(); + dst.allocator()->allocate(); + + // Create the function with the memory manager + CLSoftmaxLayer smx(mm); + smx.configure(&src, &dst); + + // Populate the memory, acquire() will happen in run() + mm->populate(*alloc.get(), 1); + + std::vector input_vals{0.0f, 1.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f,}; + library->fill_static_values(CLAccessor(src), input_vals); + + smx.run(); + + // Compute reference to compare + SimpleTensor ref_src{shape, dt}; + library->fill_static_values(ref_src, input_vals); + auto ref_dst = reference::softmax_layer(ref_src, 1., 0, false); + + validate(CLAccessor(dst), ref_dst); +} + // *INDENT-OFF* // clang-format off DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( -- cgit v1.2.1