blob: fc16dbbad96fb11406b7299e023708b55d3e8b38 [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
Jim Flynn77b284e2022-03-13 20:53:35 +00006#include <ArmNNProfilingServiceInitialiser.hpp>
7#include <ProfilingOptionsConverter.hpp>
8#include <Runtime.hpp>
9
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010010#include <armnn/Descriptors.hpp>
11#include <armnn/IRuntime.hpp>
12#include <armnn/INetwork.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010013#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000014
Jim Flynn77b284e2022-03-13 20:53:35 +000015#include <armnn/profiling/ArmNNProfiling.hpp>
16
Nikhil Raj77fe76b2021-06-09 14:55:32 +010017#include <common/include/LabelsAndEventClasses.hpp>
Jim Flynn77b284e2022-03-13 20:53:35 +000018#include <common/include/Processes.hpp>
19
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000020#include <test/ProfilingTestUtils.hpp>
21
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000022#include <HeapProfiling.hpp>
23#include <LeakChecking.hpp>
telsoa014fcda012018-03-09 14:13:49 +000024
25#ifdef WITH_VALGRIND
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010026#include <valgrind/memcheck.h>
telsoa014fcda012018-03-09 14:13:49 +000027#endif
28
Sadik Armagan1625efc2021-06-10 18:24:34 +010029#include <doctest/doctest.h>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000030#include "RuntimeTests.hpp"
Sadik Armagana097d2a2021-11-24 15:47:28 +000031#include <TestUtils.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010032
telsoa014fcda012018-03-09 14:13:49 +000033namespace armnn
34{
35
Kevin Mayd92a6e42021-02-04 10:27:41 +000036void RuntimeLoadedNetworksReserve(armnn::RuntimeImpl* runtime)
telsoa014fcda012018-03-09 14:13:49 +000037{
38 runtime->m_LoadedNetworks.reserve(1);
39}
40
Jim Flynn6c9f17d2022-03-10 23:13:01 +000041} // namespace armnn
telsoa014fcda012018-03-09 14:13:49 +000042
Sadik Armagan1625efc2021-06-10 18:24:34 +010043TEST_SUITE("Runtime")
44{
45TEST_CASE("RuntimeUnloadNetwork")
telsoa014fcda012018-03-09 14:13:49 +000046{
47 // build 2 mock-networks and load them into the runtime
telsoa01c577f2c2018-08-31 09:22:23 +010048 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +000049 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa014fcda012018-03-09 14:13:49 +000050
telsoa01c577f2c2018-08-31 09:22:23 +010051 // Mock network 1.
Keith Davis97da5e22020-03-05 16:25:28 +000052 armnn::NetworkId networkIdentifier1 = 1;
telsoa014fcda012018-03-09 14:13:49 +000053 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
54 mockNetwork1->AddInputLayer(0, "test layer");
Keith Davis97da5e22020-03-05 16:25:28 +000055 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +010056 runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000057
telsoa01c577f2c2018-08-31 09:22:23 +010058 // Mock network 2.
Keith Davis97da5e22020-03-05 16:25:28 +000059 armnn::NetworkId networkIdentifier2 = 2;
telsoa014fcda012018-03-09 14:13:49 +000060 armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create());
61 mockNetwork2->AddInputLayer(0, "test layer");
telsoa01c577f2c2018-08-31 09:22:23 +010062 runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000063
telsoa01c577f2c2018-08-31 09:22:23 +010064 // Unloads one by its networkID.
Sadik Armagan1625efc2021-06-10 18:24:34 +010065 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
telsoa014fcda012018-03-09 14:13:49 +000066
Sadik Armagan1625efc2021-06-10 18:24:34 +010067 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
telsoa014fcda012018-03-09 14:13:49 +000068}
69
Finn Williamsf37b9702021-09-01 18:06:04 +010070TEST_CASE("RuntimePreImportInputs")
71{
72 armnn::IRuntime::CreationOptions options;
Finn Williams8636bc72021-10-02 15:06:39 +010073 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
74 armnn::NetworkId networkId = 1;
Finn Williamsf37b9702021-09-01 18:06:04 +010075 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Finn Williams8636bc72021-10-02 15:06:39 +010076
Finn Williamsf37b9702021-09-01 18:06:04 +010077 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
78 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 2 layer");
79 auto addLayer = testNetwork->AddAdditionLayer("add layer");
80 auto outputLayer = testNetwork->AddOutputLayer(2, "output layer");
81
82 TensorInfo tensorInfo{{4}, armnn::DataType::Signed32};
83
84 inputLayer1->GetOutputSlot(0).Connect(addLayer->GetInputSlot(0));
85 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
Finn Williams8636bc72021-10-02 15:06:39 +010086
Finn Williamsf37b9702021-09-01 18:06:04 +010087 inputLayer2->GetOutputSlot(0).Connect(addLayer->GetInputSlot(1));
88 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
89
90 addLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
91 addLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
92
Finn Williams8636bc72021-10-02 15:06:39 +010093 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
Finn Williamsf37b9702021-09-01 18:06:04 +010094
95 std::string er;
96 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Undefined);
Finn Williams8636bc72021-10-02 15:06:39 +010097 runtime->LoadNetwork(networkId,
Finn Williamsf37b9702021-09-01 18:06:04 +010098 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
99 er,
100 networkProperties);
101
102 std::vector<int> inputData1(4, 10);
103 std::vector<int> inputData2(4, 20);
104 std::vector<int> output(4);
105
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100106 ConstTensor inputTensor1({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData1.data());
107 ConstTensor inputTensor2({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData2.data());
Finn Williamsf37b9702021-09-01 18:06:04 +0100108 Tensor outputTensor({{4}, armnn::DataType::Signed32}, output.data());
109
Finn Williams8636bc72021-10-02 15:06:39 +0100110 auto importedInputVec1 = runtime->ImportInputs(networkId, {{0, inputTensor1}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100111 CHECK(importedInputVec1.size() == 1);
112 CHECK(importedInputVec1[0] == 0);
113
Finn Williams8636bc72021-10-02 15:06:39 +0100114 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
Finn Williamsf37b9702021-09-01 18:06:04 +0100115
116 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100117 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100118 CHECK(val == 30);
119 }
120
Finn Williams8636bc72021-10-02 15:06:39 +0100121 auto importedInputVec2 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100122 CHECK(importedInputVec2.size() == 1);
123 CHECK(importedInputVec2[0] == 1);
124
125 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {{2, outputTensor}}, {1 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100126 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100127 CHECK(val == 30);
128 }
129
130 runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1});
Finn Williams8636bc72021-10-02 15:06:39 +0100131 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100132 CHECK(val == 30);
133 }
Finn Williamsf37b9702021-09-01 18:06:04 +0100134 // Duplicate ImportedInputId and LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100135 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 0});,
136 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100137 // Duplicate LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100138 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {1});,
139 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100140 // Incorrect ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100141 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {10});,
142 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100143 // Incorrect LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100144 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {1});,
145 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100146 // Incorrect layer binding id and ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100147 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {10});,
148 armnn::InvalidArgumentException);
149 auto importedInputVec3 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100150 CHECK(importedInputVec3[0] == 2);
151 // Too many ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100152 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1, 2});,
153 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100154 // Too many InputTensors
155 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(),
Finn Williams8636bc72021-10-02 15:06:39 +0100156 {{0, inputTensor2},
157 {1, inputTensor2},
158 {2, inputTensor2}},
159 {{2, outputTensor}});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100160 // Too few ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100161 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0});,
162 armnn::InvalidArgumentException);
163 runtime->ClearImportedInputs(networkId, {1});
164 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0}, {});
165 for (auto val: output) {
166 CHECK(val == 30);
167 }
168 // Using deleted pre-imported input
169 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}, {});,
170 armnn::InvalidArgumentException);
171
172 // Trying to delete deleted pre-imported tensor
173 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {1});, armnn::InvalidArgumentException);
174
175 // Trying to delete unknown pre-imported tensor
176 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {10});, armnn::InvalidArgumentException);
177}
178TEST_CASE("RuntimePreImportOutputs")
179{
180 armnn::IRuntime::CreationOptions options;
181 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
182
183 armnn::NetworkId networkId = 1;
184
185 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100186 TensorInfo tensorInfo{{4}, armnn::DataType::Float32, 0.0f, 0, true};
Finn Williams8636bc72021-10-02 15:06:39 +0100187
188 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
189 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
190
191 ActivationDescriptor activationDescriptor;
192 activationDescriptor.m_Function = ActivationFunction::BoundedReLu;
193 activationDescriptor.m_A = 2.0f;
194 activationDescriptor.m_B = 0.0f;
195 auto activationLayer1 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
196 auto outputLayer1 = testNetwork->AddOutputLayer(2, "output layer");
197
198 inputLayer1->GetOutputSlot(0).Connect(activationLayer1->GetInputSlot(0));
199
200 activationLayer1->GetOutputSlot(0).Connect(outputLayer1->GetInputSlot(0));
201 activationLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
202
203 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 1 layer");
204
205 activationDescriptor.m_A = 4.0f;
206 activationDescriptor.m_B = 2.0f;
207 auto activationLayer2 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
208 auto outputLayer2 = testNetwork->AddOutputLayer(3, "output layer");
209
210 inputLayer2->GetOutputSlot(0).Connect(activationLayer2->GetInputSlot(0));
211 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
212
213 activationLayer2->GetOutputSlot(0).Connect(outputLayer2->GetInputSlot(0));
214 activationLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
215
216 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
217
218 std::string er;
219 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Malloc);
220 runtime->LoadNetwork(networkId,
221 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
222 er,
223 networkProperties);
224
225 std::vector<float> inputData1(4, 1.0f);
226 std::vector<float> inputData2(4, 3.0f);
227
228 std::vector<float> outputData1(4);
229 std::vector<float> outputData2(4);
230
231 ConstTensor inputTensor1(tensorInfo, inputData1.data());
232 ConstTensor inputTensor2(tensorInfo, inputData2.data());
233
234 Tensor outputTensor1{tensorInfo, outputData1.data()};
235 Tensor outputTensor2{tensorInfo, outputData2.data()};
236
237 InputTensors inputTensors = {{0, inputTensor1}, {1, inputTensor2}};
238
239 std::pair<LayerBindingId, class Tensor> output1{2, outputTensor1};
240 std::pair<LayerBindingId, class Tensor> output2{3, outputTensor2};
241
242 auto testOutputs = [&]()
243 {
244 for (auto val : outputData1)
245 {
246 CHECK(val == 1.0f);
247 }
248
249 for (auto val : outputData2)
250 {
251 CHECK(val == 3.0f);
252 }
253 };
254
255 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
256
257 runtime->Execute(*memHandle.get(),inputTensors, {output1, output2});
258 testOutputs();
259
260 auto importedOutputVec = runtime->ImportOutputs(networkId, {output1, output2 });
261 CHECK(importedOutputVec.size() == 2);
262 CHECK(importedOutputVec[0] == 0);
263 CHECK(importedOutputVec[1] == 1);
264
265 runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec);
266 testOutputs();
267
268 runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {1});
269 testOutputs();
270
271 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
272 testOutputs();
273
274 auto importedInputVec = runtime->ImportInputs(networkId, inputTensors);
275 CHECK(importedInputVec.size() == 2);
276 CHECK(importedInputVec[0] == 0);
277 CHECK(importedInputVec[1] == 1);
278
279 runtime->Execute(*memHandle.get(), {}, {}, importedInputVec, importedOutputVec);
280 testOutputs();
281
282 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {output2}, {1}, {0});
283 testOutputs();
284
285 // Too many ids
286 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output2}, {}, {0, 1});,
287 armnn::InvalidArgumentException);
288
289 // Duplicate ids
290 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {1});,
291 armnn::InvalidArgumentException);
292
293 // Duplicate ids
294 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output1}, {}, {});,
295 armnn::InvalidArgumentException);
296
297 // Duplicate ids
298 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, {0, 0}),
299 armnn::InvalidArgumentException);
300
301 // Unknown id
302 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {3});,
303 armnn::InvalidArgumentException);
304
305 // Unknown id
306 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{4, outputTensor2}}, {}, {1});,
307 armnn::InvalidArgumentException);
308
309 // Input id for output
310 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
311 armnn::InvalidArgumentException);
312
313 // Input id for output
314 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});,
315 armnn::InvalidArgumentException);
316
317 // Output id for input
318 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{2, inputTensor1}}, {{0, outputTensor2}}, {1}, {1, 0});,
319 armnn::InvalidArgumentException);
320
321 runtime->ClearImportedOutputs(networkId, {1});
322
323 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
324 testOutputs();
325
326 // Trying to use deleted pre-imported tensor
327 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec),
328 armnn::InvalidArgumentException);
329
330 // Trying to delete deleted pre-imported tensor
331 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {1});, armnn::InvalidArgumentException);
332
333 // Trying to delete unknown pre-imported tensor
334 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {10});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100335}
336
surmeh013537c2c2018-05-18 16:31:43 +0100337// Note: the current builds we don't do valgrind and gperftools based leak checking at the same
telsoa01c577f2c2018-08-31 09:22:23 +0100338// time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The
339// valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow
340// to be integrated into the CI system.
surmeh013537c2c2018-05-18 16:31:43 +0100341
telsoa01c577f2c2018-08-31 09:22:23 +0100342#ifdef ARMNN_LEAK_CHECKING_ENABLED
343
344struct DisableGlobalLeakChecking
345{
346 DisableGlobalLeakChecking()
347 {
348 ARMNN_LOCAL_LEAK_CHECKING_ONLY();
349 }
350};
351
Sadik Armagan1625efc2021-06-10 18:24:34 +0100352TEST_CASE_FIXTURE(DisableGlobalLeakChecking, "RuntimeHeapMemoryUsageSanityChecks")
surmeh013537c2c2018-05-18 16:31:43 +0100353{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100354 CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE());
surmeh013537c2c2018-05-18 16:31:43 +0100355 {
356 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
357 {
358 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100359 CHECK(ARMNN_NO_LEAKS_IN_SCOPE() == true);
surmeh013537c2c2018-05-18 16:31:43 +0100360 std::unique_ptr<char[]> dummyAllocation(new char[1000]);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100361 // "A leak of 1000 bytes is expected here. "
362 // "Please make sure environment variable: HEAPCHECK=draconian is set!"
363 CHECK((ARMNN_NO_LEAKS_IN_SCOPE() == false));
364 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000);
365 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1);
surmeh013537c2c2018-05-18 16:31:43 +0100366 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100367 CHECK(ARMNN_NO_LEAKS_IN_SCOPE());
368 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0);
369 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0);
surmeh013537c2c2018-05-18 16:31:43 +0100370 }
371}
372
surmeh013537c2c2018-05-18 16:31:43 +0100373#endif // ARMNN_LEAK_CHECKING_ENABLED
374
375// 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 +0000376#ifdef WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100377// Run with the following command to get all the amazing output (in the devenv/build folder) :)
telsoa014fcda012018-03-09 14:13:49 +0000378// 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 +0100379TEST_CASE("RuntimeMemoryLeak")
telsoa014fcda012018-03-09 14:13:49 +0000380{
381 // From documentation:
382
383 // This means that no pointer to the block can be found. The block is classified as "lost",
384 // because the programmer could not possibly have freed it at program exit, since no pointer to it exists.
385 unsigned long leakedBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000386 unsigned long leakedAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000387
388 // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at,
389 // the programmer could, at least in principle, have freed it before program exit.
telsoa01c577f2c2018-08-31 09:22:23 +0100390 // We want to test this in case memory is not freed as early as it could have been.
telsoa014fcda012018-03-09 14:13:49 +0000391 unsigned long reachableBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000392 unsigned long reachableAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000393
telsoa01c577f2c2018-08-31 09:22:23 +0100394 // Needed as out params but we don't test them.
Keith Davis97da5e22020-03-05 16:25:28 +0000395 unsigned long dubious = 0;
telsoa014fcda012018-03-09 14:13:49 +0000396 unsigned long suppressed = 0;
397
398 armnn::NetworkId networkIdentifier1 = 1;
399
400 // ensure that runtime is large enough before checking for memory leaks
401 // otherwise when loading the network it will automatically reserve memory that won't be released until destruction
telsoa01c577f2c2018-08-31 09:22:23 +0100402 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000403 armnn::RuntimeImpl runtime(options);
telsoa014fcda012018-03-09 14:13:49 +0000404 armnn::RuntimeLoadedNetworksReserve(&runtime);
405
telsoa014fcda012018-03-09 14:13:49 +0000406 {
Keith Davis97da5e22020-03-05 16:25:28 +0000407 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa014fcda012018-03-09 14:13:49 +0000408
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000409 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
telsoa014fcda012018-03-09 14:13:49 +0000410 mockNetwork1->AddInputLayer(0, "test layer");
411
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000412 // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
telsoa01c577f2c2018-08-31 09:22:23 +0100413 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000414 runtime.UnloadNetwork(networkIdentifier1);
415
416 // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
417 VALGRIND_DO_QUICK_LEAK_CHECK;
418 VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
419
420 // The actual test.
421 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
422 runtime.UnloadNetwork(networkIdentifier1);
423
424 VALGRIND_DO_ADDED_LEAK_CHECK;
425 VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000426 }
427
telsoa01c577f2c2018-08-31 09:22:23 +0100428 // 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 +0100429 CHECK(leakedBefore == leakedAfter);
430 CHECK(reachableBefore == reachableAfter);
telsoa014fcda012018-03-09 14:13:49 +0000431
telsoa01c577f2c2018-08-31 09:22:23 +0100432 // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters
433 // so they are assigned to, but still considered unused, causing a warning.
Jim Flynn9265a882022-03-10 23:35:26 +0000434 armnn::IgnoreUnused(dubious);
435 armnn::IgnoreUnused(suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000436}
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +0100437#endif // WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100438
Sadik Armagan1625efc2021-06-10 18:24:34 +0100439TEST_CASE("RuntimeCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100440{
441 using namespace armnn;
442
443 // Create runtime in which test will run
444 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000445 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100446
447 // build up the structure of the network
448 INetworkPtr net(INetwork::Create());
449
450 IConnectableLayer* input = net->AddInputLayer(0);
451
452 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
453 NormalizationDescriptor descriptor;
454 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
455
456 IConnectableLayer* output = net->AddOutputLayer(0);
457
458 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
459 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
460
461 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
462 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
463
464 // optimize the network
David Beckf0b48452018-10-19 15:20:56 +0100465 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Keith Davis97da5e22020-03-05 16:25:28 +0000466 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100467
468 // Load it into the runtime. It should success.
469 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100470 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100471}
472
Sadik Armagan1625efc2021-06-10 18:24:34 +0100473TEST_CASE("RuntimeFallbackToCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100474{
475 using namespace armnn;
476
477 // Create runtime in which test will run
478 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000479 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100480
481 // build up the structure of the network
482 INetworkPtr net(INetwork::Create());
483
484 IConnectableLayer* input = net->AddInputLayer(0);
485
486 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
487 NormalizationDescriptor descriptor;
488 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
489
490 IConnectableLayer* output = net->AddOutputLayer(0);
491
492 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
493 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
494
495 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
496 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
497
498 // Allow fallback to CpuRef.
David Beckf0b48452018-10-19 15:20:56 +0100499 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +0100500 // optimize the network
Keith Davis97da5e22020-03-05 16:25:28 +0000501 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100502
503 // Load it into the runtime. It should succeed.
504 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100505 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100506}
507
Sadik Armagan1625efc2021-06-10 18:24:34 +0100508TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue")
jimfly016b0b53d2018-10-08 14:43:01 +0100509{
510 // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
511 using namespace armnn;
512
513 // Create runtime in which test will run
514 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000515 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
jimfly016b0b53d2018-10-08 14:43:01 +0100516
517 // build up the structure of the network
518 INetworkPtr net(INetwork::Create());
Keith Davis97da5e22020-03-05 16:25:28 +0000519 armnn::IConnectableLayer* input = net->AddInputLayer(0,"input");
520 armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax");
521 armnn::IConnectableLayer* output = net->AddOutputLayer(0, "output");
jimfly016b0b53d2018-10-08 14:43:01 +0100522
523 input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
524 softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
525
Keith Davis97da5e22020-03-05 16:25:28 +0000526 input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
527 armnn::DataType::QAsymmU8,
528 1.0f / 255,
529 0));
jimfly016b0b53d2018-10-08 14:43:01 +0100530
Keith Davis97da5e22020-03-05 16:25:28 +0000531 softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
532 armnn::DataType::QAsymmU8));
jimfly016b0b53d2018-10-08 14:43:01 +0100533
Keith Davis97da5e22020-03-05 16:25:28 +0000534 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
535 std::vector<std::string> errMessages;
Mike Kelly3a613cc2020-09-29 20:50:35 +0100536
537 try
538 {
539 armnn::IOptimizedNetworkPtr optNet = Optimize(*net,
Keith Davis97da5e22020-03-05 16:25:28 +0000540 backends,
541 runtime->GetDeviceSpec(),
542 OptimizerOptions(),
543 errMessages);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100544 FAIL("An exception should have been thrown");
Mike Kelly3a613cc2020-09-29 20:50:35 +0100545 }
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000546 catch (const armnn::InvalidArgumentException&)
Mike Kelly3a613cc2020-09-29 20:50:35 +0100547 {
548 // Different exceptions are thrown on different backends
549 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100550 CHECK(errMessages.size() > 0);
jimfly016b0b53d2018-10-08 14:43:01 +0100551}
552
Sadik Armagan1625efc2021-06-10 18:24:34 +0100553TEST_CASE("RuntimeBackendOptions")
Derek Lamberti836b27b2019-11-20 10:51:57 +0000554{
555 using namespace armnn;
556
557 IRuntime::CreationOptions creationOptions;
558 auto& backendOptions = creationOptions.m_BackendOptions;
559
560
561 // Define Options on explicit construction
562 BackendOptions options1("FakeBackend1",
Keith Davis97da5e22020-03-05 16:25:28 +0000563 {
564 { "Option1", 1.3f },
565 { "Option2", true }
566 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000567
568 // Add an option after construction
Keith Davis97da5e22020-03-05 16:25:28 +0000569 options1.AddOption({ "Option3", "some_value" });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000570
571 // Add the options to CreationOptions struct
572 backendOptions.push_back(options1);
573
574 // Add more Options via inplace explicit construction
Keith Davis97da5e22020-03-05 16:25:28 +0000575 backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
576 {{ "Option4", 42 }}
577 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000578
579
580 // First group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100581 CHECK(backendOptions[0].GetBackendId().Get() == "FakeBackend1");
582 CHECK(backendOptions[0].GetOption(0).GetName() == "Option1");
583 CHECK(backendOptions[0].GetOption(0).GetValue().IsFloat() == true);
584 CHECK(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000585
Sadik Armagan1625efc2021-06-10 18:24:34 +0100586 CHECK(backendOptions[0].GetOption(1).GetName() == "Option2");
587 CHECK(backendOptions[0].GetOption(1).GetValue().IsBool() == true);
588 CHECK(backendOptions[0].GetOption(1).GetValue().AsBool() == true);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000589
Sadik Armagan1625efc2021-06-10 18:24:34 +0100590 CHECK(backendOptions[0].GetOption(2).GetName() == "Option3");
591 CHECK(backendOptions[0].GetOption(2).GetValue().IsString() == true);
592 CHECK(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value");
Derek Lamberti836b27b2019-11-20 10:51:57 +0000593
594 // Second group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100595 CHECK(backendOptions[1].GetBackendId().Get() == "FakeBackend1");
596 CHECK(backendOptions[1].GetOption(0).GetName() == "Option4");
597 CHECK(backendOptions[1].GetOption(0).GetValue().IsInt() == true);
598 CHECK(backendOptions[1].GetOption(0).GetValue().AsInt() == 42);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000599}
600
Sadik Armagan1625efc2021-06-10 18:24:34 +0100601TEST_CASE("ProfilingDisable")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000602{
603 using namespace armnn;
604
Jim Flynn6c9f17d2022-03-10 23:13:01 +0000605 LogLevelSwapper logLevelSwapper(arm::pipe::LogSeverity::Fatal);
606
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000607 // Create runtime in which the test will run
608 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000609 armnn::RuntimeImpl runtime(options);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000610
611 // build up the structure of the network
612 INetworkPtr net(INetwork::Create());
613
614 IConnectableLayer* input = net->AddInputLayer(0);
615
616 // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
617 NormalizationDescriptor descriptor;
618 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
619
620 IConnectableLayer* output = net->AddOutputLayer(0);
621
622 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
623 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
624
625 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
626 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
627
628 // optimize the network
629 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000630 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000631
632 // Load it into the runtime. It should succeed.
633 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100634 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000635
Jim Flynn34430252022-03-04 15:03:58 +0000636 armnn::ArmNNProfilingServiceInitialiser initialiser;
637 ProfilingServiceRuntimeHelper profilingServiceHelper(
638 arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000639 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000640 auto readableBuffer = bufferManager.GetReadableBuffer();
641
642 // Profiling is not enabled, the post-optimisation structure should not be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100643 CHECK(!readableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000644}
645
Sadik Armagan1625efc2021-06-10 18:24:34 +0100646TEST_CASE("ProfilingEnableCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000647{
648 using namespace armnn;
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000649 using namespace arm::pipe;
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000650
651 // Create runtime in which the test will run
652 armnn::IRuntime::CreationOptions options;
653 options.m_ProfilingOptions.m_EnableProfiling = true;
Keith Davis33ed2212020-03-30 10:43:41 +0100654 options.m_ProfilingOptions.m_TimelineEnabled = true;
655
Kevin Mayd92a6e42021-02-04 10:27:41 +0000656 armnn::RuntimeImpl runtime(options);
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000657 GetProfilingService(&runtime).ResetExternalProfilingOptions(
658 ConvertExternalProfilingOptions(options.m_ProfilingOptions), false);
Keith Davis33ed2212020-03-30 10:43:41 +0100659
Jim Flynn34430252022-03-04 15:03:58 +0000660 armnn::ArmNNProfilingServiceInitialiser initialiser;
661 ProfilingServiceRuntimeHelper profilingServiceHelper(
662 arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
Keith Davis33ed2212020-03-30 10:43:41 +0100663 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
664 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
665 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000666
667 // build up the structure of the network
668 INetworkPtr net(INetwork::Create());
669
670 IConnectableLayer* input = net->AddInputLayer(0, "input");
671
672 NormalizationDescriptor descriptor;
673 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
674
675 IConnectableLayer* output = net->AddOutputLayer(0, "output");
676
677 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
678 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
679
680 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
681 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
682
683 // optimize the network
684 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000685 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000686
687 ProfilingGuid optNetGuid = optNet->GetGuid();
688
689 // Load it into the runtime. It should succeed.
690 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100691 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000692
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000693 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000694 auto readableBuffer = bufferManager.GetReadableBuffer();
695
696 // Profiling is enabled, the post-optimisation structure should be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100697 CHECK(readableBuffer != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000698
699 unsigned int size = readableBuffer->GetSize();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000700
701 const unsigned char* readableData = readableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100702 CHECK(readableData != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000703
704 unsigned int offset = 0;
705
Keith Davis97da5e22020-03-05 16:25:28 +0000706 // Verify Header
Jim Flynnf7713212020-07-14 09:50:59 +0100707 VerifyTimelineHeaderBinary(readableData, offset, size - 8);
Keith Davis97da5e22020-03-05 16:25:28 +0000708
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000709 // Post-optimisation network
710 // Network entity
Jim Flynn6398a982020-05-27 17:05:21 +0100711 VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000712
713 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000714 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
715 EmptyOptional(),
716 optNetGuid,
717 LabelsAndEventClasses::NETWORK_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000718 LabelsAndEventClasses::TYPE_GUID,
719 readableData,
720 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000721
Jim Flynnf7713212020-07-14 09:50:59 +0100722 // Network - START OF LIFE
723 ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(),
724 EmptyOptional(),
725 EmptyOptional(),
726 readableData,
727 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100728
729 // Network - START OF LIFE event relationship
730 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
731 EmptyOptional(),
732 optNetGuid,
733 networkSolEventGuid,
734 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
735 readableData,
736 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100737
738 // Process ID Label
Jim Flynn77b284e2022-03-13 20:53:35 +0000739 int processID = arm::pipe::GetCurrentId();
Jim Flynnf7713212020-07-14 09:50:59 +0100740 std::stringstream ss;
741 ss << processID;
742 std::string processIdLabel = ss.str();
743 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100744
745 // Entity - Process ID relationship
746 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
747 EmptyOptional(),
748 optNetGuid,
749 EmptyOptional(),
750 LabelsAndEventClasses::PROCESS_ID_GUID,
751 readableData,
752 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100753
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000754 // Input layer
755 // Input layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000756 VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000757
758 // Name Entity
Jim Flynn6398a982020-05-27 17:05:21 +0100759 ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000760
761 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000762 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
763 EmptyOptional(),
764 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100765 inputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000766 LabelsAndEventClasses::NAME_GUID,
767 readableData,
768 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000769
770 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000771 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
772 EmptyOptional(),
773 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100774 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000775 LabelsAndEventClasses::TYPE_GUID,
776 readableData,
777 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000778
779 // Network - Input layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000780 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
781 EmptyOptional(),
782 optNetGuid,
783 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100784 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000785 readableData,
786 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000787
788 // Normalization layer
789 // Normalization layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000790 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000791
792 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100793 ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData(
794 EmptyOptional(), "normalization", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000795
796 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000797 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
798 EmptyOptional(),
799 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100800 normalizationLayerNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000801 LabelsAndEventClasses::NAME_GUID,
802 readableData,
803 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000804
805 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000806 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
807 EmptyOptional(),
808 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100809 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000810 LabelsAndEventClasses::TYPE_GUID,
811 readableData,
812 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000813
814 // Network - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000815 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
816 EmptyOptional(),
817 optNetGuid,
818 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100819 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000820 readableData,
821 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000822
823 // Input layer - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000824 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
825 EmptyOptional(),
826 input->GetGuid(),
827 normalize->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000828 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000829 readableData,
830 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000831
832 // Normalization workload
833 // Normalization workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100834 ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
835 EmptyOptional(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000836
837 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000838 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
839 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100840 normalizationWorkloadGuid,
841 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000842 LabelsAndEventClasses::TYPE_GUID,
843 readableData,
844 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000845
846 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100847 ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
848 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000849
850 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000851 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
852 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100853 normalizationWorkloadGuid,
854 cpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000855 LabelsAndEventClasses::BACKENDID_GUID,
856 readableData,
857 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000858
859 // Normalize layer - Normalize workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000860 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
861 EmptyOptional(),
862 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100863 normalizationWorkloadGuid,
864 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000865 readableData,
866 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000867
868 // Output layer
869 // Output layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000870 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000871
872 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100873 ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
874 EmptyOptional(), "output", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000875
876 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000877 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
878 EmptyOptional(),
879 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100880 outputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000881 LabelsAndEventClasses::NAME_GUID,
882 readableData,
883 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000884
885 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000886 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
887 EmptyOptional(),
888 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100889 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000890 LabelsAndEventClasses::TYPE_GUID,
891 readableData,
892 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000893
894 // Network - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000895 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
896 EmptyOptional(),
897 optNetGuid,
898 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100899 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000900 readableData,
901 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000902
903 // Normalize layer - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000904 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
905 EmptyOptional(),
906 normalize->GetGuid(),
907 output->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000908 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000909 readableData,
910 offset);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000911
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000912 bufferManager.MarkRead(readableBuffer);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000913
914 // Creates structures for input & output.
915 std::vector<float> inputData(16);
916 std::vector<float> outputData(16);
917
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100918 TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
919 inputTensorInfo.SetConstant(true);
Keith Davis97da5e22020-03-05 16:25:28 +0000920 InputTensors inputTensors
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000921 {
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100922 {0, ConstTensor(inputTensorInfo, inputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000923 };
924 OutputTensors outputTensors
925 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000926 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000927 };
928
929 // Does the inference.
Sadik Armagan3184c902020-03-18 10:57:30 +0000930 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000931
Finn Williamsb6a402f2020-03-24 13:46:22 +0000932 // Get readable buffer for input workload
933 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100934 CHECK(inputReadableBuffer != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +0000935
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000936 // Get readable buffer for output workload
937 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100938 CHECK(outputReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000939
Finn Williamsb6a402f2020-03-24 13:46:22 +0000940 // Get readable buffer for inference timeline
941 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100942 CHECK(inferenceReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000943
944 // Validate input workload data
945 size = inputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100946 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000947
948 readableData = inputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100949 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000950
951 offset = 0;
952
Keith Davis97da5e22020-03-05 16:25:28 +0000953 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100954 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000955
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000956 // Input workload
957 // Input workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100958 ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000959
960 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000961 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
962 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100963 inputWorkloadGuid,
964 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000965 LabelsAndEventClasses::TYPE_GUID,
966 readableData,
967 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000968
969 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100970 ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
971 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000972
973 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000974 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
975 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100976 inputWorkloadGuid,
977 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000978 LabelsAndEventClasses::BACKENDID_GUID,
979 readableData,
980 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000981
982 // Input layer - Input workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000983 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
984 EmptyOptional(),
985 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100986 inputWorkloadGuid,
987 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000988 readableData,
989 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000990
991 bufferManager.MarkRead(inputReadableBuffer);
992
993 // Validate output workload data
994 size = outputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100995 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000996
997 readableData = outputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100998 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000999
1000 offset = 0;
1001
Keith Davis97da5e22020-03-05 16:25:28 +00001002 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001003 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +00001004
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001005 // Output workload
1006 // Output workload entity
Jim Flynn6398a982020-05-27 17:05:21 +01001007 ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001008
1009 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001010 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1011 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001012 outputWorkloadGuid,
1013 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001014 LabelsAndEventClasses::TYPE_GUID,
1015 readableData,
1016 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001017
1018 // BackendId entity
Keith Davis97da5e22020-03-05 16:25:28 +00001019 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001020
1021 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001022 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1023 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001024 outputWorkloadGuid,
1025 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001026 LabelsAndEventClasses::BACKENDID_GUID,
1027 readableData,
1028 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001029
1030 // Output layer - Output workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001031 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1032 EmptyOptional(),
1033 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +01001034 outputWorkloadGuid,
1035 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001036 readableData,
1037 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001038
1039 bufferManager.MarkRead(outputReadableBuffer);
David Monahan6198fe02019-12-02 08:35:43 +00001040
1041 // Validate inference data
1042 size = inferenceReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001043 CHECK(size == 976 + 8 * ThreadIdSize);
David Monahan6198fe02019-12-02 08:35:43 +00001044
1045 readableData = inferenceReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001046 CHECK(readableData != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +00001047
1048 offset = 0;
1049
Keith Davis97da5e22020-03-05 16:25:28 +00001050 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001051 VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize);
Keith Davis97da5e22020-03-05 16:25:28 +00001052
David Monahan6198fe02019-12-02 08:35:43 +00001053 // Inference timeline trace
1054 // Inference entity
Jim Flynn6398a982020-05-27 17:05:21 +01001055 ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001056
1057 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001058 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1059 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001060 inferenceGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001061 LabelsAndEventClasses::INFERENCE_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001062 LabelsAndEventClasses::TYPE_GUID,
1063 readableData,
1064 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001065
1066 // Network - Inference relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001067 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1068 EmptyOptional(),
1069 optNetGuid,
Jim Flynn6398a982020-05-27 17:05:21 +01001070 inferenceGuid,
1071 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001072 readableData,
1073 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001074
1075 // Start Inference life
1076 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001077 ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
1078 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001079
1080 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001081 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1082 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001083 inferenceGuid,
1084 inferenceEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001085 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1086 readableData,
1087 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001088
1089 // Execution
1090 // Input workload execution
1091 // Input workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001092 ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1093 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001094
1095 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001096 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1097 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001098 inputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001099 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001100 LabelsAndEventClasses::TYPE_GUID,
1101 readableData,
1102 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001103
1104 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001105 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1106 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001107 inferenceGuid,
1108 inputWorkloadExecutionGuid,
1109 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001110 readableData,
1111 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001112
1113 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001114 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1115 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001116 inputWorkloadGuid,
1117 inputWorkloadExecutionGuid,
1118 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001119 readableData,
1120 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001121
1122 // Start Input workload execution life
1123 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001124 ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
1125 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001126
1127 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001128 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1129 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001130 inputWorkloadExecutionGuid,
1131 inputWorkloadExecutionSOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001132 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1133 readableData,
1134 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001135
1136 // End of Input workload execution life
1137 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001138 ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
1139 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001140
1141 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001142 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1143 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001144 inputWorkloadExecutionGuid,
1145 inputWorkloadExecutionEOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001146 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1147 readableData,
1148 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001149
1150 // Normalize workload execution
1151 // Normalize workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001152 ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1153 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001154
1155 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001156 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1157 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001158 normalizeWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001159 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001160 LabelsAndEventClasses::TYPE_GUID,
1161 readableData,
1162 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001163
1164 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001165 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1166 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001167 inferenceGuid,
1168 normalizeWorkloadExecutionGuid,
1169 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001170 readableData,
1171 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001172
1173 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001174 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1175 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001176 normalizationWorkloadGuid,
1177 normalizeWorkloadExecutionGuid,
1178 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001179 readableData,
1180 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001181
1182 // Start Normalize workload execution life
1183 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001184 ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1185 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001186
1187 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001188 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1189 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001190 normalizeWorkloadExecutionGuid,
1191 normalizationWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001192 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1193 readableData,
1194 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001195
1196 // End of Normalize workload execution life
1197 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001198 ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1199 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001200
1201 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001202 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1203 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001204 normalizeWorkloadExecutionGuid,
1205 normalizationWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001206 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1207 readableData,
1208 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001209
1210 // Output workload execution
1211 // Output workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001212 ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1213 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001214
1215 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001216 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1217 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001218 outputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001219 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001220 LabelsAndEventClasses::TYPE_GUID,
1221 readableData,
1222 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001223
1224 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001225 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1226 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001227 inferenceGuid,
1228 outputWorkloadExecutionGuid,
1229 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001230 readableData,
1231 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001232
1233 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001234 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1235 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001236 outputWorkloadGuid,
1237 outputWorkloadExecutionGuid,
1238 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001239 readableData,
1240 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001241
1242 // Start Output workload execution life
1243 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001244 ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1245 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001246
1247 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001248 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1249 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001250 outputWorkloadExecutionGuid,
1251 outputWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001252 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1253 readableData,
1254 offset);
Finn Williams0a336dc2020-05-11 15:39:58 +01001255
David Monahan6198fe02019-12-02 08:35:43 +00001256 // End of Normalize workload execution life
1257 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001258 ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1259 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001260
1261 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001262 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1263 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001264 outputWorkloadExecutionGuid,
1265 outputWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001266 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1267 readableData,
1268 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001269
1270 // End of Inference life
1271 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001272 ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
1273 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001274
1275 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001276 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1277 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001278 inferenceGuid,
1279 inferenceEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001280 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1281 readableData,
1282 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001283
1284 bufferManager.MarkRead(inferenceReadableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001285}
1286
Sadik Armagan1625efc2021-06-10 18:24:34 +01001287TEST_CASE("ProfilingPostOptimisationStructureCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001288{
1289 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1290}
1291
Sadik Armagan1625efc2021-06-10 18:24:34 +01001292}