diff options
author | Jim Flynn <jim.flynn@arm.com> | 2020-04-29 21:12:13 +0100 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-05-26 16:33:21 +0100 |
commit | 01d0281404183c84d26e863502cac8d83044c0bf (patch) | |
tree | 526f19f39fb826d0df1035729182af27ec5a44d8 /src/profiling/test | |
parent | 42b3d7da750ab6ad39ea228985f422685f89eb45 (diff) | |
download | armnn-01d0281404183c84d26e863502cac8d83044c0bf.tar.gz |
IVGCVSW-4595 Change FileOnlyProfilingConnection to all packet processor model
Change-Id: Ieccb26190d80e570ddef8d7c22e824eda1b92d7f
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Diffstat (limited to 'src/profiling/test')
4 files changed, 150 insertions, 5 deletions
diff --git a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp index 80236ae4eb..aa877a10e9 100644 --- a/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp +++ b/src/profiling/test/FileOnlyProfilingDecoratorTests.cpp @@ -49,8 +49,11 @@ std::string UniqueFileName() BOOST_AUTO_TEST_CASE(TestFileOnlyProfiling) { - // This test requires the CpuRef backend to be enabled - if(!BackendRegistryInstance().IsBackendRegistered("CpuRef")) + // This test requires at least one backend registry to be enabled + // which can execute a NormalizationLayer + if (BackendRegistryInstance().IsBackendRegistered(GetComputeDeviceAsCString(armnn::Compute::CpuRef)) || + BackendRegistryInstance().IsBackendRegistered(GetComputeDeviceAsCString(armnn::Compute::CpuAcc)) || + BackendRegistryInstance().IsBackendRegistered(GetComputeDeviceAsCString(armnn::Compute::GpuAcc))) { return; } @@ -87,13 +90,30 @@ BOOST_AUTO_TEST_CASE(TestFileOnlyProfiling) normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32)); // optimize the network - std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; + std::vector<armnn::BackendId> backends = + { armnn::Compute::CpuRef, armnn::Compute::CpuAcc, armnn::Compute::GpuAcc }; 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); + // Creates structures for input & output. + std::vector<float> inputData(16); + std::vector<float> outputData(16); + + InputTensors inputTensors + { + {0, ConstTensor(runtime.GetInputTensorInfo(netId, 0), inputData.data())} + }; + OutputTensors outputTensors + { + {0, Tensor(runtime.GetOutputTensorInfo(netId, 0), outputData.data())} + }; + + // Does the inference. + runtime.EnqueueWorkload(netId, inputTensors, outputTensors); + static_cast<TestTimelinePacketHandler*>(localPacketHandlerPtr.get())->WaitOnInferenceCompletion(3000); } diff --git a/src/profiling/test/RequestCountersPacketHandler.cpp b/src/profiling/test/RequestCountersPacketHandler.cpp new file mode 100644 index 0000000000..76c4b0cdc6 --- /dev/null +++ b/src/profiling/test/RequestCountersPacketHandler.cpp @@ -0,0 +1,78 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "RequestCountersPacketHandler.hpp" + +#include "DirectoryCaptureCommandHandler.hpp" +#include "PacketVersionResolver.hpp" + +#include <common/include/ProfilingException.hpp> + +namespace armnn +{ + +namespace profiling +{ + +std::vector<uint32_t> RequestCountersPacketHandler::GetHeadersAccepted() +{ + std::vector<uint32_t> headers; + headers.push_back(m_CounterDirectoryMessageHeader); // counter directory + return headers; +} + +void RequestCountersPacketHandler::HandlePacket(const Packet& packet) +{ + if (packet.GetHeader() != m_CounterDirectoryMessageHeader) + { + return; + } + armnn::profiling::PacketVersionResolver packetVersionResolver; + DirectoryCaptureCommandHandler directoryCaptureCommandHandler( + 0, 2, packetVersionResolver.ResolvePacketVersion(0, 2).GetEncodedValue()); + directoryCaptureCommandHandler.operator()(packet); + const ICounterDirectory& counterDirectory = directoryCaptureCommandHandler.GetCounterDirectory(); + for (auto& category : counterDirectory.GetCategories()) + { + // Remember we need to translate the Uid's from our CounterDirectory instance to the parent one. + std::vector<uint16_t> translatedCounters; + for (auto const& copyUid : category->m_Counters) + { + translatedCounters.emplace_back(directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(copyUid)); + } + m_IdList.insert(std::end(m_IdList), std::begin(translatedCounters), std::end(translatedCounters)); + } + SendCounterSelectionPacket(); +} + +void RequestCountersPacketHandler::SendCounterSelectionPacket() +{ + uint32_t uint16_t_size = sizeof(uint16_t); + uint32_t uint32_t_size = sizeof(uint32_t); + + uint32_t offset = 0; + uint32_t bodySize = uint32_t_size + boost::numeric_cast<uint32_t>(m_IdList.size()) * uint16_t_size; + + auto uniqueData = std::make_unique<unsigned char[]>(bodySize); + auto data = reinterpret_cast<unsigned char*>(uniqueData.get()); + + // Copy capturePeriod + WriteUint32(data, offset, m_CapturePeriod); + + // Copy m_IdList + offset += uint32_t_size; + for (const uint16_t& id : m_IdList) + { + WriteUint16(data, offset, id); + offset += uint16_t_size; + } + + Packet packet(0x40000, bodySize, uniqueData); + m_Connection->ReturnPacket(packet); +} + +} // namespace profiling + +} // namespace armnn
\ No newline at end of file diff --git a/src/profiling/test/RequestCountersPacketHandler.hpp b/src/profiling/test/RequestCountersPacketHandler.hpp new file mode 100644 index 0000000000..203edcc9df --- /dev/null +++ b/src/profiling/test/RequestCountersPacketHandler.hpp @@ -0,0 +1,47 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <armnn/Types.hpp> +#include <armnn/profiling/ILocalPacketHandler.hpp> +#include "Packet.hpp" +#include "ProfilingUtils.hpp" + +namespace armnn +{ + +namespace profiling +{ + +class RequestCountersPacketHandler : public ILocalPacketHandler +{ +public: + explicit RequestCountersPacketHandler(uint32_t capturePeriod = LOWEST_CAPTURE_PERIOD) : + m_CapturePeriod(capturePeriod), + m_Connection(nullptr), + m_CounterDirectoryMessageHeader(ConstructHeader(0, 2)) {} + + std::vector<uint32_t> GetHeadersAccepted() override; // ILocalPacketHandler + + void HandlePacket(const Packet& packet) override; // ILocalPacketHandler + + void SetConnection(IInternalProfilingConnection* profilingConnection) override // ILocalPacketHandler + { + m_Connection = profilingConnection; + } + +private: + uint32_t m_CapturePeriod; + IInternalProfilingConnection* m_Connection; + uint32_t m_CounterDirectoryMessageHeader; + std::vector<uint16_t> m_IdList; + + void SendCounterSelectionPacket(); +}; + +} // namespace profiling + +} // namespace armnn
\ No newline at end of file diff --git a/src/profiling/test/TestTimelinePacketHandler.hpp b/src/profiling/test/TestTimelinePacketHandler.hpp index 67395254fc..6cc6a0c086 100644 --- a/src/profiling/test/TestTimelinePacketHandler.hpp +++ b/src/profiling/test/TestTimelinePacketHandler.hpp @@ -66,7 +66,7 @@ public: const TimelineModel& GetTimelineModel() const {return m_TimelineModel;} - virtual void SetConnection(IProfilingConnection* profilingConnection) override // ILocalPacketHandler + virtual void SetConnection(IInternalProfilingConnection* profilingConnection) override // ILocalPacketHandler { m_Connection = profilingConnection; } @@ -74,7 +74,7 @@ public: private: void ProcessDirectoryPacket(const Packet& packet); void ProcessMessagePacket(const Packet& packet); - IProfilingConnection* m_Connection; + IInternalProfilingConnection* m_Connection; std::mutex m_InferenceCompletedMutex; std::condition_variable m_InferenceCompletedConditionVariable; bool m_InferenceCompleted; |