blob: bdbc174e5b81f716db5dd47a7c42cb4e60ce9131 [file] [log] [blame]
Matteo Martincighbc2e2102019-07-24 14:56:13 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "TestDynamicBackend.hpp"
7
8#include <backendsCommon/IBackendInternal.hpp>
9
10constexpr const char* TestDynamicBackendId()
11{
Matteo Martincighe54aa062019-08-05 14:12:11 +010012#if defined(VALID_TEST_DYNAMIC_BACKEND_1)
Matteo Martincighbc2e2102019-07-24 14:56:13 +010013
14 return "ValidTestDynamicBackend";
15
Matteo Martincighe54aa062019-08-05 14:12:11 +010016#elif defined(VALID_TEST_DYNAMIC_BACKEND_2) || \
17 defined(VALID_TEST_DYNAMIC_BACKEND_4) || \
18 defined(INVALID_TEST_DYNAMIC_BACKEND_9)
19
20 // This backend id is shared among different test dynamic backends for testing purposes:
21 // the test dynamic backend 4 is actually a duplicate of the test dynamic backend 2 (with the same version),
22 // the test dynamic backend 9 is actually a duplicate of the test dynamic backend 2 (but with a version
23 // incompatible with the current Backend API)
24 return "TestValid2";
25
26#elif defined(VALID_TEST_DYNAMIC_BACKEND_3)
27
28 // The test dynamic backend 3 is a different backend than the test dynamic backend 2
29 return "TestValid3";
30
Matteo Martincighbc2e2102019-07-24 14:56:13 +010031#else
32
33 return "InvalidTestDynamicBackend";
34
35#endif
36}
37
38class TestDynamicBackend : public armnn::IBackendInternal
39{
40public:
41 TestDynamicBackend()
42 : m_BackendId(TestDynamicBackendId())
43 {}
44
45 const armnn::BackendId& GetId() const override
46 {
47 return m_BackendId;
48 }
49 IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr& memoryManager) const override
50 {
51 return IWorkloadFactoryPtr{};
52 }
53 ILayerSupportSharedPtr GetLayerSupport() const override
54 {
55 return ILayerSupportSharedPtr{};
56 }
57
58private:
59 armnn::BackendId m_BackendId;
60};
61
62const char* GetBackendId()
63{
Matteo Martincighe54aa062019-08-05 14:12:11 +010064#if defined(INVALID_TEST_DYNAMIC_BACKEND_5) || \
65 defined(INVALID_TEST_DYNAMIC_BACKEND_8)
Matteo Martincighbc2e2102019-07-24 14:56:13 +010066
67 // Return an invalid backend id
68 return nullptr;
69
70#else
71
72 // Return a valid backend id
73 return TestDynamicBackendId();
74
75#endif
76}
77
78void GetVersion(uint32_t* outMajor, uint32_t* outMinor)
79{
80 if (!outMajor || !outMinor)
81 {
82 return;
83 }
84
Matteo Martincighe54aa062019-08-05 14:12:11 +010085#if defined(INVALID_TEST_DYNAMIC_BACKEND_7) || \
86 defined(INVALID_TEST_DYNAMIC_BACKEND_8)
Matteo Martincighbc2e2102019-07-24 14:56:13 +010087
88 *outMajor = 0;
89 *outMinor = 7;
90
91#else
92
Matteo Martincighe54aa062019-08-05 14:12:11 +010093 armnn::BackendVersion apiVersion = armnn::IBackendInternal::GetApiVersion();
94
95 *outMajor = apiVersion.m_Major;
96
97#if defined(INVALID_TEST_DYNAMIC_BACKEND_9)
98
99 *outMinor = apiVersion.m_Minor + 1;
100
101#else
102
103 *outMinor = apiVersion.m_Minor;
104
105#endif
Matteo Martincighbc2e2102019-07-24 14:56:13 +0100106
107#endif
108}
109
110void* BackendFactory()
111{
112#if defined(INVALID_TEST_DYNAMIC_BACKEND_6)
113
114 // Return an invalid backend instance
115 return nullptr;
116
117#else
118
119 // Return a non-null backend instance
120 return new TestDynamicBackend();
121
122#endif
123}