ArmNN
 22.02
ProfilingTestUtils.cpp File Reference
#include "ProfilingTestUtils.hpp"
#include "ProfilingUtils.hpp"
#include <armnn/Descriptors.hpp>
#include <armnn/utility/Assert.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <Processes.hpp>
#include <ProfilingService.hpp>
#include <armnnUtils/Threads.hpp>
#include <common/include/LabelsAndEventClasses.hpp>
#include <TestUtils.hpp>
#include <doctest/doctest.h>

Go to the source code of this file.

Functions

uint32_t GetStreamMetaDataPacketSize ()
 
std::vector< BackendIdGetSuitableBackendRegistered ()
 Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered. More...
 
unsigned int OffsetToNextWord (unsigned int numberOfBytes)
 
void VerifyTimelineHeaderBinary (const unsigned char *readableData, unsigned int &offset, uint32_t packetDataLength)
 
ProfilingGuid VerifyTimelineLabelBinaryPacketData (Optional< ProfilingGuid > guid, const std::string &label, const unsigned char *readableData, unsigned int &offset)
 
void VerifyTimelineEventClassBinaryPacketData (ProfilingGuid guid, ProfilingGuid nameGuid, const unsigned char *readableData, unsigned int &offset)
 
void VerifyTimelineRelationshipBinaryPacketData (ProfilingRelationshipType relationshipType, Optional< ProfilingGuid > relationshipGuid, Optional< ProfilingGuid > headGuid, Optional< ProfilingGuid > tailGuid, Optional< ProfilingGuid > attributeGuid, const unsigned char *readableData, unsigned int &offset)
 
ProfilingGuid VerifyTimelineEntityBinaryPacketData (Optional< ProfilingGuid > guid, const unsigned char *readableData, unsigned int &offset)
 
ProfilingGuid VerifyTimelineEventBinaryPacket (Optional< uint64_t > timestamp, Optional< int > threadId, Optional< ProfilingGuid > eventGuid, const unsigned char *readableData, unsigned int &offset)
 
void VerifyPostOptimisationStructureTestImpl (armnn::BackendId backendId)
 
bool CompareOutput (std::vector< std::string > output, std::vector< std::string > expectedOutput)
 

Function Documentation

◆ CompareOutput()

bool CompareOutput ( std::vector< std::string >  output,
std::vector< std::string >  expectedOutput 
)

Definition at line 1174 of file ProfilingTestUtils.cpp.

Referenced by TEST_SUITE().

1175 {
1176  if (output.size() != expectedOutput.size())
1177  {
1178  std::cerr << "output has [" << output.size() << "] lines, expected was ["
1179  << expectedOutput.size() << "] lines" << std::endl;
1180  std::cerr << std::endl << "actual" << std::endl << std::endl;
1181  for (auto line : output)
1182  {
1183  std::cerr << line << std::endl;
1184  }
1185  std::cerr << std::endl << "expected" << std::endl << std::endl;
1186  for (auto line : expectedOutput)
1187  {
1188  std::cerr << line << std::endl;
1189  }
1190  return false;
1191  }
1192  bool bRet = true;
1193  for (unsigned long i = 0; i < output.size(); ++i)
1194  {
1195  if (output[i] != expectedOutput[i])
1196  {
1197  bRet = false;
1198  std::cerr << i << ": actual [" << output[i] << "] expected [" << expectedOutput[i] << "]" << std::endl;
1199  }
1200  }
1201  return bRet;
1202 }

◆ GetStreamMetaDataPacketSize()

uint32_t GetStreamMetaDataPacketSize ( )

Definition at line 23 of file ProfilingTestUtils.cpp.

References armnn::profiling::GetHardwareVersion(), armnn::profiling::GetProcessName(), armnn::profiling::GetSoftwareInfo(), armnn::profiling::GetSoftwareVersion(), and armnn::numeric_cast().

24 {
25  uint32_t sizeUint32 = sizeof(uint32_t);
26  uint32_t payloadSize = 0;
27  payloadSize += armnn::numeric_cast<uint32_t>(GetSoftwareInfo().size()) + 1;
28  payloadSize += armnn::numeric_cast<uint32_t>(GetHardwareVersion().size()) + 1;
29  payloadSize += armnn::numeric_cast<uint32_t>(GetSoftwareVersion().size()) + 1;
30  payloadSize += armnn::numeric_cast<uint32_t>(GetProcessName().size()) + 1;
31 
32  // Add packetVersionEntries
33  payloadSize += 13 * 2 * sizeUint32;
34  // Add packetVersionCountSize
35  payloadSize += sizeUint32;
36 
37  uint32_t headerSize = 2 * sizeUint32;
38  uint32_t bodySize = 10 * sizeUint32;
39 
40  return headerSize + bodySize + payloadSize;
41 }
std::string GetHardwareVersion()
std::string GetProcessName()
std::string GetSoftwareInfo()
std::string GetSoftwareVersion()
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ GetSuitableBackendRegistered()

std::vector<BackendId> GetSuitableBackendRegistered ( )

Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered.

Definition at line 43 of file ProfilingTestUtils.cpp.

References armnn::BackendRegistryInstance(), armnn::CpuAcc, armnn::CpuRef, armnn::GetComputeDeviceAsCString(), and armnn::GpuAcc.

Referenced by TEST_SUITE().

44 {
45  std::vector<BackendId> suitableBackends;
47  {
48  suitableBackends.push_back(armnn::Compute::CpuRef);
49  }
51  {
52  suitableBackends.push_back(armnn::Compute::CpuAcc);
53  }
55  {
56  suitableBackends.push_back(armnn::Compute::GpuAcc);
57  }
58  return suitableBackends;
59 }
CPU Execution: Reference C++ kernels.
BackendRegistry & BackendRegistryInstance()
constexpr char const * GetComputeDeviceAsCString(Compute compute)
Deprecated function that will be removed together with the Compute enum.
Definition: BackendId.hpp:34
GPU Execution: OpenCL: ArmCompute.
CPU Execution: NEON: ArmCompute.

◆ OffsetToNextWord()

unsigned int OffsetToNextWord ( unsigned int  numberOfBytes)
inline

Definition at line 61 of file ProfilingTestUtils.cpp.

References armnn::profiling::uint32_t_size.

Referenced by VerifyTimelineLabelBinaryPacketData().

