xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/NEON/UNIT/MemoryManager.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "arm_compute/runtime/Allocator.h"
25 #include "arm_compute/runtime/BlobLifetimeManager.h"
26 #include "arm_compute/runtime/MemoryGroup.h"
27 #include "arm_compute/runtime/MemoryManagerOnDemand.h"
28 #include "arm_compute/runtime/NEON/functions/NENormalizationLayer.h"
29 #include "arm_compute/runtime/PoolManager.h"
30 #include "arm_compute/runtime/TensorAllocator.h"
31 #include "tests/AssetsLibrary.h"
32 #include "tests/Globals.h"
33 #include "tests/NEON/Accessor.h"
34 #include "tests/Utils.h"
35 #include "tests/framework/Asserts.h"
36 #include "tests/framework/Macros.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 TEST_SUITE(NEON)
TEST_SUITE(UNIT)45 TEST_SUITE(UNIT)
46 TEST_SUITE(MemoryManager)
47 
48 TEST_CASE(BlobMemoryManagerSimpleWithinFunctionLevel, framework::DatasetMode::ALL)
49 {
50     Allocator allocator{};
51     auto      lifetime_mgr = std::make_shared<BlobLifetimeManager>();
52     auto      pool_mgr     = std::make_shared<PoolManager>();
53     auto      mm           = std::make_shared<MemoryManagerOnDemand>(lifetime_mgr, pool_mgr);
54 
55     // Create tensors
56     Tensor src = create_tensor<Tensor>(TensorShape(27U, 11U, 3U), DataType::F32, 1);
57     Tensor dst = create_tensor<Tensor>(TensorShape(27U, 11U, 3U), DataType::F32, 1);
58 
59     // Create and configure function
60     NENormalizationLayer norm_layer_1(mm);
61     NENormalizationLayer norm_layer_2(mm);
62     norm_layer_1.configure(&src, &dst, NormalizationLayerInfo(NormType::CROSS_MAP, 3));
63     norm_layer_2.configure(&src, &dst, NormalizationLayerInfo(NormType::IN_MAP_1D, 3));
64 
65     ARM_COMPUTE_ASSERT(src.info()->is_resizable());
66     ARM_COMPUTE_ASSERT(dst.info()->is_resizable());
67 
68     // Allocate tensors
69     src.allocator()->allocate();
70     dst.allocator()->allocate();
71 
72     ARM_COMPUTE_ASSERT(!src.info()->is_resizable());
73     ARM_COMPUTE_ASSERT(!dst.info()->is_resizable());
74 
75     // Finalize memory manager
76     mm->populate(allocator, 1 /* num_pools */);
77     ARM_COMPUTE_EXPECT(mm->pool_manager()->num_pools() == 1, framework::LogLevel::ERRORS);
78     ARM_COMPUTE_EXPECT(mm->lifetime_manager()->are_all_finalized(), framework::LogLevel::ERRORS);
79 
80     // Fill tensors
81     arm_compute::test::library->fill_tensor_uniform(Accessor(src), 0);
82 
83     // Compute functions
84     norm_layer_1.run();
85     norm_layer_2.run();
86 
87     // Clear manager
88     mm->clear();
89     ARM_COMPUTE_EXPECT(mm->pool_manager()->num_pools() == 0, framework::LogLevel::ERRORS);
90 }
91 
92 TEST_SUITE_END()
93 TEST_SUITE_END()
94 TEST_SUITE_END()
95 } // namespace validation
96 } // namespace test
97 } // namespace arm_compute
98