blob: 73e36eaf561828d72c7f5505be7c78138d858042 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
telsoa014fcda012018-03-09 14:13:49 +00005
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +01006#include <armnn/Descriptors.hpp>
7#include <armnn/IRuntime.hpp>
8#include <armnn/INetwork.hpp>
Jim Flynn4c9ed1d2022-01-23 23:57:20 +00009#include <ProfilingOptionsConverter.hpp>
Jim Flynnf7713212020-07-14 09:50:59 +010010#include <Processes.hpp>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000011#include <Runtime.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010012#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000013
Jim Flynn4c9ed1d2022-01-23 23:57:20 +000014
Nikhil Raj77fe76b2021-06-09 14:55:32 +010015#include <common/include/LabelsAndEventClasses.hpp>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000016#include <test/ProfilingTestUtils.hpp>
17
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000018#include <HeapProfiling.hpp>
19#include <LeakChecking.hpp>
telsoa014fcda012018-03-09 14:13:49 +000020
21#ifdef WITH_VALGRIND
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010022#include <valgrind/memcheck.h>
telsoa014fcda012018-03-09 14:13:49 +000023#endif
24
Sadik Armagan1625efc2021-06-10 18:24:34 +010025#include <doctest/doctest.h>
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +000026#include "RuntimeTests.hpp"
Sadik Armagana097d2a2021-11-24 15:47:28 +000027#include <TestUtils.hpp>
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +010028
telsoa014fcda012018-03-09 14:13:49 +000029namespace armnn
30{
31
Kevin Mayd92a6e42021-02-04 10:27:41 +000032void RuntimeLoadedNetworksReserve(armnn::RuntimeImpl* runtime)
telsoa014fcda012018-03-09 14:13:49 +000033{
34 runtime->m_LoadedNetworks.reserve(1);
35}
36
37}
38
Sadik Armagan1625efc2021-06-10 18:24:34 +010039TEST_SUITE("Runtime")
40{
41TEST_CASE("RuntimeUnloadNetwork")
telsoa014fcda012018-03-09 14:13:49 +000042{
43 // build 2 mock-networks and load them into the runtime
telsoa01c577f2c2018-08-31 09:22:23 +010044 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +000045 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa014fcda012018-03-09 14:13:49 +000046
telsoa01c577f2c2018-08-31 09:22:23 +010047 // Mock network 1.
Keith Davis97da5e22020-03-05 16:25:28 +000048 armnn::NetworkId networkIdentifier1 = 1;
telsoa014fcda012018-03-09 14:13:49 +000049 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
50 mockNetwork1->AddInputLayer(0, "test layer");
Keith Davis97da5e22020-03-05 16:25:28 +000051 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +010052 runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000053
telsoa01c577f2c2018-08-31 09:22:23 +010054 // Mock network 2.
Keith Davis97da5e22020-03-05 16:25:28 +000055 armnn::NetworkId networkIdentifier2 = 2;
telsoa014fcda012018-03-09 14:13:49 +000056 armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create());
57 mockNetwork2->AddInputLayer(0, "test layer");
telsoa01c577f2c2018-08-31 09:22:23 +010058 runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec()));
telsoa014fcda012018-03-09 14:13:49 +000059
telsoa01c577f2c2018-08-31 09:22:23 +010060 // Unloads one by its networkID.
Sadik Armagan1625efc2021-06-10 18:24:34 +010061 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success);
telsoa014fcda012018-03-09 14:13:49 +000062
Sadik Armagan1625efc2021-06-10 18:24:34 +010063 CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure);
telsoa014fcda012018-03-09 14:13:49 +000064}
65
Finn Williamsf37b9702021-09-01 18:06:04 +010066TEST_CASE("RuntimePreImportInputs")
67{
68 armnn::IRuntime::CreationOptions options;
Finn Williams8636bc72021-10-02 15:06:39 +010069 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
70 armnn::NetworkId networkId = 1;
Finn Williamsf37b9702021-09-01 18:06:04 +010071 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Finn Williams8636bc72021-10-02 15:06:39 +010072
Finn Williamsf37b9702021-09-01 18:06:04 +010073 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
74 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 2 layer");
75 auto addLayer = testNetwork->AddAdditionLayer("add layer");
76 auto outputLayer = testNetwork->AddOutputLayer(2, "output layer");
77
78 TensorInfo tensorInfo{{4}, armnn::DataType::Signed32};
79
80 inputLayer1->GetOutputSlot(0).Connect(addLayer->GetInputSlot(0));
81 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
Finn Williams8636bc72021-10-02 15:06:39 +010082
Finn Williamsf37b9702021-09-01 18:06:04 +010083 inputLayer2->GetOutputSlot(0).Connect(addLayer->GetInputSlot(1));
84 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
85
86 addLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0));
87 addLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo);
88
Finn Williams8636bc72021-10-02 15:06:39 +010089 std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef};
Finn Williamsf37b9702021-09-01 18:06:04 +010090
91 std::string er;
92 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Undefined);
Finn Williams8636bc72021-10-02 15:06:39 +010093 runtime->LoadNetwork(networkId,
Finn Williamsf37b9702021-09-01 18:06:04 +010094 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
95 er,
96 networkProperties);
97
98 std::vector<int> inputData1(4, 10);
99 std::vector<int> inputData2(4, 20);
100 std::vector<int> output(4);
101
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100102 ConstTensor inputTensor1({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData1.data());
103 ConstTensor inputTensor2({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData2.data());
Finn Williamsf37b9702021-09-01 18:06:04 +0100104 Tensor outputTensor({{4}, armnn::DataType::Signed32}, output.data());
105
Finn Williams8636bc72021-10-02 15:06:39 +0100106 auto importedInputVec1 = runtime->ImportInputs(networkId, {{0, inputTensor1}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100107 CHECK(importedInputVec1.size() == 1);
108 CHECK(importedInputVec1[0] == 0);
109
Finn Williams8636bc72021-10-02 15:06:39 +0100110 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
Finn Williamsf37b9702021-09-01 18:06:04 +0100111
112 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100113 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100114 CHECK(val == 30);
115 }
116
Finn Williams8636bc72021-10-02 15:06:39 +0100117 auto importedInputVec2 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100118 CHECK(importedInputVec2.size() == 1);
119 CHECK(importedInputVec2[0] == 1);
120
121 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {{2, outputTensor}}, {1 /* pre-imported id */});
Finn Williams8636bc72021-10-02 15:06:39 +0100122 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100123 CHECK(val == 30);
124 }
125
126 runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1});
Finn Williams8636bc72021-10-02 15:06:39 +0100127 for (auto val: output) {
Finn Williamsf37b9702021-09-01 18:06:04 +0100128 CHECK(val == 30);
129 }
Finn Williamsf37b9702021-09-01 18:06:04 +0100130 // Duplicate ImportedInputId and LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100131 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 0});,
132 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100133 // Duplicate LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100134 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {1});,
135 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100136 // Incorrect ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100137 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {10});,
138 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100139 // Incorrect LayerBindingId
Finn Williams8636bc72021-10-02 15:06:39 +0100140 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {1});,
141 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100142 // Incorrect layer binding id and ImportedInputId
Finn Williams8636bc72021-10-02 15:06:39 +0100143 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {10});,
144 armnn::InvalidArgumentException);
145 auto importedInputVec3 = runtime->ImportInputs(networkId, {{1, inputTensor2}});
Finn Williamsf37b9702021-09-01 18:06:04 +0100146 CHECK(importedInputVec3[0] == 2);
147 // Too many ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100148 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1, 2});,
149 armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100150 // Too many InputTensors
151 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(),
Finn Williams8636bc72021-10-02 15:06:39 +0100152 {{0, inputTensor2},
153 {1, inputTensor2},
154 {2, inputTensor2}},
155 {{2, outputTensor}});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100156 // Too few ImportedInputIds
Finn Williams8636bc72021-10-02 15:06:39 +0100157 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0});,
158 armnn::InvalidArgumentException);
159 runtime->ClearImportedInputs(networkId, {1});
160 runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0}, {});
161 for (auto val: output) {
162 CHECK(val == 30);
163 }
164 // Using deleted pre-imported input
165 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}, {});,
166 armnn::InvalidArgumentException);
167
168 // Trying to delete deleted pre-imported tensor
169 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {1});, armnn::InvalidArgumentException);
170
171 // Trying to delete unknown pre-imported tensor
172 CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {10});, armnn::InvalidArgumentException);
173}
174TEST_CASE("RuntimePreImportOutputs")
175{
176 armnn::IRuntime::CreationOptions options;
177 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
178
179 armnn::NetworkId networkId = 1;
180
181 armnn::INetworkPtr testNetwork(armnn::INetwork::Create());
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100182 TensorInfo tensorInfo{{4}, armnn::DataType::Float32, 0.0f, 0, true};
Finn Williams8636bc72021-10-02 15:06:39 +0100183
184 auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer");
185 inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
186
187 ActivationDescriptor activationDescriptor;
188 activationDescriptor.m_Function = ActivationFunction::BoundedReLu;
189 activationDescriptor.m_A = 2.0f;
190 activationDescriptor.m_B = 0.0f;
191 auto activationLayer1 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
192 auto outputLayer1 = testNetwork->AddOutputLayer(2, "output layer");
193
194 inputLayer1->GetOutputSlot(0).Connect(activationLayer1->GetInputSlot(0));
195
196 activationLayer1->GetOutputSlot(0).Connect(outputLayer1->GetInputSlot(0));
197 activationLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo);
198
199 auto inputLayer2 = testNetwork->AddInputLayer(1, "input 1 layer");
200
201 activationDescriptor.m_A = 4.0f;
202 activationDescriptor.m_B = 2.0f;
203 auto activationLayer2 = testNetwork->AddActivationLayer(activationDescriptor, "add layer");
204 auto outputLayer2 = testNetwork->AddOutputLayer(3, "output layer");
205
206 inputLayer2->GetOutputSlot(0).Connect(activationLayer2->GetInputSlot(0));
207 inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
208
209 activationLayer2->GetOutputSlot(0).Connect(outputLayer2->GetInputSlot(0));
210 activationLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo);
211
212 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
213
214 std::string er;
215 armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Malloc);
216 runtime->LoadNetwork(networkId,
217 Optimize(*testNetwork, backends, runtime->GetDeviceSpec()),
218 er,
219 networkProperties);
220
221 std::vector<float> inputData1(4, 1.0f);
222 std::vector<float> inputData2(4, 3.0f);
223
224 std::vector<float> outputData1(4);
225 std::vector<float> outputData2(4);
226
227 ConstTensor inputTensor1(tensorInfo, inputData1.data());
228 ConstTensor inputTensor2(tensorInfo, inputData2.data());
229
230 Tensor outputTensor1{tensorInfo, outputData1.data()};
231 Tensor outputTensor2{tensorInfo, outputData2.data()};
232
233 InputTensors inputTensors = {{0, inputTensor1}, {1, inputTensor2}};
234
235 std::pair<LayerBindingId, class Tensor> output1{2, outputTensor1};
236 std::pair<LayerBindingId, class Tensor> output2{3, outputTensor2};
237
238 auto testOutputs = [&]()
239 {
240 for (auto val : outputData1)
241 {
242 CHECK(val == 1.0f);
243 }
244
245 for (auto val : outputData2)
246 {
247 CHECK(val == 3.0f);
248 }
249 };
250
251 auto memHandle = runtime->CreateWorkingMemHandle(networkId);
252
253 runtime->Execute(*memHandle.get(),inputTensors, {output1, output2});
254 testOutputs();
255
256 auto importedOutputVec = runtime->ImportOutputs(networkId, {output1, output2 });
257 CHECK(importedOutputVec.size() == 2);
258 CHECK(importedOutputVec[0] == 0);
259 CHECK(importedOutputVec[1] == 1);
260
261 runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec);
262 testOutputs();
263
264 runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {1});
265 testOutputs();
266
267 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
268 testOutputs();
269
270 auto importedInputVec = runtime->ImportInputs(networkId, inputTensors);
271 CHECK(importedInputVec.size() == 2);
272 CHECK(importedInputVec[0] == 0);
273 CHECK(importedInputVec[1] == 1);
274
275 runtime->Execute(*memHandle.get(), {}, {}, importedInputVec, importedOutputVec);
276 testOutputs();
277
278 runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {output2}, {1}, {0});
279 testOutputs();
280
281 // Too many ids
282 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output2}, {}, {0, 1});,
283 armnn::InvalidArgumentException);
284
285 // Duplicate ids
286 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {1});,
287 armnn::InvalidArgumentException);
288
289 // Duplicate ids
290 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output1}, {}, {});,
291 armnn::InvalidArgumentException);
292
293 // Duplicate ids
294 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, {0, 0}),
295 armnn::InvalidArgumentException);
296
297 // Unknown id
298 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {3});,
299 armnn::InvalidArgumentException);
300
301 // Unknown id
302 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{4, outputTensor2}}, {}, {1});,
303 armnn::InvalidArgumentException);
304
305 // Input id for output
306 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, 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 // Output id for input
314 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{2, inputTensor1}}, {{0, outputTensor2}}, {1}, {1, 0});,
315 armnn::InvalidArgumentException);
316
317 runtime->ClearImportedOutputs(networkId, {1});
318
319 runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0});
320 testOutputs();
321
322 // Trying to use deleted pre-imported tensor
323 CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec),
324 armnn::InvalidArgumentException);
325
326 // Trying to delete deleted pre-imported tensor
327 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {1});, armnn::InvalidArgumentException);
328
329 // Trying to delete unknown pre-imported tensor
330 CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {10});, armnn::InvalidArgumentException);
Finn Williamsf37b9702021-09-01 18:06:04 +0100331}
332
surmeh013537c2c2018-05-18 16:31:43 +0100333// Note: the current builds we don't do valgrind and gperftools based leak checking at the same
telsoa01c577f2c2018-08-31 09:22:23 +0100334// time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The
335// valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow
336// to be integrated into the CI system.
surmeh013537c2c2018-05-18 16:31:43 +0100337
telsoa01c577f2c2018-08-31 09:22:23 +0100338#ifdef ARMNN_LEAK_CHECKING_ENABLED
339
340struct DisableGlobalLeakChecking
341{
342 DisableGlobalLeakChecking()
343 {
344 ARMNN_LOCAL_LEAK_CHECKING_ONLY();
345 }
346};
347
Sadik Armagan1625efc2021-06-10 18:24:34 +0100348TEST_CASE_FIXTURE(DisableGlobalLeakChecking, "RuntimeHeapMemoryUsageSanityChecks")
surmeh013537c2c2018-05-18 16:31:43 +0100349{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100350 CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE());
surmeh013537c2c2018-05-18 16:31:43 +0100351 {
352 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer");
353 {
354 ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner");
Sadik Armagan1625efc2021-06-10 18:24:34 +0100355 CHECK(ARMNN_NO_LEAKS_IN_SCOPE() == true);
surmeh013537c2c2018-05-18 16:31:43 +0100356 std::unique_ptr<char[]> dummyAllocation(new char[1000]);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100357 // "A leak of 1000 bytes is expected here. "
358 // "Please make sure environment variable: HEAPCHECK=draconian is set!"
359 CHECK((ARMNN_NO_LEAKS_IN_SCOPE() == false));
360 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000);
361 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1);
surmeh013537c2c2018-05-18 16:31:43 +0100362 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100363 CHECK(ARMNN_NO_LEAKS_IN_SCOPE());
364 CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0);
365 CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0);
surmeh013537c2c2018-05-18 16:31:43 +0100366 }
367}
368
surmeh013537c2c2018-05-18 16:31:43 +0100369#endif // ARMNN_LEAK_CHECKING_ENABLED
370
371// 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 +0000372#ifdef WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100373// Run with the following command to get all the amazing output (in the devenv/build folder) :)
telsoa014fcda012018-03-09 14:13:49 +0000374// 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 +0100375TEST_CASE("RuntimeMemoryLeak")
telsoa014fcda012018-03-09 14:13:49 +0000376{
377 // From documentation:
378
379 // This means that no pointer to the block can be found. The block is classified as "lost",
380 // because the programmer could not possibly have freed it at program exit, since no pointer to it exists.
381 unsigned long leakedBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000382 unsigned long leakedAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000383
384 // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at,
385 // the programmer could, at least in principle, have freed it before program exit.
telsoa01c577f2c2018-08-31 09:22:23 +0100386 // We want to test this in case memory is not freed as early as it could have been.
telsoa014fcda012018-03-09 14:13:49 +0000387 unsigned long reachableBefore = 0;
Keith Davis97da5e22020-03-05 16:25:28 +0000388 unsigned long reachableAfter = 0;
telsoa014fcda012018-03-09 14:13:49 +0000389
telsoa01c577f2c2018-08-31 09:22:23 +0100390 // Needed as out params but we don't test them.
Keith Davis97da5e22020-03-05 16:25:28 +0000391 unsigned long dubious = 0;
telsoa014fcda012018-03-09 14:13:49 +0000392 unsigned long suppressed = 0;
393
394 armnn::NetworkId networkIdentifier1 = 1;
395
396 // ensure that runtime is large enough before checking for memory leaks
397 // otherwise when loading the network it will automatically reserve memory that won't be released until destruction
telsoa01c577f2c2018-08-31 09:22:23 +0100398 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000399 armnn::RuntimeImpl runtime(options);
telsoa014fcda012018-03-09 14:13:49 +0000400 armnn::RuntimeLoadedNetworksReserve(&runtime);
401
telsoa014fcda012018-03-09 14:13:49 +0000402 {
Keith Davis97da5e22020-03-05 16:25:28 +0000403 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
telsoa014fcda012018-03-09 14:13:49 +0000404
Francis Murtagh3d2b4b22021-02-15 18:23:17 +0000405 armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create());
telsoa014fcda012018-03-09 14:13:49 +0000406 mockNetwork1->AddInputLayer(0, "test layer");
407
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000408 // Warm-up load/unload pair to put the runtime in a stable state (memory-wise).
telsoa01c577f2c2018-08-31 09:22:23 +0100409 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
Matteo Martincigh9326aab2018-11-15 10:54:54 +0000410 runtime.UnloadNetwork(networkIdentifier1);
411
412 // Checks for leaks before we load the network and record them so that we can see the delta after unloading.
413 VALGRIND_DO_QUICK_LEAK_CHECK;
414 VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed);
415
416 // The actual test.
417 runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec()));
418 runtime.UnloadNetwork(networkIdentifier1);
419
420 VALGRIND_DO_ADDED_LEAK_CHECK;
421 VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000422 }
423
telsoa01c577f2c2018-08-31 09:22:23 +0100424 // 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 +0100425 CHECK(leakedBefore == leakedAfter);
426 CHECK(reachableBefore == reachableAfter);
telsoa014fcda012018-03-09 14:13:49 +0000427
telsoa01c577f2c2018-08-31 09:22:23 +0100428 // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters
429 // so they are assigned to, but still considered unused, causing a warning.
Jan Eilers8eb25602020-03-09 12:13:48 +0000430 IgnoreUnused(dubious);
431 IgnoreUnused(suppressed);
telsoa014fcda012018-03-09 14:13:49 +0000432}
Aron Virginas-Tarc26ba752018-10-22 13:32:01 +0100433#endif // WITH_VALGRIND
telsoa01c577f2c2018-08-31 09:22:23 +0100434
Sadik Armagan1625efc2021-06-10 18:24:34 +0100435TEST_CASE("RuntimeCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100436{
437 using namespace armnn;
438
439 // Create runtime in which test will run
440 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000441 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100442
443 // build up the structure of the network
444 INetworkPtr net(INetwork::Create());
445
446 IConnectableLayer* input = net->AddInputLayer(0);
447
448 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
449 NormalizationDescriptor descriptor;
450 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
451
452 IConnectableLayer* output = net->AddOutputLayer(0);
453
454 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
455 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
456
457 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
458 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
459
460 // optimize the network
David Beckf0b48452018-10-19 15:20:56 +0100461 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Keith Davis97da5e22020-03-05 16:25:28 +0000462 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100463
464 // Load it into the runtime. It should success.
465 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100466 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100467}
468
Sadik Armagan1625efc2021-06-10 18:24:34 +0100469TEST_CASE("RuntimeFallbackToCpuRef")
telsoa01c577f2c2018-08-31 09:22:23 +0100470{
471 using namespace armnn;
472
473 // Create runtime in which test will run
474 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000475 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
telsoa01c577f2c2018-08-31 09:22:23 +0100476
477 // build up the structure of the network
478 INetworkPtr net(INetwork::Create());
479
480 IConnectableLayer* input = net->AddInputLayer(0);
481
482 // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef.
483 NormalizationDescriptor descriptor;
484 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
485
486 IConnectableLayer* output = net->AddOutputLayer(0);
487
488 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
489 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
490
491 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
492 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
493
494 // Allow fallback to CpuRef.
David Beckf0b48452018-10-19 15:20:56 +0100495 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef };
telsoa01c577f2c2018-08-31 09:22:23 +0100496 // optimize the network
Keith Davis97da5e22020-03-05 16:25:28 +0000497 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
telsoa01c577f2c2018-08-31 09:22:23 +0100498
499 // Load it into the runtime. It should succeed.
500 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100501 CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
telsoa01c577f2c2018-08-31 09:22:23 +0100502}
503
Sadik Armagan1625efc2021-06-10 18:24:34 +0100504TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue")
jimfly016b0b53d2018-10-08 14:43:01 +0100505{
506 // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929
507 using namespace armnn;
508
509 // Create runtime in which test will run
510 armnn::IRuntime::CreationOptions options;
Keith Davis97da5e22020-03-05 16:25:28 +0000511 armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
jimfly016b0b53d2018-10-08 14:43:01 +0100512
513 // build up the structure of the network
514 INetworkPtr net(INetwork::Create());
Keith Davis97da5e22020-03-05 16:25:28 +0000515 armnn::IConnectableLayer* input = net->AddInputLayer(0,"input");
516 armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax");
517 armnn::IConnectableLayer* output = net->AddOutputLayer(0, "output");
jimfly016b0b53d2018-10-08 14:43:01 +0100518
519 input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0));
520 softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0));
521
Keith Davis97da5e22020-03-05 16:25:28 +0000522 input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
523 armnn::DataType::QAsymmU8,
524 1.0f / 255,
525 0));
jimfly016b0b53d2018-10-08 14:43:01 +0100526
Keith Davis97da5e22020-03-05 16:25:28 +0000527 softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }),
528 armnn::DataType::QAsymmU8));
jimfly016b0b53d2018-10-08 14:43:01 +0100529
Keith Davis97da5e22020-03-05 16:25:28 +0000530 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
531 std::vector<std::string> errMessages;
Mike Kelly3a613cc2020-09-29 20:50:35 +0100532
533 try
534 {
535 armnn::IOptimizedNetworkPtr optNet = Optimize(*net,
Keith Davis97da5e22020-03-05 16:25:28 +0000536 backends,
537 runtime->GetDeviceSpec(),
538 OptimizerOptions(),
539 errMessages);
Sadik Armagan1625efc2021-06-10 18:24:34 +0100540 FAIL("An exception should have been thrown");
Mike Kelly3a613cc2020-09-29 20:50:35 +0100541 }
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000542 catch (const armnn::InvalidArgumentException&)
Mike Kelly3a613cc2020-09-29 20:50:35 +0100543 {
544 // Different exceptions are thrown on different backends
545 }
Sadik Armagan1625efc2021-06-10 18:24:34 +0100546 CHECK(errMessages.size() > 0);
jimfly016b0b53d2018-10-08 14:43:01 +0100547}
548
Sadik Armagan1625efc2021-06-10 18:24:34 +0100549TEST_CASE("RuntimeBackendOptions")
Derek Lamberti836b27b2019-11-20 10:51:57 +0000550{
551 using namespace armnn;
552
553 IRuntime::CreationOptions creationOptions;
554 auto& backendOptions = creationOptions.m_BackendOptions;
555
556
557 // Define Options on explicit construction
558 BackendOptions options1("FakeBackend1",
Keith Davis97da5e22020-03-05 16:25:28 +0000559 {
560 { "Option1", 1.3f },
561 { "Option2", true }
562 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000563
564 // Add an option after construction
Keith Davis97da5e22020-03-05 16:25:28 +0000565 options1.AddOption({ "Option3", "some_value" });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000566
567 // Add the options to CreationOptions struct
568 backendOptions.push_back(options1);
569
570 // Add more Options via inplace explicit construction
Keith Davis97da5e22020-03-05 16:25:28 +0000571 backendOptions.emplace_back(BackendOptions{ "FakeBackend1",
572 {{ "Option4", 42 }}
573 });
Derek Lamberti836b27b2019-11-20 10:51:57 +0000574
575
576 // First group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100577 CHECK(backendOptions[0].GetBackendId().Get() == "FakeBackend1");
578 CHECK(backendOptions[0].GetOption(0).GetName() == "Option1");
579 CHECK(backendOptions[0].GetOption(0).GetValue().IsFloat() == true);
580 CHECK(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000581
Sadik Armagan1625efc2021-06-10 18:24:34 +0100582 CHECK(backendOptions[0].GetOption(1).GetName() == "Option2");
583 CHECK(backendOptions[0].GetOption(1).GetValue().IsBool() == true);
584 CHECK(backendOptions[0].GetOption(1).GetValue().AsBool() == true);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000585
Sadik Armagan1625efc2021-06-10 18:24:34 +0100586 CHECK(backendOptions[0].GetOption(2).GetName() == "Option3");
587 CHECK(backendOptions[0].GetOption(2).GetValue().IsString() == true);
588 CHECK(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value");
Derek Lamberti836b27b2019-11-20 10:51:57 +0000589
590 // Second group
Sadik Armagan1625efc2021-06-10 18:24:34 +0100591 CHECK(backendOptions[1].GetBackendId().Get() == "FakeBackend1");
592 CHECK(backendOptions[1].GetOption(0).GetName() == "Option4");
593 CHECK(backendOptions[1].GetOption(0).GetValue().IsInt() == true);
594 CHECK(backendOptions[1].GetOption(0).GetValue().AsInt() == 42);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000595}
596
Sadik Armagan1625efc2021-06-10 18:24:34 +0100597TEST_CASE("ProfilingDisable")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000598{
599 using namespace armnn;
600
601 // Create runtime in which the test will run
602 armnn::IRuntime::CreationOptions options;
Kevin Mayd92a6e42021-02-04 10:27:41 +0000603 armnn::RuntimeImpl runtime(options);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000604
605 // build up the structure of the network
606 INetworkPtr net(INetwork::Create());
607
608 IConnectableLayer* input = net->AddInputLayer(0);
609
610 // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef.
611 NormalizationDescriptor descriptor;
612 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor);
613
614 IConnectableLayer* output = net->AddOutputLayer(0);
615
616 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
617 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
618
619 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
620 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
621
622 // optimize the network
623 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000624 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000625
626 // Load it into the runtime. It should succeed.
627 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100628 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000629
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000630 ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
631 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000632 auto readableBuffer = bufferManager.GetReadableBuffer();
633
634 // Profiling is not enabled, the post-optimisation structure should not be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100635 CHECK(!readableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000636}
637
Sadik Armagan1625efc2021-06-10 18:24:34 +0100638TEST_CASE("ProfilingEnableCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000639{
640 using namespace armnn;
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000641 using namespace arm::pipe;
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000642
643 // Create runtime in which the test will run
644 armnn::IRuntime::CreationOptions options;
645 options.m_ProfilingOptions.m_EnableProfiling = true;
Keith Davis33ed2212020-03-30 10:43:41 +0100646 options.m_ProfilingOptions.m_TimelineEnabled = true;
647
Kevin Mayd92a6e42021-02-04 10:27:41 +0000648 armnn::RuntimeImpl runtime(options);
Jim Flynn4c9ed1d2022-01-23 23:57:20 +0000649 GetProfilingService(&runtime).ResetExternalProfilingOptions(
650 ConvertExternalProfilingOptions(options.m_ProfilingOptions), false);
Keith Davis33ed2212020-03-30 10:43:41 +0100651
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000652 ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
Keith Davis33ed2212020-03-30 10:43:41 +0100653 profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
654 profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
655 profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000656
657 // build up the structure of the network
658 INetworkPtr net(INetwork::Create());
659
660 IConnectableLayer* input = net->AddInputLayer(0, "input");
661
662 NormalizationDescriptor descriptor;
663 IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
664
665 IConnectableLayer* output = net->AddOutputLayer(0, "output");
666
667 input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
668 normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
669
670 input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
671 normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
672
673 // optimize the network
674 std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
Sadik Armagan3184c902020-03-18 10:57:30 +0000675 IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000676
677 ProfilingGuid optNetGuid = optNet->GetGuid();
678
679 // Load it into the runtime. It should succeed.
680 armnn::NetworkId netId;
Sadik Armagan1625efc2021-06-10 18:24:34 +0100681 CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000682
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000683 BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000684 auto readableBuffer = bufferManager.GetReadableBuffer();
685
686 // Profiling is enabled, the post-optimisation structure should be created
Sadik Armagan1625efc2021-06-10 18:24:34 +0100687 CHECK(readableBuffer != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000688
689 unsigned int size = readableBuffer->GetSize();
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000690
691 const unsigned char* readableData = readableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100692 CHECK(readableData != nullptr);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000693
694 unsigned int offset = 0;
695
Keith Davis97da5e22020-03-05 16:25:28 +0000696 // Verify Header
Jim Flynnf7713212020-07-14 09:50:59 +0100697 VerifyTimelineHeaderBinary(readableData, offset, size - 8);
Keith Davis97da5e22020-03-05 16:25:28 +0000698
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000699 // Post-optimisation network
700 // Network entity
Jim Flynn6398a982020-05-27 17:05:21 +0100701 VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000702
703 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000704 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
705 EmptyOptional(),
706 optNetGuid,
707 LabelsAndEventClasses::NETWORK_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000708 LabelsAndEventClasses::TYPE_GUID,
709 readableData,
710 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000711
Jim Flynnf7713212020-07-14 09:50:59 +0100712 // Network - START OF LIFE
713 ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(),
714 EmptyOptional(),
715 EmptyOptional(),
716 readableData,
717 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100718
719 // Network - START OF LIFE event relationship
720 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
721 EmptyOptional(),
722 optNetGuid,
723 networkSolEventGuid,
724 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
725 readableData,
726 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100727
728 // Process ID Label
729 int processID = armnnUtils::Processes::GetCurrentId();
730 std::stringstream ss;
731 ss << processID;
732 std::string processIdLabel = ss.str();
733 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100734
735 // Entity - Process ID relationship
736 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
737 EmptyOptional(),
738 optNetGuid,
739 EmptyOptional(),
740 LabelsAndEventClasses::PROCESS_ID_GUID,
741 readableData,
742 offset);
Jim Flynnf7713212020-07-14 09:50:59 +0100743
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000744 // Input layer
745 // Input layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000746 VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000747
748 // Name Entity
Jim Flynn6398a982020-05-27 17:05:21 +0100749 ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000750
751 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000752 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
753 EmptyOptional(),
754 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100755 inputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000756 LabelsAndEventClasses::NAME_GUID,
757 readableData,
758 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000759
760 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000761 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
762 EmptyOptional(),
763 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100764 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000765 LabelsAndEventClasses::TYPE_GUID,
766 readableData,
767 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000768
769 // Network - Input layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000770 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
771 EmptyOptional(),
772 optNetGuid,
773 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100774 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000775 readableData,
776 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000777
778 // Normalization layer
779 // Normalization layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000780 VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000781
782 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100783 ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData(
784 EmptyOptional(), "normalization", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000785
786 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000787 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
788 EmptyOptional(),
789 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100790 normalizationLayerNameGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000791 LabelsAndEventClasses::NAME_GUID,
792 readableData,
793 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000794
795 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000796 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
797 EmptyOptional(),
798 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100799 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000800 LabelsAndEventClasses::TYPE_GUID,
801 readableData,
802 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000803
804 // Network - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000805 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
806 EmptyOptional(),
807 optNetGuid,
808 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100809 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000810 readableData,
811 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000812
813 // Input layer - Normalize layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000814 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
815 EmptyOptional(),
816 input->GetGuid(),
817 normalize->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000818 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000819 readableData,
820 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000821
822 // Normalization workload
823 // Normalization workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100824 ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData(
825 EmptyOptional(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000826
827 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000828 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
829 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100830 normalizationWorkloadGuid,
831 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000832 LabelsAndEventClasses::TYPE_GUID,
833 readableData,
834 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000835
836 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100837 ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
838 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000839
840 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000841 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
842 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100843 normalizationWorkloadGuid,
844 cpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000845 LabelsAndEventClasses::BACKENDID_GUID,
846 readableData,
847 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000848
849 // Normalize layer - Normalize workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000850 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
851 EmptyOptional(),
852 normalize->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100853 normalizationWorkloadGuid,
854 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000855 readableData,
856 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000857
858 // Output layer
859 // Output layer entity
Keith Davis97da5e22020-03-05 16:25:28 +0000860 VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000861
862 // Name entity
Jim Flynn6398a982020-05-27 17:05:21 +0100863 ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
864 EmptyOptional(), "output", readableData, offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000865
866 // Entity - Name relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000867 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
868 EmptyOptional(),
869 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100870 outputLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000871 LabelsAndEventClasses::NAME_GUID,
872 readableData,
873 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000874
875 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000876 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
877 EmptyOptional(),
878 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100879 LabelsAndEventClasses::LAYER_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000880 LabelsAndEventClasses::TYPE_GUID,
881 readableData,
882 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000883
884 // Network - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000885 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
886 EmptyOptional(),
887 optNetGuid,
888 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100889 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000890 readableData,
891 offset);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000892
893 // Normalize layer - Output layer relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000894 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
895 EmptyOptional(),
896 normalize->GetGuid(),
897 output->GetGuid(),
Keith Davis97da5e22020-03-05 16:25:28 +0000898 LabelsAndEventClasses::CONNECTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000899 readableData,
900 offset);
Derek Lamberti836b27b2019-11-20 10:51:57 +0000901
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +0000902 bufferManager.MarkRead(readableBuffer);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000903
904 // Creates structures for input & output.
905 std::vector<float> inputData(16);
906 std::vector<float> outputData(16);
907
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100908 TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
909 inputTensorInfo.SetConstant(true);
Keith Davis97da5e22020-03-05 16:25:28 +0000910 InputTensors inputTensors
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000911 {
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100912 {0, ConstTensor(inputTensorInfo, inputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000913 };
914 OutputTensors outputTensors
915 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000916 {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000917 };
918
919 // Does the inference.
Sadik Armagan3184c902020-03-18 10:57:30 +0000920 runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000921
Finn Williamsb6a402f2020-03-24 13:46:22 +0000922 // Get readable buffer for input workload
923 auto inputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100924 CHECK(inputReadableBuffer != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +0000925
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000926 // Get readable buffer for output workload
927 auto outputReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100928 CHECK(outputReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000929
Finn Williamsb6a402f2020-03-24 13:46:22 +0000930 // Get readable buffer for inference timeline
931 auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100932 CHECK(inferenceReadableBuffer != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000933
934 // Validate input workload data
935 size = inputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100936 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000937
938 readableData = inputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100939 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000940
941 offset = 0;
942
Keith Davis97da5e22020-03-05 16:25:28 +0000943 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100944 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000945
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000946 // Input workload
947 // Input workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100948 ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000949
950 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000951 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
952 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100953 inputWorkloadGuid,
954 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000955 LabelsAndEventClasses::TYPE_GUID,
956 readableData,
957 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000958
959 // BackendId entity
Jim Flynn6398a982020-05-27 17:05:21 +0100960 ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData(
961 EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000962
963 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000964 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
965 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +0100966 inputWorkloadGuid,
967 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +0000968 LabelsAndEventClasses::BACKENDID_GUID,
969 readableData,
970 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000971
972 // Input layer - Input workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +0000973 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
974 EmptyOptional(),
975 input->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +0100976 inputWorkloadGuid,
977 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +0000978 readableData,
979 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000980
981 bufferManager.MarkRead(inputReadableBuffer);
982
983 // Validate output workload data
984 size = outputReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100985 CHECK(size == 164);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000986
987 readableData = outputReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +0100988 CHECK(readableData != nullptr);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000989
990 offset = 0;
991
Keith Davis97da5e22020-03-05 16:25:28 +0000992 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +0100993 VerifyTimelineHeaderBinary(readableData, offset, 156);
Keith Davis97da5e22020-03-05 16:25:28 +0000994
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000995 // Output workload
996 // Output workload entity
Jim Flynn6398a982020-05-27 17:05:21 +0100997 ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +0000998
999 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001000 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1001 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001002 outputWorkloadGuid,
1003 LabelsAndEventClasses::WORKLOAD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001004 LabelsAndEventClasses::TYPE_GUID,
1005 readableData,
1006 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001007
1008 // BackendId entity
Keith Davis97da5e22020-03-05 16:25:28 +00001009 VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001010
1011 // Entity - BackendId relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001012 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1013 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001014 outputWorkloadGuid,
1015 CpuRefLabelGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001016 LabelsAndEventClasses::BACKENDID_GUID,
1017 readableData,
1018 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001019
1020 // Output layer - Output workload relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001021 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1022 EmptyOptional(),
1023 output->GetGuid(),
Jim Flynn6398a982020-05-27 17:05:21 +01001024 outputWorkloadGuid,
1025 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001026 readableData,
1027 offset);
Narumol Prangnawarataa68e012019-11-29 17:17:43 +00001028
1029 bufferManager.MarkRead(outputReadableBuffer);
David Monahan6198fe02019-12-02 08:35:43 +00001030
1031 // Validate inference data
1032 size = inferenceReadableBuffer->GetSize();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001033 CHECK(size == 976 + 8 * ThreadIdSize);
David Monahan6198fe02019-12-02 08:35:43 +00001034
1035 readableData = inferenceReadableBuffer->GetReadableData();
Sadik Armagan1625efc2021-06-10 18:24:34 +01001036 CHECK(readableData != nullptr);
David Monahan6198fe02019-12-02 08:35:43 +00001037
1038 offset = 0;
1039
Keith Davis97da5e22020-03-05 16:25:28 +00001040 // Verify Header
Finn Williams0a336dc2020-05-11 15:39:58 +01001041 VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize);
Keith Davis97da5e22020-03-05 16:25:28 +00001042
David Monahan6198fe02019-12-02 08:35:43 +00001043 // Inference timeline trace
1044 // Inference entity
Jim Flynn6398a982020-05-27 17:05:21 +01001045 ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001046
1047 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001048 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1049 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001050 inferenceGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001051 LabelsAndEventClasses::INFERENCE_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001052 LabelsAndEventClasses::TYPE_GUID,
1053 readableData,
1054 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001055
1056 // Network - Inference relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001057 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1058 EmptyOptional(),
1059 optNetGuid,
Jim Flynn6398a982020-05-27 17:05:21 +01001060 inferenceGuid,
1061 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001062 readableData,
1063 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001064
1065 // Start Inference life
1066 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001067 ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
1068 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001069
1070 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001071 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1072 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001073 inferenceGuid,
1074 inferenceEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001075 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1076 readableData,
1077 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001078
1079 // Execution
1080 // Input workload execution
1081 // Input workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001082 ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1083 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001084
1085 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001086 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1087 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001088 inputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001089 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001090 LabelsAndEventClasses::TYPE_GUID,
1091 readableData,
1092 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001093
1094 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001095 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1096 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001097 inferenceGuid,
1098 inputWorkloadExecutionGuid,
1099 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001100 readableData,
1101 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001102
1103 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001104 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1105 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001106 inputWorkloadGuid,
1107 inputWorkloadExecutionGuid,
1108 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001109 readableData,
1110 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001111
1112 // Start Input workload execution life
1113 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001114 ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
1115 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001116
1117 // Input workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001118 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1119 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001120 inputWorkloadExecutionGuid,
1121 inputWorkloadExecutionSOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001122 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1123 readableData,
1124 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001125
1126 // End of Input workload execution life
1127 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001128 ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
1129 EmptyOptional(), EmptyOptional(), 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,
1133 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001134 inputWorkloadExecutionGuid,
1135 inputWorkloadExecutionEOLEventId,
Keith Davis97da5e22020-03-05 16:25:28 +00001136 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1137 readableData,
1138 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001139
1140 // Normalize workload execution
1141 // Normalize workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001142 ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1143 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001144
1145 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001146 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1147 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001148 normalizeWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001149 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001150 LabelsAndEventClasses::TYPE_GUID,
1151 readableData,
1152 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001153
1154 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001155 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1156 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001157 inferenceGuid,
1158 normalizeWorkloadExecutionGuid,
1159 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001160 readableData,
1161 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001162
1163 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001164 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1165 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001166 normalizationWorkloadGuid,
1167 normalizeWorkloadExecutionGuid,
1168 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001169 readableData,
1170 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001171
1172 // Start Normalize workload execution life
1173 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001174 ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1175 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001176
1177 // Normalize workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001178 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1179 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001180 normalizeWorkloadExecutionGuid,
1181 normalizationWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001182 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1183 readableData,
1184 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001185
1186 // End of Normalize workload execution life
1187 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001188 ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1189 EmptyOptional(), EmptyOptional(), 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,
1193 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001194 normalizeWorkloadExecutionGuid,
1195 normalizationWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001196 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1197 readableData,
1198 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001199
1200 // Output workload execution
1201 // Output workload execution entity
Jim Flynn6398a982020-05-27 17:05:21 +01001202 ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1203 EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001204
1205 // Entity - Type relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001206 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1207 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001208 outputWorkloadExecutionGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001209 LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001210 LabelsAndEventClasses::TYPE_GUID,
1211 readableData,
1212 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001213
1214 // Inference - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001215 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1216 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001217 inferenceGuid,
1218 outputWorkloadExecutionGuid,
1219 LabelsAndEventClasses::CHILD_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001220 readableData,
1221 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001222
1223 // Workload - Workload execution relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001224 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1225 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001226 outputWorkloadGuid,
1227 outputWorkloadExecutionGuid,
1228 LabelsAndEventClasses::EXECUTION_OF_GUID,
Keith Davis97da5e22020-03-05 16:25:28 +00001229 readableData,
1230 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001231
1232 // Start Output workload execution life
1233 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001234 ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1235 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001236
1237 // Output workload execution - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001238 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1239 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001240 outputWorkloadExecutionGuid,
1241 outputWorkloadExecutionSOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001242 LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1243 readableData,
1244 offset);
Finn Williams0a336dc2020-05-11 15:39:58 +01001245
David Monahan6198fe02019-12-02 08:35:43 +00001246 // End of Normalize workload execution life
1247 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001248 ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1249 EmptyOptional(), EmptyOptional(), 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,
1253 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001254 outputWorkloadExecutionGuid,
1255 outputWorkloadExecutionEOLEventGuid,
Keith Davis97da5e22020-03-05 16:25:28 +00001256 LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1257 readableData,
1258 offset);
David Monahan6198fe02019-12-02 08:35:43 +00001259
1260 // End of Inference life
1261 // Event packet - timeline, threadId, eventGuid
Jim Flynn6398a982020-05-27 17:05:21 +01001262 ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
1263 EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
David Monahan6198fe02019-12-02 08:35:43 +00001264
1265 // Inference - event relationship
Keith Davis97da5e22020-03-05 16:25:28 +00001266 VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1267 EmptyOptional(),
Jim Flynn6398a982020-05-27 17:05:21 +01001268 inferenceGuid,
1269 inferenceEOLEventGuid,
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 bufferManager.MarkRead(inferenceReadableBuffer);
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001275}
1276
Sadik Armagan1625efc2021-06-10 18:24:34 +01001277TEST_CASE("ProfilingPostOptimisationStructureCpuRef")
Narumol Prangnawaratdf31cfe2019-11-22 11:26:06 +00001278{
1279 VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef);
1280}
1281
Sadik Armagan1625efc2021-06-10 18:24:34 +01001282}