62 {
63  unsigned int uint32_t_size = sizeof(uint32_t);
64 
65  unsigned int remainder = numberOfBytes % uint32_t_size;
66  if (remainder == 0)
67  {
68  return numberOfBytes;
69  }
70 
71  return numberOfBytes + uint32_t_size - remainder;
72 }

◆ VerifyPostOptimisationStructureTestImpl()

void VerifyPostOptimisationStructureTestImpl ( armnn::BackendId  backendId)

Definition at line 363 of file ProfilingTestUtils.cpp.

References IOutputSlot::Connect(), INetwork::Create(), RuntimeImpl::EnqueueWorkload(), armnn::Float32, ProfilingServiceRuntimeHelper::ForceTransitionToState(), BackendId::Get(), armnnUtils::Processes::GetCurrentId(), RuntimeImpl::GetDeviceSpec(), IConnectableLayer::GetGuid(), IConnectableLayer::GetInputSlot(), RuntimeImpl::GetInputTensorInfo(), IConnectableLayer::GetOutputSlot(), RuntimeImpl::GetOutputTensorInfo(), ProfilingServiceRuntimeHelper::GetProfilingBufferManager(), armnn::GetProfilingService(), BufferManager::GetReadableBuffer(), RuntimeImpl::LoadNetwork(), Convolution2dDescriptor::m_BiasEnabled, IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, Convolution2dDescriptor::m_PadBottom, Convolution2dDescriptor::m_PadLeft, Convolution2dDescriptor::m_PadRight, Convolution2dDescriptor::m_PadTop, IRuntime::CreationOptions::m_ProfilingOptions, Convolution2dDescriptor::m_StrideX, Convolution2dDescriptor::m_StrideY, IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, armnn::Optimize(), ProfilingService::ResetExternalProfilingOptions(), TensorInfo::SetConstant(), IOutputSlot::SetTensorInfo(), armnn::Success, armnn::profiling::ThreadIdSize, VerifyTimelineEntityBinaryPacketData(), VerifyTimelineEventBinaryPacket(), VerifyTimelineHeaderBinary(), VerifyTimelineLabelBinaryPacketData(), and VerifyTimelineRelationshipBinaryPacketData().

Referenced by TEST_SUITE().

