Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ProfilingTestUtils.hpp" |
| 7 | #include "ProfilingUtils.hpp" |
| 8 | |
| 9 | #include <armnn/Descriptors.hpp> |
| 10 | #include <LabelsAndEventClasses.hpp> |
| 11 | #include <ProfilingService.hpp> |
| 12 | |
| 13 | #include <boost/test/unit_test.hpp> |
| 14 | |
| 15 | inline unsigned int OffsetToNextWord(unsigned int numberOfBytes) |
| 16 | { |
| 17 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 18 | |
| 19 | unsigned int remainder = numberOfBytes % uint32_t_size; |
| 20 | if (remainder == 0) |
| 21 | { |
| 22 | return numberOfBytes; |
| 23 | } |
| 24 | |
| 25 | return numberOfBytes + uint32_t_size - remainder; |
| 26 | } |
| 27 | |
| 28 | void VerifyTimelineLabelBinaryPacket(Optional<ProfilingGuid> guid, |
| 29 | const std::string& label, |
| 30 | const unsigned char* readableData, |
| 31 | unsigned int& offset) |
| 32 | { |
| 33 | BOOST_ASSERT(readableData); |
| 34 | |
| 35 | // Utils |
| 36 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 37 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 38 | unsigned int label_size = boost::numeric_cast<unsigned int>(label.size()); |
| 39 | |
| 40 | // Check the TimelineLabelBinaryPacket header |
| 41 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 42 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 43 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 44 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 45 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 46 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 47 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 48 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 49 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 50 | offset += uint32_t_size; |
| 51 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 52 | uint32_t eventBinaryPacketSequenceNumber = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 53 | uint32_t eventBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 54 | BOOST_CHECK(eventBinaryPacketSequenceNumber == 0); |
| 55 | BOOST_CHECK(eventBinaryPacketDataLength == 16 + OffsetToNextWord(label_size + 1)); |
| 56 | |
| 57 | // Check the decl id |
| 58 | offset += uint32_t_size; |
| 59 | uint32_t eventClassDeclId = ReadUint32(readableData, offset); |
| 60 | BOOST_CHECK(eventClassDeclId == 0); |
| 61 | |
| 62 | // Check the profiling GUID |
| 63 | offset += uint32_t_size; |
| 64 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
| 65 | if (guid.has_value()) |
| 66 | { |
| 67 | BOOST_CHECK(readProfilingGuid == guid.value()); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | BOOST_CHECK(readProfilingGuid == ProfilingService::Instance().GenerateStaticId(label)); |
| 72 | } |
| 73 | |
| 74 | // Check the SWTrace label |
| 75 | offset += uint64_t_size; |
| 76 | uint32_t swTraceLabelLength = ReadUint32(readableData, offset); |
| 77 | BOOST_CHECK(swTraceLabelLength == label_size + 1); // Label length including the null-terminator |
| 78 | offset += uint32_t_size; |
| 79 | BOOST_CHECK(std::memcmp(readableData + offset, // Offset to the label in the buffer |
| 80 | label.data(), // The original label |
| 81 | swTraceLabelLength - 1) == 0); // The length of the label |
| 82 | BOOST_CHECK(readableData[offset + swTraceLabelLength] == '\0'); // The null-terminator |
| 83 | |
| 84 | // SWTrace strings are written in blocks of words, so the offset has to be updated to the next whole word |
| 85 | offset += OffsetToNextWord(swTraceLabelLength); |
| 86 | } |
| 87 | |
| 88 | void VerifyTimelineEventClassBinaryPacket(ProfilingGuid guid, |
| 89 | const unsigned char* readableData, |
| 90 | unsigned int& offset) |
| 91 | { |
| 92 | BOOST_ASSERT(readableData); |
| 93 | |
| 94 | // Utils |
| 95 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 96 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 97 | |
| 98 | // Check the TimelineEventClassBinaryPacket header |
| 99 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 100 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 101 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 102 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 103 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 104 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 105 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 106 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 107 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 108 | offset += uint32_t_size; |
| 109 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 110 | uint32_t eventBinaryPacketSequenceNumber = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 111 | uint32_t eventBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 112 | BOOST_CHECK(eventBinaryPacketSequenceNumber == 0); |
| 113 | BOOST_CHECK(eventBinaryPacketDataLength == 12); |
| 114 | |
| 115 | // Check the decl id |
| 116 | offset += uint32_t_size; |
| 117 | uint32_t eventClassDeclId = ReadUint32(readableData, offset); |
| 118 | BOOST_CHECK(eventClassDeclId == 2); |
| 119 | |
| 120 | // Check the profiling GUID |
| 121 | offset += uint32_t_size; |
| 122 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
| 123 | BOOST_CHECK(readProfilingGuid == guid); |
| 124 | |
| 125 | // Update the offset to allow parsing to be continued after this function returns |
| 126 | offset += uint64_t_size; |
| 127 | } |
| 128 | |
| 129 | void VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType, |
| 130 | Optional<ProfilingGuid> relationshipGuid, |
| 131 | Optional<ProfilingGuid> headGuid, |
| 132 | Optional<ProfilingGuid> tailGuid, |
| 133 | const unsigned char* readableData, |
| 134 | unsigned int& offset) |
| 135 | { |
| 136 | BOOST_ASSERT(readableData); |
| 137 | |
| 138 | uint32_t relationshipTypeUint = 0; |
| 139 | switch (relationshipType) |
| 140 | { |
| 141 | case ProfilingRelationshipType::RetentionLink: |
| 142 | relationshipTypeUint = 0; |
| 143 | break; |
| 144 | case ProfilingRelationshipType::ExecutionLink: |
| 145 | relationshipTypeUint = 1; |
| 146 | break; |
| 147 | case ProfilingRelationshipType::DataLink: |
| 148 | relationshipTypeUint = 2; |
| 149 | break; |
| 150 | case ProfilingRelationshipType::LabelLink: |
| 151 | relationshipTypeUint = 3; |
| 152 | break; |
| 153 | default: |
| 154 | BOOST_ERROR("Unknown relationship type"); |
| 155 | } |
| 156 | |
| 157 | // Utils |
| 158 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 159 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 160 | |
| 161 | // Check the TimelineLabelBinaryPacket header |
| 162 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 163 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 164 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 165 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 166 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 167 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 168 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 169 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 170 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 171 | offset += uint32_t_size; |
| 172 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 173 | uint32_t eventBinaryPacketSequenceNumber = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 174 | uint32_t eventBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 175 | BOOST_CHECK(eventBinaryPacketSequenceNumber == 0); |
| 176 | BOOST_CHECK(eventBinaryPacketDataLength == 32); |
| 177 | |
| 178 | // Check the decl id |
| 179 | offset += uint32_t_size; |
| 180 | uint32_t eventClassDeclId = ReadUint32(readableData, offset); |
| 181 | BOOST_CHECK(eventClassDeclId == 3); |
| 182 | |
| 183 | // Check the relationship type |
| 184 | offset += uint32_t_size; |
| 185 | uint32_t readRelationshipTypeUint = ReadUint32(readableData, offset); |
| 186 | BOOST_CHECK(readRelationshipTypeUint == relationshipTypeUint); |
| 187 | |
| 188 | // Check the relationship GUID |
| 189 | offset += uint32_t_size; |
| 190 | uint64_t readRelationshipGuid = ReadUint64(readableData, offset); |
| 191 | if (relationshipGuid.has_value()) |
| 192 | { |
| 193 | BOOST_CHECK(readRelationshipGuid == relationshipGuid.value()); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | BOOST_CHECK(readRelationshipGuid != ProfilingGuid(0)); |
| 198 | } |
| 199 | |
| 200 | // Check the head of relationship GUID |
| 201 | offset += uint64_t_size; |
| 202 | uint64_t readHeadRelationshipGuid = ReadUint64(readableData, offset); |
| 203 | if (headGuid.has_value()) |
| 204 | { |
| 205 | BOOST_CHECK(readHeadRelationshipGuid == headGuid.value()); |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | BOOST_CHECK(readHeadRelationshipGuid != ProfilingGuid(0)); |
| 210 | } |
| 211 | |
| 212 | // Check the tail of relationship GUID |
| 213 | offset += uint64_t_size; |
| 214 | uint64_t readTailRelationshipGuid = ReadUint64(readableData, offset); |
| 215 | if (tailGuid.has_value()) |
| 216 | { |
| 217 | BOOST_CHECK(readTailRelationshipGuid == tailGuid.value()); |
| 218 | } |
| 219 | else |
| 220 | { |
| 221 | BOOST_CHECK(readTailRelationshipGuid != ProfilingGuid(0)); |
| 222 | } |
| 223 | |
| 224 | // Update the offset to allow parsing to be continued after this function returns |
| 225 | offset += uint64_t_size; |
| 226 | } |
| 227 | |
| 228 | void VerifyTimelineEntityBinaryPacket(Optional<ProfilingGuid> guid, |
| 229 | const unsigned char* readableData, |
| 230 | unsigned int& offset) |
| 231 | { |
| 232 | BOOST_ASSERT(readableData); |
| 233 | |
| 234 | // Utils |
| 235 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 236 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 237 | |
| 238 | // Reading TimelineEntityClassBinaryPacket |
| 239 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 240 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 241 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 242 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 243 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 244 | |
| 245 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 246 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 247 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 248 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 249 | |
| 250 | offset += uint32_t_size; |
| 251 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 252 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 253 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 254 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
| 255 | BOOST_CHECK(entityBinaryPacketDataLength == 12); |
| 256 | |
| 257 | // Check the decl_id |
| 258 | offset += uint32_t_size; |
| 259 | uint32_t entityDeclId = ReadUint32(readableData, offset); |
| 260 | BOOST_CHECK(entityDeclId == 1); |
| 261 | |
| 262 | // Check the profiling GUID |
| 263 | offset += uint32_t_size; |
| 264 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
| 265 | |
| 266 | if (guid.has_value()) |
| 267 | { |
| 268 | BOOST_CHECK(readProfilingGuid == guid.value()); |
| 269 | } |
| 270 | else |
| 271 | { |
| 272 | BOOST_CHECK(readProfilingGuid != ProfilingGuid(0)); |
| 273 | } |
| 274 | |
| 275 | offset += uint64_t_size; |
| 276 | } |
| 277 | |
| 278 | void VerifyTimelineEventBinaryPacket(Optional<uint64_t> timestamp, |
| 279 | Optional<std::thread::id> threadId, |
| 280 | Optional<ProfilingGuid> eventGuid, |
| 281 | const unsigned char* readableData, |
| 282 | unsigned int& offset) |
| 283 | { |
| 284 | BOOST_ASSERT(readableData); |
| 285 | |
| 286 | // Utils |
| 287 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 288 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 289 | unsigned int threadId_size = sizeof(std::thread::id); |
| 290 | |
| 291 | // Reading TimelineEventBinaryPacket |
| 292 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 293 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 294 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 295 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 296 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 297 | |
| 298 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 299 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 300 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 301 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 302 | |
| 303 | offset += uint32_t_size; |
| 304 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 305 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 306 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 307 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
| 308 | BOOST_CHECK(entityBinaryPacketDataLength == 20 + threadId_size); |
| 309 | |
| 310 | // Check the decl_id |
| 311 | offset += uint32_t_size; |
| 312 | uint32_t entityDeclId = ReadUint32(readableData, offset); |
| 313 | BOOST_CHECK(entityDeclId == 4); |
| 314 | |
| 315 | // Check the timestamp |
| 316 | offset += uint32_t_size; |
| 317 | uint64_t readTimestamp = ReadUint64(readableData, offset); |
| 318 | if (timestamp.has_value()) |
| 319 | { |
| 320 | BOOST_CHECK(readTimestamp == timestamp.value()); |
| 321 | } |
| 322 | else |
| 323 | { |
| 324 | BOOST_CHECK(readTimestamp != 0); |
| 325 | } |
| 326 | |
| 327 | // Check the thread id |
| 328 | offset += uint64_t_size; |
| 329 | std::vector<uint8_t> readThreadId(threadId_size, 0); |
| 330 | ReadBytes(readableData, offset, threadId_size, readThreadId.data()); |
| 331 | if (threadId.has_value()) |
| 332 | { |
| 333 | BOOST_CHECK(readThreadId == threadId.value()); |
| 334 | } |
| 335 | else |
| 336 | { |
| 337 | BOOST_CHECK(readThreadId == std::this_thread::get_id()); |
| 338 | } |
| 339 | |
| 340 | // Check the event GUID |
| 341 | offset += threadId_size; |
| 342 | uint64_t readEventGuid = ReadUint64(readableData, offset); |
| 343 | if (eventGuid.has_value()) |
| 344 | { |
| 345 | BOOST_CHECK(readEventGuid == eventGuid.value()); |
| 346 | } |
| 347 | else |
| 348 | { |
| 349 | BOOST_CHECK(readEventGuid != ProfilingGuid(0)); |
| 350 | } |
| 351 | |
| 352 | offset += uint64_t_size; |
| 353 | } |
| 354 | |
| 355 | void VerifyPostOptimisationStructureTestImpl(armnn::BackendId backendId) |
| 356 | { |
| 357 | using namespace armnn; |
| 358 | |
| 359 | // Create runtime in which test will run |
| 360 | armnn::IRuntime::CreationOptions options; |
| 361 | options.m_ProfilingOptions.m_EnableProfiling = true; |
| 362 | armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options)); |
| 363 | |
| 364 | // build up the structure of the network |
| 365 | INetworkPtr net(INetwork::Create()); |
| 366 | |
| 367 | // Convolution details |
| 368 | TensorInfo inputInfo({ 1, 2, 5, 1 }, DataType::Float32); |
| 369 | TensorInfo weightInfo({ 3, 2, 3, 1}, DataType::Float32); |
| 370 | TensorInfo biasInfo({ 3 }, DataType::Float32); |
| 371 | TensorInfo outputInfo({ 1, 3, 7, 1}, DataType::Float32); |
| 372 | std::vector<float> weightsData{ |
| 373 | 1.0f, 0.0f, 0.0f, |
| 374 | 0.0f, 2.0f, -1.5f, |
| 375 | |
| 376 | 0.0f, 0.0f, 0.0f, |
| 377 | 0.2f, 0.2f, 0.2f, |
| 378 | |
| 379 | 0.5f, 0.0f, 0.5f, |
| 380 | 0.0f, -1.0f, 0.0f |
| 381 | }; |
| 382 | ConstTensor weights(weightInfo, weightsData); |
| 383 | |
| 384 | Optional<ConstTensor> optionalBiases; |
| 385 | std::vector<float> biasesData{ 1.0f, 0.0f, 0.0f }; |
| 386 | ConstTensor biases(biasInfo, biasesData); |
| 387 | optionalBiases = Optional<ConstTensor>(biases); |
| 388 | |
| 389 | // Input layer |
| 390 | IConnectableLayer* input = net->AddInputLayer(0, "input"); |
| 391 | |
| 392 | // Convolution2d layer |
| 393 | Convolution2dDescriptor conv2dDesc; |
| 394 | conv2dDesc.m_StrideX = 1; |
| 395 | conv2dDesc.m_StrideY = 1; |
| 396 | conv2dDesc.m_PadLeft = 0; |
| 397 | conv2dDesc.m_PadRight = 0; |
| 398 | conv2dDesc.m_PadTop = 2; |
| 399 | conv2dDesc.m_PadBottom = 2; |
| 400 | conv2dDesc.m_BiasEnabled = true; |
| 401 | IConnectableLayer* conv2d = net->AddConvolution2dLayer(conv2dDesc, weights, optionalBiases); |
| 402 | |
| 403 | // Activation layer |
| 404 | armnn::ActivationDescriptor activationDesc; |
| 405 | armnn::IConnectableLayer* const activation = net->AddActivationLayer(activationDesc, "activation"); |
| 406 | |
| 407 | // Output layer |
| 408 | IConnectableLayer* output = net->AddOutputLayer(0, "output"); |
| 409 | |
| 410 | input->GetOutputSlot(0).Connect(conv2d->GetInputSlot(0)); |
| 411 | conv2d->GetOutputSlot(0).Connect(activation->GetInputSlot(0)); |
| 412 | activation->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 413 | |
| 414 | input->GetOutputSlot(0).SetTensorInfo(inputInfo); |
| 415 | conv2d->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 416 | activation->GetOutputSlot(0).SetTensorInfo(outputInfo); |
| 417 | |
| 418 | // optimize the network |
| 419 | std::vector<armnn::BackendId> backends = { backendId }; |
| 420 | IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec()); |
| 421 | |
| 422 | ProfilingGuid optNetGuid = optNet->GetGuid(); |
| 423 | |
| 424 | // Load it into the runtime. It should success. |
| 425 | armnn::NetworkId netId; |
| 426 | BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success); |
| 427 | |
| 428 | profiling::ProfilingServiceRuntimeHelper profilingServiceHelper; |
| 429 | profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager(); |
| 430 | auto readableBuffer = bufferManager.GetReadableBuffer(); |
| 431 | |
| 432 | // Profiling is enable, the post-optimisation structure should be created |
| 433 | BOOST_CHECK(readableBuffer != nullptr); |
| 434 | |
| 435 | unsigned int size = readableBuffer->GetSize(); |
| 436 | BOOST_CHECK(size == 1980); |
| 437 | |
| 438 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 439 | BOOST_CHECK(readableData != nullptr); |
| 440 | |
| 441 | unsigned int offset = 0; |
| 442 | |
| 443 | // Post-optimisation network |
| 444 | // Network entity |
| 445 | VerifyTimelineEntityBinaryPacket(optNetGuid, readableData, offset); |
| 446 | |
| 447 | // Entity - Type relationship |
| 448 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 449 | EmptyOptional(), |
| 450 | optNetGuid, |
| 451 | EmptyOptional(), |
| 452 | readableData, |
| 453 | offset); |
| 454 | |
| 455 | // Type label relationship |
| 456 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 457 | EmptyOptional(), |
| 458 | EmptyOptional(), |
| 459 | LabelsAndEventClasses::TYPE_GUID, |
| 460 | readableData, |
| 461 | offset); |
| 462 | |
| 463 | // Input layer |
| 464 | // Input layer entity |
| 465 | VerifyTimelineEntityBinaryPacket(input->GetGuid(), readableData, offset); |
| 466 | |
| 467 | // Name Entity |
| 468 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), "input", readableData, offset); |
| 469 | |
| 470 | // Entity - Name relationship |
| 471 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 472 | EmptyOptional(), |
| 473 | input->GetGuid(), |
| 474 | EmptyOptional(), |
| 475 | readableData, |
| 476 | offset); |
| 477 | |
| 478 | // Name label relationship |
| 479 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 480 | EmptyOptional(), |
| 481 | EmptyOptional(), |
| 482 | LabelsAndEventClasses::NAME_GUID, |
| 483 | readableData, |
| 484 | offset); |
| 485 | |
| 486 | // Entity - Type relationship |
| 487 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 488 | EmptyOptional(), |
| 489 | input->GetGuid(), |
| 490 | EmptyOptional(), |
| 491 | readableData, |
| 492 | offset); |
| 493 | |
| 494 | // Type label relationship |
| 495 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 496 | EmptyOptional(), |
| 497 | EmptyOptional(), |
| 498 | LabelsAndEventClasses::TYPE_GUID, |
| 499 | readableData, |
| 500 | offset); |
| 501 | |
| 502 | // Network - Input layer relationship |
| 503 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 504 | EmptyOptional(), |
| 505 | optNetGuid, |
| 506 | input->GetGuid(), |
| 507 | readableData, |
| 508 | offset); |
| 509 | |
| 510 | // Conv2d layer |
| 511 | // Conv2d layer entity |
| 512 | VerifyTimelineEntityBinaryPacket(conv2d->GetGuid(), readableData, offset); |
| 513 | |
| 514 | // Name entity |
| 515 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), "<Unnamed>", readableData, offset); |
| 516 | |
| 517 | // Entity - Name relationship |
| 518 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 519 | EmptyOptional(), |
| 520 | conv2d->GetGuid(), |
| 521 | EmptyOptional(), |
| 522 | readableData, |
| 523 | offset); |
| 524 | |
| 525 | // Name label relationship |
| 526 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 527 | EmptyOptional(), |
| 528 | EmptyOptional(), |
| 529 | LabelsAndEventClasses::NAME_GUID, |
| 530 | readableData, |
| 531 | offset); |
| 532 | |
| 533 | // Entity - Type relationship |
| 534 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 535 | EmptyOptional(), |
| 536 | conv2d->GetGuid(), |
| 537 | EmptyOptional(), |
| 538 | readableData, |
| 539 | offset); |
| 540 | |
| 541 | // Type label relationship |
| 542 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 543 | EmptyOptional(), |
| 544 | EmptyOptional(), |
| 545 | LabelsAndEventClasses::TYPE_GUID, |
| 546 | readableData, |
| 547 | offset); |
| 548 | |
| 549 | // Network - Conv2d layer relationship |
| 550 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 551 | EmptyOptional(), |
| 552 | optNetGuid, |
| 553 | conv2d->GetGuid(), |
| 554 | readableData, |
| 555 | offset); |
| 556 | |
| 557 | // Input layer - Conv2d layer relationship |
| 558 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 559 | EmptyOptional(), |
| 560 | input->GetGuid(), |
| 561 | conv2d->GetGuid(), |
| 562 | readableData, |
| 563 | offset); |
| 564 | |
| 565 | // Entity - Type relationship |
| 566 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 567 | EmptyOptional(), |
| 568 | EmptyOptional(), |
| 569 | LabelsAndEventClasses::CONNECTION_GUID, |
| 570 | readableData, |
| 571 | offset); |
| 572 | |
| 573 | // Type label relationship |
| 574 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 575 | EmptyOptional(), |
| 576 | EmptyOptional(), |
| 577 | LabelsAndEventClasses::TYPE_GUID, |
| 578 | readableData, |
| 579 | offset); |
| 580 | |
| 581 | // Conv2d workload |
| 582 | // Conv2d workload entity |
| 583 | VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); |
| 584 | |
| 585 | // Entity - Type relationship |
| 586 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 587 | EmptyOptional(), |
| 588 | EmptyOptional(), |
| 589 | EmptyOptional(), |
| 590 | readableData, |
| 591 | offset); |
| 592 | |
| 593 | // Type label relationship |
| 594 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 595 | EmptyOptional(), |
| 596 | EmptyOptional(), |
| 597 | LabelsAndEventClasses::TYPE_GUID, |
| 598 | readableData, |
| 599 | offset); |
| 600 | |
| 601 | // BackendId entity |
| 602 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), backendId.Get(), readableData, offset); |
| 603 | |
| 604 | // Entity - BackendId relationship |
| 605 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 606 | EmptyOptional(), |
| 607 | EmptyOptional(), |
| 608 | EmptyOptional(), |
| 609 | readableData, |
| 610 | offset); |
| 611 | |
| 612 | // BackendId label relationship |
| 613 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 614 | EmptyOptional(), |
| 615 | EmptyOptional(), |
| 616 | LabelsAndEventClasses::BACKENDID_GUID, |
| 617 | readableData, |
| 618 | offset); |
| 619 | |
| 620 | // Conv2d layer - Conv2d workload relationship |
| 621 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 622 | EmptyOptional(), |
| 623 | conv2d->GetGuid(), |
| 624 | EmptyOptional(), |
| 625 | readableData, |
| 626 | offset); |
| 627 | |
| 628 | // Activation layer |
| 629 | // Activation layer entity |
| 630 | VerifyTimelineEntityBinaryPacket(activation->GetGuid(), readableData, offset); |
| 631 | |
| 632 | // Name entity |
| 633 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), "activation", readableData, offset); |
| 634 | |
| 635 | // Entity - Name relationship |
| 636 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 637 | EmptyOptional(), |
| 638 | activation->GetGuid(), |
| 639 | EmptyOptional(), |
| 640 | readableData, |
| 641 | offset); |
| 642 | |
| 643 | // Name label relationship |
| 644 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 645 | EmptyOptional(), |
| 646 | EmptyOptional(), |
| 647 | LabelsAndEventClasses::NAME_GUID, |
| 648 | readableData, |
| 649 | offset); |
| 650 | |
| 651 | // Entity - Type relationship |
| 652 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 653 | EmptyOptional(), |
| 654 | activation->GetGuid(), |
| 655 | EmptyOptional(), |
| 656 | readableData, |
| 657 | offset); |
| 658 | |
| 659 | // Type label relationship |
| 660 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 661 | EmptyOptional(), |
| 662 | EmptyOptional(), |
| 663 | LabelsAndEventClasses::TYPE_GUID, |
| 664 | readableData, |
| 665 | offset); |
| 666 | |
| 667 | // Network - Activation layer relationship |
| 668 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 669 | EmptyOptional(), |
| 670 | optNetGuid, |
| 671 | activation->GetGuid(), |
| 672 | readableData, |
| 673 | offset); |
| 674 | |
| 675 | // Conv2d layer - Activation layer relationship |
| 676 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 677 | EmptyOptional(), |
| 678 | conv2d->GetGuid(), |
| 679 | activation->GetGuid(), |
| 680 | readableData, |
| 681 | offset); |
| 682 | |
| 683 | // Entity - Type relationship |
| 684 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 685 | EmptyOptional(), |
| 686 | EmptyOptional(), |
| 687 | LabelsAndEventClasses::CONNECTION_GUID, |
| 688 | readableData, |
| 689 | offset); |
| 690 | |
| 691 | // Type label relationship |
| 692 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 693 | EmptyOptional(), |
| 694 | EmptyOptional(), |
| 695 | LabelsAndEventClasses::TYPE_GUID, |
| 696 | readableData, |
| 697 | offset); |
| 698 | |
| 699 | // Activation workload |
| 700 | // Activation workload entity |
| 701 | VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); |
| 702 | |
| 703 | // Entity - Type relationship |
| 704 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 705 | EmptyOptional(), |
| 706 | EmptyOptional(), |
| 707 | EmptyOptional(), |
| 708 | readableData, |
| 709 | offset); |
| 710 | |
| 711 | // Type label relationship |
| 712 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 713 | EmptyOptional(), |
| 714 | EmptyOptional(), |
| 715 | LabelsAndEventClasses::TYPE_GUID, |
| 716 | readableData, |
| 717 | offset); |
| 718 | |
| 719 | // BackendId entity |
| 720 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), backendId.Get(), readableData, offset); |
| 721 | |
| 722 | // Entity - BackendId relationship |
| 723 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 724 | EmptyOptional(), |
| 725 | EmptyOptional(), |
| 726 | EmptyOptional(), |
| 727 | readableData, |
| 728 | offset); |
| 729 | |
| 730 | // BackendId label relationship |
| 731 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 732 | EmptyOptional(), |
| 733 | EmptyOptional(), |
| 734 | LabelsAndEventClasses::BACKENDID_GUID, |
| 735 | readableData, |
| 736 | offset); |
| 737 | |
| 738 | // Activation layer - Activation workload relationship |
| 739 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 740 | EmptyOptional(), |
| 741 | activation->GetGuid(), |
| 742 | EmptyOptional(), |
| 743 | readableData, |
| 744 | offset); |
| 745 | |
| 746 | // Output layer |
| 747 | // Output layer entity |
| 748 | VerifyTimelineEntityBinaryPacket(output->GetGuid(), readableData, offset); |
| 749 | |
| 750 | // Name entity |
| 751 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), "output", readableData, offset); |
| 752 | |
| 753 | // Entity - Name relationship |
| 754 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 755 | EmptyOptional(), |
| 756 | output->GetGuid(), |
| 757 | EmptyOptional(), |
| 758 | readableData, |
| 759 | offset); |
| 760 | |
| 761 | // Name label relationship |
| 762 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 763 | EmptyOptional(), |
| 764 | EmptyOptional(), |
| 765 | LabelsAndEventClasses::NAME_GUID, |
| 766 | readableData, |
| 767 | offset); |
| 768 | |
| 769 | // Entity - Type relationship |
| 770 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 771 | EmptyOptional(), |
| 772 | output->GetGuid(), |
| 773 | EmptyOptional(), |
| 774 | readableData, |
| 775 | offset); |
| 776 | |
| 777 | // Type label relationship |
| 778 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 779 | EmptyOptional(), |
| 780 | EmptyOptional(), |
| 781 | LabelsAndEventClasses::TYPE_GUID, |
| 782 | readableData, |
| 783 | offset); |
| 784 | |
| 785 | // Network - Output layer relationship |
| 786 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 787 | EmptyOptional(), |
| 788 | optNetGuid, |
| 789 | output->GetGuid(), |
| 790 | readableData, |
| 791 | offset); |
| 792 | |
| 793 | // Activation layer - Output layer relationship |
| 794 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 795 | EmptyOptional(), |
| 796 | activation->GetGuid(), |
| 797 | output->GetGuid(), |
| 798 | readableData, |
| 799 | offset); |
| 800 | |
| 801 | // Entity - Type relationship |
| 802 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 803 | EmptyOptional(), |
| 804 | EmptyOptional(), |
| 805 | LabelsAndEventClasses::CONNECTION_GUID, |
| 806 | readableData, |
| 807 | offset); |
| 808 | |
| 809 | // Type label relationship |
| 810 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 811 | EmptyOptional(), |
| 812 | EmptyOptional(), |
| 813 | LabelsAndEventClasses::TYPE_GUID, |
| 814 | readableData, |
| 815 | offset); |
| 816 | |
| 817 | bufferManager.MarkRead(readableBuffer); |
| 818 | } |