aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2019-09-18 12:04:56 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2019-09-27 17:20:08 +0000
commit40958adf8bad8fd9fefe591ee55a381f7bbb6fea (patch)
treec96403fb2f47908278c4d33c63fbfc856b7aa0e0
parentbc166d5a8e350bed6b50d7315f8e8502fc9a17b1 (diff)
downloadComputeLibrary-40958adf8bad8fd9fefe591ee55a381f7bbb6fea.tar.gz
COMPMID-2663: Interface to unbound mappings.
Adds an interface to ILifetimeManager to unbound a list of mappings. Change-Id: I927fa1e0f83e6be778fd36794439f51d36dde408 Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com> Reviewed-on: https://review.mlplatform.org/c/1988 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--arm_compute/runtime/ILifetimeManager.h9
-rw-r--r--arm_compute/runtime/ISimpleLifetimeManager.h3
-rw-r--r--src/runtime/BlobLifetimeManager.cpp4
-rw-r--r--src/runtime/ISimpleLifetimeManager.cpp21
-rw-r--r--tests/validation/UNIT/LifetimeManager.cpp125
5 files changed, 155 insertions, 7 deletions
diff --git a/arm_compute/runtime/ILifetimeManager.h b/arm_compute/runtime/ILifetimeManager.h
index 3684ddf8fb..261882bbea 100644
--- a/arm_compute/runtime/ILifetimeManager.h
+++ b/arm_compute/runtime/ILifetimeManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -48,6 +48,13 @@ public:
* @param[in] group The group id of the group
*/
virtual void register_group(IMemoryGroup *group) = 0;
+ /** Unbound and release elements associated with a group
+ *
+ * @param[in] group Group to unbound its elements
+ *
+ * @return True if group was registered and released else false.
+ */
+ virtual bool release_group(IMemoryGroup *group) = 0;
/** Registers and starts lifetime of an object
*
* @param[in] obj Object to register
diff --git a/arm_compute/runtime/ISimpleLifetimeManager.h b/arm_compute/runtime/ISimpleLifetimeManager.h
index 4384283b94..7ba11cc1b3 100644
--- a/arm_compute/runtime/ISimpleLifetimeManager.h
+++ b/arm_compute/runtime/ISimpleLifetimeManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018 ARM Limited.
+ * Copyright (c) 2017-2019 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -57,6 +57,7 @@ public:
// Inherited methods overridden:
void register_group(IMemoryGroup *group) override;
+ bool release_group(IMemoryGroup *group) override;
void start_lifetime(void *obj) override;
void end_lifetime(void *obj, IMemory &obj_memory, size_t size, size_t alignment) override;
bool are_all_finalized() const override;
diff --git a/src/runtime/BlobLifetimeManager.cpp b/src/runtime/BlobLifetimeManager.cpp
index 7a4760a990..fb83834b5f 100644
--- a/src/runtime/BlobLifetimeManager.cpp
+++ b/src/runtime/BlobLifetimeManager.cpp
@@ -71,7 +71,7 @@ void BlobLifetimeManager::update_blobs_and_mappings()
std::vector<BlobInfo> group_sizes;
std::transform(std::begin(_free_blobs), std::end(_free_blobs), std::back_inserter(group_sizes), [](const Blob & b)
{
- return BlobInfo{ b.max_size, b.max_alignment };
+ return BlobInfo{ b.max_size, b.max_alignment, b.bound_elements.size() };
});
// Update blob sizes
@@ -80,7 +80,7 @@ void BlobLifetimeManager::update_blobs_and_mappings()
group_sizes.resize(max_size);
std::transform(std::begin(_blobs), std::end(_blobs), std::begin(group_sizes), std::begin(_blobs), [](BlobInfo lhs, BlobInfo rhs)
{
- return BlobInfo{ std::max(lhs.size, rhs.size), std::max(lhs.alignment, rhs.alignment) };
+ return BlobInfo{ std::max(lhs.size, rhs.size), std::max(lhs.alignment, rhs.alignment), std::max(lhs.owners, rhs.owners) };
});
// Calculate group mappings
diff --git a/src/runtime/ISimpleLifetimeManager.cpp b/src/runtime/ISimpleLifetimeManager.cpp
index 39a4096799..b01de57c35 100644
--- a/src/runtime/ISimpleLifetimeManager.cpp
+++ b/src/runtime/ISimpleLifetimeManager.cpp
@@ -35,8 +35,8 @@
#include <map>
#include <vector>
-using namespace arm_compute;
-
+namespace arm_compute
+{
ISimpleLifetimeManager::ISimpleLifetimeManager()
: _active_group(nullptr), _active_elements(), _free_blobs(), _occupied_blobs(), _finalized_groups()
{
@@ -51,6 +51,20 @@ void ISimpleLifetimeManager::register_group(IMemoryGroup *group)
}
}
+bool ISimpleLifetimeManager::release_group(IMemoryGroup *group)
+{
+ if(group == nullptr)
+ {
+ return false;
+ }
+ const bool status = bool(_finalized_groups.erase(group));
+ if(status)
+ {
+ group->mappings().clear();
+ }
+ return status;
+}
+
void ISimpleLifetimeManager::start_lifetime(void *obj)
{
ARM_COMPUTE_ERROR_ON(obj == nullptr);
@@ -109,7 +123,7 @@ void ISimpleLifetimeManager::end_lifetime(void *obj, IMemory &obj_memory, size_t
update_blobs_and_mappings();
// Update finalized groups
- _finalized_groups[_active_group] = std::move(_active_elements);
+ _finalized_groups[_active_group].insert(std::begin(_active_elements), std::end(_active_elements));
// Reset state
_active_elements.clear();
@@ -125,3 +139,4 @@ bool ISimpleLifetimeManager::are_all_finalized() const
return !e.second.status;
});
}
+} // namespace arm_compute
diff --git a/tests/validation/UNIT/LifetimeManager.cpp b/tests/validation/UNIT/LifetimeManager.cpp
new file mode 100644
index 0000000000..d4c0a51346
--- /dev/null
+++ b/tests/validation/UNIT/LifetimeManager.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2019 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.
+ */
+#include "arm_compute/runtime/BlobLifetimeManager.h"
+#include "arm_compute/runtime/Memory.h"
+#include "arm_compute/runtime/MemoryGroup.h"
+#include "arm_compute/runtime/MemoryManagerOnDemand.h"
+#include "arm_compute/runtime/PoolManager.h"
+#include "tests/framework/Asserts.h"
+#include "tests/framework/Macros.h"
+#include "tests/framework/datasets/Datasets.h"
+#include "tests/validation/Validation.h"
+#include "utils/TypePrinter.h"
+
+namespace arm_compute
+{
+namespace test
+{
+namespace validation
+{
+namespace
+{
+/** Mock class of memory manageable objects */
+class MockMemoryManageable : public IMemoryManageable
+{
+public:
+ void associate_memory_group(IMemoryGroup *memory_group) override
+ {
+ }
+};
+/** Creates a lifetime of three objects where the two of them can share the same underlying within the given scope
+ *
+ * @warning Contents and pointers of the objects registered will be invalid at the end of the function thus do not dereference.
+ *
+ * @param[in] mg The memory group under which the manageable objects will be registered
+ */
+void generate_lifetime_info(MemoryGroup &mg)
+{
+ MockMemoryManageable a{}, b{}, c{};
+ Memory m_a{}, m_b{}, m_c{};
+
+ // Generate a custom lifetime for the objects
+ mg.manage(&a);
+ mg.manage(&b);
+ mg.finalize_memory(&a, m_a, 12U /* size */, 8U /* alignment */);
+ mg.manage(&c);
+ mg.finalize_memory(&b, m_b, 128U /* size */, 16U /* alignment */);
+ mg.finalize_memory(&c, m_c, 32U /* size */, 0U /* alignment */);
+}
+} // namespace
+TEST_SUITE(UNIT)
+TEST_SUITE(LifetimeManager)
+
+/** Validate memory group register */
+TEST_CASE(MemoryGroupRegister, framework::DatasetMode::ALL)
+{
+ auto lft_mgr = std::make_shared<BlobLifetimeManager>();
+ auto pool_mgr = std::make_shared<PoolManager>();
+ auto mm = std::make_shared<MemoryManagerOnDemand>(lft_mgr, pool_mgr);
+ MemoryGroup mg(mm);
+
+ // Register group
+ lft_mgr->register_group(&mg);
+
+ // Generate lifetime information
+ generate_lifetime_info(mg);
+
+ // Validate lifetime manager state
+ ARM_COMPUTE_EXPECT(lft_mgr->info().size() == 2, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(lft_mgr->info()[0].size == 128, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(lft_mgr->info()[0].alignment == 16, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(lft_mgr->info()[0].owners == 1, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(lft_mgr->info()[1].size == 32, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(lft_mgr->info()[1].alignment == 8, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(lft_mgr->info()[1].owners == 2, framework::LogLevel::ERRORS);
+ ARM_COMPUTE_EXPECT(mg.mappings().size() == 3, framework::LogLevel::ERRORS);
+}
+
+/** Validate memory group release */
+TEST_CASE(MemoryGroupRelease, framework::DatasetMode::ALL)
+{
+ auto lft_mgr = std::make_shared<BlobLifetimeManager>();
+ auto pool_mgr = std::make_shared<PoolManager>();
+ auto mm = std::make_shared<MemoryManagerOnDemand>(lft_mgr, pool_mgr);
+ MemoryGroup mg(mm);
+
+ // Register group
+ lft_mgr->register_group(&mg);
+
+ // Generate lifetime information
+ generate_lifetime_info(mg);
+
+ // Check group mappings
+ ARM_COMPUTE_EXPECT(mg.mappings().size() == 3, framework::LogLevel::ERRORS);
+
+ // Release group and validate its mappings
+ lft_mgr->release_group(&mg);
+ ARM_COMPUTE_EXPECT(mg.mappings().size() == 0, framework::LogLevel::ERRORS);
+}
+
+TEST_SUITE_END() // LifetimeManager
+TEST_SUITE_END()
+} // namespace validation
+} // namespace test
+} // namespace arm_compute