364 {
365  using namespace armnn;
366 
367  // Create runtime in which test will run
369  options.m_ProfilingOptions.m_EnableProfiling = true;
370  options.m_ProfilingOptions.m_TimelineEnabled = true;
371  armnn::RuntimeImpl runtime(options);
373 
374  profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
375  profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
376  profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
377  profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
378 
379  // build up the structure of the network
381 
382  // Convolution details
383  TensorInfo inputInfo({ 1, 2, 5, 1 }, DataType::Float32);
384  TensorInfo weightInfo({ 3, 2, 3, 1 }, DataType::Float32, 0.0f, 0, true);
385  TensorInfo biasInfo({ 3 }, DataType::Float32, 0.0f, 0, true);
386  TensorInfo outputInfo({ 1, 3, 7, 1 }, DataType::Float32);
387  std::vector<float> weightsData{
388  1.0f, 0.0f, 0.0f,
389  0.0f, 2.0f, -1.5f,
390 
391  0.0f, 0.0f, 0.0f,
392  0.2f, 0.2f, 0.2f,
393 
394  0.5f, 0.0f, 0.5f,
395  0.0f, -1.0f, 0.0f
396  };
397  ConstTensor weights(weightInfo, weightsData);
398 
399  Optional<ConstTensor> optionalBiases;
400  std::vector<float> biasesData{ 1.0f, 0.0f, 0.0f };
401  ConstTensor biases(biasInfo, biasesData);
402  optionalBiases = Optional<ConstTensor>(biases);
403 
404  // Input layer
405  IConnectableLayer* input = net->AddInputLayer(0, "input");
406 
407  // Convolution2d layer
408  Convolution2dDescriptor conv2dDesc;
409  conv2dDesc.m_StrideX = 1;
410  conv2dDesc.m_StrideY = 1;
411  conv2dDesc.m_PadLeft = 0;
412  conv2dDesc.m_PadRight = 0;
413  conv2dDesc.m_PadTop = 2;
414  conv2dDesc.m_PadBottom = 2;
415  conv2dDesc.m_BiasEnabled = true;
416  IConnectableLayer* conv2d = net->AddConvolution2dLayer(conv2dDesc, weights, optionalBiases);
417 
418  // Abs layer
420  armnn::IConnectableLayer* const abs = net->AddElementwiseUnaryLayer(absDesc, "abs");
421 
422  // Output layer
423  IConnectableLayer* output = net->AddOutputLayer(0, "output");
424 
425  input->GetOutputSlot(0).Connect(conv2d->GetInputSlot(0));
426  conv2d->GetOutputSlot(0).Connect(abs->GetInputSlot(0));
427  abs->GetOutputSlot(0).Connect(output->GetInputSlot(0));
428 
429  input->GetOutputSlot(0).SetTensorInfo(inputInfo);
430  conv2d->GetOutputSlot(0).SetTensorInfo(outputInfo);
431  abs->GetOutputSlot(0).SetTensorInfo(outputInfo);
432 
433  // optimize the network
434  std::vector<armnn::BackendId> backends = { backendId };
435  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
436 
437  ProfilingGuid optNetGuid = optNet->GetGuid();
438 
439  // Load it into the runtime. It should success.
440  armnn::NetworkId netId;
441  CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
442 
443  profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
444  auto readableBuffer = bufferManager.GetReadableBuffer();
445 
446  // Profiling is enabled, the post-optimisation structure should be created
447  CHECK(readableBuffer != nullptr);
448  unsigned int size = readableBuffer->GetSize();
449 
450  const unsigned char* readableData = readableBuffer->GetReadableData();
451  CHECK(readableData != nullptr);
452 
453  unsigned int offset = 0;
454 
455  // Verify Header
456  VerifyTimelineHeaderBinary(readableData, offset, size - 8);
457 
458  // Post-optimisation network
459  // Network entity
460  VerifyTimelineEntityBinaryPacketData(optNetGuid, readableData, offset);
461 
462  // Entity - Type relationship
463  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
464  EmptyOptional(),
465  optNetGuid,
466  LabelsAndEventClasses::NETWORK_GUID,
467  LabelsAndEventClasses::TYPE_GUID,
468  readableData,
469  offset);
470 
471  // Network - START OF LIFE
472  ProfilingGuid networkSolEventGuid = VerifyTimelineEventBinaryPacket(EmptyOptional(),
473  EmptyOptional(),
474  EmptyOptional(),
475  readableData,
476  offset);
477 
478  // Network - START OF LIFE event relationship
479  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
480  EmptyOptional(),
481  optNetGuid,
482  networkSolEventGuid,
483  LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
484  readableData,
485  offset);
486 
487  // Process ID Label
488  int processID = armnnUtils::Processes::GetCurrentId();
489  std::stringstream ss;
490  ss << processID;
491  std::string processIdLabel = ss.str();
492  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), processIdLabel, readableData, offset);
493 
494  // Entity - Process ID relationship
495  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
496  EmptyOptional(),
497  optNetGuid,
498  EmptyOptional(),
499  LabelsAndEventClasses::PROCESS_ID_GUID,
500  readableData,
501  offset);
502 
503  // Input layer
504  // Input layer entity
505  VerifyTimelineEntityBinaryPacketData(input->GetGuid(), readableData, offset);
506 
507  // Name Entity
508  ProfilingGuid inputLabelGuid = VerifyTimelineLabelBinaryPacketData(EmptyOptional(), "input", readableData, offset);
509 
510  // Entity - Name relationship
511  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
512  EmptyOptional(),
513  input->GetGuid(),
514  inputLabelGuid,
515  LabelsAndEventClasses::NAME_GUID,
516  readableData,
517  offset);
518 
519  // Entity - Type relationship
520  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
521  EmptyOptional(),
522  input->GetGuid(),
523  LabelsAndEventClasses::LAYER_GUID,
524  LabelsAndEventClasses::TYPE_GUID,
525  readableData,
526  offset);
527 
528  // Network - Input layer relationship
529  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
530  EmptyOptional(),
531  optNetGuid,
532  input->GetGuid(),
533  LabelsAndEventClasses::CHILD_GUID,
534  readableData,
535  offset);
536 
537  // Conv2d layer
538  // Conv2d layer entity
539  VerifyTimelineEntityBinaryPacketData(conv2d->GetGuid(), readableData, offset);
540 
541  // Name entity
542  ProfilingGuid conv2dNameLabelGuid = VerifyTimelineLabelBinaryPacketData(
543  EmptyOptional(), "<Unnamed>", readableData, offset);
544 
545  // Entity - Name relationship
546  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
547  EmptyOptional(),
548  conv2d->GetGuid(),
549  conv2dNameLabelGuid,
550  LabelsAndEventClasses::NAME_GUID,
551  readableData,
552  offset);
553 
554  // Entity - Type relationship
555  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
556  EmptyOptional(),
557  conv2d->GetGuid(),
558  LabelsAndEventClasses::LAYER_GUID,
559  LabelsAndEventClasses::TYPE_GUID,
560  readableData,
561  offset);
562 
563  // Network - Conv2d layer relationship
564  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
565  EmptyOptional(),
566  optNetGuid,
567  conv2d->GetGuid(),
568  LabelsAndEventClasses::CHILD_GUID,
569  readableData,
570  offset);
571 
572  // Input layer - Conv2d layer relationship
573  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
574  EmptyOptional(),
575  input->GetGuid(),
576  conv2d->GetGuid(),
577  LabelsAndEventClasses::CONNECTION_GUID,
578  readableData,
579  offset);
580 
581  // Conv2d workload
582  // Conv2d workload entity
583  ProfilingGuid conv2DWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
584 
585  // Entity - Type relationship
586  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
587  EmptyOptional(),
588  conv2DWorkloadGuid,
589  LabelsAndEventClasses::WORKLOAD_GUID,
590  LabelsAndEventClasses::TYPE_GUID,
591  readableData,
592  offset);
593 
594  // BackendId entity
595  ProfilingGuid backendIdLabelGuid = VerifyTimelineLabelBinaryPacketData(
596  EmptyOptional(), backendId.Get(), readableData, offset);
597 
598  // Entity - BackendId relationship
599  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
600  EmptyOptional(),
601  conv2DWorkloadGuid,
602  backendIdLabelGuid,
603  LabelsAndEventClasses::BACKENDID_GUID,
604  readableData,
605  offset);
606 
607 
608  // Conv2d layer - Conv2d workload relationship
609  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
610  EmptyOptional(),
611  conv2d->GetGuid(),
612  conv2DWorkloadGuid,
613  LabelsAndEventClasses::CHILD_GUID,
614  readableData,
615  offset);
616 
617  // Abs layer
618  // Abs layer entity
619  VerifyTimelineEntityBinaryPacketData(abs->GetGuid(), readableData, offset);
620 
621  // Name entity
622  ProfilingGuid absLabelGuid = VerifyTimelineLabelBinaryPacketData(
623  EmptyOptional(), "abs", readableData, offset);
624 
625  // Entity - Name relationship
626  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
627  EmptyOptional(),
628  abs->GetGuid(),
629  absLabelGuid,
630  LabelsAndEventClasses::NAME_GUID,
631  readableData,
632  offset);
633 
634  // Entity - Type relationship
635  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
636  EmptyOptional(),
637  abs->GetGuid(),
638  LabelsAndEventClasses::LAYER_GUID,
639  LabelsAndEventClasses::TYPE_GUID,
640  readableData,
641  offset);
642 
643  // Network - Abs layer relationship
644  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
645  EmptyOptional(),
646  optNetGuid,
647  abs->GetGuid(),
648  LabelsAndEventClasses::CHILD_GUID,
649  readableData,
650  offset);
651 
652  // Conv2d layer - Abs layer relationship
653  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
654  EmptyOptional(),
655  conv2d->GetGuid(),
656  abs->GetGuid(),
657  LabelsAndEventClasses::CONNECTION_GUID,
658  readableData,
659  offset);
660 
661  // Abs workload
662  // Abs workload entity
663  ProfilingGuid absWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
664 
665  // Entity - Type relationship
666  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
667  EmptyOptional(),
668  absWorkloadGuid,
669  LabelsAndEventClasses::WORKLOAD_GUID,
670  LabelsAndEventClasses::TYPE_GUID,
671  readableData,
672  offset);
673 
674  // BackendId entity
675  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), backendId.Get(), readableData, offset);
676 
677  // Entity - BackendId relationship
678  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
679  EmptyOptional(),
680  absWorkloadGuid,
681  backendIdLabelGuid,
682  LabelsAndEventClasses::BACKENDID_GUID,
683  readableData,
684  offset);
685 
686  // Abs layer - Abs workload relationship
687  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
688  EmptyOptional(),
689  abs->GetGuid(),
690  absWorkloadGuid,
691  LabelsAndEventClasses::CHILD_GUID,
692  readableData,
693  offset);
694 
695  // Output layer
696  // Output layer entity
697  VerifyTimelineEntityBinaryPacketData(output->GetGuid(), readableData, offset);
698 
699  // Name entity
700  ProfilingGuid outputLabelGuid = VerifyTimelineLabelBinaryPacketData(
701  EmptyOptional(), "output", readableData, offset);
702 
703  // Entity - Name relationship
704  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
705  EmptyOptional(),
706  output->GetGuid(),
707  outputLabelGuid,
708  LabelsAndEventClasses::NAME_GUID,
709  readableData,
710  offset);
711 
712  // Entity - Type relationship
713  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
714  EmptyOptional(),
715  output->GetGuid(),
716  LabelsAndEventClasses::LAYER_GUID,
717  LabelsAndEventClasses::TYPE_GUID,
718  readableData,
719  offset);
720 
721  // Network - Output layer relationship
722  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
723  EmptyOptional(),
724  optNetGuid,
725  output->GetGuid(),
726  LabelsAndEventClasses::CHILD_GUID,
727  readableData,
728  offset);
729 
730  // Abs layer - Output layer relationship
731  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
732  EmptyOptional(),
733  abs->GetGuid(),
734  output->GetGuid(),
735  LabelsAndEventClasses::CONNECTION_GUID,
736  readableData,
737  offset);
738 
739  bufferManager.MarkRead(readableBuffer);
740 
741  // Creates structures for input & output.
742  std::vector<float> inputData(inputInfo.GetNumElements());
743  std::vector<float> outputData(outputInfo.GetNumElements());
744 
745  TensorInfo inputTensorInfo = runtime.GetInputTensorInfo(netId, 0);
746  inputTensorInfo.SetConstant(true);
747  InputTensors inputTensors
748  {
749  {0, ConstTensor(inputTensorInfo, inputData.data())}
750  };
751  OutputTensors outputTensors
752  {
753  {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())}
754  };
755 
756  // Does the inference.
757  runtime.EnqueueWorkload(netId, inputTensors, outputTensors);
758 
759  // Get readable buffer for input workload
760  auto inputReadableBuffer = bufferManager.GetReadableBuffer();
761  CHECK(inputReadableBuffer != nullptr);
762 
763  // Get readable buffer for output workload
764  auto outputReadableBuffer = bufferManager.GetReadableBuffer();
765  CHECK(outputReadableBuffer != nullptr);
766 
767  // Get readable buffer for inference timeline
768  auto inferenceReadableBuffer = bufferManager.GetReadableBuffer();
769  CHECK(inferenceReadableBuffer != nullptr);
770 
771  // Validate input workload data
772  size = inputReadableBuffer->GetSize();
773  CHECK(size == 164);
774 
775  readableData = inputReadableBuffer->GetReadableData();
776  CHECK(readableData != nullptr);
777 
778  offset = 0;
779 
780  // Verify Header
781  VerifyTimelineHeaderBinary(readableData, offset, 156);
782 
783  // Input workload
784  // Input workload entity
785  ProfilingGuid inputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
786 
787  // Entity - Type relationship
788  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
789  EmptyOptional(),
790  inputWorkloadGuid,
791  LabelsAndEventClasses::WORKLOAD_GUID,
792  LabelsAndEventClasses::TYPE_GUID,
793  readableData,
794  offset);
795 
796  // BackendId entity
797  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), backendId.Get(), readableData, offset);
798 
799  // Entity - BackendId relationship
800  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
801  EmptyOptional(),
802  inputWorkloadGuid,
803  backendIdLabelGuid,
804  LabelsAndEventClasses::BACKENDID_GUID,
805  readableData,
806  offset);
807 
808  // Input layer - Input workload relationship
809  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
810  EmptyOptional(),
811  input->GetGuid(),
812  inputWorkloadGuid,
813  LabelsAndEventClasses::CHILD_GUID,
814  readableData,
815  offset);
816 
817  bufferManager.MarkRead(inputReadableBuffer);
818 
819  // Validate output workload data
820  size = outputReadableBuffer->GetSize();
821  CHECK(size == 164);
822 
823  readableData = outputReadableBuffer->GetReadableData();
824  CHECK(readableData != nullptr);
825 
826  offset = 0;
827 
828  // Verify Header
829  VerifyTimelineHeaderBinary(readableData, offset, 156);
830 
831  // Output workload
832  // Output workload entity
833  ProfilingGuid outputWorkloadGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
834 
835  // Entity - Type relationship
836  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
837  EmptyOptional(),
838  outputWorkloadGuid,
839  LabelsAndEventClasses::WORKLOAD_GUID,
840  LabelsAndEventClasses::TYPE_GUID,
841  readableData,
842  offset);
843 
844  // BackendId entity
845  VerifyTimelineLabelBinaryPacketData(EmptyOptional(), backendId.Get(), readableData, offset);
846 
847  // Entity - BackendId relationship
848  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
849  EmptyOptional(),
850  outputWorkloadGuid,
851  backendIdLabelGuid,
852  LabelsAndEventClasses::BACKENDID_GUID,
853  readableData,
854  offset);
855 
856  // Output layer - Output workload relationship
857  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
858  EmptyOptional(),
859  output->GetGuid(),
860  outputWorkloadGuid,
861  LabelsAndEventClasses::CHILD_GUID,
862  readableData,
863  offset);
864 
865  bufferManager.MarkRead(outputReadableBuffer);
866 
867  // Validate inference data
868  size = inferenceReadableBuffer->GetSize();
869 
870  CHECK(size == 1228 + 10 * ThreadIdSize);
871 
872  readableData = inferenceReadableBuffer->GetReadableData();
873  CHECK(readableData != nullptr);
874 
875  offset = 0;
876 
877  // Verify Header
878  VerifyTimelineHeaderBinary(readableData, offset, 1220 + 10 * ThreadIdSize);
879 
880  // Inference timeline trace
881  // Inference entity
882  ProfilingGuid inferenceGuid = VerifyTimelineEntityBinaryPacketData(EmptyOptional(), readableData, offset);
883 
884  // Entity - Type relationship
885  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
886  EmptyOptional(),
887  inferenceGuid,
888  LabelsAndEventClasses::INFERENCE_GUID,
889  LabelsAndEventClasses::TYPE_GUID,
890  readableData,
891  offset);
892 
893  // Network - Inference relationship
894  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
895  EmptyOptional(),
896  optNetGuid,
897  inferenceGuid,
898  LabelsAndEventClasses::EXECUTION_OF_GUID,
899  readableData,
900  offset);
901 
902  // Start Inference life
903  // Event packet - timeline, threadId, eventGuid
904  ProfilingGuid inferenceEventGuid = VerifyTimelineEventBinaryPacket(
905  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
906 
907  // Inference - event relationship
908  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
909  EmptyOptional(),
910  inferenceGuid,
911  inferenceEventGuid,
912  LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
913  readableData,
914  offset);
915 
916  // Execution
917  // Input workload execution
918  // Input workload execution entity
919  ProfilingGuid inputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
920  EmptyOptional(), readableData, offset);
921 
922  // Entity - Type relationship
923  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
924  EmptyOptional(),
925  inputWorkloadExecutionGuid,
926  LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
927  LabelsAndEventClasses::TYPE_GUID,
928  readableData,
929  offset);
930 
931  // Inference - Workload execution relationship
932  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
933  EmptyOptional(),
934  inferenceGuid,
935  inputWorkloadExecutionGuid,
936  LabelsAndEventClasses::CHILD_GUID,
937  readableData,
938  offset);
939 
940  // Workload - Workload execution relationship
941  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
942  EmptyOptional(),
943  inputWorkloadGuid,
944  inputWorkloadExecutionGuid,
945  LabelsAndEventClasses::EXECUTION_OF_GUID,
946  readableData,
947  offset);
948 
949  // Start Input workload execution life
950  // Event packet - timeline, threadId, eventGuid
951  ProfilingGuid inputWorkloadExecutionSOLEventId = VerifyTimelineEventBinaryPacket(
952  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
953 
954  // Input workload execution - event relationship
955  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
956  EmptyOptional(),
957  inputWorkloadExecutionGuid,
958  inputWorkloadExecutionSOLEventId,
959  LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
960  readableData,
961  offset);
962 
963  // End of Input workload execution life
964  // Event packet - timeline, threadId, eventGuid
965  ProfilingGuid inputWorkloadExecutionEOLEventId = VerifyTimelineEventBinaryPacket(
966  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
967 
968  // Input workload execution - event relationship
969  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
970  EmptyOptional(),
971  inputWorkloadExecutionGuid,
972  inputWorkloadExecutionEOLEventId,
973  LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
974  readableData,
975  offset);
976 
977  // Conv2d workload execution
978  // Conv2d workload execution entity
979  ProfilingGuid conv2DWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
980  EmptyOptional(), readableData, offset);
981 
982  // Entity - Type relationship
983  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
984  EmptyOptional(),
985  conv2DWorkloadExecutionGuid,
986  LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
987  LabelsAndEventClasses::TYPE_GUID,
988  readableData,
989  offset);
990 
991  // Inference - Workload execution relationship
992  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
993  EmptyOptional(),
994  inferenceGuid,
995  conv2DWorkloadExecutionGuid,
996  LabelsAndEventClasses::CHILD_GUID,
997  readableData,
998  offset);
999 
1000  // Workload - Workload execution relationship
1001  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1002  EmptyOptional(),
1003  conv2DWorkloadGuid,
1004  conv2DWorkloadExecutionGuid,
1005  LabelsAndEventClasses::EXECUTION_OF_GUID,
1006  readableData,
1007  offset);
1008 
1009  // Start Conv2d workload execution life
1010  // Event packet - timeline, threadId, eventGuid
1011  ProfilingGuid conv2DWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1012  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1013 
1014  // Conv2d workload execution - event relationship
1015  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1016  EmptyOptional(),
1017  conv2DWorkloadExecutionGuid,
1018  conv2DWorkloadExecutionSOLEventGuid,
1019  LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1020  readableData,
1021  offset);
1022 
1023  // End of Conv2d workload execution life
1024  // Event packet - timeline, threadId, eventGuid
1025  ProfilingGuid conv2DWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1026  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1027 
1028  // Conv2d workload execution - event relationship
1029  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1030  EmptyOptional(),
1031  conv2DWorkloadExecutionGuid,
1032  conv2DWorkloadExecutionEOLEventGuid,
1033  LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1034  readableData,
1035  offset);
1036 
1037  // Abs workload execution
1038  // Abs workload execution entity
1039  ProfilingGuid absWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1040  EmptyOptional(), readableData, offset);
1041 
1042  // Entity - Type relationship
1043  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1044  EmptyOptional(),
1045  absWorkloadExecutionGuid,
1046  LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
1047  LabelsAndEventClasses::TYPE_GUID,
1048  readableData,
1049  offset);
1050 
1051  // Inference - Workload execution relationship
1052  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1053  EmptyOptional(),
1054  inferenceGuid,
1055  absWorkloadExecutionGuid,
1056  LabelsAndEventClasses::CHILD_GUID,
1057  readableData,
1058  offset);
1059 
1060  // Workload - Workload execution relationship
1061  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1062  EmptyOptional(),
1063  absWorkloadGuid,
1064  absWorkloadExecutionGuid,
1065  LabelsAndEventClasses::EXECUTION_OF_GUID,
1066  readableData,
1067  offset);
1068 
1069  // Start Abs workload execution life
1070  // Event packet - timeline, threadId, eventGuid
1071  ProfilingGuid absWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1072  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1073 
1074  // Abs workload execution - event relationship
1075  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1076  EmptyOptional(),
1077  absWorkloadExecutionGuid,
1078  absWorkloadExecutionSOLEventGuid,
1079  LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1080  readableData,
1081  offset);
1082 
1083  // End of Abs workload execution life
1084  // Event packet - timeline, threadId, eventGuid
1085  ProfilingGuid absWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1086  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1087 
1088  // Abs workload execution - event relationship
1089  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1090  EmptyOptional(),
1091  absWorkloadExecutionGuid,
1092  absWorkloadExecutionEOLEventGuid,
1093  LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1094  readableData,
1095  offset);
1096 
1097  // Output workload execution
1098  // Output workload execution entity
1099  ProfilingGuid outputWorkloadExecutionGuid = VerifyTimelineEntityBinaryPacketData(
1100  EmptyOptional(), readableData, offset);
1101 
1102  // Entity - Type relationship
1103  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::LabelLink,
1104  EmptyOptional(),
1105  outputWorkloadExecutionGuid,
1106  LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID,
1107  LabelsAndEventClasses::TYPE_GUID,
1108  readableData,
1109  offset);
1110 
1111  // Inference - Workload execution relationship
1112  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1113  EmptyOptional(),
1114  inferenceGuid,
1115  outputWorkloadExecutionGuid,
1116  LabelsAndEventClasses::CHILD_GUID,
1117  readableData,
1118  offset);
1119 
1120  // Workload - Workload execution relationship
1121  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::RetentionLink,
1122  EmptyOptional(),
1123  outputWorkloadGuid,
1124  outputWorkloadExecutionGuid,
1125  LabelsAndEventClasses::EXECUTION_OF_GUID,
1126  readableData,
1127  offset);
1128 
1129  // Start Output workload execution life
1130  // Event packet - timeline, threadId, eventGuid
1131  ProfilingGuid outputWorkloadExecutionSOLEventGuid = VerifyTimelineEventBinaryPacket(
1132  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1133 
1134  // Output workload execution - event relationship
1135  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1136  EmptyOptional(),
1137  outputWorkloadExecutionGuid,
1138  outputWorkloadExecutionSOLEventGuid,
1139  LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS,
1140  readableData,
1141  offset);
1142 
1143  // End of Normalize workload execution life
1144  // Event packet - timeline, threadId, eventGuid
1145  ProfilingGuid outputWorkloadExecutionEOLEventGuid = VerifyTimelineEventBinaryPacket(
1146  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1147 
1148  // Output workload execution - event relationship
1149  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1150  EmptyOptional(),
1151  outputWorkloadExecutionGuid,
1152  outputWorkloadExecutionEOLEventGuid,
1153  LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1154  readableData,
1155  offset);
1156 
1157  // End of Inference life
1158  // Event packet - timeline, threadId, eventGuid
1159  ProfilingGuid inferenceEOLEventGuid = VerifyTimelineEventBinaryPacket(
1160  EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset);
1161 
1162  // Inference - event relationship
1163  VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType::ExecutionLink,
1164  EmptyOptional(),
1165  inferenceGuid,
1166  inferenceEOLEventGuid,
1167  LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS,
1168  readableData,
1169  offset);
1170 
1171  bufferManager.MarkRead(inferenceReadableBuffer);
1172 }
profiling::ProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)
Definition: TestUtils.cpp:57
uint32_t m_PadBottom
Padding bottom value in the height dimension.
bool m_BiasEnabled
Enable/disable bias.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:66
ProfilingGuid VerifyTimelineEntityBinaryPacketData(Optional< ProfilingGuid > guid, const unsigned char *readableData, unsigned int &offset)
A Convolution2dDescriptor for the Convolution2dLayer.
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:392
uint32_t m_PadRight
Padding right value in the width dimension.
Copyright (c) 2021 ARM Limited and Contributors.
bool m_EnableProfiling
Indicates whether external profiling is enabled or not.
Definition: IRuntime.hpp:136
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Definition: Tensor.hpp:319
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1680
void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType, Optional< ProfilingGuid > relationshipGuid, Optional< ProfilingGuid > headGuid, Optional< ProfilingGuid > tailGuid, Optional< ProfilingGuid > attributeGuid, const unsigned char *readableData, unsigned int &offset)
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
int NetworkId
Definition: IRuntime.hpp:25
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:393
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:242
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
IPacketBufferPtr GetReadableBuffer() override
constexpr unsigned int ThreadIdSize
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
void VerifyTimelineHeaderBinary(const unsigned char *readableData, unsigned int &offset, uint32_t packetDataLength)
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
const std::string & Get() const
Definition: BackendId.hpp:138
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
void SetConstant(const bool IsConstant=true)
Marks the data corresponding to this tensor info as constant.
Definition: Tensor.cpp:516
bool m_TimelineEnabled
Indicates whether external timeline profiling is enabled or not.
Definition: IRuntime.hpp:138
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:241
ProfilingGuid VerifyTimelineEventBinaryPacket(Optional< uint64_t > timestamp, Optional< int > threadId, Optional< ProfilingGuid > eventGuid, const unsigned char *readableData, unsigned int &offset)
virtual int Connect(IInputSlot &destination)=0
ProfilingGuid VerifyTimelineLabelBinaryPacketData(Optional< ProfilingGuid > guid, const std::string &label, const unsigned char *readableData, unsigned int &offset)
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:151
static INetworkPtr Create(NetworkOptions networkOptions={})
Definition: Network.cpp:492
uint32_t m_PadLeft
Padding left value in the width dimension.

