aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test/OptimizerTests.cpp
diff options
context:
space:
mode:
authorJan Eilers <jan.eilers@arm.com>2021-07-22 13:17:04 +0100
committerDavid Monahan <david.monahan@arm.com>2021-08-10 16:35:33 +0100
commitc1c872f12797ef6fe52c4589113e7efc353e56eb (patch)
tree911320c5306f9d2273ee76201806bfb12cbe4cd3 /src/armnn/test/OptimizerTests.cpp
parentf487486c843a38fced90229923433d09f99fc2e5 (diff)
downloadarmnn-c1c872f12797ef6fe52c4589113e7efc353e56eb.tar.gz
Adds CustomAllocator interface and Sample App
* Updates the runtime options with a CustomAllocatorMap which allows to define a CustomAllocator for specific backends * Change IBackendInternal interface to use a shared pointer to a custom allocator * Update ClBackend.hpp/cpp to use the CustomAllocator * Adds an example application and unit test which uses a CustomAllocator for GpuAcc * Refactor of the interface to use MemorySource instead of the user Mapping cl_mem directly * Modify the BackendRegistry to also hold a registry of CustomAllocators * BackendRegistry Deregister will also deregister any allocators associated with that backend id * set_global_allocator within the BaseMemoryManager so that it always matches the currently used allocator Signed-off-by: Jan Eilers <jan.eilers@arm.com> Change-Id: I156d819686021865f4375e6cb7a5c5dec8fee9e8 Signed-off-by: David Monahan <david.monahan@arm.com>
Diffstat (limited to 'src/armnn/test/OptimizerTests.cpp')
-rw-r--r--src/armnn/test/OptimizerTests.cpp133
1 files changed, 3 insertions, 130 deletions
diff --git a/src/armnn/test/OptimizerTests.cpp b/src/armnn/test/OptimizerTests.cpp
index 19bd58193a..38aef671d2 100644
--- a/src/armnn/test/OptimizerTests.cpp
+++ b/src/armnn/test/OptimizerTests.cpp
@@ -220,9 +220,10 @@ public:
return m_BackendCapabilities;
};
- virtual bool UseCustomMemoryAllocator(armnn::Optional<std::string&> errMsg) override
+ virtual bool UseCustomMemoryAllocator(std::shared_ptr<ICustomAllocator> allocator,
+ armnn::Optional<std::string&> errMsg) override
{
- IgnoreUnused(errMsg);
+ IgnoreUnused(errMsg, allocator);
m_CustomAllocator = true;
return m_CustomAllocator;
}
@@ -925,131 +926,3 @@ TEST_CASE("OptimizeForExclusiveConnectionsWithoutFuseTest")
&IsLayerOfType<armnn::OutputLayer>));
}
} // Optimizer TestSuite
-
-TEST_SUITE("Runtime")
-{
-// This test really belongs into RuntimeTests.cpp but it requires all sort of MockBackends which are
-// already defined here
-TEST_CASE("RuntimeProtectedModeOption")
-{
- using namespace armnn;
-
- struct MockPolicy
- {
- static const BackendId& GetIdStatic()
- {
- static BackendId id = "MockBackend";
- return id;
- }
- };
-
- struct ProtectedPolicy
- {
- static const BackendId& GetIdStatic()
- {
- static BackendId id = "MockBackendProtectedContent";
- return id;
- }
- };
-
- struct SillyPolicy
- {
- static const BackendId& GetIdStatic()
- {
- static BackendId id = "SillyMockBackend";
- return id;
- }
- };
-
- BackendCapabilities mockBackendCapabilities("MockBackend",
- {
- {"ProtectedContentAllocation", false}
- });
- BackendCapabilities mockProtectedBackendCapabilities("MockBackendProtectedContent",
- {
- {"ProtectedContentAllocation", true}
- });
-
- auto& backendRegistry = BackendRegistryInstance();
-
- // clean up from previous test runs
- std::vector<BackendId> mockBackends = {"MockBackend", "MockBackendProtectedContent", "SillyMockBackend"};
- for (auto& backend : mockBackends)
- {
- backendRegistry.Deregister(backend);
- }
-
- // Create a bunch of MockBackends with different capabilities
- // 1. Doesn't support protected mode even though it knows about this capability
- backendRegistry.Register("MockBackend", [mockBackendCapabilities]()
- {
- return std::make_unique<MockBackend<MockPolicy>>(mockBackendCapabilities);
- });
- // 2. Supports protected mode and has it implemented correctly
- backendRegistry.Register("MockBackendProtectedContent", [mockProtectedBackendCapabilities]()
- {
- return std::make_unique<MockBackend<ProtectedPolicy>>(mockProtectedBackendCapabilities);
- });
- // 3. Claims to support protected mode but doesn't have the UseCustomMemoryAllocator function implemented
- backendRegistry.Register("SillyMockBackend", [mockProtectedBackendCapabilities]()
- {
- return std::make_unique<NoProtectedModeMockBackend<SillyPolicy>>(mockProtectedBackendCapabilities);
- });
-
- // Creates a runtime that is not in protected mode
- {
- IRuntime::CreationOptions creationOptions;
- creationOptions.m_ProtectedMode = false;
-
- IRuntimePtr run = IRuntime::Create(creationOptions);
-
- const armnn::BackendIdSet supportedDevices = run->GetDeviceSpec().GetSupportedBackends();
- // Both MockBackends that are registered should show up in the runtimes supported backends list
- for (auto& backend : mockBackends)
- {
- CHECK(std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) != supportedDevices.cend());
- }
- }
-
- // If the runtime is in protected mode only backends that support protected content should be added
- {
- IRuntime::CreationOptions creationOptions;
- creationOptions.m_ProtectedMode = true;
-
- IRuntimePtr run = IRuntime::Create(creationOptions);
-
- const armnn::BackendIdSet supportedDevices = run->GetDeviceSpec().GetSupportedBackends();
- // Only the MockBackends that claims support for protected content should show up in the
- // runtimes supported backends list
- CHECK(std::find(supportedDevices.cbegin(),
- supportedDevices.cend(),
- "MockBackendProtectedContent") != supportedDevices.cend());
- CHECK(std::find(supportedDevices.cbegin(),
- supportedDevices.cend(),
- "MockBackend") == supportedDevices.cend());
- CHECK(std::find(supportedDevices.cbegin(),
- supportedDevices.cend(),
- "SillyMockBackend") == supportedDevices.cend());
- }
-
- // If the runtime is in protected mode only backends that support protected content should be added
- {
- IRuntime::CreationOptions creationOptions;
- creationOptions.m_ProtectedMode = true;
-
- IRuntimePtr run = IRuntime::Create(creationOptions);
-
- const armnn::BackendIdSet supportedDevices = run->GetDeviceSpec().GetSupportedBackends();
- // Only the MockBackend that claims support for protected content should show up in the
- // runtimes supported backends list
- CHECK(std::find(supportedDevices.cbegin(),
- supportedDevices.cend(),
- "MockBackendProtectedContent") != supportedDevices.cend());
-
- CHECK(std::find(supportedDevices.cbegin(),
- supportedDevices.cend(),
- "MockBackend") == supportedDevices.cend());
- }
-
-}
-}