blob: fcfcc48f96da14a7d43dd7919e7a7efc85b3bc5e [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,
Jim Flynndecd08b2022-03-13 22:35:46 +0000715 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000716 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
Jim Flynndecd08b2022-03-13 22:35:46 +0000723 ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(arm::pipe::EmptyOptional(),
724 arm::pipe::EmptyOptional(),
725 arm::pipe::EmptyOptional(),
Jim Flynnf7713212020-07-14 09:50:59 +0100726 readableData,
727 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100728
729 // Network - START OF LIFE event relationship
730 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000731 arm::pipe::EmptyOptional(),
Jim Flynnf7713212020-07-14 09:50:59 +0100732 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();
Jim Flynndecd08b2022-03-13 22:35:46 +0000743 VerifyTimelineLabelBinaryPacketData(arm::pipe::EmptyOptional(), processIdLabel, readableData, offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100744
745 // Entity - Process ID relationship
746 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000747 arm::pipe::EmptyOptional(),
Jim Flynnf7713212020-07-14 09:50:59 +0100748 optNetGuid,
Jim Flynndecd08b2022-03-13 22:35:46 +0000749 arm::pipe::EmptyOptional(),
Jim Flynnf7713212020-07-14 09:50:59 +0100750 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 Flynndecd08b2022-03-13 22:35:46 +0000759 ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(
760 arm::pipe::EmptyOptional(), "input", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000761
762 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000763 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000764 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000765 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100766 inputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000767 LabelsAndEventClasses::NAME_GUID,
768 readableData,
769 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000770
771 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000772 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000773 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000774 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100775 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000776 LabelsAndEventClasses::TYPE_GUID,
777 readableData,
778 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000779
780 // Network - Input layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000781 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000782 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000783 optNetGuid,
784 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100785 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000786 readableData,
787 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000788
789 // Normalization layer
790 // Normalization layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000791 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000792
793 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100794 ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +0000795 arm::pipe::EmptyOptional(), "normalization", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000796
797 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000798 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000799 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000800 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100801 normalizationLayerNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000802 LabelsAndEventClasses::NAME_GUID,
803 readableData,
804 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000805
806 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000807 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000808 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000809 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100810 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000811 LabelsAndEventClasses::TYPE_GUID,
812 readableData,
813 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000814
815 // Network - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000816 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000817 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000818 optNetGuid,
819 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100820 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000821 readableData,
822 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000823
824 // Input layer - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000825 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000826 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000827 input->GetGuid(),
828 normalize->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000829 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000830 readableData,
831 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000832
833 // Normalization workload
834 // Normalization workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100835 ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +0000836 arm::pipe::EmptyOptional(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000837
838 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000839 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000840 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100841 normalizationWorkloadGuid,
842 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000843 LabelsAndEventClasses::TYPE_GUID,
844 readableData,
845 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000846
847 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100848 ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +0000849 arm::pipe::EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000850
851 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000852 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000853 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100854 normalizationWorkloadGuid,
855 cpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000856 LabelsAndEventClasses::BACKENDID_GUID,
857 readableData,
858 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000859
860 // Normalize layer - Normalize workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000861 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000862 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000863 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100864 normalizationWorkloadGuid,
865 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000866 readableData,
867 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000868
869 // Output layer
870 // Output layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000871 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000872
873 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100874 ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +0000875 arm::pipe::EmptyOptional(), "output", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000876
877 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000878 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000879 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000880 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100881 outputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000882 LabelsAndEventClasses::NAME_GUID,
883 readableData,
884 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000885
886 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000887 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000888 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000889 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100890 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000891 LabelsAndEventClasses::TYPE_GUID,
892 readableData,
893 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000894
895 // Network - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000896 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000897 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000898 optNetGuid,
899 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100900 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000901 readableData,
902 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000903
904 // Normalize layer - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000905 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000906 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000907 normalize->GetGuid(),
908 output->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000909 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000910 readableData,
911 offset);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000912
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000913 bufferManager.MarkRead(readableBuffer);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000914
915 // Creates structures for input & output.
916 std::vector<float> inputData(16);
917 std::vector<float> outputData(16);
918
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100919 TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
920 inputTensorInfo.SetConstant(true);
Keith Davis97da5e22020-03-05 16:25:28 +0000921 InputTensors inputTensors
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000922 {
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100923 {0, ConstTensor(inputTensorInfo, inputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000924 };
925 OutputTensors outputTensors
926 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000927 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000928 };
929
930 // Does the inference.
Sadik Armagan3184c902020-03-18 10:57:30 +0000931 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000932
Finn Williamsb6a402f2020-03-24 13:46:22 +0000933 // Get readable buffer for input workload
934 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100935 CHECK(inputReadableBuffer != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +0000936
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000937 // Get readable buffer for output workload
938 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100939 CHECK(outputReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000940
Finn Williamsb6a402f2020-03-24 13:46:22 +0000941 // Get readable buffer for inference timeline
942 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100943 CHECK(inferenceReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000944
945 // Validate input workload data
946 size = inputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100947 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000948
949 readableData = inputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100950 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000951
952 offset = 0;
953
Keith Davis97da5e22020-03-05 16:25:28 +0000954 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100955 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000956
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000957 // Input workload
958 // Input workload entity
Jim Flynndecd08b2022-03-13 22:35:46 +0000959 ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
960 arm::pipe::EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000961
962 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000963 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000964 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100965 inputWorkloadGuid,
966 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000967 LabelsAndEventClasses::TYPE_GUID,
968 readableData,
969 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000970
971 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100972 ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +0000973 arm::pipe::EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000974
975 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000976 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000977 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100978 inputWorkloadGuid,
979 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000980 LabelsAndEventClasses::BACKENDID_GUID,
981 readableData,
982 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000983
984 // Input layer - Input workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000985 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +0000986 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +0000987 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100988 inputWorkloadGuid,
989 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000990 readableData,
991 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000992
993 bufferManager.MarkRead(inputReadableBuffer);
994
995 // Validate output workload data
996 size = outputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100997 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000998
999 readableData = outputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001000 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001001
1002 offset = 0;
1003
Keith Davis97da5e22020-03-05 16:25:28 +00001004 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001005 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +00001006
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001007 // Output workload
1008 // Output workload entity
Jim Flynndecd08b2022-03-13 22:35:46 +00001009 ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
1010 arm::pipe::EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001011
1012 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001013 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001014 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001015 outputWorkloadGuid,
1016 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001017 LabelsAndEventClasses::TYPE_GUID,
1018 readableData,
1019 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001020
1021 // BackendId entity
Jim Flynndecd08b2022-03-13 22:35:46 +00001022 VerifyTimelineLabelBinaryPacketData(arm::pipe::EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001023
1024 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001025 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001026 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001027 outputWorkloadGuid,
1028 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001029 LabelsAndEventClasses::BACKENDID_GUID,
1030 readableData,
1031 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001032
1033 // Output layer - Output workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001034 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001035 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +00001036 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +01001037 outputWorkloadGuid,
1038 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001039 readableData,
1040 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001041
1042 bufferManager.MarkRead(outputReadableBuffer);
David Monahan6198fe02019-12-02 08:35:43 +00001043
1044 // Validate inference data
1045 size = inferenceReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001046 CHECK(size == 976 + 8 * ThreadIdSize);
David Monahan6198fe02019-12-02 08:35:43 +00001047
1048 readableData = inferenceReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001049 CHECK(readableData != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +00001050
1051 offset = 0;
1052
Keith Davis97da5e22020-03-05 16:25:28 +00001053 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001054 VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize);
Keith Davis97da5e22020-03-05 16:25:28 +00001055
David Monahan6198fe02019-12-02 08:35:43 +00001056 // Inference timeline trace
1057 // Inference entity
Jim Flynndecd08b2022-03-13 22:35:46 +00001058 ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(
1059 arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001060
1061 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001062 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001063 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001064 inferenceGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001065 LabelsAndEventClasses::INFERENCE_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001066 LabelsAndEventClasses::TYPE_GUID,
1067 readableData,
1068 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001069
1070 // Network - Inference relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001071 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001072 arm::pipe::EmptyOptional(),
Keith Davis97da5e22020-03-05 16:25:28 +00001073 optNetGuid,
Jim Flynn6398a982020-05-27 17:05:21 +01001074 inferenceGuid,
1075 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001076 readableData,
1077 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001078
1079 // Start Inference life
1080 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001081 ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001082 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001083
1084 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001085 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001086 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001087 inferenceGuid,
1088 inferenceEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001089 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1090 readableData,
1091 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001092
1093 // Execution
1094 // Input workload execution
1095 // Input workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001096 ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +00001097 arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001098
1099 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001100 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001101 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001102 inputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001103 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001104 LabelsAndEventClasses::TYPE_GUID,
1105 readableData,
1106 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001107
1108 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001109 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001110 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001111 inferenceGuid,
1112 inputWorkloadExecutionGuid,
1113 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001114 readableData,
1115 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001116
1117 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001118 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001119 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001120 inputWorkloadGuid,
1121 inputWorkloadExecutionGuid,
1122 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001123 readableData,
1124 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001125
1126 // Start Input workload execution life
1127 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001128 ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001129 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001130
1131 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001132 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001133 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001134 inputWorkloadExecutionGuid,
1135 inputWorkloadExecutionSOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001136 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1137 readableData,
1138 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001139
1140 // End of Input workload execution life
1141 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001142 ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001143 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001144
1145 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001146 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001147 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001148 inputWorkloadExecutionGuid,
1149 inputWorkloadExecutionEOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001150 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1151 readableData,
1152 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001153
1154 // Normalize workload execution
1155 // Normalize workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001156 ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +00001157 arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001158
1159 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001160 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001161 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001162 normalizeWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001163 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001164 LabelsAndEventClasses::TYPE_GUID,
1165 readableData,
1166 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001167
1168 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001169 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001170 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001171 inferenceGuid,
1172 normalizeWorkloadExecutionGuid,
1173 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001174 readableData,
1175 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001176
1177 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001178 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001179 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001180 normalizationWorkloadGuid,
1181 normalizeWorkloadExecutionGuid,
1182 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001183 readableData,
1184 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001185
1186 // Start Normalize workload execution life
1187 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001188 ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001189 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001190
1191 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001192 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001193 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001194 normalizeWorkloadExecutionGuid,
1195 normalizationWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001196 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1197 readableData,
1198 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001199
1200 // End of Normalize workload execution life
1201 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001202 ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001203 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001204
1205 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001206 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001207 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001208 normalizeWorkloadExecutionGuid,
1209 normalizationWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001210 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1211 readableData,
1212 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001213
1214 // Output workload execution
1215 // Output workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001216 ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
Jim Flynndecd08b2022-03-13 22:35:46 +00001217 arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001218
1219 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001220 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001221 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001222 outputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001223 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001224 LabelsAndEventClasses::TYPE_GUID,
1225 readableData,
1226 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001227
1228 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001229 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001230 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001231 inferenceGuid,
1232 outputWorkloadExecutionGuid,
1233 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001234 readableData,
1235 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001236
1237 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001238 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001239 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001240 outputWorkloadGuid,
1241 outputWorkloadExecutionGuid,
1242 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001243 readableData,
1244 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001245
1246 // Start Output workload execution life
1247 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001248 ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001249 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001250
1251 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001252 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001253 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001254 outputWorkloadExecutionGuid,
1255 outputWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001256 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1257 readableData,
1258 offset);
Finn Williams0a336dc2020-05-11 15:39:58 +01001259
David Monahan6198fe02019-12-02 08:35:43 +00001260 // End of Normalize workload execution life
1261 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001262 ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001263 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001264
1265 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001266 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001267 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001268 outputWorkloadExecutionGuid,
1269 outputWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001270 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1271 readableData,
1272 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001273
1274 // End of Inference life
1275 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001276 ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
Jim Flynndecd08b2022-03-13 22:35:46 +00001277 arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), arm::pipe::EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001278
1279 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001280 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
Jim Flynndecd08b2022-03-13 22:35:46 +00001281 arm::pipe::EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001282 inferenceGuid,
1283 inferenceEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001284 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1285 readableData,
1286 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001287
1288 bufferManager.MarkRead(inferenceReadableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001289}
1290
Sadik Armagan1625efc2021-06-10 18:24:34 +01001291TEST_CASE("ProfilingPostOptimisationStructureCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001292{
1293 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1294}
1295
Sadik Armagan1625efc2021-06-10 18:24:34 +01001296}