◆ VerifyTimelineEntityBinaryPacketData()

ProfilingGuid VerifyTimelineEntityBinaryPacketData ( Optional< ProfilingGuid >  guid,
const unsigned char *  readableData,
unsigned int &  offset 
)

Definition at line 269 of file ProfilingTestUtils.cpp.

References ARMNN_ASSERT, OptionalBase::has_value(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint64(), armnn::profiling::uint32_t_size, and OptionalReferenceSwitch< std::is_reference< T >::value, T >::value().

Referenced by TEST_SUITE(), and VerifyPostOptimisationStructureTestImpl().

272 {
273  ARMNN_ASSERT(readableData);
274 
275  // Utils
276  unsigned int uint32_t_size = sizeof(uint32_t);
277  unsigned int uint64_t_size = sizeof(uint64_t);
278 
279  // Reading TimelineEntityClassBinaryPacket
280  // Check the decl_id
281  uint32_t entityDeclId = ReadUint32(readableData, offset);
282  CHECK(entityDeclId == 1);
283 
284  // Check the profiling GUID
285  offset += uint32_t_size;
286  uint64_t readProfilingGuid = ReadUint64(readableData, offset);
287 
288  if (guid.has_value())
289  {
290  CHECK(readProfilingGuid == guid.value());
291  }
292  else
293  {
294  CHECK(readProfilingGuid != ProfilingGuid(0));
295  }
296 
297  offset += uint64_t_size;
298 
299  ProfilingGuid entityGuid(readProfilingGuid);
300  return entityGuid;
301 }
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
bool has_value() const noexcept
Definition: Optional.hpp:53
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ VerifyTimelineEventBinaryPacket()

ProfilingGuid VerifyTimelineEventBinaryPacket ( Optional< uint64_t >  timestamp,
Optional< int >  threadId,
Optional< ProfilingGuid >  eventGuid,
const unsigned char *  readableData,
unsigned int &  offset 
)

Definition at line 303 of file ProfilingTestUtils.cpp.

References ARMNN_ASSERT, armnnUtils::Threads::GetCurrentThreadId(), OptionalBase::has_value(), armnn::profiling::ReadBytes(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint64(), armnn::profiling::ThreadIdSize, armnn::profiling::uint32_t_size, and OptionalReferenceSwitch< std::is_reference< T >::value, T >::value().

Referenced by TEST_SUITE(), and VerifyPostOptimisationStructureTestImpl().

308 {
309  ARMNN_ASSERT(readableData);
310 
311  // Utils
312  unsigned int uint32_t_size = sizeof(uint32_t);
313  unsigned int uint64_t_size = sizeof(uint64_t);
314 
315  // Reading TimelineEventBinaryPacket
316  // Check the decl_id
317  uint32_t entityDeclId = ReadUint32(readableData, offset);
318  CHECK(entityDeclId == 4);
319 
320  // Check the timestamp
321  offset += uint32_t_size;
322  uint64_t readTimestamp = ReadUint64(readableData, offset);
323  if (timestamp.has_value())
324  {
325  CHECK(readTimestamp == timestamp.value());
326  }
327  else
328  {
329  CHECK(readTimestamp != 0);
330  }
331 
332  // Check the thread id
333  offset += uint64_t_size;
334  std::vector<uint8_t> readThreadId(ThreadIdSize, 0);
335  ReadBytes(readableData, offset, ThreadIdSize, readThreadId.data());
336  if (threadId.has_value())
337  {
338  CHECK(readThreadId == threadId.value());
339  }
340  else
341  {
342  CHECK(readThreadId == armnnUtils::Threads::GetCurrentThreadId());
343  }
344 
345  // Check the event GUID
346  offset += ThreadIdSize;
347  uint64_t readEventGuid = ReadUint64(readableData, offset);
348  if (eventGuid.has_value())
349  {
350  CHECK(readEventGuid == eventGuid.value());
351  }
352  else
353  {
354  CHECK(readEventGuid != ProfilingGuid(0));
355  }
356 
357  offset += uint64_t_size;
358 
359  ProfilingGuid eventid(readEventGuid);
360  return eventid;
361 }
int GetCurrentThreadId()
Definition: Threads.cpp:27
void ReadBytes(const IPacketBufferPtr &packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
bool has_value() const noexcept
Definition: Optional.hpp:53
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
constexpr unsigned int ThreadIdSize
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ VerifyTimelineEventClassBinaryPacketData()

void VerifyTimelineEventClassBinaryPacketData ( ProfilingGuid  guid,
ProfilingGuid  nameGuid,
const unsigned char *  readableData,
unsigned int &  offset 
)

Definition at line 147 of file ProfilingTestUtils.cpp.

References ARMNN_ASSERT, armnn::profiling::ReadUint32(), armnn::profiling::ReadUint64(), and armnn::profiling::uint32_t_size.

151 {
152  ARMNN_ASSERT(readableData);
153 
154  // Utils
155  unsigned int uint32_t_size = sizeof(uint32_t);
156  unsigned int uint64_t_size = sizeof(uint64_t);
157 
158  // Check the decl id
159  uint32_t eventClassDeclId = ReadUint32(readableData, offset);
160  CHECK(eventClassDeclId == 2);
161 
162  // Check the profiling GUID
163  offset += uint32_t_size;
164  uint64_t readProfilingGuid = ReadUint64(readableData, offset);
165  CHECK(readProfilingGuid == guid);
166 
167  offset += uint64_t_size;
168  uint64_t readProfiilngNameGuid = ReadUint64(readableData, offset);
169  CHECK(readProfiilngNameGuid == nameGuid);
170 
171  // Update the offset to allow parsing to be continued after this function returns
172  offset += uint64_t_size;
173 }
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ VerifyTimelineHeaderBinary()

void VerifyTimelineHeaderBinary ( const unsigned char *  readableData,
unsigned int &  offset,
uint32_t  packetDataLength 
)

Definition at line 74 of file ProfilingTestUtils.cpp.

References ARMNN_ASSERT, armnn::profiling::ReadUint32(), and armnn::profiling::uint32_t_size.

Referenced by TEST_SUITE(), and VerifyPostOptimisationStructureTestImpl().

77 {
78  ARMNN_ASSERT(readableData);
79 
80  // Utils
81  unsigned int uint32_t_size = sizeof(uint32_t);
82 
83  // Check the TimelineEventClassBinaryPacket header
84  uint32_t timelineBinaryPacketHeaderWord0 = ReadUint32(readableData, offset);
85  uint32_t timelineBinaryPacketFamily = (timelineBinaryPacketHeaderWord0 >> 26) & 0x0000003F;
86  uint32_t timelineBinaryPacketClass = (timelineBinaryPacketHeaderWord0 >> 19) & 0x0000007F;
87  uint32_t timelineBinaryPacketType = (timelineBinaryPacketHeaderWord0 >> 16) & 0x00000007;
88  uint32_t timelineBinaryPacketStreamId = (timelineBinaryPacketHeaderWord0 >> 0) & 0x00000007;
89  CHECK(timelineBinaryPacketFamily == 1);
90  CHECK(timelineBinaryPacketClass == 0);
91  CHECK(timelineBinaryPacketType == 1);
92  CHECK(timelineBinaryPacketStreamId == 0);
93  offset += uint32_t_size;
94  uint32_t timelineBinaryPacketHeaderWord1 = ReadUint32(readableData, offset);
95  uint32_t timelineBinaryPacketSequenceNumber = (timelineBinaryPacketHeaderWord1 >> 24) & 0x00000001;
96  uint32_t timelineBinaryPacketDataLength = (timelineBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF;
97  CHECK(timelineBinaryPacketSequenceNumber == 0);
98  CHECK(timelineBinaryPacketDataLength == packetDataLength);
99  offset += uint32_t_size;
100 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ VerifyTimelineLabelBinaryPacketData()

ProfilingGuid VerifyTimelineLabelBinaryPacketData ( Optional< ProfilingGuid >  guid,
const std::string &  label,
const unsigned char *  readableData,
unsigned int &  offset 
)

Definition at line 102 of file ProfilingTestUtils.cpp.

References ARMNN_ASSERT, ProfilingService::GetStaticId(), OptionalBase::has_value(), armnn::numeric_cast(), OffsetToNextWord(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint64(), armnn::profiling::uint32_t_size, and OptionalReferenceSwitch< std::is_reference< T >::value, T >::value().

Referenced by TEST_SUITE(), and VerifyPostOptimisationStructureTestImpl().

106 {
107  ARMNN_ASSERT(readableData);
108 
109  // Utils
110  unsigned int uint32_t_size = sizeof(uint32_t);
111  unsigned int uint64_t_size = sizeof(uint64_t);
112  unsigned int label_size = armnn::numeric_cast<unsigned int>(label.size());
113 
114  // Check the decl id
115  uint32_t eventClassDeclId = ReadUint32(readableData, offset);
116  CHECK(eventClassDeclId == 0);
117 
118  // Check the profiling GUID
119  offset += uint32_t_size;
120  uint64_t readProfilingGuid = ReadUint64(readableData, offset);
121  if (guid.has_value())
122  {
123  CHECK(readProfilingGuid == guid.value());
124  }
125  else
126  {
127  armnn::profiling::ProfilingService profilingService;
128  CHECK(readProfilingGuid == profilingService.GetStaticId(label));
129  }
130 
131  // Check the SWTrace label
132  offset += uint64_t_size;
133  uint32_t swTraceLabelLength = ReadUint32(readableData, offset);
134  CHECK(swTraceLabelLength == label_size + 1); // Label length including the null-terminator
135  offset += uint32_t_size;
136  CHECK(std::memcmp(readableData + offset, // Offset to the label in the buffer
137  label.data(), // The original label
138  swTraceLabelLength - 1) == 0); // The length of the label
139 
140  // SWTrace strings are written in blocks of words, so the offset has to be updated to the next whole word
141  offset += OffsetToNextWord(swTraceLabelLength);
142 
143  ProfilingGuid labelGuid(readProfilingGuid);
144  return labelGuid;
145 }
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
unsigned int OffsetToNextWord(unsigned int numberOfBytes)
static ProfilingStaticGuid GetStaticId(const std::string &str)
bool has_value() const noexcept
Definition: Optional.hpp:53
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ VerifyTimelineRelationshipBinaryPacketData()

void VerifyTimelineRelationshipBinaryPacketData ( ProfilingRelationshipType  relationshipType,
Optional< ProfilingGuid >  relationshipGuid,
Optional< ProfilingGuid >  headGuid,
Optional< ProfilingGuid >  tailGuid,
Optional< ProfilingGuid >  attributeGuid,
const unsigned char *  readableData,
unsigned int &  offset 
)

Definition at line 175 of file ProfilingTestUtils.cpp.

References ARMNN_ASSERT, OptionalBase::has_value(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint64(), armnn::profiling::uint32_t_size, and OptionalReferenceSwitch< std::is_reference< T >::value, T >::value().

Referenced by TEST_SUITE(), and VerifyPostOptimisationStructureTestImpl().

182 {
183  ARMNN_ASSERT(readableData);
184 
185  uint32_t relationshipTypeUint = 0;
186  switch (relationshipType)
187  {
188  case ProfilingRelationshipType::RetentionLink:
189  relationshipTypeUint = 0;
190  break;
191  case ProfilingRelationshipType::ExecutionLink:
192  relationshipTypeUint = 1;
193  break;
194  case ProfilingRelationshipType::DataLink:
195  relationshipTypeUint = 2;
196  break;
197  case ProfilingRelationshipType::LabelLink:
198  relationshipTypeUint = 3;
199  break;
200  default:
201  FAIL("Unknown relationship type");
202  }
203 
204  // Utils
205  unsigned int uint32_t_size = sizeof(uint32_t);
206  unsigned int uint64_t_size = sizeof(uint64_t);
207 
208  // Check the decl id
209  uint32_t eventClassDeclId = ReadUint32(readableData, offset);
210  CHECK(eventClassDeclId == 3);
211 
212  // Check the relationship type
213  offset += uint32_t_size;
214  uint32_t readRelationshipTypeUint = ReadUint32(readableData, offset);
215  CHECK(readRelationshipTypeUint == relationshipTypeUint);
216 
217  // Check the relationship GUID
218  offset += uint32_t_size;
219  uint64_t readRelationshipGuid = ReadUint64(readableData, offset);
220  if (relationshipGuid.has_value())
221  {
222  CHECK(readRelationshipGuid == relationshipGuid.value());
223  }
224  else
225  {
226  CHECK(readRelationshipGuid != ProfilingGuid(0));
227  }
228 
229  // Check the head GUID of the relationship
230  offset += uint64_t_size;
231  uint64_t readHeadRelationshipGuid = ReadUint64(readableData, offset);
232  if (headGuid.has_value())
233  {
234  CHECK(readHeadRelationshipGuid == headGuid.value());
235  }
236  else
237  {
238  CHECK(readHeadRelationshipGuid != ProfilingGuid(0));
239  }
240 
241  // Check the tail GUID of the relationship
242  offset += uint64_t_size;
243  uint64_t readTailRelationshipGuid = ReadUint64(readableData, offset);
244  if (tailGuid.has_value())
245  {
246  CHECK(readTailRelationshipGuid == tailGuid.value());
247  }
248  else
249  {
250  CHECK(readTailRelationshipGuid != ProfilingGuid(0));
251  }
252 
253  // Check the attribute GUID of the relationship
254  offset += uint64_t_size;
255  uint64_t readAttributeRelationshipGuid = ReadUint64(readableData, offset);
256  if (attributeGuid.has_value())
257  {
258  CHECK(readAttributeRelationshipGuid == attributeGuid.value());
259  }
260  else
261  {
262  CHECK(readAttributeRelationshipGuid == ProfilingGuid(0));
263  }
264 
265  // Update the offset to allow parsing to be continued after this function returns
266  offset += uint64_t_size;
267 }
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
bool has_value() const noexcept
Definition: Optional.hpp:53
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)