blob: 9cf322c98f1c50f0d35a00172d7e7785dff9ef46 [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
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000016
Nikhil Raj77fe76b2021-06-09 14:55:32 +010017#include <common/include/LabelsAndEventClasses.hpp>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000018#include <test/ProfilingTestUtils.hpp>
19
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000020#include <HeapProfiling.hpp>
21#include <LeakChecking.hpp>
telsoa014fcda012018-03-09 14:13:49 +000022
23#ifdef WITH_VALGRIND
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010024#include <valgrind/memcheck.h>
telsoa014fcda012018-03-09 14:13:49 +000025#endif
26
Sadik Armagan1625efc2021-06-10 18:24:34 +010027#include <doctest/doctest.h>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000028#include "RuntimeTests.hpp"
Sadik Armagana097d2a2021-11-24 15:47:28 +000029#include <TestUtils.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010030
telsoa014fcda012018-03-09 14:13:49 +000031namespace armnn
32{
33
Kevin Mayd92a6e42021-02-04 10:27:41 +000034void RuntimeLoadedNetworksReserve(armnn::RuntimeImpl* runtime)
telsoa014fcda012018-03-09 14:13:49 +000035{
36 runtime->m_LoadedNetworks.reserve(1);
37}
38
39}
40
Sadik Armagan1625efc2021-06-10 18:24:34 +010041TEST_SUITE("Runtime")
42{
43TEST_CASE("RuntimeUnloadNetwork")
telsoa014fcda012018-03-09 14:13:49 +000044{
45 // build 2 mock-networks and load them into the runtime
telsoa01c577f2c2018-08-31 09:22:23 +010046 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +000047 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa014fcda012018-03-09 14:13:49 +000048
telsoa01c577f2c2018-08-31 09:22:23 +010049 // Mock network 1.
Keith Davis97da5e22020-03-05 16:25:28 +000050 armnn::NetworkId networkIdentifier1 = 1;
telsoa014fcda012018-03-09 14:13:49 +000051 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
52 mockNetwork1->AddInputLayer(0, "test layer");
Keith Davis97da5e22020-03-05 16:25:28 +000053 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +010054 runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000055
telsoa01c577f2c2018-08-31 09:22:23 +010056 // Mock network 2.
Keith Davis97da5e22020-03-05 16:25:28 +000057 armnn::NetworkId networkIdentifier2 = 2;
telsoa014fcda012018-03-09 14:13:49 +000058 armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create());
59 mockNetwork2->AddInputLayer(0, "test layer");
telsoa01c577f2c2018-08-31 09:22:23 +010060 runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000061
telsoa01c577f2c2018-08-31 09:22:23 +010062 // Unloads one by its networkID.
Sadik Armagan1625efc2021-06-10 18:24:34 +010063 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
telsoa014fcda012018-03-09 14:13:49 +000064
Sadik Armagan1625efc2021-06-10 18:24:34 +010065 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
telsoa014fcda012018-03-09 14:13:49 +000066}
67
Finn Williamsf37b9702021-09-01 18:06:04 +010068TEST_CASE("RuntimePreImportInputs")
69{
70 armnn::IRuntime::CreationOptions options;
Finn Williams8636bc72021-10-02 15:06:39 +010071 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
72 armnn::NetworkId networkId = 1;
Finn Williamsf37b9702021-09-01 18:06:04 +010073 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Finn Williams8636bc72021-10-02 15:06:39 +010074
Finn Williamsf37b9702021-09-01 18:06:04 +010075 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
76 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 2 layer");
77 auto addLayer = testNetwork->AddAdditionLayer("add layer");
78 auto outputLayer = testNetwork->AddOutputLayer(2, "output layer");
79
80 TensorInfo tensorInfo{{4}, armnn::DataType::Signed32};
81
82 inputLayer1->GetOutputSlot(0).Connect(addLayer->GetInputSlot(0));
83 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
Finn Williams8636bc72021-10-02 15:06:39 +010084
Finn Williamsf37b9702021-09-01 18:06:04 +010085 inputLayer2->GetOutputSlot(0).Connect(addLayer->GetInputSlot(1));
86 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
87
88 addLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
89 addLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
90
Finn Williams8636bc72021-10-02 15:06:39 +010091 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
Finn Williamsf37b9702021-09-01 18:06:04 +010092
93 std::string er;
94 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Undefined);
Finn Williams8636bc72021-10-02 15:06:39 +010095 runtime->LoadNetwork(networkId,
Finn Williamsf37b9702021-09-01 18:06:04 +010096 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
97 er,
98 networkProperties);
99
100 std::vector<int> inputData1(4, 10);
101 std::vector<int> inputData2(4, 20);
102 std::vector<int> output(4);
103
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100104 ConstTensor inputTensor1({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData1.data());
105 ConstTensor inputTensor2({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData2.data());
Finn Williamsf37b9702021-09-01 18:06:04 +0100106 Tensor outputTensor({{4}, armnn::DataType::Signed32}, output.data());
107
Finn Williams8636bc72021-10-02 15:06:39 +0100108 auto importedInputVec1 = runtime->ImportInputs(networkId, {{0, inputTensor1}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100109 CHECK(importedInputVec1.size() == 1);
110 CHECK(importedInputVec1[0] == 0);
111
Finn Williams8636bc72021-10-02 15:06:39 +0100112 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
Finn Williamsf37b9702021-09-01 18:06:04 +0100113
114 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100115 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100116 CHECK(val == 30);
117 }
118
Finn Williams8636bc72021-10-02 15:06:39 +0100119 auto importedInputVec2 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100120 CHECK(importedInputVec2.size() == 1);
121 CHECK(importedInputVec2[0] == 1);
122
123 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {{2, outputTensor}}, {1 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100124 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100125 CHECK(val == 30);
126 }
127
128 runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1});
Finn Williams8636bc72021-10-02 15:06:39 +0100129 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100130 CHECK(val == 30);
131 }
Finn Williamsf37b9702021-09-01 18:06:04 +0100132 // Duplicate ImportedInputId and LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100133 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 0});,
134 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100135 // Duplicate LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100136 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {1});,
137 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100138 // Incorrect ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100139 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {10});,
140 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100141 // Incorrect LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100142 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {1});,
143 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100144 // Incorrect layer binding id and ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100145 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {10});,
146 armnn::InvalidArgumentException);
147 auto importedInputVec3 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100148 CHECK(importedInputVec3[0] == 2);
149 // Too many ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100150 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1, 2});,
151 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100152 // Too many InputTensors
153 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(),
Finn Williams8636bc72021-10-02 15:06:39 +0100154 {{0, inputTensor2},
155 {1, inputTensor2},
156 {2, inputTensor2}},
157 {{2, outputTensor}});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100158 // Too few ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100159 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0});,
160 armnn::InvalidArgumentException);
161 runtime->ClearImportedInputs(networkId, {1});
162 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0}, {});
163 for (auto val: output) {
164 CHECK(val == 30);
165 }
166 // Using deleted pre-imported input
167 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}, {});,
168 armnn::InvalidArgumentException);
169
170 // Trying to delete deleted pre-imported tensor
171 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {1});, armnn::InvalidArgumentException);
172
173 // Trying to delete unknown pre-imported tensor
174 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {10});, armnn::InvalidArgumentException);
175}
176TEST_CASE("RuntimePreImportOutputs")
177{
178 armnn::IRuntime::CreationOptions options;
179 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
180
181 armnn::NetworkId networkId = 1;
182
183 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100184 TensorInfo tensorInfo{{4}, armnn::DataType::Float32, 0.0f, 0, true};
Finn Williams8636bc72021-10-02 15:06:39 +0100185
186 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
187 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
188
189 ActivationDescriptor activationDescriptor;
190 activationDescriptor.m_Function = ActivationFunction::BoundedReLu;
191 activationDescriptor.m_A = 2.0f;
192 activationDescriptor.m_B = 0.0f;
193 auto activationLayer1 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
194 auto outputLayer1 = testNetwork->AddOutputLayer(2, "output layer");
195
196 inputLayer1->GetOutputSlot(0).Connect(activationLayer1->GetInputSlot(0));
197
198 activationLayer1->GetOutputSlot(0).Connect(outputLayer1->GetInputSlot(0));
199 activationLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
200
201 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 1 layer");
202
203 activationDescriptor.m_A = 4.0f;
204 activationDescriptor.m_B = 2.0f;
205 auto activationLayer2 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
206 auto outputLayer2 = testNetwork->AddOutputLayer(3, "output layer");
207
208 inputLayer2->GetOutputSlot(0).Connect(activationLayer2->GetInputSlot(0));
209 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
210
211 activationLayer2->GetOutputSlot(0).Connect(outputLayer2->GetInputSlot(0));
212 activationLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
213
214 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
215
216 std::string er;
217 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Malloc);
218 runtime->LoadNetwork(networkId,
219 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
220 er,
221 networkProperties);
222
223 std::vector<float> inputData1(4, 1.0f);
224 std::vector<float> inputData2(4, 3.0f);
225
226 std::vector<float> outputData1(4);
227 std::vector<float> outputData2(4);
228
229 ConstTensor inputTensor1(tensorInfo, inputData1.data());
230 ConstTensor inputTensor2(tensorInfo, inputData2.data());
231
232 Tensor outputTensor1{tensorInfo, outputData1.data()};
233 Tensor outputTensor2{tensorInfo, outputData2.data()};
234
235 InputTensors inputTensors = {{0, inputTensor1}, {1, inputTensor2}};
236
237 std::pair<LayerBindingId, class Tensor> output1{2, outputTensor1};
238 std::pair<LayerBindingId, class Tensor> output2{3, outputTensor2};
239
240 auto testOutputs = [&]()
241 {
242 for (auto val : outputData1)
243 {
244 CHECK(val == 1.0f);
245 }
246
247 for (auto val : outputData2)
248 {
249 CHECK(val == 3.0f);
250 }
251 };
252
253 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
254
255 runtime->Execute(*memHandle.get(),inputTensors, {output1, output2});
256 testOutputs();
257
258 auto importedOutputVec = runtime->ImportOutputs(networkId, {output1, output2 });
259 CHECK(importedOutputVec.size() == 2);
260 CHECK(importedOutputVec[0] == 0);
261 CHECK(importedOutputVec[1] == 1);
262
263 runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec);
264 testOutputs();
265
266 runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {1});
267 testOutputs();
268
269 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
270 testOutputs();
271
272 auto importedInputVec = runtime->ImportInputs(networkId, inputTensors);
273 CHECK(importedInputVec.size() == 2);
274 CHECK(importedInputVec[0] == 0);
275 CHECK(importedInputVec[1] == 1);
276
277 runtime->Execute(*memHandle.get(), {}, {}, importedInputVec, importedOutputVec);
278 testOutputs();
279
280 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {output2}, {1}, {0});
281 testOutputs();
282
283 // Too many ids
284 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output2}, {}, {0, 1});,
285 armnn::InvalidArgumentException);
286
287 // Duplicate ids
288 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {1});,
289 armnn::InvalidArgumentException);
290
291 // Duplicate ids
292 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output1}, {}, {});,
293 armnn::InvalidArgumentException);
294
295 // Duplicate ids
296 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, {0, 0}),
297 armnn::InvalidArgumentException);
298
299 // Unknown id
300 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {3});,
301 armnn::InvalidArgumentException);
302
303 // Unknown id
304 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{4, outputTensor2}}, {}, {1});,
305 armnn::InvalidArgumentException);
306
307 // Input id for output
308 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
309 armnn::InvalidArgumentException);
310
311 // Input id for output
312 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
313 armnn::InvalidArgumentException);
314
315 // Output id for input
316 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{2, inputTensor1}}, {{0, outputTensor2}}, {1}, {1, 0});,
317 armnn::InvalidArgumentException);
318
319 runtime->ClearImportedOutputs(networkId, {1});
320
321 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
322 testOutputs();
323
324 // Trying to use deleted pre-imported tensor
325 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec),
326 armnn::InvalidArgumentException);
327
328 // Trying to delete deleted pre-imported tensor
329 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {1});, armnn::InvalidArgumentException);
330
331 // Trying to delete unknown pre-imported tensor
332 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {10});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100333}
334
surmeh013537c2c2018-05-18 16:31:43 +0100335// Note: the current builds we don't do valgrind and gperftools based leak checking at the same
telsoa01c577f2c2018-08-31 09:22:23 +0100336// time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The
337// valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow
338// to be integrated into the CI system.
surmeh013537c2c2018-05-18 16:31:43 +0100339
telsoa01c577f2c2018-08-31 09:22:23 +0100340#ifdef ARMNN_LEAK_CHECKING_ENABLED
341
342struct DisableGlobalLeakChecking
343{
344 DisableGlobalLeakChecking()
345 {
346 ARMNN_LOCAL_LEAK_CHECKING_ONLY();
347 }
348};
349
Sadik Armagan1625efc2021-06-10 18:24:34 +0100350TEST_CASE_FIXTURE(DisableGlobalLeakChecking, "RuntimeHeapMemoryUsageSanityChecks")
surmeh013537c2c2018-05-18 16:31:43 +0100351{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100352 CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE());
surmeh013537c2c2018-05-18 16:31:43 +0100353 {
354 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
355 {
356 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100357 CHECK(ARMNN_NO_LEAKS_IN_SCOPE() == true);
surmeh013537c2c2018-05-18 16:31:43 +0100358 std::unique_ptr<char[]> dummyAllocation(new char[1000]);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100359 // "A leak of 1000 bytes is expected here. "
360 // "Please make sure environment variable: HEAPCHECK=draconian is set!"
361 CHECK((ARMNN_NO_LEAKS_IN_SCOPE() == false));
362 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000);
363 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1);
surmeh013537c2c2018-05-18 16:31:43 +0100364 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100365 CHECK(ARMNN_NO_LEAKS_IN_SCOPE());
366 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0);
367 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0);
surmeh013537c2c2018-05-18 16:31:43 +0100368 }
369}
370
surmeh013537c2c2018-05-18 16:31:43 +0100371#endif // ARMNN_LEAK_CHECKING_ENABLED
372
373// 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 +0000374#ifdef WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100375// Run with the following command to get all the amazing output (in the devenv/build folder) :)
telsoa014fcda012018-03-09 14:13:49 +0000376// 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 +0100377TEST_CASE("RuntimeMemoryLeak")
telsoa014fcda012018-03-09 14:13:49 +0000378{
379 // From documentation:
380
381 // This means that no pointer to the block can be found. The block is classified as "lost",
382 // because the programmer could not possibly have freed it at program exit, since no pointer to it exists.
383 unsigned long leakedBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000384 unsigned long leakedAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000385
386 // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at,
387 // the programmer could, at least in principle, have freed it before program exit.
telsoa01c577f2c2018-08-31 09:22:23 +0100388 // We want to test this in case memory is not freed as early as it could have been.
telsoa014fcda012018-03-09 14:13:49 +0000389 unsigned long reachableBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000390 unsigned long reachableAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000391
telsoa01c577f2c2018-08-31 09:22:23 +0100392 // Needed as out params but we don't test them.
Keith Davis97da5e22020-03-05 16:25:28 +0000393 unsigned long dubious = 0;
telsoa014fcda012018-03-09 14:13:49 +0000394 unsigned long suppressed = 0;
395
396 armnn::NetworkId networkIdentifier1 = 1;
397
398 // ensure that runtime is large enough before checking for memory leaks
399 // otherwise when loading the network it will automatically reserve memory that won't be released until destruction
telsoa01c577f2c2018-08-31 09:22:23 +0100400 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000401 armnn::RuntimeImpl runtime(options);
telsoa014fcda012018-03-09 14:13:49 +0000402 armnn::RuntimeLoadedNetworksReserve(&runtime);
403
telsoa014fcda012018-03-09 14:13:49 +0000404 {
Keith Davis97da5e22020-03-05 16:25:28 +0000405 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa014fcda012018-03-09 14:13:49 +0000406
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000407 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
telsoa014fcda012018-03-09 14:13:49 +0000408 mockNetwork1->AddInputLayer(0, "test layer");
409
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000410 // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
telsoa01c577f2c2018-08-31 09:22:23 +0100411 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000412 runtime.UnloadNetwork(networkIdentifier1);
413
414 // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
415 VALGRIND_DO_QUICK_LEAK_CHECK;
416 VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
417
418 // The actual test.
419 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
420 runtime.UnloadNetwork(networkIdentifier1);
421
422 VALGRIND_DO_ADDED_LEAK_CHECK;
423 VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000424 }
425
telsoa01c577f2c2018-08-31 09:22:23 +0100426 // 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 +0100427 CHECK(leakedBefore == leakedAfter);
428 CHECK(reachableBefore == reachableAfter);
telsoa014fcda012018-03-09 14:13:49 +0000429
telsoa01c577f2c2018-08-31 09:22:23 +0100430 // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters
431 // so they are assigned to, but still considered unused, causing a warning.
Jim Flynn9265a882022-03-10 23:35:26 +0000432 armnn::IgnoreUnused(dubious);
433 armnn::IgnoreUnused(suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000434}
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +0100435#endif // WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100436
Sadik Armagan1625efc2021-06-10 18:24:34 +0100437TEST_CASE("RuntimeCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100438{
439 using namespace armnn;
440
441 // Create runtime in which test will run
442 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000443 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100444
445 // build up the structure of the network
446 INetworkPtr net(INetwork::Create());
447
448 IConnectableLayer* input = net->AddInputLayer(0);
449
450 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
451 NormalizationDescriptor descriptor;
452 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
453
454 IConnectableLayer* output = net->AddOutputLayer(0);
455
456 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
457 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
458
459 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
460 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
461
462 // optimize the network
David Beckf0b48452018-10-19 15:20:56 +0100463 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Keith Davis97da5e22020-03-05 16:25:28 +0000464 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100465
466 // Load it into the runtime. It should success.
467 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100468 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100469}
470
Sadik Armagan1625efc2021-06-10 18:24:34 +0100471TEST_CASE("RuntimeFallbackToCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100472{
473 using namespace armnn;
474
475 // Create runtime in which test will run
476 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000477 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100478
479 // build up the structure of the network
480 INetworkPtr net(INetwork::Create());
481
482 IConnectableLayer* input = net->AddInputLayer(0);
483
484 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
485 NormalizationDescriptor descriptor;
486 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
487
488 IConnectableLayer* output = net->AddOutputLayer(0);
489
490 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
491 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
492
493 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
494 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
495
496 // Allow fallback to CpuRef.
David Beckf0b48452018-10-19 15:20:56 +0100497 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +0100498 // optimize the network
Keith Davis97da5e22020-03-05 16:25:28 +0000499 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100500
501 // Load it into the runtime. It should succeed.
502 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100503 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100504}
505
Sadik Armagan1625efc2021-06-10 18:24:34 +0100506TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue")
jimfly016b0b53d2018-10-08 14:43:01 +0100507{
508 // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
509 using namespace armnn;
510
511 // Create runtime in which test will run
512 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000513 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
jimfly016b0b53d2018-10-08 14:43:01 +0100514
515 // build up the structure of the network
516 INetworkPtr net(INetwork::Create());
Keith Davis97da5e22020-03-05 16:25:28 +0000517 armnn::IConnectableLayer* input = net->AddInputLayer(0,"input");
518 armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax");
519 armnn::IConnectableLayer* output = net->AddOutputLayer(0, "output");
jimfly016b0b53d2018-10-08 14:43:01 +0100520
521 input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
522 softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
523
Keith Davis97da5e22020-03-05 16:25:28 +0000524 input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
525 armnn::DataType::QAsymmU8,
526 1.0f / 255,
527 0));
jimfly016b0b53d2018-10-08 14:43:01 +0100528
Keith Davis97da5e22020-03-05 16:25:28 +0000529 softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
530 armnn::DataType::QAsymmU8));
jimfly016b0b53d2018-10-08 14:43:01 +0100531
Keith Davis97da5e22020-03-05 16:25:28 +0000532 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
533 std::vector<std::string> errMessages;
Mike Kelly3a613cc2020-09-29 20:50:35 +0100534
535 try
536 {
537 armnn::IOptimizedNetworkPtr optNet = Optimize(*net,
Keith Davis97da5e22020-03-05 16:25:28 +0000538 backends,
539 runtime->GetDeviceSpec(),
540 OptimizerOptions(),
541 errMessages);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100542 FAIL("An exception should have been thrown");
Mike Kelly3a613cc2020-09-29 20:50:35 +0100543 }
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000544 catch (const armnn::InvalidArgumentException&)
Mike Kelly3a613cc2020-09-29 20:50:35 +0100545 {
546 // Different exceptions are thrown on different backends
547 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100548 CHECK(errMessages.size() > 0);
jimfly016b0b53d2018-10-08 14:43:01 +0100549}
550
Sadik Armagan1625efc2021-06-10 18:24:34 +0100551TEST_CASE("RuntimeBackendOptions")
Derek Lamberti836b27b2019-11-20 10:51:57 +0000552{
553 using namespace armnn;
554
555 IRuntime::CreationOptions creationOptions;
556 auto& backendOptions = creationOptions.m_BackendOptions;
557
558
559 // Define Options on explicit construction
560 BackendOptions options1("FakeBackend1",
Keith Davis97da5e22020-03-05 16:25:28 +0000561 {
562 { "Option1", 1.3f },
563 { "Option2", true }
564 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000565
566 // Add an option after construction
Keith Davis97da5e22020-03-05 16:25:28 +0000567 options1.AddOption({ "Option3", "some_value" });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000568
569 // Add the options to CreationOptions struct
570 backendOptions.push_back(options1);
571
572 // Add more Options via inplace explicit construction
Keith Davis97da5e22020-03-05 16:25:28 +0000573 backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
574 {{ "Option4", 42 }}
575 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000576
577
578 // First group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100579 CHECK(backendOptions[0].GetBackendId().Get() == "FakeBackend1");
580 CHECK(backendOptions[0].GetOption(0).GetName() == "Option1");
581 CHECK(backendOptions[0].GetOption(0).GetValue().IsFloat() == true);
582 CHECK(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000583
Sadik Armagan1625efc2021-06-10 18:24:34 +0100584 CHECK(backendOptions[0].GetOption(1).GetName() == "Option2");
585 CHECK(backendOptions[0].GetOption(1).GetValue().IsBool() == true);
586 CHECK(backendOptions[0].GetOption(1).GetValue().AsBool() == true);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000587
Sadik Armagan1625efc2021-06-10 18:24:34 +0100588 CHECK(backendOptions[0].GetOption(2).GetName() == "Option3");
589 CHECK(backendOptions[0].GetOption(2).GetValue().IsString() == true);
590 CHECK(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value");
Derek Lamberti836b27b2019-11-20 10:51:57 +0000591
592 // Second group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100593 CHECK(backendOptions[1].GetBackendId().Get() == "FakeBackend1");
594 CHECK(backendOptions[1].GetOption(0).GetName() == "Option4");
595 CHECK(backendOptions[1].GetOption(0).GetValue().IsInt() == true);
596 CHECK(backendOptions[1].GetOption(0).GetValue().AsInt() == 42);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000597}
598
Sadik Armagan1625efc2021-06-10 18:24:34 +0100599TEST_CASE("ProfilingDisable")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000600{
601 using namespace armnn;
602
603 // Create runtime in which the test will run
604 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000605 armnn::RuntimeImpl runtime(options);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000606
607 // build up the structure of the network
608 INetworkPtr net(INetwork::Create());
609
610 IConnectableLayer* input = net->AddInputLayer(0);
611
612 // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
613 NormalizationDescriptor descriptor;
614 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
615
616 IConnectableLayer* output = net->AddOutputLayer(0);
617
618 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
619 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
620
621 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
622 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
623
624 // optimize the network
625 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000626 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000627
628 // Load it into the runtime. It should succeed.
629 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100630 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000631
Jim Flynn34430252022-03-04 15:03:58 +0000632 armnn::ArmNNProfilingServiceInitialiser initialiser;
633 ProfilingServiceRuntimeHelper profilingServiceHelper(
634 arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000635 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000636 auto readableBuffer = bufferManager.GetReadableBuffer();
637
638 // Profiling is not enabled, the post-optimisation structure should not be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100639 CHECK(!readableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000640}
641
Sadik Armagan1625efc2021-06-10 18:24:34 +0100642TEST_CASE("ProfilingEnableCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000643{
644 using namespace armnn;
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000645 using namespace arm::pipe;
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000646
647 // Create runtime in which the test will run
648 armnn::IRuntime::CreationOptions options;
649 options.m_ProfilingOptions.m_EnableProfiling = true;
Keith Davis33ed2212020-03-30 10:43:41 +0100650 options.m_ProfilingOptions.m_TimelineEnabled = true;
651
Kevin Mayd92a6e42021-02-04 10:27:41 +0000652 armnn::RuntimeImpl runtime(options);
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000653 GetProfilingService(&runtime).ResetExternalProfilingOptions(
654 ConvertExternalProfilingOptions(options.m_ProfilingOptions), false);
Keith Davis33ed2212020-03-30 10:43:41 +0100655
Jim Flynn34430252022-03-04 15:03:58 +0000656 armnn::ArmNNProfilingServiceInitialiser initialiser;
657 ProfilingServiceRuntimeHelper profilingServiceHelper(
658 arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
Keith Davis33ed2212020-03-30 10:43:41 +0100659 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
660 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
661 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000662
663 // build up the structure of the network
664 INetworkPtr net(INetwork::Create());
665
666 IConnectableLayer* input = net->AddInputLayer(0, "input");
667
668 NormalizationDescriptor descriptor;
669 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
670
671 IConnectableLayer* output = net->AddOutputLayer(0, "output");
672
673 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
674 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
675
676 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
677 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
678
679 // optimize the network
680 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000681 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000682
683 ProfilingGuid optNetGuid = optNet->GetGuid();
684
685 // Load it into the runtime. It should succeed.
686 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100687 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000688
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000689 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000690 auto readableBuffer = bufferManager.GetReadableBuffer();
691
692 // Profiling is enabled, the post-optimisation structure should be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100693 CHECK(readableBuffer != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000694
695 unsigned int size = readableBuffer->GetSize();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000696
697 const unsigned char* readableData = readableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100698 CHECK(readableData != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000699
700 unsigned int offset = 0;
701
Keith Davis97da5e22020-03-05 16:25:28 +0000702 // Verify Header
Jim Flynnf7713212020-07-14 09:50:59 +0100703 VerifyTimelineHeaderBinary(readableData, offset, size - 8);
Keith Davis97da5e22020-03-05 16:25:28 +0000704
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000705 // Post-optimisation network
706 // Network entity
Jim Flynn6398a982020-05-27 17:05:21 +0100707 VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000708
709 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000710 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
711 EmptyOptional(),
712 optNetGuid,
713 LabelsAndEventClasses::NETWORK_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000714 LabelsAndEventClasses::TYPE_GUID,
715 readableData,
716 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000717
Jim Flynnf7713212020-07-14 09:50:59 +0100718 // Network - START OF LIFE
719 ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(),
720 EmptyOptional(),
721 EmptyOptional(),
722 readableData,
723 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100724
725 // Network - START OF LIFE event relationship
726 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
727 EmptyOptional(),
728 optNetGuid,
729 networkSolEventGuid,
730 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
731 readableData,
732 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100733
734 // Process ID Label
735 int processID = armnnUtils::Processes::GetCurrentId();
736 std::stringstream ss;
737 ss << processID;
738 std::string processIdLabel = ss.str();
739 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100740
741 // Entity - Process ID relationship
742 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
743 EmptyOptional(),
744 optNetGuid,
745 EmptyOptional(),
746 LabelsAndEventClasses::PROCESS_ID_GUID,
747 readableData,
748 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100749
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000750 // Input layer
751 // Input layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000752 VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000753
754 // Name Entity
Jim Flynn6398a982020-05-27 17:05:21 +0100755 ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000756
757 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000758 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
759 EmptyOptional(),
760 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100761 inputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000762 LabelsAndEventClasses::NAME_GUID,
763 readableData,
764 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000765
766 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000767 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
768 EmptyOptional(),
769 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100770 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000771 LabelsAndEventClasses::TYPE_GUID,
772 readableData,
773 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000774
775 // Network - Input layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000776 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
777 EmptyOptional(),
778 optNetGuid,
779 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100780 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000781 readableData,
782 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000783
784 // Normalization layer
785 // Normalization layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000786 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000787
788 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100789 ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData(
790 EmptyOptional(), "normalization", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000791
792 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000793 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
794 EmptyOptional(),
795 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100796 normalizationLayerNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000797 LabelsAndEventClasses::NAME_GUID,
798 readableData,
799 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000800
801 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000802 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
803 EmptyOptional(),
804 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100805 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000806 LabelsAndEventClasses::TYPE_GUID,
807 readableData,
808 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000809
810 // Network - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000811 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
812 EmptyOptional(),
813 optNetGuid,
814 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100815 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000816 readableData,
817 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000818
819 // Input layer - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000820 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
821 EmptyOptional(),
822 input->GetGuid(),
823 normalize->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000824 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000825 readableData,
826 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000827
828 // Normalization workload
829 // Normalization workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100830 ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
831 EmptyOptional(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000832
833 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000834 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
835 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100836 normalizationWorkloadGuid,
837 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000838 LabelsAndEventClasses::TYPE_GUID,
839 readableData,
840 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000841
842 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100843 ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
844 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000845
846 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000847 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
848 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100849 normalizationWorkloadGuid,
850 cpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000851 LabelsAndEventClasses::BACKENDID_GUID,
852 readableData,
853 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000854
855 // Normalize layer - Normalize workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000856 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
857 EmptyOptional(),
858 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100859 normalizationWorkloadGuid,
860 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000861 readableData,
862 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000863
864 // Output layer
865 // Output layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000866 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000867
868 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100869 ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
870 EmptyOptional(), "output", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000871
872 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000873 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
874 EmptyOptional(),
875 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100876 outputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000877 LabelsAndEventClasses::NAME_GUID,
878 readableData,
879 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000880
881 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000882 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
883 EmptyOptional(),
884 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100885 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000886 LabelsAndEventClasses::TYPE_GUID,
887 readableData,
888 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000889
890 // Network - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000891 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
892 EmptyOptional(),
893 optNetGuid,
894 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100895 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000896 readableData,
897 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000898
899 // Normalize layer - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000900 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
901 EmptyOptional(),
902 normalize->GetGuid(),
903 output->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000904 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000905 readableData,
906 offset);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000907
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000908 bufferManager.MarkRead(readableBuffer);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000909
910 // Creates structures for input & output.
911 std::vector<float> inputData(16);
912 std::vector<float> outputData(16);
913
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100914 TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
915 inputTensorInfo.SetConstant(true);
Keith Davis97da5e22020-03-05 16:25:28 +0000916 InputTensors inputTensors
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000917 {
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100918 {0, ConstTensor(inputTensorInfo, inputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000919 };
920 OutputTensors outputTensors
921 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000922 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000923 };
924
925 // Does the inference.
Sadik Armagan3184c902020-03-18 10:57:30 +0000926 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000927
Finn Williamsb6a402f2020-03-24 13:46:22 +0000928 // Get readable buffer for input workload
929 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100930 CHECK(inputReadableBuffer != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +0000931
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000932 // Get readable buffer for output workload
933 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100934 CHECK(outputReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000935
Finn Williamsb6a402f2020-03-24 13:46:22 +0000936 // Get readable buffer for inference timeline
937 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100938 CHECK(inferenceReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000939
940 // Validate input workload data
941 size = inputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100942 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000943
944 readableData = inputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100945 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000946
947 offset = 0;
948
Keith Davis97da5e22020-03-05 16:25:28 +0000949 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100950 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000951
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000952 // Input workload
953 // Input workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100954 ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000955
956 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000957 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
958 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100959 inputWorkloadGuid,
960 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000961 LabelsAndEventClasses::TYPE_GUID,
962 readableData,
963 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000964
965 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100966 ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
967 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000968
969 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000970 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
971 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100972 inputWorkloadGuid,
973 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000974 LabelsAndEventClasses::BACKENDID_GUID,
975 readableData,
976 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000977
978 // Input layer - Input workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000979 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
980 EmptyOptional(),
981 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100982 inputWorkloadGuid,
983 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000984 readableData,
985 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000986
987 bufferManager.MarkRead(inputReadableBuffer);
988
989 // Validate output workload data
990 size = outputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100991 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000992
993 readableData = outputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100994 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000995
996 offset = 0;
997
Keith Davis97da5e22020-03-05 16:25:28 +0000998 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100999 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +00001000
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001001 // Output workload
1002 // Output workload entity
Jim Flynn6398a982020-05-27 17:05:21 +01001003 ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001004
1005 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001006 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1007 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001008 outputWorkloadGuid,
1009 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001010 LabelsAndEventClasses::TYPE_GUID,
1011 readableData,
1012 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001013
1014 // BackendId entity
Keith Davis97da5e22020-03-05 16:25:28 +00001015 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001016
1017 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001018 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1019 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001020 outputWorkloadGuid,
1021 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001022 LabelsAndEventClasses::BACKENDID_GUID,
1023 readableData,
1024 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001025
1026 // Output layer - Output workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001027 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1028 EmptyOptional(),
1029 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +01001030 outputWorkloadGuid,
1031 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001032 readableData,
1033 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001034
1035 bufferManager.MarkRead(outputReadableBuffer);
David Monahan6198fe02019-12-02 08:35:43 +00001036
1037 // Validate inference data
1038 size = inferenceReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001039 CHECK(size == 976 + 8 * ThreadIdSize);
David Monahan6198fe02019-12-02 08:35:43 +00001040
1041 readableData = inferenceReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001042 CHECK(readableData != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +00001043
1044 offset = 0;
1045
Keith Davis97da5e22020-03-05 16:25:28 +00001046 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001047 VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize);
Keith Davis97da5e22020-03-05 16:25:28 +00001048
David Monahan6198fe02019-12-02 08:35:43 +00001049 // Inference timeline trace
1050 // Inference entity
Jim Flynn6398a982020-05-27 17:05:21 +01001051 ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001052
1053 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001054 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1055 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001056 inferenceGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001057 LabelsAndEventClasses::INFERENCE_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001058 LabelsAndEventClasses::TYPE_GUID,
1059 readableData,
1060 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001061
1062 // Network - Inference relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001063 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1064 EmptyOptional(),
1065 optNetGuid,
Jim Flynn6398a982020-05-27 17:05:21 +01001066 inferenceGuid,
1067 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001068 readableData,
1069 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001070
1071 // Start Inference life
1072 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001073 ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
1074 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001075
1076 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001077 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1078 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001079 inferenceGuid,
1080 inferenceEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001081 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1082 readableData,
1083 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001084
1085 // Execution
1086 // Input workload execution
1087 // Input workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001088 ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1089 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001090
1091 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001092 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1093 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001094 inputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001095 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001096 LabelsAndEventClasses::TYPE_GUID,
1097 readableData,
1098 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001099
1100 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001101 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1102 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001103 inferenceGuid,
1104 inputWorkloadExecutionGuid,
1105 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001106 readableData,
1107 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001108
1109 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001110 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1111 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001112 inputWorkloadGuid,
1113 inputWorkloadExecutionGuid,
1114 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001115 readableData,
1116 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001117
1118 // Start Input workload execution life
1119 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001120 ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
1121 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001122
1123 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001124 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1125 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001126 inputWorkloadExecutionGuid,
1127 inputWorkloadExecutionSOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001128 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1129 readableData,
1130 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001131
1132 // End of Input workload execution life
1133 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001134 ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
1135 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001136
1137 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001138 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1139 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001140 inputWorkloadExecutionGuid,
1141 inputWorkloadExecutionEOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001142 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1143 readableData,
1144 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001145
1146 // Normalize workload execution
1147 // Normalize workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001148 ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1149 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001150
1151 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001152 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1153 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001154 normalizeWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001155 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001156 LabelsAndEventClasses::TYPE_GUID,
1157 readableData,
1158 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001159
1160 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001161 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1162 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001163 inferenceGuid,
1164 normalizeWorkloadExecutionGuid,
1165 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001166 readableData,
1167 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001168
1169 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001170 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1171 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001172 normalizationWorkloadGuid,
1173 normalizeWorkloadExecutionGuid,
1174 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001175 readableData,
1176 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001177
1178 // Start Normalize workload execution life
1179 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001180 ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1181 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001182
1183 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001184 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1185 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001186 normalizeWorkloadExecutionGuid,
1187 normalizationWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001188 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1189 readableData,
1190 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001191
1192 // End of Normalize workload execution life
1193 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001194 ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1195 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001196
1197 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001198 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1199 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001200 normalizeWorkloadExecutionGuid,
1201 normalizationWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001202 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1203 readableData,
1204 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001205
1206 // Output workload execution
1207 // Output workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001208 ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1209 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001210
1211 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001212 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1213 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001214 outputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001215 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001216 LabelsAndEventClasses::TYPE_GUID,
1217 readableData,
1218 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001219
1220 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001221 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1222 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001223 inferenceGuid,
1224 outputWorkloadExecutionGuid,
1225 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001226 readableData,
1227 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001228
1229 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001230 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1231 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001232 outputWorkloadGuid,
1233 outputWorkloadExecutionGuid,
1234 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001235 readableData,
1236 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001237
1238 // Start Output workload execution life
1239 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001240 ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1241 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001242
1243 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001244 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1245 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001246 outputWorkloadExecutionGuid,
1247 outputWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001248 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1249 readableData,
1250 offset);
Finn Williams0a336dc2020-05-11 15:39:58 +01001251
David Monahan6198fe02019-12-02 08:35:43 +00001252 // End of Normalize workload execution life
1253 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001254 ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1255 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001256
1257 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001258 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1259 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001260 outputWorkloadExecutionGuid,
1261 outputWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001262 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1263 readableData,
1264 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001265
1266 // End of Inference life
1267 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001268 ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
1269 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001270
1271 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001272 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1273 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001274 inferenceGuid,
1275 inferenceEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001276 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1277 readableData,
1278 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001279
1280 bufferManager.MarkRead(inferenceReadableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001281}
1282
Sadik Armagan1625efc2021-06-10 18:24:34 +01001283TEST_CASE("ProfilingPostOptimisationStructureCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001284{
1285 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1286}
1287
Sadik Armagan1625efc2021-06-10 18:24:34 +01001288}