ArmNN
 20.05
FileOnlyProfilingDecoratorTests.cpp File Reference
#include <Filesystem.hpp>
#include <ProfilingService.hpp>
#include <Runtime.hpp>
#include "PrintPacketHeaderHandler.hpp"
#include "TestTimelinePacketHandler.hpp"
#include <boost/filesystem.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/test/unit_test.hpp>
#include <cstdio>
#include <sstream>
#include <sys/stat.h>

Go to the source code of this file.

Functions

std::string UniqueFileName ()
 
 BOOST_AUTO_TEST_CASE (TestFileOnlyProfiling)
 
profilingService ResetExternalProfilingOptions (options, true)
 
profilingService Update ()
 
 BOOST_CHECK (profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
 
 while (profilingService.GetCurrentState() !=ProfilingState::Active &&packetCount< 3)
 
 BOOST_CHECK (boost::filesystem::exists(tempPath.c_str())==true)
 
 BOOST_CHECK (profilingService.IsCounterRegistered(0)==true)
 
profilingService IncrementCounterValue (0)
 
 BOOST_CHECK (profilingService.GetAbsoluteCounterValue(0) > 0)
 
helper WaitForPacketsSent ()
 
 BOOST_CHECK (armnnUtils::Filesystem::GetFileSize(tempPath.string().c_str()) > 0)
 
 BOOST_CHECK (armnnUtils::Filesystem::Remove(tempPath.string().c_str()))
 

Variables

boost::filesystem::path tempFile = UniqueFileName()
 
 tempPath = tempPath / tempFile
 
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
 
options m_EnableProfiling = true
 
options m_FileOnly = true
 
options m_IncomingCaptureFile = ""
 
options m_OutgoingCaptureFile = tempPath.string()
 
options m_CapturePeriod = 100
 
FileOnlyHelperService helper
 
armnn::profiling::ProfilingService profilingService
 
uint32_t packetCount = 0
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( TestFileOnlyProfiling  )

Definition at line 50 of file FileOnlyProfilingDecoratorTests.cpp.

References armnn::BackendRegistryInstance(), armnn::BOOST_AUTO_TEST_CASE(), IOutputSlot::Connect(), armnn::CpuRef, INetwork::Create(), armnn::Float32, Runtime::GetDeviceSpec(), IConnectableLayer::GetInputSlot(), IConnectableLayer::GetOutputSlot(), Runtime::LoadNetwork(), IRuntime::CreationOptions::ExternalProfilingOptions::m_CapturePeriod, IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::ExternalProfilingOptions::m_FileOnly, IRuntime::CreationOptions::ExternalProfilingOptions::m_LocalPacketHandlers, IRuntime::CreationOptions::m_ProfilingOptions, IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, armnn::Optimize(), IOutputSlot::SetTensorInfo(), armnn::Success, tempFile, tempPath, and UniqueFileName().

51 {
52  // This test requires the CpuRef backend to be enabled
53  if(!BackendRegistryInstance().IsBackendRegistered("CpuRef"))
54  {
55  return;
56  }
57 
58  // Create a temporary file name.
59  boost::filesystem::path tempPath = boost::filesystem::temp_directory_path();
60  boost::filesystem::path tempFile = UniqueFileName();
61  tempPath = tempPath / tempFile;
62  armnn::Runtime::CreationOptions creationOptions;
63  creationOptions.m_ProfilingOptions.m_EnableProfiling = true;
64  creationOptions.m_ProfilingOptions.m_FileOnly = true;
65  creationOptions.m_ProfilingOptions.m_CapturePeriod = 100;
66  creationOptions.m_ProfilingOptions.m_TimelineEnabled = true;
67  ILocalPacketHandlerSharedPtr localPacketHandlerPtr = std::make_shared<TestTimelinePacketHandler>();
68  creationOptions.m_ProfilingOptions.m_LocalPacketHandlers.push_back(localPacketHandlerPtr);
69 
70  armnn::Runtime runtime(creationOptions);
71 
72  // Load a simple network
73  // build up the structure of the network
74  INetworkPtr net(INetwork::Create());
75 
76  IConnectableLayer* input = net->AddInputLayer(0, "input");
77 
78  NormalizationDescriptor descriptor;
79  IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
80 
81  IConnectableLayer* output = net->AddOutputLayer(0, "output");
82 
83  input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
84  normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
85 
86  input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
87  normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
88 
89  // optimize the network
90  std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
91  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
92 
93  // Load it into the runtime. It should succeed.
94  armnn::NetworkId netId;
95  BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
96 
97  static_cast<TestTimelinePacketHandler*>(localPacketHandlerPtr.get())->WaitOnInferenceCompletion(3000);
98 }
std::shared_ptr< ILocalPacketHandler > ILocalPacketHandlerSharedPtr
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
CPU Execution: Reference C++ kernels.
std::string UniqueFileName()
BackendRegistry & BackendRegistryInstance()
int NetworkId
Definition: IRuntime.hpp:20
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
std::vector< armnn::profiling::ILocalPacketHandlerSharedPtr > m_LocalPacketHandlers
Definition: IRuntime.hpp:81
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:1003
boost::filesystem::path tempFile
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:573
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
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:101
virtual int Connect(IInputSlot &destination)=0
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:83

◆ BOOST_CHECK() [1/6]

BOOST_CHECK ( profilingService.  GetCurrentState() = =ProfilingState::WaitingForAck)

Referenced by ArgMinMaxInferOutputShape1dTest(), ArgMinMaxInferOutputShape2dTest(), ArgMinMaxInferOutputShape3dTest(), ArgMinMaxInferOutputShape4dTest(), BatchToSpaceInferOutputShapeTest(), BOOST_AUTO_TEST_CASE(), armnn::BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), TestLayerVisitor::CheckConstTensors(), TestConvolution2dLayerVisitor::CheckDescriptor(), TestDepthwiseConvolution2dLayerVisitor::CheckDescriptor(), TestFullyConnectedLayerVistor::CheckDescriptor(), TestBatchNormalizationLayerVisitor::CheckDescriptor(), TestLstmLayerVisitor::CheckDescriptor(), TestQLstmLayerVisitor::CheckDescriptor(), TestLayerVisitor::CheckLayerName(), TestLayerVisitor::CheckLayerPointer(), TestLayerVisitor::CheckOptionalConstTensors(), ParserFlatbuffersFixture::CheckTensors(), CheckTimelineDirectory(), CheckTimelinePackets(), Convolution2dInferOutputShapeTest(), DepthwiseConvolution2dInferOutputShapeTest(), GetBasePath(), GetSoftmaxProfilerJson(), GetTestFilePath(), PreluInferOutputShapeAlphaBiggerTest(), PreluInferOutputShapeInputBiggerTest(), PreluInferOutputShapeNoMatchTest(), PreluInferOutputShapeSameDimsTest(), QLstmInferOutputShapeTest(), QuantizedLstmEndToEnd(), QuantizedLstmInferOutputShapeTest(), RunSoftmaxProfilerJsonPrinterTest(), SendTimelinePacketToCommandHandler(), SpaceToDepthInferOutputShapeTest(), StackInferOutputShapeFromInputsMatchTest(), StackInferOutputShapeFromInputsNoMatchTest(), StringToSwTraceStringTestHelper(), SwapProfilingConnectionFactoryHelper::SwapProfilingConnectionFactoryHelper(), TransposeConvolution2dInferOutputShapeTest(), ValidateProfilerJson(), VerifyPostOptimisationStructureTestImpl(), VerifyTimelineEntityBinaryPacketData(), VerifyTimelineEventBinaryPacket(), VerifyTimelineEventClassBinaryPacketData(), VerifyTimelineHeaderBinary(), VerifyTimelineLabelBinaryPacketData(), VerifyTimelineRelationshipBinaryPacketData(), while(), and SwapProfilingConnectionFactoryHelper::~SwapProfilingConnectionFactoryHelper().

