Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 5 | |
Aron Virginas-Tar | c26ba75 | 2018-10-22 13:32:01 +0100 | [diff] [blame] | 6 | #include <armnn/Descriptors.hpp> |
| 7 | #include <armnn/IRuntime.hpp> |
| 8 | #include <armnn/INetwork.hpp> |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame^] | 9 | #include <armnn/profiling/ArmNNProfiling.hpp> |
| 10 | #include <ArmNNProfilingServiceInitialiser.hpp> |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 11 | #include <ProfilingOptionsConverter.hpp> |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 12 | #include <Processes.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 13 | #include <Runtime.hpp> |
Aron Virginas-Tar | c26ba75 | 2018-10-22 13:32:01 +0100 | [diff] [blame] | 14 | #include <armnn/TypesUtils.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 16 | |
Nikhil Raj | 77fe76b | 2021-06-09 14:55:32 +0100 | [diff] [blame] | 17 | #include <common/include/LabelsAndEventClasses.hpp> |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 18 | #include <test/ProfilingTestUtils.hpp> |
| 19 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 20 | #include <HeapProfiling.hpp> |
| 21 | #include <LeakChecking.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 22 | |
| 23 | #ifdef WITH_VALGRIND |
Aron Virginas-Tar | c26ba75 | 2018-10-22 13:32:01 +0100 | [diff] [blame] | 24 | #include <valgrind/memcheck.h> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | #endif |
| 26 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 27 | #include <doctest/doctest.h> |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 28 | #include "RuntimeTests.hpp" |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 29 | #include <TestUtils.hpp> |
Aron Virginas-Tar | c26ba75 | 2018-10-22 13:32:01 +0100 | [diff] [blame] | 30 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | namespace armnn |
| 32 | { |
| 33 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 34 | void RuntimeLoadedNetworksReserve(armnn::RuntimeImpl* runtime) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 35 | { |
| 36 | runtime->m_LoadedNetworks.reserve(1); |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 41 | TEST_SUITE("Runtime") |
| 42 | { |
| 43 | TEST_CASE("RuntimeUnloadNetwork") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 44 | { |
| 45 | // build 2 mock-networks and load them into the runtime |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 46 | armnn::IRuntime::CreationOptions options; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 47 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 48 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 49 | // Mock network 1. |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 50 | armnn::NetworkId networkIdentifier1 = 1; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 51 | armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create()); |
| 52 | mockNetwork1->AddInputLayer(0, "test layer"); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 53 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 54 | runtime->LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime->GetDeviceSpec())); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 56 | // Mock network 2. |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 57 | armnn::NetworkId networkIdentifier2 = 2; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 58 | armnn::INetworkPtr mockNetwork2(armnn::INetwork::Create()); |
| 59 | mockNetwork2->AddInputLayer(0, "test layer"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 60 | runtime->LoadNetwork(networkIdentifier2, Optimize(*mockNetwork2, backends, runtime->GetDeviceSpec())); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 61 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | // Unloads one by its networkID. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 63 | CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Success); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 64 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 65 | CHECK(runtime->UnloadNetwork(networkIdentifier1) == armnn::Status::Failure); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 68 | TEST_CASE("RuntimePreImportInputs") |
| 69 | { |
| 70 | armnn::IRuntime::CreationOptions options; |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 71 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 72 | armnn::NetworkId networkId = 1; |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 73 | armnn::INetworkPtr testNetwork(armnn::INetwork::Create()); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 74 | |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 75 | auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer"); |
| 76 | auto inputLayer2 = testNetwork->AddInputLayer(1, "input 2 layer"); |
| 77 | auto addLayer = testNetwork->AddAdditionLayer("add layer"); |
| 78 | auto outputLayer = testNetwork->AddOutputLayer(2, "output layer"); |
| 79 | |
| 80 | TensorInfo tensorInfo{{4}, armnn::DataType::Signed32}; |
| 81 | |
| 82 | inputLayer1->GetOutputSlot(0).Connect(addLayer->GetInputSlot(0)); |
| 83 | inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 84 | |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 85 | inputLayer2->GetOutputSlot(0).Connect(addLayer->GetInputSlot(1)); |
| 86 | inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 87 | |
| 88 | addLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 89 | addLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 90 | |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 91 | std::vector<armnn::BackendId> backends = {armnn::Compute::CpuRef}; |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 92 | |
| 93 | std::string er; |
| 94 | armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Undefined); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 95 | runtime->LoadNetwork(networkId, |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 96 | Optimize(*testNetwork, backends, runtime->GetDeviceSpec()), |
| 97 | er, |
| 98 | networkProperties); |
| 99 | |
| 100 | std::vector<int> inputData1(4, 10); |
| 101 | std::vector<int> inputData2(4, 20); |
| 102 | std::vector<int> output(4); |
| 103 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 104 | ConstTensor inputTensor1({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData1.data()); |
| 105 | ConstTensor inputTensor2({{4}, armnn::DataType::Signed32, 0.0f, 0, true}, inputData2.data()); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 106 | Tensor outputTensor({{4}, armnn::DataType::Signed32}, output.data()); |
| 107 | |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 108 | auto importedInputVec1 = runtime->ImportInputs(networkId, {{0, inputTensor1}}); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 109 | CHECK(importedInputVec1.size() == 1); |
| 110 | CHECK(importedInputVec1[0] == 0); |
| 111 | |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 112 | auto memHandle = runtime->CreateWorkingMemHandle(networkId); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 113 | |
| 114 | runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0 /* pre-imported id */}); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 115 | for (auto val: output) { |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 116 | CHECK(val == 30); |
| 117 | } |
| 118 | |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 119 | auto importedInputVec2 = runtime->ImportInputs(networkId, {{1, inputTensor2}}); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 120 | CHECK(importedInputVec2.size() == 1); |
| 121 | CHECK(importedInputVec2[0] == 1); |
| 122 | |
| 123 | runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {{2, outputTensor}}, {1 /* pre-imported id */}); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 124 | for (auto val: output) { |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 125 | CHECK(val == 30); |
| 126 | } |
| 127 | |
| 128 | runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 129 | for (auto val: output) { |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 130 | CHECK(val == 30); |
| 131 | } |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 132 | // Duplicate ImportedInputId and LayerBindingId |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 133 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 0});, |
| 134 | armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 135 | // Duplicate LayerBindingId |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 136 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {1});, |
| 137 | armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 138 | // Incorrect ImportedInputId |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 139 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {10});, |
| 140 | armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 141 | // Incorrect LayerBindingId |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 142 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {1});, |
| 143 | armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 144 | // Incorrect layer binding id and ImportedInputId |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 145 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{-2, inputTensor2}}, {{2, outputTensor}}, {10});, |
| 146 | armnn::InvalidArgumentException); |
| 147 | auto importedInputVec3 = runtime->ImportInputs(networkId, {{1, inputTensor2}}); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 148 | CHECK(importedInputVec3[0] == 2); |
| 149 | // Too many ImportedInputIds |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 150 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1, 2});, |
| 151 | armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 152 | // Too many InputTensors |
| 153 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 154 | {{0, inputTensor2}, |
| 155 | {1, inputTensor2}, |
| 156 | {2, inputTensor2}}, |
| 157 | {{2, outputTensor}});, armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 158 | // Too few ImportedInputIds |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 159 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0});, |
| 160 | armnn::InvalidArgumentException); |
| 161 | runtime->ClearImportedInputs(networkId, {1}); |
| 162 | runtime->Execute(*memHandle.get(), {{1, inputTensor2}}, {{2, outputTensor}}, {0}, {}); |
| 163 | for (auto val: output) { |
| 164 | CHECK(val == 30); |
| 165 | } |
| 166 | // Using deleted pre-imported input |
| 167 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {}, {{2, outputTensor}}, {0, 1}, {});, |
| 168 | armnn::InvalidArgumentException); |
| 169 | |
| 170 | // Trying to delete deleted pre-imported tensor |
| 171 | CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {1});, armnn::InvalidArgumentException); |
| 172 | |
| 173 | // Trying to delete unknown pre-imported tensor |
| 174 | CHECK_THROWS_AS(runtime->ClearImportedInputs(networkId, {10});, armnn::InvalidArgumentException); |
| 175 | } |
| 176 | TEST_CASE("RuntimePreImportOutputs") |
| 177 | { |
| 178 | armnn::IRuntime::CreationOptions options; |
| 179 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 180 | |
| 181 | armnn::NetworkId networkId = 1; |
| 182 | |
| 183 | armnn::INetworkPtr testNetwork(armnn::INetwork::Create()); |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 184 | TensorInfo tensorInfo{{4}, armnn::DataType::Float32, 0.0f, 0, true}; |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 185 | |
| 186 | auto inputLayer1 = testNetwork->AddInputLayer(0, "input 1 layer"); |
| 187 | inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 188 | |
| 189 | ActivationDescriptor activationDescriptor; |
| 190 | activationDescriptor.m_Function = ActivationFunction::BoundedReLu; |
| 191 | activationDescriptor.m_A = 2.0f; |
| 192 | activationDescriptor.m_B = 0.0f; |
| 193 | auto activationLayer1 = testNetwork->AddActivationLayer(activationDescriptor, "add layer"); |
| 194 | auto outputLayer1 = testNetwork->AddOutputLayer(2, "output layer"); |
| 195 | |
| 196 | inputLayer1->GetOutputSlot(0).Connect(activationLayer1->GetInputSlot(0)); |
| 197 | |
| 198 | activationLayer1->GetOutputSlot(0).Connect(outputLayer1->GetInputSlot(0)); |
| 199 | activationLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 200 | |
| 201 | auto inputLayer2 = testNetwork->AddInputLayer(1, "input 1 layer"); |
| 202 | |
| 203 | activationDescriptor.m_A = 4.0f; |
| 204 | activationDescriptor.m_B = 2.0f; |
| 205 | auto activationLayer2 = testNetwork->AddActivationLayer(activationDescriptor, "add layer"); |
| 206 | auto outputLayer2 = testNetwork->AddOutputLayer(3, "output layer"); |
| 207 | |
| 208 | inputLayer2->GetOutputSlot(0).Connect(activationLayer2->GetInputSlot(0)); |
| 209 | inputLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 210 | |
| 211 | activationLayer2->GetOutputSlot(0).Connect(outputLayer2->GetInputSlot(0)); |
| 212 | activationLayer2->GetOutputSlot(0).SetTensorInfo(tensorInfo); |
| 213 | |
| 214 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 215 | |
| 216 | std::string er; |
| 217 | armnn::INetworkProperties networkProperties(true, MemorySource::Malloc, MemorySource::Malloc); |
| 218 | runtime->LoadNetwork(networkId, |
| 219 | Optimize(*testNetwork, backends, runtime->GetDeviceSpec()), |
| 220 | er, |
| 221 | networkProperties); |
| 222 | |
| 223 | std::vector<float> inputData1(4, 1.0f); |
| 224 | std::vector<float> inputData2(4, 3.0f); |
| 225 | |
| 226 | std::vector<float> outputData1(4); |
| 227 | std::vector<float> outputData2(4); |
| 228 | |
| 229 | ConstTensor inputTensor1(tensorInfo, inputData1.data()); |
| 230 | ConstTensor inputTensor2(tensorInfo, inputData2.data()); |
| 231 | |
| 232 | Tensor outputTensor1{tensorInfo, outputData1.data()}; |
| 233 | Tensor outputTensor2{tensorInfo, outputData2.data()}; |
| 234 | |
| 235 | InputTensors inputTensors = {{0, inputTensor1}, {1, inputTensor2}}; |
| 236 | |
| 237 | std::pair<LayerBindingId, class Tensor> output1{2, outputTensor1}; |
| 238 | std::pair<LayerBindingId, class Tensor> output2{3, outputTensor2}; |
| 239 | |
| 240 | auto testOutputs = [&]() |
| 241 | { |
| 242 | for (auto val : outputData1) |
| 243 | { |
| 244 | CHECK(val == 1.0f); |
| 245 | } |
| 246 | |
| 247 | for (auto val : outputData2) |
| 248 | { |
| 249 | CHECK(val == 3.0f); |
| 250 | } |
| 251 | }; |
| 252 | |
| 253 | auto memHandle = runtime->CreateWorkingMemHandle(networkId); |
| 254 | |
| 255 | runtime->Execute(*memHandle.get(),inputTensors, {output1, output2}); |
| 256 | testOutputs(); |
| 257 | |
| 258 | auto importedOutputVec = runtime->ImportOutputs(networkId, {output1, output2 }); |
| 259 | CHECK(importedOutputVec.size() == 2); |
| 260 | CHECK(importedOutputVec[0] == 0); |
| 261 | CHECK(importedOutputVec[1] == 1); |
| 262 | |
| 263 | runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec); |
| 264 | testOutputs(); |
| 265 | |
| 266 | runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {1}); |
| 267 | testOutputs(); |
| 268 | |
| 269 | runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0}); |
| 270 | testOutputs(); |
| 271 | |
| 272 | auto importedInputVec = runtime->ImportInputs(networkId, inputTensors); |
| 273 | CHECK(importedInputVec.size() == 2); |
| 274 | CHECK(importedInputVec[0] == 0); |
| 275 | CHECK(importedInputVec[1] == 1); |
| 276 | |
| 277 | runtime->Execute(*memHandle.get(), {}, {}, importedInputVec, importedOutputVec); |
| 278 | testOutputs(); |
| 279 | |
| 280 | runtime->Execute(*memHandle.get(), {{0, inputTensor1}}, {output2}, {1}, {0}); |
| 281 | testOutputs(); |
| 282 | |
| 283 | // Too many ids |
| 284 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output2}, {}, {0, 1});, |
| 285 | armnn::InvalidArgumentException); |
| 286 | |
| 287 | // Duplicate ids |
| 288 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {1});, |
| 289 | armnn::InvalidArgumentException); |
| 290 | |
| 291 | // Duplicate ids |
| 292 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1, output1}, {}, {});, |
| 293 | armnn::InvalidArgumentException); |
| 294 | |
| 295 | // Duplicate ids |
| 296 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, {0, 0}), |
| 297 | armnn::InvalidArgumentException); |
| 298 | |
| 299 | // Unknown id |
| 300 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {output1}, {}, {3});, |
| 301 | armnn::InvalidArgumentException); |
| 302 | |
| 303 | // Unknown id |
| 304 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{4, outputTensor2}}, {}, {1});, |
| 305 | armnn::InvalidArgumentException); |
| 306 | |
| 307 | // Input id for output |
| 308 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});, |
| 309 | armnn::InvalidArgumentException); |
| 310 | |
| 311 | // Input id for output |
| 312 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {{0, outputTensor2}}, {}, {1});, |
| 313 | armnn::InvalidArgumentException); |
| 314 | |
| 315 | // Output id for input |
| 316 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), {{2, inputTensor1}}, {{0, outputTensor2}}, {1}, {1, 0});, |
| 317 | armnn::InvalidArgumentException); |
| 318 | |
| 319 | runtime->ClearImportedOutputs(networkId, {1}); |
| 320 | |
| 321 | runtime->Execute(*memHandle.get(), inputTensors, {output2}, {}, {0}); |
| 322 | testOutputs(); |
| 323 | |
| 324 | // Trying to use deleted pre-imported tensor |
| 325 | CHECK_THROWS_AS(runtime->Execute(*memHandle.get(), inputTensors, {}, {}, importedOutputVec), |
| 326 | armnn::InvalidArgumentException); |
| 327 | |
| 328 | // Trying to delete deleted pre-imported tensor |
| 329 | CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {1});, armnn::InvalidArgumentException); |
| 330 | |
| 331 | // Trying to delete unknown pre-imported tensor |
| 332 | CHECK_THROWS_AS(runtime->ClearImportedOutputs(networkId, {10});, armnn::InvalidArgumentException); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 333 | } |
| 334 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 335 | // Note: the current builds we don't do valgrind and gperftools based leak checking at the same |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 336 | // time, so in practice WITH_VALGRIND and ARMNN_LEAK_CHECKING_ENABLED are exclusive. The |
| 337 | // valgrind tests can stay for x86 builds, but on hikey Valgrind is just way too slow |
| 338 | // to be integrated into the CI system. |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 339 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 340 | #ifdef ARMNN_LEAK_CHECKING_ENABLED |
| 341 | |
| 342 | struct DisableGlobalLeakChecking |
| 343 | { |
| 344 | DisableGlobalLeakChecking() |
| 345 | { |
| 346 | ARMNN_LOCAL_LEAK_CHECKING_ONLY(); |
| 347 | } |
| 348 | }; |
| 349 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 350 | TEST_CASE_FIXTURE(DisableGlobalLeakChecking, "RuntimeHeapMemoryUsageSanityChecks") |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 351 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 352 | CHECK(ARMNN_LEAK_CHECKER_IS_ACTIVE()); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 353 | { |
| 354 | ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Outer"); |
| 355 | { |
| 356 | ARMNN_SCOPED_LEAK_CHECKER("Sanity_Check_Inner"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 357 | CHECK(ARMNN_NO_LEAKS_IN_SCOPE() == true); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 358 | std::unique_ptr<char[]> dummyAllocation(new char[1000]); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 359 | // "A leak of 1000 bytes is expected here. " |
| 360 | // "Please make sure environment variable: HEAPCHECK=draconian is set!" |
| 361 | CHECK((ARMNN_NO_LEAKS_IN_SCOPE() == false)); |
| 362 | CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 1000); |
| 363 | CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 1); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 364 | } |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 365 | CHECK(ARMNN_NO_LEAKS_IN_SCOPE()); |
| 366 | CHECK(ARMNN_BYTES_LEAKED_IN_SCOPE() == 0); |
| 367 | CHECK(ARMNN_OBJECTS_LEAKED_IN_SCOPE() == 0); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 371 | #endif // ARMNN_LEAK_CHECKING_ENABLED |
| 372 | |
| 373 | // Note: this part of the code is due to be removed when we fully trust the gperftools based results. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 374 | #ifdef WITH_VALGRIND |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 375 | // Run with the following command to get all the amazing output (in the devenv/build folder) :) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 376 | // valgrind --leak-check=full --show-leak-kinds=all --log-file=Valgrind_Memcheck_Leak_Report.txt armnn/test/UnitTests |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 377 | TEST_CASE("RuntimeMemoryLeak") |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 378 | { |
| 379 | // From documentation: |
| 380 | |
| 381 | // This means that no pointer to the block can be found. The block is classified as "lost", |
| 382 | // because the programmer could not possibly have freed it at program exit, since no pointer to it exists. |
| 383 | unsigned long leakedBefore = 0; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 384 | unsigned long leakedAfter = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 385 | |
| 386 | // A start-pointer or chain of start-pointers to the block is found. Since the block is still pointed at, |
| 387 | // the programmer could, at least in principle, have freed it before program exit. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 388 | // We want to test this in case memory is not freed as early as it could have been. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 389 | unsigned long reachableBefore = 0; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 390 | unsigned long reachableAfter = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 391 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 392 | // Needed as out params but we don't test them. |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 393 | unsigned long dubious = 0; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 394 | unsigned long suppressed = 0; |
| 395 | |
| 396 | armnn::NetworkId networkIdentifier1 = 1; |
| 397 | |
| 398 | // ensure that runtime is large enough before checking for memory leaks |
| 399 | // otherwise when loading the network it will automatically reserve memory that won't be released until destruction |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 400 | armnn::IRuntime::CreationOptions options; |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 401 | armnn::RuntimeImpl runtime(options); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 402 | armnn::RuntimeLoadedNetworksReserve(&runtime); |
| 403 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 404 | { |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 405 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 406 | |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 407 | armnn::INetworkPtr mockNetwork1(armnn::INetwork::Create()); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 408 | mockNetwork1->AddInputLayer(0, "test layer"); |
| 409 | |
Matteo Martincigh | 9326aab | 2018-11-15 10:54:54 +0000 | [diff] [blame] | 410 | // Warm-up load/unload pair to put the runtime in a stable state (memory-wise). |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 411 | runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec())); |
Matteo Martincigh | 9326aab | 2018-11-15 10:54:54 +0000 | [diff] [blame] | 412 | runtime.UnloadNetwork(networkIdentifier1); |
| 413 | |
| 414 | // Checks for leaks before we load the network and record them so that we can see the delta after unloading. |
| 415 | VALGRIND_DO_QUICK_LEAK_CHECK; |
| 416 | VALGRIND_COUNT_LEAKS(leakedBefore, dubious, reachableBefore, suppressed); |
| 417 | |
| 418 | // The actual test. |
| 419 | runtime.LoadNetwork(networkIdentifier1, Optimize(*mockNetwork1, backends, runtime.GetDeviceSpec())); |
| 420 | runtime.UnloadNetwork(networkIdentifier1); |
| 421 | |
| 422 | VALGRIND_DO_ADDED_LEAK_CHECK; |
| 423 | VALGRIND_COUNT_LEAKS(leakedAfter, dubious, reachableAfter, suppressed); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 424 | } |
| 425 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 426 | // If we're not running under Valgrind, these vars will have been initialised to 0, so this will always pass. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 427 | CHECK(leakedBefore == leakedAfter); |
| 428 | CHECK(reachableBefore == reachableAfter); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 429 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 430 | // These are needed because VALGRIND_COUNT_LEAKS is a macro that assigns to the parameters |
| 431 | // so they are assigned to, but still considered unused, causing a warning. |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 432 | IgnoreUnused(dubious); |
| 433 | IgnoreUnused(suppressed); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 434 | } |
Aron Virginas-Tar | c26ba75 | 2018-10-22 13:32:01 +0100 | [diff] [blame] | 435 | #endif // WITH_VALGRIND |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 436 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 437 | TEST_CASE("RuntimeCpuRef") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 438 | { |
| 439 | using namespace armnn; |
| 440 | |
| 441 | // Create runtime in which test will run |
| 442 | armnn::IRuntime::CreationOptions options; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 443 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 444 | |
| 445 | // build up the structure of the network |
| 446 | INetworkPtr net(INetwork::Create()); |
| 447 | |
| 448 | IConnectableLayer* input = net->AddInputLayer(0); |
| 449 | |
| 450 | // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef. |
| 451 | NormalizationDescriptor descriptor; |
| 452 | IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor); |
| 453 | |
| 454 | IConnectableLayer* output = net->AddOutputLayer(0); |
| 455 | |
| 456 | input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); |
| 457 | normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 458 | |
| 459 | input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 460 | normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 461 | |
| 462 | // optimize the network |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 463 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 464 | IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 465 | |
| 466 | // Load it into the runtime. It should success. |
| 467 | armnn::NetworkId netId; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 468 | CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 469 | } |
| 470 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 471 | TEST_CASE("RuntimeFallbackToCpuRef") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 472 | { |
| 473 | using namespace armnn; |
| 474 | |
| 475 | // Create runtime in which test will run |
| 476 | armnn::IRuntime::CreationOptions options; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 477 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 478 | |
| 479 | // build up the structure of the network |
| 480 | INetworkPtr net(INetwork::Create()); |
| 481 | |
| 482 | IConnectableLayer* input = net->AddInputLayer(0); |
| 483 | |
| 484 | // This layer configuration isn't supported by CpuAcc, should be fall back to CpuRef. |
| 485 | NormalizationDescriptor descriptor; |
| 486 | IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor); |
| 487 | |
| 488 | IConnectableLayer* output = net->AddOutputLayer(0); |
| 489 | |
| 490 | input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); |
| 491 | normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 492 | |
| 493 | input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 494 | normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 495 | |
| 496 | // Allow fallback to CpuRef. |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 497 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc, armnn::Compute::CpuRef }; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 498 | // optimize the network |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 499 | IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 500 | |
| 501 | // Load it into the runtime. It should succeed. |
| 502 | armnn::NetworkId netId; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 503 | CHECK(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 504 | } |
| 505 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 506 | TEST_CASE("IVGCVSW_1929_QuantizedSoftmaxIssue") |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 507 | { |
| 508 | // Test for issue reported by Chris Nix in https://jira.arm.com/browse/IVGCVSW-1929 |
| 509 | using namespace armnn; |
| 510 | |
| 511 | // Create runtime in which test will run |
| 512 | armnn::IRuntime::CreationOptions options; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 513 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 514 | |
| 515 | // build up the structure of the network |
| 516 | INetworkPtr net(INetwork::Create()); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 517 | armnn::IConnectableLayer* input = net->AddInputLayer(0,"input"); |
| 518 | armnn::IConnectableLayer* softmax = net->AddSoftmaxLayer(armnn::SoftmaxDescriptor(), "softmax"); |
| 519 | armnn::IConnectableLayer* output = net->AddOutputLayer(0, "output"); |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 520 | |
| 521 | input->GetOutputSlot(0).Connect(softmax->GetInputSlot(0)); |
| 522 | softmax->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 523 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 524 | input->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }), |
| 525 | armnn::DataType::QAsymmU8, |
| 526 | 1.0f / 255, |
| 527 | 0)); |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 528 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 529 | softmax->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo(armnn::TensorShape({ 1, 5 }), |
| 530 | armnn::DataType::QAsymmU8)); |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 531 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 532 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 533 | std::vector<std::string> errMessages; |
Mike Kelly | 3a613cc | 2020-09-29 20:50:35 +0100 | [diff] [blame] | 534 | |
| 535 | try |
| 536 | { |
| 537 | armnn::IOptimizedNetworkPtr optNet = Optimize(*net, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 538 | backends, |
| 539 | runtime->GetDeviceSpec(), |
| 540 | OptimizerOptions(), |
| 541 | errMessages); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 542 | FAIL("An exception should have been thrown"); |
Mike Kelly | 3a613cc | 2020-09-29 20:50:35 +0100 | [diff] [blame] | 543 | } |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 544 | catch (const armnn::InvalidArgumentException&) |
Mike Kelly | 3a613cc | 2020-09-29 20:50:35 +0100 | [diff] [blame] | 545 | { |
| 546 | // Different exceptions are thrown on different backends |
| 547 | } |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 548 | CHECK(errMessages.size() > 0); |
jimfly01 | 6b0b53d | 2018-10-08 14:43:01 +0100 | [diff] [blame] | 549 | } |
| 550 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 551 | TEST_CASE("RuntimeBackendOptions") |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 552 | { |
| 553 | using namespace armnn; |
| 554 | |
| 555 | IRuntime::CreationOptions creationOptions; |
| 556 | auto& backendOptions = creationOptions.m_BackendOptions; |
| 557 | |
| 558 | |
| 559 | // Define Options on explicit construction |
| 560 | BackendOptions options1("FakeBackend1", |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 561 | { |
| 562 | { "Option1", 1.3f }, |
| 563 | { "Option2", true } |
| 564 | }); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 565 | |
| 566 | // Add an option after construction |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 567 | options1.AddOption({ "Option3", "some_value" }); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 568 | |
| 569 | // Add the options to CreationOptions struct |
| 570 | backendOptions.push_back(options1); |
| 571 | |
| 572 | // Add more Options via inplace explicit construction |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 573 | backendOptions.emplace_back(BackendOptions{ "FakeBackend1", |
| 574 | {{ "Option4", 42 }} |
| 575 | }); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 576 | |
| 577 | |
| 578 | // First group |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 579 | CHECK(backendOptions[0].GetBackendId().Get() == "FakeBackend1"); |
| 580 | CHECK(backendOptions[0].GetOption(0).GetName() == "Option1"); |
| 581 | CHECK(backendOptions[0].GetOption(0).GetValue().IsFloat() == true); |
| 582 | CHECK(backendOptions[0].GetOption(0).GetValue().AsFloat() == 1.3f); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 583 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 584 | CHECK(backendOptions[0].GetOption(1).GetName() == "Option2"); |
| 585 | CHECK(backendOptions[0].GetOption(1).GetValue().IsBool() == true); |
| 586 | CHECK(backendOptions[0].GetOption(1).GetValue().AsBool() == true); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 587 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 588 | CHECK(backendOptions[0].GetOption(2).GetName() == "Option3"); |
| 589 | CHECK(backendOptions[0].GetOption(2).GetValue().IsString() == true); |
| 590 | CHECK(backendOptions[0].GetOption(2).GetValue().AsString() == "some_value"); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 591 | |
| 592 | // Second group |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 593 | CHECK(backendOptions[1].GetBackendId().Get() == "FakeBackend1"); |
| 594 | CHECK(backendOptions[1].GetOption(0).GetName() == "Option4"); |
| 595 | CHECK(backendOptions[1].GetOption(0).GetValue().IsInt() == true); |
| 596 | CHECK(backendOptions[1].GetOption(0).GetValue().AsInt() == 42); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 597 | } |
| 598 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 599 | TEST_CASE("ProfilingDisable") |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 600 | { |
| 601 | using namespace armnn; |
| 602 | |
| 603 | // Create runtime in which the test will run |
| 604 | armnn::IRuntime::CreationOptions options; |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 605 | armnn::RuntimeImpl runtime(options); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 606 | |
| 607 | // build up the structure of the network |
| 608 | INetworkPtr net(INetwork::Create()); |
| 609 | |
| 610 | IConnectableLayer* input = net->AddInputLayer(0); |
| 611 | |
| 612 | // This layer configuration isn't supported by CpuAcc, should fall back to CpuRef. |
| 613 | NormalizationDescriptor descriptor; |
| 614 | IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor); |
| 615 | |
| 616 | IConnectableLayer* output = net->AddOutputLayer(0); |
| 617 | |
| 618 | input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); |
| 619 | normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 620 | |
| 621 | input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 622 | normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 623 | |
| 624 | // optimize the network |
| 625 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 626 | IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec()); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 627 | |
| 628 | // Load it into the runtime. It should succeed. |
| 629 | armnn::NetworkId netId; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 630 | CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 631 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame^] | 632 | armnn::ArmNNProfilingServiceInitialiser initialiser; |
| 633 | ProfilingServiceRuntimeHelper profilingServiceHelper( |
| 634 | arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime)); |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 635 | BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager(); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 636 | auto readableBuffer = bufferManager.GetReadableBuffer(); |
| 637 | |
| 638 | // Profiling is not enabled, the post-optimisation structure should not be created |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 639 | CHECK(!readableBuffer); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 640 | } |
| 641 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 642 | TEST_CASE("ProfilingEnableCpuRef") |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 643 | { |
| 644 | using namespace armnn; |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 645 | using namespace arm::pipe; |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 646 | |
| 647 | // Create runtime in which the test will run |
| 648 | armnn::IRuntime::CreationOptions options; |
| 649 | options.m_ProfilingOptions.m_EnableProfiling = true; |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 650 | options.m_ProfilingOptions.m_TimelineEnabled = true; |
| 651 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 652 | armnn::RuntimeImpl runtime(options); |
Jim Flynn | 4c9ed1d | 2022-01-23 23:57:20 +0000 | [diff] [blame] | 653 | GetProfilingService(&runtime).ResetExternalProfilingOptions( |
| 654 | ConvertExternalProfilingOptions(options.m_ProfilingOptions), false); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 655 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame^] | 656 | armnn::ArmNNProfilingServiceInitialiser initialiser; |
| 657 | ProfilingServiceRuntimeHelper profilingServiceHelper( |
| 658 | arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime)); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 659 | profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected); |
| 660 | profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck); |
| 661 | profilingServiceHelper.ForceTransitionToState(ProfilingState::Active); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 662 | |
| 663 | // build up the structure of the network |
| 664 | INetworkPtr net(INetwork::Create()); |
| 665 | |
| 666 | IConnectableLayer* input = net->AddInputLayer(0, "input"); |
| 667 | |
| 668 | NormalizationDescriptor descriptor; |
| 669 | IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization"); |
| 670 | |
| 671 | IConnectableLayer* output = net->AddOutputLayer(0, "output"); |
| 672 | |
| 673 | input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); |
| 674 | normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 675 | |
| 676 | input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 677 | normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); |
| 678 | |
| 679 | // optimize the network |
| 680 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 681 | IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec()); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 682 | |
| 683 | ProfilingGuid optNetGuid = optNet->GetGuid(); |
| 684 | |
| 685 | // Load it into the runtime. It should succeed. |
| 686 | armnn::NetworkId netId; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 687 | CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 688 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 689 | BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager(); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 690 | auto readableBuffer = bufferManager.GetReadableBuffer(); |
| 691 | |
| 692 | // Profiling is enabled, the post-optimisation structure should be created |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 693 | CHECK(readableBuffer != nullptr); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 694 | |
| 695 | unsigned int size = readableBuffer->GetSize(); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 696 | |
| 697 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 698 | CHECK(readableData != nullptr); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 699 | |
| 700 | unsigned int offset = 0; |
| 701 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 702 | // Verify Header |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 703 | VerifyTimelineHeaderBinary(readableData, offset, size - 8); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 704 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 705 | // Post-optimisation network |
| 706 | // Network entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 707 | VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 708 | |
| 709 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 710 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 711 | EmptyOptional(), |
| 712 | optNetGuid, |
| 713 | LabelsAndEventClasses::NETWORK_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 714 | LabelsAndEventClasses::TYPE_GUID, |
| 715 | readableData, |
| 716 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 717 | |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 718 | // Network - START OF LIFE |
| 719 | ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(), |
| 720 | EmptyOptional(), |
| 721 | EmptyOptional(), |
| 722 | readableData, |
| 723 | offset); |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 724 | |
| 725 | // Network - START OF LIFE event relationship |
| 726 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 727 | EmptyOptional(), |
| 728 | optNetGuid, |
| 729 | networkSolEventGuid, |
| 730 | LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 731 | readableData, |
| 732 | offset); |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 733 | |
| 734 | // Process ID Label |
| 735 | int processID = armnnUtils::Processes::GetCurrentId(); |
| 736 | std::stringstream ss; |
| 737 | ss << processID; |
| 738 | std::string processIdLabel = ss.str(); |
| 739 | VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset); |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 740 | |
| 741 | // Entity - Process ID relationship |
| 742 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 743 | EmptyOptional(), |
| 744 | optNetGuid, |
| 745 | EmptyOptional(), |
| 746 | LabelsAndEventClasses::PROCESS_ID_GUID, |
| 747 | readableData, |
| 748 | offset); |
Jim Flynn | f771321 | 2020-07-14 09:50:59 +0100 | [diff] [blame] | 749 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 750 | // Input layer |
| 751 | // Input layer entity |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 752 | VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 753 | |
| 754 | // Name Entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 755 | ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 756 | |
| 757 | // Entity - Name relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 758 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 759 | EmptyOptional(), |
| 760 | input->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 761 | inputLabelGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 762 | LabelsAndEventClasses::NAME_GUID, |
| 763 | readableData, |
| 764 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 765 | |
| 766 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 767 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 768 | EmptyOptional(), |
| 769 | input->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 770 | LabelsAndEventClasses::LAYER_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 771 | LabelsAndEventClasses::TYPE_GUID, |
| 772 | readableData, |
| 773 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 774 | |
| 775 | // Network - Input layer relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 776 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 777 | EmptyOptional(), |
| 778 | optNetGuid, |
| 779 | input->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 780 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 781 | readableData, |
| 782 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 783 | |
| 784 | // Normalization layer |
| 785 | // Normalization layer entity |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 786 | VerifyTimelineEntityBinaryPacketData(normalize->GetGuid(), readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 787 | |
| 788 | // Name entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 789 | ProfilingGuid normalizationLayerNameGuid = VerifyTimelineLabelBinaryPacketData( |
| 790 | EmptyOptional(), "normalization", readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 791 | |
| 792 | // Entity - Name relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 793 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 794 | EmptyOptional(), |
| 795 | normalize->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 796 | normalizationLayerNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 797 | LabelsAndEventClasses::NAME_GUID, |
| 798 | readableData, |
| 799 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 800 | |
| 801 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 802 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 803 | EmptyOptional(), |
| 804 | normalize->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 805 | LabelsAndEventClasses::LAYER_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 806 | LabelsAndEventClasses::TYPE_GUID, |
| 807 | readableData, |
| 808 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 809 | |
| 810 | // Network - Normalize layer relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 811 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 812 | EmptyOptional(), |
| 813 | optNetGuid, |
| 814 | normalize->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 815 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 816 | readableData, |
| 817 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 818 | |
| 819 | // Input layer - Normalize layer relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 820 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 821 | EmptyOptional(), |
| 822 | input->GetGuid(), |
| 823 | normalize->GetGuid(), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 824 | LabelsAndEventClasses::CONNECTION_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 825 | readableData, |
| 826 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 827 | |
| 828 | // Normalization workload |
| 829 | // Normalization workload entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 830 | ProfilingGuid normalizationWorkloadGuid = VerifyTimelineEntityBinaryPacketData( |
| 831 | EmptyOptional(), readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 832 | |
| 833 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 834 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 835 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 836 | normalizationWorkloadGuid, |
| 837 | LabelsAndEventClasses::WORKLOAD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 838 | LabelsAndEventClasses::TYPE_GUID, |
| 839 | readableData, |
| 840 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 841 | |
| 842 | // BackendId entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 843 | ProfilingGuid cpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData( |
| 844 | EmptyOptional(), "CpuRef", readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 845 | |
| 846 | // Entity - BackendId relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 847 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 848 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 849 | normalizationWorkloadGuid, |
| 850 | cpuRefLabelGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 851 | LabelsAndEventClasses::BACKENDID_GUID, |
| 852 | readableData, |
| 853 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 854 | |
| 855 | // Normalize layer - Normalize workload relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 856 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 857 | EmptyOptional(), |
| 858 | normalize->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 859 | normalizationWorkloadGuid, |
| 860 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 861 | readableData, |
| 862 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 863 | |
| 864 | // Output layer |
| 865 | // Output layer entity |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 866 | VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 867 | |
| 868 | // Name entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 869 | ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData( |
| 870 | EmptyOptional(), "output", readableData, offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 871 | |
| 872 | // Entity - Name relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 873 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 874 | EmptyOptional(), |
| 875 | output->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 876 | outputLabelGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 877 | LabelsAndEventClasses::NAME_GUID, |
| 878 | readableData, |
| 879 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 880 | |
| 881 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 882 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 883 | EmptyOptional(), |
| 884 | output->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 885 | LabelsAndEventClasses::LAYER_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 886 | LabelsAndEventClasses::TYPE_GUID, |
| 887 | readableData, |
| 888 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 889 | |
| 890 | // Network - Output layer relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 891 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 892 | EmptyOptional(), |
| 893 | optNetGuid, |
| 894 | output->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 895 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 896 | readableData, |
| 897 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 898 | |
| 899 | // Normalize layer - Output layer relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 900 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 901 | EmptyOptional(), |
| 902 | normalize->GetGuid(), |
| 903 | output->GetGuid(), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 904 | LabelsAndEventClasses::CONNECTION_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 905 | readableData, |
| 906 | offset); |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 907 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 908 | bufferManager.MarkRead(readableBuffer); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 909 | |
| 910 | // Creates structures for input & output. |
| 911 | std::vector<float> inputData(16); |
| 912 | std::vector<float> outputData(16); |
| 913 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 914 | TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0); |
| 915 | inputTensorInfo.SetConstant(true); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 916 | InputTensors inputTensors |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 917 | { |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 918 | {0, ConstTensor(inputTensorInfo, inputData.data())} |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 919 | }; |
| 920 | OutputTensors outputTensors |
| 921 | { |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 922 | {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())} |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 923 | }; |
| 924 | |
| 925 | // Does the inference. |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 926 | runtime.EnqueueWorkload(netId, inputTensors, outputTensors); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 927 | |
Finn Williams | b6a402f | 2020-03-24 13:46:22 +0000 | [diff] [blame] | 928 | // Get readable buffer for input workload |
| 929 | auto inputReadableBuffer = bufferManager.GetReadableBuffer(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 930 | CHECK(inputReadableBuffer != nullptr); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 931 | |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 932 | // Get readable buffer for output workload |
| 933 | auto outputReadableBuffer = bufferManager.GetReadableBuffer(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 934 | CHECK(outputReadableBuffer != nullptr); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 935 | |
Finn Williams | b6a402f | 2020-03-24 13:46:22 +0000 | [diff] [blame] | 936 | // Get readable buffer for inference timeline |
| 937 | auto inferenceReadableBuffer = bufferManager.GetReadableBuffer(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 938 | CHECK(inferenceReadableBuffer != nullptr); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 939 | |
| 940 | // Validate input workload data |
| 941 | size = inputReadableBuffer->GetSize(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 942 | CHECK(size == 164); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 943 | |
| 944 | readableData = inputReadableBuffer->GetReadableData(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 945 | CHECK(readableData != nullptr); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 946 | |
| 947 | offset = 0; |
| 948 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 949 | // Verify Header |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 950 | VerifyTimelineHeaderBinary(readableData, offset, 156); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 951 | |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 952 | // Input workload |
| 953 | // Input workload entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 954 | ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 955 | |
| 956 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 957 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 958 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 959 | inputWorkloadGuid, |
| 960 | LabelsAndEventClasses::WORKLOAD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 961 | LabelsAndEventClasses::TYPE_GUID, |
| 962 | readableData, |
| 963 | offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 964 | |
| 965 | // BackendId entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 966 | ProfilingGuid CpuRefLabelGuid = VerifyTimelineLabelBinaryPacketData( |
| 967 | EmptyOptional(), "CpuRef", readableData, offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 968 | |
| 969 | // Entity - BackendId relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 970 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 971 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 972 | inputWorkloadGuid, |
| 973 | CpuRefLabelGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 974 | LabelsAndEventClasses::BACKENDID_GUID, |
| 975 | readableData, |
| 976 | offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 977 | |
| 978 | // Input layer - Input workload relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 979 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 980 | EmptyOptional(), |
| 981 | input->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 982 | inputWorkloadGuid, |
| 983 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 984 | readableData, |
| 985 | offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 986 | |
| 987 | bufferManager.MarkRead(inputReadableBuffer); |
| 988 | |
| 989 | // Validate output workload data |
| 990 | size = outputReadableBuffer->GetSize(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 991 | CHECK(size == 164); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 992 | |
| 993 | readableData = outputReadableBuffer->GetReadableData(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 994 | CHECK(readableData != nullptr); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 995 | |
| 996 | offset = 0; |
| 997 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 998 | // Verify Header |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 999 | VerifyTimelineHeaderBinary(readableData, offset, 156); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1000 | |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 1001 | // Output workload |
| 1002 | // Output workload entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1003 | ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 1004 | |
| 1005 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1006 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 1007 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1008 | outputWorkloadGuid, |
| 1009 | LabelsAndEventClasses::WORKLOAD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1010 | LabelsAndEventClasses::TYPE_GUID, |
| 1011 | readableData, |
| 1012 | offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 1013 | |
| 1014 | // BackendId entity |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1015 | VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "CpuRef", readableData, offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 1016 | |
| 1017 | // Entity - BackendId relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1018 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 1019 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1020 | outputWorkloadGuid, |
| 1021 | CpuRefLabelGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1022 | LabelsAndEventClasses::BACKENDID_GUID, |
| 1023 | readableData, |
| 1024 | offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 1025 | |
| 1026 | // Output layer - Output workload relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1027 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1028 | EmptyOptional(), |
| 1029 | output->GetGuid(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1030 | outputWorkloadGuid, |
| 1031 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1032 | readableData, |
| 1033 | offset); |
Narumol Prangnawarat | aa68e01 | 2019-11-29 17:17:43 +0000 | [diff] [blame] | 1034 | |
| 1035 | bufferManager.MarkRead(outputReadableBuffer); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1036 | |
| 1037 | // Validate inference data |
| 1038 | size = inferenceReadableBuffer->GetSize(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1039 | CHECK(size == 976 + 8 * ThreadIdSize); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1040 | |
| 1041 | readableData = inferenceReadableBuffer->GetReadableData(); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1042 | CHECK(readableData != nullptr); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1043 | |
| 1044 | offset = 0; |
| 1045 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1046 | // Verify Header |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 1047 | VerifyTimelineHeaderBinary(readableData, offset, 968 + 8 * ThreadIdSize); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1048 | |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1049 | // Inference timeline trace |
| 1050 | // Inference entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1051 | ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1052 | |
| 1053 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1054 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 1055 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1056 | inferenceGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1057 | LabelsAndEventClasses::INFERENCE_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1058 | LabelsAndEventClasses::TYPE_GUID, |
| 1059 | readableData, |
| 1060 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1061 | |
| 1062 | // Network - Inference relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1063 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1064 | EmptyOptional(), |
| 1065 | optNetGuid, |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1066 | inferenceGuid, |
| 1067 | LabelsAndEventClasses::EXECUTION_OF_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1068 | readableData, |
| 1069 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1070 | |
| 1071 | // Start Inference life |
| 1072 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1073 | ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket( |
| 1074 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1075 | |
| 1076 | // Inference - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1077 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1078 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1079 | inferenceGuid, |
| 1080 | inferenceEventGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1081 | LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 1082 | readableData, |
| 1083 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1084 | |
| 1085 | // Execution |
| 1086 | // Input workload execution |
| 1087 | // Input workload execution entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1088 | ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData( |
| 1089 | EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1090 | |
| 1091 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1092 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 1093 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1094 | inputWorkloadExecutionGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1095 | LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1096 | LabelsAndEventClasses::TYPE_GUID, |
| 1097 | readableData, |
| 1098 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1099 | |
| 1100 | // Inference - Workload execution relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1101 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1102 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1103 | inferenceGuid, |
| 1104 | inputWorkloadExecutionGuid, |
| 1105 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1106 | readableData, |
| 1107 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1108 | |
| 1109 | // Workload - Workload execution relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1110 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1111 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1112 | inputWorkloadGuid, |
| 1113 | inputWorkloadExecutionGuid, |
| 1114 | LabelsAndEventClasses::EXECUTION_OF_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1115 | readableData, |
| 1116 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1117 | |
| 1118 | // Start Input workload execution life |
| 1119 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1120 | ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket( |
| 1121 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1122 | |
| 1123 | // Input workload execution - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1124 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1125 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1126 | inputWorkloadExecutionGuid, |
| 1127 | inputWorkloadExecutionSOLEventId, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1128 | LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 1129 | readableData, |
| 1130 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1131 | |
| 1132 | // End of Input workload execution life |
| 1133 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1134 | ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket( |
| 1135 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1136 | |
| 1137 | // Input workload execution - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1138 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1139 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1140 | inputWorkloadExecutionGuid, |
| 1141 | inputWorkloadExecutionEOLEventId, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1142 | LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 1143 | readableData, |
| 1144 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1145 | |
| 1146 | // Normalize workload execution |
| 1147 | // Normalize workload execution entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1148 | ProfilingGuid normalizeWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData( |
| 1149 | EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1150 | |
| 1151 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1152 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 1153 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1154 | normalizeWorkloadExecutionGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1155 | LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1156 | LabelsAndEventClasses::TYPE_GUID, |
| 1157 | readableData, |
| 1158 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1159 | |
| 1160 | // Inference - Workload execution relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1161 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1162 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1163 | inferenceGuid, |
| 1164 | normalizeWorkloadExecutionGuid, |
| 1165 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1166 | readableData, |
| 1167 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1168 | |
| 1169 | // Workload - Workload execution relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1170 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1171 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1172 | normalizationWorkloadGuid, |
| 1173 | normalizeWorkloadExecutionGuid, |
| 1174 | LabelsAndEventClasses::EXECUTION_OF_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1175 | readableData, |
| 1176 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1177 | |
| 1178 | // Start Normalize workload execution life |
| 1179 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1180 | ProfilingGuid normalizationWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket( |
| 1181 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1182 | |
| 1183 | // Normalize workload execution - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1184 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1185 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1186 | normalizeWorkloadExecutionGuid, |
| 1187 | normalizationWorkloadExecutionSOLEventGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1188 | LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 1189 | readableData, |
| 1190 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1191 | |
| 1192 | // End of Normalize workload execution life |
| 1193 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1194 | ProfilingGuid normalizationWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket( |
| 1195 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1196 | |
| 1197 | // Normalize workload execution - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1198 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1199 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1200 | normalizeWorkloadExecutionGuid, |
| 1201 | normalizationWorkloadExecutionEOLEventGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1202 | LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 1203 | readableData, |
| 1204 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1205 | |
| 1206 | // Output workload execution |
| 1207 | // Output workload execution entity |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1208 | ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData( |
| 1209 | EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1210 | |
| 1211 | // Entity - Type relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1212 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink, |
| 1213 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1214 | outputWorkloadExecutionGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1215 | LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1216 | LabelsAndEventClasses::TYPE_GUID, |
| 1217 | readableData, |
| 1218 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1219 | |
| 1220 | // Inference - Workload execution relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1221 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1222 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1223 | inferenceGuid, |
| 1224 | outputWorkloadExecutionGuid, |
| 1225 | LabelsAndEventClasses::CHILD_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1226 | readableData, |
| 1227 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1228 | |
| 1229 | // Workload - Workload execution relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1230 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink, |
| 1231 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1232 | outputWorkloadGuid, |
| 1233 | outputWorkloadExecutionGuid, |
| 1234 | LabelsAndEventClasses::EXECUTION_OF_GUID, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1235 | readableData, |
| 1236 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1237 | |
| 1238 | // Start Output workload execution life |
| 1239 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1240 | ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket( |
| 1241 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Output workload execution - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1244 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1245 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1246 | outputWorkloadExecutionGuid, |
| 1247 | outputWorkloadExecutionSOLEventGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1248 | LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 1249 | readableData, |
| 1250 | offset); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 1251 | |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1252 | // End of Normalize workload execution life |
| 1253 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1254 | ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket( |
| 1255 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1256 | |
| 1257 | // Output workload execution - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1258 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1259 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1260 | outputWorkloadExecutionGuid, |
| 1261 | outputWorkloadExecutionEOLEventGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1262 | LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 1263 | readableData, |
| 1264 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1265 | |
| 1266 | // End of Inference life |
| 1267 | // Event packet - timeline, threadId, eventGuid |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1268 | ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket( |
| 1269 | EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1270 | |
| 1271 | // Inference - event relationship |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1272 | VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink, |
| 1273 | EmptyOptional(), |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 1274 | inferenceGuid, |
| 1275 | inferenceEOLEventGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 1276 | LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 1277 | readableData, |
| 1278 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 1279 | |
| 1280 | bufferManager.MarkRead(inferenceReadableBuffer); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1283 | TEST_CASE("ProfilingPostOptimisationStructureCpuRef") |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 1284 | { |
| 1285 | VerifyPostOptimisationStructureTestImpl(armnn::Compute::CpuRef); |
| 1286 | } |
| 1287 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 1288 | } |