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