◆ BOOST_CHECK() [2/6]

BOOST_CHECK ( boost::filesystem::exists(tempPath.c_str())  = =true)

◆ BOOST_CHECK() [3/6]

BOOST_CHECK ( profilingService.  IsCounterRegistered0 = =true)

◆ BOOST_CHECK() [4/6]

BOOST_CHECK ( profilingService.  GetAbsoluteCounterValue0,
 
)

◆ BOOST_CHECK() [5/6]

BOOST_CHECK ( armnnUtils::Filesystem::GetFileSize(tempPath.string().c_str())  ,
 
)

◆ BOOST_CHECK() [6/6]

BOOST_CHECK ( armnnUtils::Filesystem::Remove(tempPath.string().c_str())  )

◆ IncrementCounterValue()

profilingService IncrementCounterValue ( )

◆ ResetExternalProfilingOptions()

profilingService ResetExternalProfilingOptions ( options  ,
true   
)

◆ UniqueFileName()

std::string UniqueFileName ( )

Definition at line 38 of file FileOnlyProfilingDecoratorTests.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

39 {
40  std::time_t t = std::time(nullptr);
41  char mbstr[100];
42  std::strftime(mbstr, sizeof(mbstr), "%Y_%m_%d_%H_%M_%S_", std::localtime(&t));
43  std::stringstream ss;
44  ss << mbstr;
45  ss << t;
46  ss << ".bin";
47  return ss.str();
48 }

◆ Update()

profilingService Update ( )

◆ WaitForPacketsSent()

helper WaitForPacketsSent ( )

◆ while()

Variable Documentation

◆ helper

FileOnlyHelperService helper

Definition at line 113 of file FileOnlyProfilingDecoratorTests.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ m_CapturePeriod

◆ m_EnableProfiling

◆ m_FileOnly

options m_FileOnly = true

Definition at line 108 of file FileOnlyProfilingDecoratorTests.cpp.

◆ m_IncomingCaptureFile

options m_IncomingCaptureFile = ""

Definition at line 109 of file FileOnlyProfilingDecoratorTests.cpp.

◆ m_OutgoingCaptureFile

options m_OutgoingCaptureFile = tempPath.string()

Definition at line 110 of file FileOnlyProfilingDecoratorTests.cpp.

◆ options

◆ packetCount

uint32_t packetCount = 0

◆ profilingService

◆ tempFile

boost::filesystem::path tempFile = UniqueFileName()

Definition at line 104 of file FileOnlyProfilingDecoratorTests.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ tempPath

tempPath = tempPath / tempFile

Definition at line 105 of file FileOnlyProfilingDecoratorTests.cpp.

Referenced by BOOST_AUTO_TEST_CASE().