10 #include <boost/test/unit_test.hpp> 11 #include <boost/test/tools/output_test_stream.hpp> 12 #include <boost/algorithm/string.hpp> 27 return static_cast<size_t>(-1);
30 return profiler->m_EventSequence.size();
37 void RegisterUnregisterProfilerSingleThreadImpl(
bool &res)
49 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
53 res &= profiler.get() == profilerManager.
GetProfiler();
68 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
71 BOOST_TEST(!profiler->IsProfilingEnabled());
74 profiler->EnableProfiling(
true);
77 BOOST_TEST(profiler->IsProfilingEnabled());
80 profiler->EnableProfiling(
false);
83 BOOST_TEST(!profiler->IsProfilingEnabled());
89 RegisterUnregisterProfilerSingleThreadImpl(res);
95 bool res[3] = {
false,
false,
false};
96 std::thread thread1([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[0]); });
97 std::thread thread2([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[1]); });
98 std::thread thread3([&res]() { RegisterUnregisterProfilerSingleThreadImpl(res[2]); });
104 for (
int i = 0 ; i < 3 ; i++)
128 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
141 BOOST_TEST(eventSequenceSizeBefore == eventSequenceSizeAfter);
145 profiler->EnableProfiling(
true);
157 BOOST_TEST(eventSequenceSizeAfter == eventSequenceSizeBefore + 1);
161 profiler->EnableProfiling(
false);
164 #if defined(ARMNNREF_ENABLED) 181 mockNetwork->AddInputLayer(0,
"test layer");
183 runtime->LoadNetwork(networkIdentifier,
armnn::Optimize(*mockNetwork, backends, runtime->GetDeviceSpec()));
189 runtime->UnloadNetwork(networkIdentifier);
203 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
207 profiler->EnableProfiling(
true);
220 std::this_thread::sleep_for(std::chrono::milliseconds(10));
225 BOOST_TEST(eventSequenceSizeAfter == eventSequenceSizeBefore + 1);
227 boost::test_tools::output_test_stream output;
228 profiler->AnalyzeEventsAndWriteResults(output);
229 BOOST_TEST(!output.is_empty(
false));
232 BOOST_CHECK(boost::contains(output.str(),
"test"));
235 BOOST_CHECK(boost::contains(output.str(),
"Event Sequence - Name"));
236 BOOST_CHECK(boost::contains(output.str(),
"Event Stats - Name"));
237 BOOST_CHECK(boost::contains(output.str(),
"Total"));
238 BOOST_CHECK(boost::contains(output.str(),
"Device"));
240 BOOST_CHECK(boost::contains(output.str(),
"CpuAcc"));
242 BOOST_CHECK(!(boost::contains(output.str(),
"e+")));
244 BOOST_CHECK(!(boost::contains(output.str(),
"+")));
246 BOOST_CHECK(!(boost::contains(output.str(),
" 0 ")));
250 profiler->EnableProfiling(
false);
258 virtual ~TestInstrument() {}
259 void Start()
override {}
260 void Stop()
override {}
262 std::vector<armnn::Measurement> GetMeasurements()
const override 264 std::vector<armnn::Measurement> measurements;
267 armnn::Measurement::Unit::TIME_MS));
270 armnn::Measurement::Unit::TIME_US));
274 const char* GetName()
const override 276 return "TestInstrument";
284 std::unique_ptr<armnn::Profiler> profiler = std::make_unique<armnn::Profiler>();
287 profiler->EnableProfiling(
true);
308 std::stringbuf buffer;
309 std::ostream json(&buffer);
310 profiler->Print(json);
312 std::string output = buffer.str();
316 profiler->EnableProfiling(
false);
320 std::string blessedOutput(
"{\n\t\"ArmNN\": {\n\t\t\"inference_measurements_#1\": {\n\t\t\t\"type\": \"" 321 "Event\",\n\t\t\t\"Measurement1_#1\": {\n\t\t\t\t\"type\": \"" 322 "Measurement\",\n\t\t\t\t\"raw\": [\n\t\t\t\t\t1.000000\n\t\t\t\t],\n\t\t\t\t\"" 323 "unit\": \"ms\"\n\t\t\t},\n\t\t\t\"Measurement2_#1\": {\n\t\t\t\t\"type\": \"" 324 "Measurement\",\n\t\t\t\t\"raw\": [\n\t\t\t\t\t2.000000\n\t\t\t\t],\n\t\t\t\t\"" 325 "unit\": \"us\"\n\t\t\t},\n\t\t\t\"Level 0_#2\": {\n\t\t\t\t\"type\": \"" 326 "Event\",\n\t\t\t\t\"Measurement1_#2\": {\n\t\t\t\t\t\"type\": \"" 327 "Measurement\",\n\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t1.000000\n\t\t\t\t\t],\n\t\t\t\t\t\"" 328 "unit\": \"ms\"\n\t\t\t\t},\n\t\t\t\t\"Measurement2_#2\": {\n\t\t\t\t\t\"type\": \"" 329 "Measurement\",\n\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t2.000000\n\t\t\t\t\t],\n\t\t\t\t\t\"" 330 "unit\": \"us\"\n\t\t\t\t},\n\t\t\t\t\"Level 1A_#3\": {\n\t\t\t\t\t\"type\": \"" 331 "Event\",\n\t\t\t\t\t\"Measurement1_#3\": {\n\t\t\t\t\t\t\"type\": \"" 332 "Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 333 "1.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 334 "unit\": \"ms\"\n\t\t\t\t\t},\n\t\t\t\t\t\"Measurement2_#3\": {\n\t\t\t\t\t\t\"type\": \"" 335 "Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 336 "2.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 337 "unit\": \"us\"\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t\"Level 1B_#4\": {\n\t\t\t\t\t\"" 338 "type\": \"Event\",\n\t\t\t\t\t\"Measurement1_#4\": {\n\t\t\t\t\t\t\"type\": \"" 339 "Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 340 "1.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 341 "unit\": \"ms\"\n\t\t\t\t\t},\n\t\t\t\t\t\"Measurement2_#4\": {\n\t\t\t\t\t\t\"" 342 "type\": \"Measurement\",\n\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t" 343 "2.000000\n\t\t\t\t\t\t],\n\t\t\t\t\t\t\"" 344 "unit\": \"us\"\n\t\t\t\t\t},\n\t\t\t\t\t\"Level 2A_#5\": {\n\t\t\t\t\t\t\"" 345 "type\": \"Event\",\n\t\t\t\t\t\t\"Measurement1_#5\": {\n\t\t\t\t\t\t\t\"type\": \"" 346 "Measurement\",\n\t\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t\t" 347 "1.000000\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\"" 348 "unit\": \"ms\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"Measurement2_#5\": {\n\t\t\t\t\t\t\t\"" 349 "type\": \"Measurement\",\n\t\t\t\t\t\t\t\"raw\": [\n\t\t\t\t\t\t\t\t" 350 "2.000000\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\"" 351 "unit\": \"us\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n");
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
size_t GetProfilerEventSequenceSize(armnn::Profiler *profiler)
static IRuntimePtr Create(const CreationOptions &options)
CPU Execution: Reference C++ kernels.
void RegisterProfiler(Profiler *profiler)
static ProfilerManager & GetInstance()
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
#define ARMNN_SCOPED_PROFILING_EVENT_WITH_INSTRUMENTS(backendId,...)
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.
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
BOOST_AUTO_TEST_SUITE_END()
CPU Execution: NEON: ArmCompute.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
static INetworkPtr Create()