From 4e755a50e35a1f5ac1b011dc4baf89e6d97f116e Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Sun, 29 Mar 2020 17:48:26 +0100 Subject: IVGCVSW-4595 Add IFileOnlyPacketHandlers to file only profiling connection Change-Id: Ib49a8cbbf323da4109cdab9750e6c4d276e484b7 Signed-off-by: Jim Flynn --- .../test/FileOnlyProfilingDecoratorTests.cpp | 68 ++++++++++++++++++++-- 1 file changed, 63 insertions(+), 5 deletions(-) (limited to 'src/profiling/test/FileOnlyProfilingDecoratorTests.cpp') diff --git a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp index baadb8555d..964489478e 100644 --- a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp +++ b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp @@ -3,12 +3,14 @@ // SPDX-License-Identifier: MIT // -#include "../FileOnlyProfilingConnection.hpp" - +#include +#include +#include +#include #include #include -#include -#include +#include "PrintPacketHeaderHandler.hpp" +#include "TestTimelinePacketHandler.hpp" #include #include @@ -37,11 +39,67 @@ class FileOnlyHelperService : public ProfilingService BOOST_AUTO_TEST_SUITE(FileOnlyProfilingDecoratorTests) +std::string UniqueFileName() +{ + std::time_t t = std::time(nullptr); + char mbstr[100]; + std::strftime(mbstr, sizeof(mbstr), "%Y_%m_%d_%H_%M_%S_", std::localtime(&t)); + std::stringstream ss; + ss << mbstr; + ss << t; + ss << ".bin"; + return ss.str(); +} + +BOOST_AUTO_TEST_CASE(TestFileOnlyProfiling) +{ + // Create a temporary file name. + boost::filesystem::path tempPath = boost::filesystem::temp_directory_path(); + boost::filesystem::path tempFile = UniqueFileName(); + tempPath = tempPath / tempFile; + armnn::Runtime::CreationOptions creationOptions; + creationOptions.m_ProfilingOptions.m_EnableProfiling = true; + creationOptions.m_ProfilingOptions.m_FileOnly = true; + creationOptions.m_ProfilingOptions.m_CapturePeriod = 100; + creationOptions.m_ProfilingOptions.m_TimelineEnabled = true; + ILocalPacketHandlerSharedPtr localPacketHandlerPtr = std::make_shared(); + creationOptions.m_ProfilingOptions.m_LocalPacketHandlers.push_back(localPacketHandlerPtr); + + armnn::Runtime runtime(creationOptions); + + // Load a simple network + // build up the structure of the network + INetworkPtr net(INetwork::Create()); + + IConnectableLayer* input = net->AddInputLayer(0, "input"); + + NormalizationDescriptor descriptor; + IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization"); + + IConnectableLayer* output = net->AddOutputLayer(0, "output"); + + input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0)); + normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); + + input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); + normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); + + // optimize the network + std::vector backends = { armnn::Compute::CpuRef }; + IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec()); + + // Load it into the runtime. It should succeed. + armnn::NetworkId netId; + BOOST_TEST(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success); + + static_cast(localPacketHandlerPtr.get())->WaitOnInferenceCompletion(3000); +} + BOOST_AUTO_TEST_CASE(DumpOutgoingValidFileEndToEnd, * boost::unit_test::disabled()) { // Create a temporary file name. boost::filesystem::path tempPath = boost::filesystem::temp_directory_path(); - boost::filesystem::path tempFile = boost::filesystem::unique_path(); + boost::filesystem::path tempFile = UniqueFileName(); tempPath = tempPath / tempFile; armnn::Runtime::CreationOptions::ExternalProfilingOptions options; options.m_EnableProfiling = true; -- cgit v1.2.1