blob: 89a87197bd55198f70bd7c6de16fa81e735c3888 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
telsoa014fcda012018-03-09 14:13:49 +00005
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +01006#include <armnn/Descriptors.hpp>
7#include <armnn/IRuntime.hpp>
8#include <armnn/INetwork.hpp>
Jim Flynn34430252022-03-04 15:03:58 +00009#include <armnn/profiling/ArmNNProfiling.hpp>
10#include <ArmNNProfilingServiceInitialiser.hpp>
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000011#include <ProfilingOptionsConverter.hpp>
Jim Flynnf7713212020-07-14 09:50:59 +010012#include <Processes.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000013#include <Runtime.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010014#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000015
Nikhil Raj77fe76b2021-06-09 14:55:32 +010016#include <common/include/LabelsAndEventClasses.hpp>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000017#include <test/ProfilingTestUtils.hpp>
18
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000019#include <HeapProfiling.hpp>
20#include <LeakChecking.hpp>
telsoa014fcda012018-03-09 14:13:49 +000021
22#ifdef WITH_VALGRIND
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010023#include <valgrind/memcheck.h>
telsoa014fcda012018-03-09 14:13:49 +000024#endif
25
Sadik Armagan1625efc2021-06-10 18:24:34 +010026#include <doctest/doctest.h>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000027#include "RuntimeTests.hpp"
Sadik Armagana097d2a2021-11-24 15:47:28 +000028#include <TestUtils.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010029
telsoa014fcda012018-03-09 14:13:49 +000030namespace armnn
31{
32
Kevin Mayd92a6e42021-02-04 10:27:41 +000033void RuntimeLoadedNetworksReserve(armnn::RuntimeImpl* runtime)
telsoa014fcda012018-03-09 14:13:49 +000034{
35 runtime->m_LoadedNetworks.reserve(1);
36}
37
Jim Flynn6c9f17d2022-03-10 23:13:01 +000038} // namespace armnn
telsoa014fcda012018-03-09 14:13:49 +000039
Sadik Armagan1625efc2021-06-10 18:24:34 +010040TEST_SUITE("Runtime")
41{
42TEST_CASE("RuntimeUnloadNetwork")
telsoa014fcda012018-03-09 14:13:49 +000043{
44 // build 2 mock-networks and load them into the runtime
telsoa01c577f2c2018-08-31 09:22:23 +010045 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +000046 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa014fcda012018-03-09 14:13:49 +000047
telsoa01c577f2c2018-08-31 09:22:23 +010048 // Mock network 1.
Keith Davis97da5e22020-03-05 16:25:28 +000049 armnn::NetworkId networkIdentifier1 = 1;
telsoa014fcda012018-03-09 14:13:49 +000050 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
51 mockNetwork1->AddInputLayer(0, "test layer");
Keith Davis97da5e22020-03-05 16:25:28 +000052 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +010053 runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000054
telsoa01c577f2c2018-08-31 09:22:23 +010055 // Mock network 2.
Keith Davis97da5e22020-03-05 16:25:28 +000056 armnn::NetworkId networkIdentifier2 = 2;
telsoa014fcda012018-03-09 14:13:49 +000057 armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create());
58 mockNetwork2->AddInputLayer(0, "test layer");
telsoa01c577f2c2018-08-31 09:22:23 +010059 runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000060
telsoa01c577f2c2018-08-31 09:22:23 +010061 // Unloads one by its networkID.
Sadik Armagan1625efc2021-06-10 18:24:34 +010062 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
telsoa014fcda012018-03-09 14:13:49 +000063
Sadik Armagan1625efc2021-06-10 18:24:34 +010064 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
telsoa014fcda012018-03-09 14:13:49 +000065}
66
Finn Williamsf37b9702021-09-01 18:06:04 +010067TEST_CASE("RuntimePreImportInputs")
68{
69 armnn::IRuntime::CreationOptions options;
Finn Williams8636bc72021-10-02 15:06:39 +010070 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
71 armnn::NetworkId networkId = 1;
Finn Williamsf37b9702021-09-01 18:06:04 +010072 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Finn Williams8636bc72021-10-02 15:06:39 +010073
Finn Williamsf37b9702021-09-01 18:06:04 +010074 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
75 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 2 layer");
76 auto addLayer = testNetwork->AddAdditionLayer("add layer");
77 auto outputLayer = testNetwork->AddOutputLayer(2, "output layer");
78
79 TensorInfo tensorInfo{{4}, armnn::DataType::Signed32};
80
81 inputLayer1->GetOutputSlot(0).Connect(addLayer->GetInputSlot(0));
82 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
Finn Williams8636bc72021-10-02 15:06:39 +010083
Finn Williamsf37b9702021-09-01 18:06:04 +010084 inputLayer2->GetOutputSlot(0).Connect(addLayer->GetInputSlot(1));
85 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
86
87 addLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
88 addLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
89
Finn Williams8636bc72021-10-02 15:06:39 +010090 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
Finn Williamsf37b9702021-09-01 18:06:04 +010091
92 std::string er;
93 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Undefined);
Finn Williams8636bc72021-10-02 15:06:39 +010094 runtime->LoadNetwork(networkId,
Finn Williamsf37b9702021-09-01 18:06:04 +010095 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
96 er,
97 networkProperties);
98
99 std::vector<int> inputData1(4, 10);
100 std::vector<int> inputData2(4, 20);
101 std::vector<int> output(4);
102
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100103 ConstTensor inputTensor1({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData1.data());
104 ConstTensor inputTensor2({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData2.data());
Finn Williamsf37b9702021-09-01 18:06:04 +0100105 Tensor outputTensor({{4}, armnn::DataType::Signed32}, output.data());
106
Finn Williams8636bc72021-10-02 15:06:39 +0100107 auto importedInputVec1 = runtime->ImportInputs(networkId, {{0, inputTensor1}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100108 CHECK(importedInputVec1.size() == 1);
109 CHECK(importedInputVec1[0] == 0);
110
Finn Williams8636bc72021-10-02 15:06:39 +0100111 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
Finn Williamsf37b9702021-09-01 18:06:04 +0100112
113 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100114 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100115 CHECK(val == 30);
116 }
117
Finn Williams8636bc72021-10-02 15:06:39 +0100118 auto importedInputVec2 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100119 CHECK(importedInputVec2.size() == 1);
120 CHECK(importedInputVec2[0] == 1);
121
122 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {{2, outputTensor}}, {1 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100123 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100124 CHECK(val == 30);
125 }
126
127 runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1});
Finn Williams8636bc72021-10-02 15:06:39 +0100128 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100129 CHECK(val == 30);
130 }
Finn Williamsf37b9702021-09-01 18:06:04 +0100131 // Duplicate ImportedInputId and LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100132 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 0});,
133 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100134 // Duplicate LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100135 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {1});,
136 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100137 // Incorrect ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100138 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {10});,
139 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100140 // Incorrect LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100141 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {1});,
142 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100143 // Incorrect layer binding id and ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100144 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {10});,
145 armnn::InvalidArgumentException);
146 auto importedInputVec3 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100147 CHECK(importedInputVec3[0] == 2);
148 // Too many ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100149 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1, 2});,
150 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100151 // Too many InputTensors
152 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(),
Finn Williams8636bc72021-10-02 15:06:39 +0100153 {{0, inputTensor2},
154 {1, inputTensor2},
155 {2, inputTensor2}},
156 {{2, outputTensor}});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100157 // Too few ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100158 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0});,
159 armnn::InvalidArgumentException);
160 runtime->ClearImportedInputs(networkId, {1});
161 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0}, {});
162 for (auto val: output) {
163 CHECK(val == 30);
164 }
165 // Using deleted pre-imported input
166 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}, {});,
167 armnn::InvalidArgumentException);
168
169 // Trying to delete deleted pre-imported tensor
170 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {1});, armnn::InvalidArgumentException);
171
172 // Trying to delete unknown pre-imported tensor
173 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {10});, armnn::InvalidArgumentException);
174}
175TEST_CASE("RuntimePreImportOutputs")
176{
177 armnn::IRuntime::CreationOptions options;
178 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
179
180 armnn::NetworkId networkId = 1;
181
182 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100183 TensorInfo tensorInfo{{4}, armnn::DataType::Float32, 0.0f, 0, true};
Finn Williams8636bc72021-10-02 15:06:39 +0100184
185 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
186 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
187
188 ActivationDescriptor activationDescriptor;
189 activationDescriptor.m_Function = ActivationFunction::BoundedReLu;
190 activationDescriptor.m_A = 2.0f;
191 activationDescriptor.m_B = 0.0f;
192 auto activationLayer1 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
193 auto outputLayer1 = testNetwork->AddOutputLayer(2, "output layer");
194
195 inputLayer1->GetOutputSlot(0).Connect(activationLayer1->GetInputSlot(0));
196
197 activationLayer1->GetOutputSlot(0).Connect(outputLayer1->GetInputSlot(0));
198 activationLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
199
200 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 1 layer");
201
202 activationDescriptor.m_A = 4.0f;
203 activationDescriptor.m_B = 2.0f;
204 auto activationLayer2 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
205 auto outputLayer2 = testNetwork->AddOutputLayer(3, "output layer");
206
207 inputLayer2->GetOutputSlot(0).Connect(activationLayer2->GetInputSlot(0));
208 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
209
210 activationLayer2->GetOutputSlot(0).Connect(outputLayer2->GetInputSlot(0));
211 activationLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
212
213 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
214
215 std::string er;
216 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Malloc);
217 runtime->LoadNetwork(networkId,
218 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
219 er,
220 networkProperties);
221
222 std::vector<float> inputData1(4, 1.0f);
223 std::vector<float> inputData2(4, 3.0f);
224
225 std::vector<float> outputData1(4);
226 std::vector<float> outputData2(4);
227
228 ConstTensor inputTensor1(tensorInfo, inputData1.data());
229 ConstTensor inputTensor2(tensorInfo, inputData2.data());
230
231 Tensor outputTensor1{tensorInfo, outputData1.data()};
232 Tensor outputTensor2{tensorInfo, outputData2.data()};
233
234 InputTensors inputTensors = {{0, inputTensor1}, {1, inputTensor2}};
235
236 std::pair<LayerBindingId, class Tensor> output1{2, outputTensor1};
237 std::pair<LayerBindingId, class Tensor> output2{3, outputTensor2};
238
239 auto testOutputs = [&]()
240 {
241 for (auto val : outputData1)
242 {
243 CHECK(val == 1.0f);
244 }
245
246 for (auto val : outputData2)
247 {
248 CHECK(val == 3.0f);
249 }
250 };
251
252 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
253
254 runtime->Execute(*memHandle.get(),inputTensors, {output1, output2});
255 testOutputs();
256
257 auto importedOutputVec = runtime->ImportOutputs(networkId, {output1, output2 });
258 CHECK(importedOutputVec.size() == 2);
259 CHECK(importedOutputVec[0] == 0);
260 CHECK(importedOutputVec[1] == 1);
261
262 runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec);
263 testOutputs();
264
265 runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {1});
266 testOutputs();
267
268 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
269 testOutputs();
270
271 auto importedInputVec = runtime->ImportInputs(networkId, inputTensors);
272 CHECK(importedInputVec.size() == 2);
273 CHECK(importedInputVec[0] == 0);
274 CHECK(importedInputVec[1] == 1);
275
276 runtime->Execute(*memHandle.get(), {}, {}, importedInputVec, importedOutputVec);
277 testOutputs();
278
279 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {output2}, {1}, {0});
280 testOutputs();
281
282 // Too many ids
283 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output2}, {}, {0, 1});,
284 armnn::InvalidArgumentException);
285
286 // Duplicate ids
287 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {1});,
288 armnn::InvalidArgumentException);
289
290 // Duplicate ids
291 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output1}, {}, {});,
292 armnn::InvalidArgumentException);
293
294 // Duplicate ids
295 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, {0, 0}),
296 armnn::InvalidArgumentException);
297
298 // Unknown id
299 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {3});,
300 armnn::InvalidArgumentException);
301
302 // Unknown id
303 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{4, outputTensor2}}, {}, {1});,
304 armnn::InvalidArgumentException);
305
306 // Input id for output
307 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
308 armnn::InvalidArgumentException);
309
310 // Input id for output
311 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
312 armnn::InvalidArgumentException);
313
314 // Output id for input
315 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{2, inputTensor1}}, {{0, outputTensor2}}, {1}, {1, 0});,
316 armnn::InvalidArgumentException);
317
318 runtime->ClearImportedOutputs(networkId, {1});
319
320 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
321 testOutputs();
322
323 // Trying to use deleted pre-imported tensor
324 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec),
325 armnn::InvalidArgumentException);
326
327 // Trying to delete deleted pre-imported tensor
328 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {1});, armnn::InvalidArgumentException);
329
330 // Trying to delete unknown pre-imported tensor
331 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {10});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100332}
333
surmeh013537c2c2018-05-18 16:31:43 +0100334// Note: the current builds we don't do valgrind and gperftools based leak checking at the same
telsoa01c577f2c2018-08-31 09:22:23 +0100335// time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The
336// valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow
337// to be integrated into the CI system.
surmeh013537c2c2018-05-18 16:31:43 +0100338
telsoa01c577f2c2018-08-31 09:22:23 +0100339#ifdef ARMNN_LEAK_CHECKING_ENABLED
340
341struct DisableGlobalLeakChecking
342{
343 DisableGlobalLeakChecking()
344 {
345 ARMNN_LOCAL_LEAK_CHECKING_ONLY();
346 }
347};
348
Sadik Armagan1625efc2021-06-10 18:24:34 +0100349TEST_CASE_FIXTURE(DisableGlobalLeakChecking, "RuntimeHeapMemoryUsageSanityChecks")
surmeh013537c2c2018-05-18 16:31:43 +0100350{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100351 CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE());
surmeh013537c2c2018-05-18 16:31:43 +0100352 {
353 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
354 {
355 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100356 CHECK(ARMNN_NO_LEAKS_IN_SCOPE() == true);
surmeh013537c2c2018-05-18 16:31:43 +0100357 std::unique_ptr<char[]> dummyAllocation(new char[1000]);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100358 // "A leak of 1000 bytes is expected here. "
359 // "Please make sure environment variable: HEAPCHECK=draconian is set!"
360 CHECK((ARMNN_NO_LEAKS_IN_SCOPE() == false));
361 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000);
362 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1);
surmeh013537c2c2018-05-18 16:31:43 +0100363 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100364 CHECK(ARMNN_NO_LEAKS_IN_SCOPE());
365 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0);
366 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0);
surmeh013537c2c2018-05-18 16:31:43 +0100367 }
368}
369
surmeh013537c2c2018-05-18 16:31:43 +0100370#endif // ARMNN_LEAK_CHECKING_ENABLED
371
372// Note: this part of the code is due to be removed when we fully trust the gperftools based results.
telsoa014fcda012018-03-09 14:13:49 +0000373#ifdef WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100374// Run with the following command to get all the amazing output (in the devenv/build folder) :)
telsoa014fcda012018-03-09 14:13:49 +0000375// valgrind --leak-check=full --show-leak-kinds=all --log-file=Valgrind_Memcheck_Leak_Report.txt armnn/test/UnitTests
Sadik Armagan1625efc2021-06-10 18:24:34 +0100376TEST_CASE("RuntimeMemoryLeak")
telsoa014fcda012018-03-09 14:13:49 +0000377{
378 // From documentation:
379
380 // This means that no pointer to the block can be found. The block is classified as "lost",
381 // because the programmer could not possibly have freed it at program exit, since no pointer to it exists.
382 unsigned long leakedBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000383 unsigned long leakedAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000384
385 // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at,
386 // the programmer could, at least in principle, have freed it before program exit.
telsoa01c577f2c2018-08-31 09:22:23 +0100387 // We want to test this in case memory is not freed as early as it could have been.
telsoa014fcda012018-03-09 14:13:49 +0000388 unsigned long reachableBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000389 unsigned long reachableAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000390
telsoa01c577f2c2018-08-31 09:22:23 +0100391 // Needed as out params but we don't test them.
Keith Davis97da5e22020-03-05 16:25:28 +0000392 unsigned long dubious = 0;
telsoa014fcda012018-03-09 14:13:49 +0000393 unsigned long suppressed = 0;
394
395 armnn::NetworkId networkIdentifier1 = 1;
396
397 // ensure that runtime is large enough before checking for memory leaks
398 // otherwise when loading the network it will automatically reserve memory that won't be released until destruction
telsoa01c577f2c2018-08-31 09:22:23 +0100399 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000400 armnn::RuntimeImpl runtime(options);
telsoa014fcda012018-03-09 14:13:49 +0000401 armnn::RuntimeLoadedNetworksReserve(&runtime);
402
telsoa014fcda012018-03-09 14:13:49 +0000403 {
Keith Davis97da5e22020-03-05 16:25:28 +0000404 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa014fcda012018-03-09 14:13:49 +0000405
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000406 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
telsoa014fcda012018-03-09 14:13:49 +0000407 mockNetwork1->AddInputLayer(0, "test layer");
408
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000409 // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
telsoa01c577f2c2018-08-31 09:22:23 +0100410 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000411 runtime.UnloadNetwork(networkIdentifier1);
412
413 // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
414 VALGRIND_DO_QUICK_LEAK_CHECK;
415 VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
416
417 // The actual test.
418 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
419 runtime.UnloadNetwork(networkIdentifier1);
420
421 VALGRIND_DO_ADDED_LEAK_CHECK;
422 VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000423 }
424
telsoa01c577f2c2018-08-31 09:22:23 +0100425 // If we're not running under Valgrind, these vars will have been initialised to 0, so this will always pass.
Sadik Armagan1625efc2021-06-10 18:24:34 +0100426 CHECK(leakedBefore == leakedAfter);
427 CHECK(reachableBefore == reachableAfter);
telsoa014fcda012018-03-09 14:13:49 +0000428
telsoa01c577f2c2018-08-31 09:22:23 +0100429 // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters
430 // so they are assigned to, but still considered unused, causing a warning.
Jim Flynn9265a882022-03-10 23:35:26 +0000431 armnn::IgnoreUnused(dubious);
432 armnn::IgnoreUnused(suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000433}
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +0100434#endif // WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100435
Sadik Armagan1625efc2021-06-10 18:24:34 +0100436TEST_CASE("RuntimeCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100437{
438 using namespace armnn;
439
440 // Create runtime in which test will run
441 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000442 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100443
444 // build up the structure of the network
445 INetworkPtr net(INetwork::Create());
446
447 IConnectableLayer* input = net->AddInputLayer(0);
448
449 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
450 NormalizationDescriptor descriptor;
451 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
452
453 IConnectableLayer* output = net->AddOutputLayer(0);
454
455 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
456 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
457
458 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
459 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
460
461 // optimize the network
David Beckf0b48452018-10-19 15:20:56 +0100462 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Keith Davis97da5e22020-03-05 16:25:28 +0000463 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100464
465 // Load it into the runtime. It should success.
466 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100467 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100468}
469
Sadik Armagan1625efc2021-06-10 18:24:34 +0100470TEST_CASE("RuntimeFallbackToCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100471{
472 using namespace armnn;
473
474 // Create runtime in which test will run
475 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000476 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100477
478 // build up the structure of the network
479 INetworkPtr net(INetwork::Create());
480
481 IConnectableLayer* input = net->AddInputLayer(0);
482
483 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
484 NormalizationDescriptor descriptor;
485 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
486
487 IConnectableLayer* output = net->AddOutputLayer(0);
488
489 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
490 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
491
492 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
493 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
494
495 // Allow fallback to CpuRef.
David Beckf0b48452018-10-19 15:20:56 +0100496 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +0100497 // optimize the network
Keith Davis97da5e22020-03-05 16:25:28 +0000498 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100499
500 // Load it into the runtime. It should succeed.
501 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100502 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100503}
504
Sadik Armagan1625efc2021-06-10 18:24:34 +0100505TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue")
jimfly016b0b53d2018-10-08 14:43:01 +0100506{
507 // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
508 using namespace armnn;
509
510 // Create runtime in which test will run
511 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000512 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
jimfly016b0b53d2018-10-08 14:43:01 +0100513
514 // build up the structure of the network
515 INetworkPtr net(INetwork::Create());
Keith Davis97da5e22020-03-05 16:25:28 +0000516 armnn::IConnectableLayer* input = net->AddInputLayer(0,"input");
517 armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax");
518 armnn::IConnectableLayer* output = net->AddOutputLayer(0, "output");
jimfly016b0b53d2018-10-08 14:43:01 +0100519
520 input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
521 softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
522
Keith Davis97da5e22020-03-05 16:25:28 +0000523 input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
524 armnn::DataType::QAsymmU8,
525 1.0f / 255,
526 0));
jimfly016b0b53d2018-10-08 14:43:01 +0100527
Keith Davis97da5e22020-03-05 16:25:28 +0000528 softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
529 armnn::DataType::QAsymmU8));
jimfly016b0b53d2018-10-08 14:43:01 +0100530
Keith Davis97da5e22020-03-05 16:25:28 +0000531 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
532 std::vector<std::string> errMessages;
Mike Kelly3a613cc2020-09-29 20:50:35 +0100533
534 try
535 {
536 armnn::IOptimizedNetworkPtr optNet = Optimize(*net,
Keith Davis97da5e22020-03-05 16:25:28 +0000537 backends,
538 runtime->GetDeviceSpec(),
539 OptimizerOptions(),
540 errMessages);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100541 FAIL("An exception should have been thrown");
Mike Kelly3a613cc2020-09-29 20:50:35 +0100542 }
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000543 catch (const armnn::InvalidArgumentException&)
Mike Kelly3a613cc2020-09-29 20:50:35 +0100544 {
545 // Different exceptions are thrown on different backends
546 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100547 CHECK(errMessages.size() > 0);
jimfly016b0b53d2018-10-08 14:43:01 +0100548}
549
Sadik Armagan1625efc2021-06-10 18:24:34 +0100550TEST_CASE("RuntimeBackendOptions")
Derek Lamberti836b27b2019-11-20 10:51:57 +0000551{
552 using namespace armnn;
553
554 IRuntime::CreationOptions creationOptions;
555 auto& backendOptions = creationOptions.m_BackendOptions;
556
557
558 // Define Options on explicit construction
559 BackendOptions options1("FakeBackend1",
Keith Davis97da5e22020-03-05 16:25:28 +0000560 {
561 { "Option1", 1.3f },
562 { "Option2", true }
563 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000564
565 // Add an option after construction
Keith Davis97da5e22020-03-05 16:25:28 +0000566 options1.AddOption({ "Option3", "some_value" });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000567
568 // Add the options to CreationOptions struct
569 backendOptions.push_back(options1);
570
571 // Add more Options via inplace explicit construction
Keith Davis97da5e22020-03-05 16:25:28 +0000572 backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
573 {{ "Option4", 42 }}
574 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000575
576
577 // First group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100578 CHECK(backendOptions[0].GetBackendId().Get() == "FakeBackend1");
579 CHECK(backendOptions[0].GetOption(0).GetName() == "Option1");
580 CHECK(backendOptions[0].GetOption(0).GetValue().IsFloat() == true);
581 CHECK(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000582
Sadik Armagan1625efc2021-06-10 18:24:34 +0100583 CHECK(backendOptions[0].GetOption(1).GetName() == "Option2");
584 CHECK(backendOptions[0].GetOption(1).GetValue().IsBool() == true);
585 CHECK(backendOptions[0].GetOption(1).GetValue().AsBool() == true);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000586
Sadik Armagan1625efc2021-06-10 18:24:34 +0100587 CHECK(backendOptions[0].GetOption(2).GetName() == "Option3");
588 CHECK(backendOptions[0].GetOption(2).GetValue().IsString() == true);
589 CHECK(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value");
Derek Lamberti836b27b2019-11-20 10:51:57 +0000590
591 // Second group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100592 CHECK(backendOptions[1].GetBackendId().Get() == "FakeBackend1");
593 CHECK(backendOptions[1].GetOption(0).GetName() == "Option4");
594 CHECK(backendOptions[1].GetOption(0).GetValue().IsInt() == true);
595 CHECK(backendOptions[1].GetOption(0).GetValue().AsInt() == 42);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000596}
597
Sadik Armagan1625efc2021-06-10 18:24:34 +0100598TEST_CASE("ProfilingDisable")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000599{
600 using namespace armnn;
601
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000602 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
603
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000604 // Create runtime in which the test will run
605 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000606 armnn::RuntimeImpl runtime(options);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000607
608 // build up the structure of the network
609 INetworkPtr net(INetwork::Create());
610
611 IConnectableLayer* input = net->AddInputLayer(0);
612
613 // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
614 NormalizationDescriptor descriptor;
615 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
616
617 IConnectableLayer* output = net->AddOutputLayer(0);
618
619 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
620 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
621
622 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
623 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
624
625 // optimize the network
626 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000627 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000628
629 // Load it into the runtime. It should succeed.
630 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100631 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000632
Jim Flynn34430252022-03-04 15:03:58 +0000633 armnn::ArmNNProfilingServiceInitialiser initialiser;
634 ProfilingServiceRuntimeHelper profilingServiceHelper(
635 arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000636 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000637 auto readableBuffer = bufferManager.GetReadableBuffer();
638
639 // Profiling is not enabled, the post-optimisation structure should not be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100640 CHECK(!readableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000641}
642
Sadik Armagan1625efc2021-06-10 18:24:34 +0100643TEST_CASE("ProfilingEnableCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000644{
645 using namespace armnn;
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000646 using namespace arm::pipe;
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000647
648 // Create runtime in which the test will run
649 armnn::IRuntime::CreationOptions options;
650 options.m_ProfilingOptions.m_EnableProfiling = true;
Keith Davis33ed2212020-03-30 10:43:41 +0100651 options.m_ProfilingOptions.m_TimelineEnabled = true;
652
Kevin Mayd92a6e42021-02-04 10:27:41 +0000653 armnn::RuntimeImpl runtime(options);
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000654 GetProfilingService(&runtime).ResetExternalProfilingOptions(
655 ConvertExternalProfilingOptions(options.m_ProfilingOptions), false);
Keith Davis33ed2212020-03-30 10:43:41 +0100656
Jim Flynn34430252022-03-04 15:03:58 +0000657 armnn::ArmNNProfilingServiceInitialiser initialiser;
658 ProfilingServiceRuntimeHelper profilingServiceHelper(
659 arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
Keith Davis33ed2212020-03-30 10:43:41 +0100660 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
661 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
662 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000663
664 // build up the structure of the network
665 INetworkPtr net(INetwork::Create());
666
667 IConnectableLayer* input = net->AddInputLayer(0, "input");
668
669 NormalizationDescriptor descriptor;
670 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
671
672 IConnectableLayer* output = net->AddOutputLayer(0, "output");
673
674 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
675 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
676
677 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
678 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
679
680 // optimize the network
681 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000682 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000683
684 ProfilingGuid optNetGuid = optNet->GetGuid();
685
686 // Load it into the runtime. It should succeed.
687 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100688 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000689
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000690 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000691 auto readableBuffer = bufferManager.GetReadableBuffer();
692
693 // Profiling is enabled, the post-optimisation structure should be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100694 CHECK(readableBuffer != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000695
696 unsigned int size = readableBuffer->GetSize();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000697
698 const unsigned char* readableData = readableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100699 CHECK(readableData != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000700
701 unsigned int offset = 0;
702
Keith Davis97da5e22020-03-05 16:25:28 +0000703 // Verify Header
Jim Flynnf7713212020-07-14 09:50:59 +0100704 VerifyTimelineHeaderBinary(readableData, offset, size - 8);
Keith Davis97da5e22020-03-05 16:25:28 +0000705
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000706 // Post-optimisation network
707 // Network entity
Jim Flynn6398a982020-05-27 17:05:21 +0100708 VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000709
710 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000711 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
712 EmptyOptional(),
713 optNetGuid,
714 LabelsAndEventClasses::NETWORK_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000715 LabelsAndEventClasses::TYPE_GUID,
716 readableData,
717 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000718
Jim Flynnf7713212020-07-14 09:50:59 +0100719 // Network - START OF LIFE
720 ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(),
721 EmptyOptional(),
722 EmptyOptional(),
723 readableData,
724 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100725
726 // Network - START OF LIFE event relationship
727 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
728 EmptyOptional(),
729 optNetGuid,
730 networkSolEventGuid,
731 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
732 readableData,
733 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100734
735 // Process ID Label
736 int processID = armnnUtils::Processes::GetCurrentId();
737 std::stringstream ss;
738 ss << processID;
739 std::string processIdLabel = ss.str();
740 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100741
742 // Entity - Process ID relationship
743 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
744 EmptyOptional(),
745 optNetGuid,
746 EmptyOptional(),
747 LabelsAndEventClasses::PROCESS_ID_GUID,
748 readableData,
749 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100750
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000751 // Input layer
752 // Input layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000753 VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000754
755 // Name Entity
Jim Flynn6398a982020-05-27 17:05:21 +0100756 ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000757
758 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000759 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
760 EmptyOptional(),
761 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100762 inputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000763 LabelsAndEventClasses::NAME_GUID,
764 readableData,
765 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000766
767 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000768 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
769 EmptyOptional(),
770 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100771 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000772 LabelsAndEventClasses::TYPE_GUID,
773 readableData,
774 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000775
776 // Network - Input layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000777 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
778 EmptyOptional(),
779 optNetGuid,
780 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100781 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000782 readableData,
783 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000784
785 // Normalization layer
786 // Normalization layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000787 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000788
789 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100790 ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData(
791 EmptyOptional(), "normalization", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000792
793 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000794 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
795 EmptyOptional(),
796 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100797 normalizationLayerNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000798 LabelsAndEventClasses::NAME_GUID,
799 readableData,
800 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000801
802 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000803 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
804 EmptyOptional(),
805 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100806 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000807 LabelsAndEventClasses::TYPE_GUID,
808 readableData,
809 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000810
811 // Network - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000812 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
813 EmptyOptional(),
814 optNetGuid,
815 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100816 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000817 readableData,
818 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000819
820 // Input layer - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000821 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
822 EmptyOptional(),
823 input->GetGuid(),
824 normalize->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000825 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000826 readableData,
827 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000828
829 // Normalization workload
830 // Normalization workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100831 ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
832 EmptyOptional(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000833
834 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000835 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
836 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100837 normalizationWorkloadGuid,
838 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000839 LabelsAndEventClasses::TYPE_GUID,
840 readableData,
841 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000842
843 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100844 ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
845 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000846
847 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000848 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
849 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100850 normalizationWorkloadGuid,
851 cpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000852 LabelsAndEventClasses::BACKENDID_GUID,
853 readableData,
854 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000855
856 // Normalize layer - Normalize workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000857 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
858 EmptyOptional(),
859 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100860 normalizationWorkloadGuid,
861 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000862 readableData,
863 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000864
865 // Output layer
866 // Output layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000867 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000868
869 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100870 ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
871 EmptyOptional(), "output", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000872
873 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000874 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
875 EmptyOptional(),
876 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100877 outputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000878 LabelsAndEventClasses::NAME_GUID,
879 readableData,
880 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000881
882 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000883 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
884 EmptyOptional(),
885 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100886 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000887 LabelsAndEventClasses::TYPE_GUID,
888 readableData,
889 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000890
891 // Network - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000892 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
893 EmptyOptional(),
894 optNetGuid,
895 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100896 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000897 readableData,
898 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000899
900 // Normalize layer - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000901 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
902 EmptyOptional(),
903 normalize->GetGuid(),
904 output->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000905 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000906 readableData,
907 offset);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000908
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000909 bufferManager.MarkRead(readableBuffer);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000910
911 // Creates structures for input & output.
912 std::vector<float> inputData(16);
913 std::vector<float> outputData(16);
914
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100915 TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
916 inputTensorInfo.SetConstant(true);
Keith Davis97da5e22020-03-05 16:25:28 +0000917 InputTensors inputTensors
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000918 {
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100919 {0, ConstTensor(inputTensorInfo, inputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000920 };
921 OutputTensors outputTensors
922 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000923 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000924 };
925
926 // Does the inference.
Sadik Armagan3184c902020-03-18 10:57:30 +0000927 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000928
Finn Williamsb6a402f2020-03-24 13:46:22 +0000929 // Get readable buffer for input workload
930 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100931 CHECK(inputReadableBuffer != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +0000932
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000933 // Get readable buffer for output workload
934 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100935 CHECK(outputReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000936
Finn Williamsb6a402f2020-03-24 13:46:22 +0000937 // Get readable buffer for inference timeline
938 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100939 CHECK(inferenceReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000940
941 // Validate input workload data
942 size = inputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100943 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000944
945 readableData = inputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100946 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000947
948 offset = 0;
949
Keith Davis97da5e22020-03-05 16:25:28 +0000950 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100951 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000952
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000953 // Input workload
954 // Input workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100955 ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000956
957 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000958 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
959 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100960 inputWorkloadGuid,
961 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000962 LabelsAndEventClasses::TYPE_GUID,
963 readableData,
964 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000965
966 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100967 ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
968 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000969
970 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000971 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
972 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100973 inputWorkloadGuid,
974 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000975 LabelsAndEventClasses::BACKENDID_GUID,
976 readableData,
977 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000978
979 // Input layer - Input workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000980 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
981 EmptyOptional(),
982 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100983 inputWorkloadGuid,
984 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000985 readableData,
986 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000987
988 bufferManager.MarkRead(inputReadableBuffer);
989
990 // Validate output workload data
991 size = outputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100992 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000993
994 readableData = outputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100995 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000996
997 offset = 0;
998
Keith Davis97da5e22020-03-05 16:25:28 +0000999 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001000 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +00001001
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001002 // Output workload
1003 // Output workload entity
Jim Flynn6398a982020-05-27 17:05:21 +01001004 ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001005
1006 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001007 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1008 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001009 outputWorkloadGuid,
1010 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001011 LabelsAndEventClasses::TYPE_GUID,
1012 readableData,
1013 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001014
1015 // BackendId entity
Keith Davis97da5e22020-03-05 16:25:28 +00001016 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001017
1018 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001019 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1020 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001021 outputWorkloadGuid,
1022 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001023 LabelsAndEventClasses::BACKENDID_GUID,
1024 readableData,
1025 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001026
1027 // Output layer - Output workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001028 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1029 EmptyOptional(),
1030 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +01001031 outputWorkloadGuid,
1032 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001033 readableData,
1034 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001035
1036 bufferManager.MarkRead(outputReadableBuffer);
David Monahan6198fe02019-12-02 08:35:43 +00001037
1038 // Validate inference data
1039 size = inferenceReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001040 CHECK(size == 976 + 8 * ThreadIdSize);
David Monahan6198fe02019-12-02 08:35:43 +00001041
1042 readableData = inferenceReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001043 CHECK(readableData != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +00001044
1045 offset = 0;
1046
Keith Davis97da5e22020-03-05 16:25:28 +00001047 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001048 VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize);
Keith Davis97da5e22020-03-05 16:25:28 +00001049
David Monahan6198fe02019-12-02 08:35:43 +00001050 // Inference timeline trace
1051 // Inference entity
Jim Flynn6398a982020-05-27 17:05:21 +01001052 ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001053
1054 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001055 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1056 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001057 inferenceGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001058 LabelsAndEventClasses::INFERENCE_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001059 LabelsAndEventClasses::TYPE_GUID,
1060 readableData,
1061 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001062
1063 // Network - Inference relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001064 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1065 EmptyOptional(),
1066 optNetGuid,
Jim Flynn6398a982020-05-27 17:05:21 +01001067 inferenceGuid,
1068 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001069 readableData,
1070 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001071
1072 // Start Inference life
1073 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001074 ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
1075 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001076
1077 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001078 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1079 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001080 inferenceGuid,
1081 inferenceEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001082 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1083 readableData,
1084 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001085
1086 // Execution
1087 // Input workload execution
1088 // Input workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001089 ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1090 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001091
1092 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001093 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1094 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001095 inputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001096 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001097 LabelsAndEventClasses::TYPE_GUID,
1098 readableData,
1099 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001100
1101 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001102 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1103 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001104 inferenceGuid,
1105 inputWorkloadExecutionGuid,
1106 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001107 readableData,
1108 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001109
1110 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001111 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1112 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001113 inputWorkloadGuid,
1114 inputWorkloadExecutionGuid,
1115 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001116 readableData,
1117 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001118
1119 // Start Input workload execution life
1120 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001121 ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
1122 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001123
1124 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001125 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1126 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001127 inputWorkloadExecutionGuid,
1128 inputWorkloadExecutionSOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001129 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1130 readableData,
1131 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001132
1133 // End of Input workload execution life
1134 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001135 ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
1136 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001137
1138 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001139 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1140 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001141 inputWorkloadExecutionGuid,
1142 inputWorkloadExecutionEOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001143 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1144 readableData,
1145 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001146
1147 // Normalize workload execution
1148 // Normalize workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001149 ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1150 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001151
1152 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001153 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1154 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001155 normalizeWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001156 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001157 LabelsAndEventClasses::TYPE_GUID,
1158 readableData,
1159 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001160
1161 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001162 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1163 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001164 inferenceGuid,
1165 normalizeWorkloadExecutionGuid,
1166 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001167 readableData,
1168 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001169
1170 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001171 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1172 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001173 normalizationWorkloadGuid,
1174 normalizeWorkloadExecutionGuid,
1175 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001176 readableData,
1177 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001178
1179 // Start Normalize workload execution life
1180 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001181 ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1182 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001183
1184 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001185 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1186 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001187 normalizeWorkloadExecutionGuid,
1188 normalizationWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001189 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1190 readableData,
1191 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001192
1193 // End of Normalize workload execution life
1194 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001195 ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1196 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001197
1198 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001199 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1200 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001201 normalizeWorkloadExecutionGuid,
1202 normalizationWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001203 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1204 readableData,
1205 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001206
1207 // Output workload execution
1208 // Output workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001209 ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1210 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001211
1212 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001213 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1214 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001215 outputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001216 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001217 LabelsAndEventClasses::TYPE_GUID,
1218 readableData,
1219 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001220
1221 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001222 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1223 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001224 inferenceGuid,
1225 outputWorkloadExecutionGuid,
1226 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001227 readableData,
1228 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001229
1230 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001231 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1232 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001233 outputWorkloadGuid,
1234 outputWorkloadExecutionGuid,
1235 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001236 readableData,
1237 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001238
1239 // Start Output workload execution life
1240 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001241 ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1242 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001243
1244 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001245 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1246 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001247 outputWorkloadExecutionGuid,
1248 outputWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001249 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1250 readableData,
1251 offset);
Finn Williams0a336dc2020-05-11 15:39:58 +01001252
David Monahan6198fe02019-12-02 08:35:43 +00001253 // End of Normalize workload execution life
1254 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001255 ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1256 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001257
1258 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001259 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1260 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001261 outputWorkloadExecutionGuid,
1262 outputWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001263 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1264 readableData,
1265 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001266
1267 // End of Inference life
1268 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001269 ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
1270 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001271
1272 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001273 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1274 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001275 inferenceGuid,
1276 inferenceEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001277 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1278 readableData,
1279 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001280
1281 bufferManager.MarkRead(inferenceReadableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001282}
1283
Sadik Armagan1625efc2021-06-10 18:24:34 +01001284TEST_CASE("ProfilingPostOptimisationStructureCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001285{
1286 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1287}
1288
Sadik Armagan1625efc2021-06-10 18:24:34 +01001289}