From 59da369d2a66e49eb0f84d596ed7162621c32d06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89anna=20=C3=93=20Cath=C3=A1in?= Date: Thu, 16 Apr 2020 08:54:12 +0100 Subject: MLECO-712 Enable creation of runtime with external profiling support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ie0af439817eb4ed70e6112b2eb6f4a2c787a6bd0 Signed-off-by: Éanna Ó Catháin --- .../src/pyarmnn/swig/modules/armnn_runtime.i | 43 ++++++++++++++++++++++ python/pyarmnn/test/test_runtime.py | 36 +++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_runtime.i b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_runtime.i index e9a895e700..ec65cc010a 100644 --- a/python/pyarmnn/src/pyarmnn/swig/modules/armnn_runtime.i +++ b/python/pyarmnn/src/pyarmnn/swig/modules/armnn_runtime.i @@ -25,6 +25,46 @@ namespace std { #pragma SWIG nowarn=SWIGWARN_PARSE_NESTED_CLASS +%{ +typedef armnn::IRuntime::CreationOptions::ExternalProfilingOptions ExternalProfilingOptions; +%} + +struct ExternalProfilingOptions +{ + %feature("docstring", + " + Structure for holding ExternalProfiling options. + + Contains: + m_EnableProfiling (bool): If set enables profiling in armnn + + m_OutgoingCaptureFile (string): If specified the outgoing external profiling packets will be captured + in this file, in the specified format + + m_IncomingCaptureFile (string): If specified the incoming external profiling packets will be + captured in this file + + m_FileOnly (bool): If enabled, then the 'file-only' test mode of external profiling will be enabled + + m_CapturePeriod (uint32_t): If profiling is enabled in 'file-only' mode this is the + capture period that will be used in the test + + m_FileFormat (string): If profiling is enabled, this specifies the output file format + + m_TimelineEnabled: Set if timeline reporting is enabled or not + + ") ExternalProfilingOptions; + + ExternalProfilingOptions(); + bool m_EnableProfiling; + std::string m_OutgoingCaptureFile; + std::string m_IncomingCaptureFile; + bool m_FileOnly; + uint32_t m_CapturePeriod; + std::string m_FileFormat; + bool m_TimelineEnabled; +}; + %{ typedef armnn::IRuntime::CreationOptions CreationOptions; %} @@ -46,12 +86,15 @@ struct CreationOptions m_DynamicBackendsPath (string): Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive. Only a single path is allowed for the override. + m_ProfilingOptions (ExternalProfilingOptions): Struct to set the profiling options + ") CreationOptions; CreationOptions(); std::shared_ptr m_GpuAccTunedParameters; bool m_EnableGpuProfiling; std::string m_DynamicBackendsPath; + ExternalProfilingOptions m_ProfilingOptions; }; namespace armnn diff --git a/python/pyarmnn/test/test_runtime.py b/python/pyarmnn/test/test_runtime.py index 2943be8f16..ff0ad40b55 100644 --- a/python/pyarmnn/test/test_runtime.py +++ b/python/pyarmnn/test/test_runtime.py @@ -14,6 +14,7 @@ def random_runtime(shared_data_folder): network = parser.CreateNetworkFromBinaryFile(os.path.join(shared_data_folder, 'mock_model.tflite')) preferred_backends = [ann.BackendId('CpuRef')] options = ann.CreationOptions() + runtime = ann.IRuntime(options) graphs_count = parser.GetSubgraphCount() @@ -95,7 +96,6 @@ def test_python_disowns_network(random_runtime): assert not opt_network.thisown - def test_load_network(random_runtime): preferred_backends = random_runtime[0] network = random_runtime[1] @@ -108,6 +108,40 @@ def test_load_network(random_runtime): assert "" == messages assert net_id == 0 +def test_create_runtime_with_external_profiling_enabled(): + + options = ann.CreationOptions() + + options.m_ProfilingOptions.m_FileOnly = True + options.m_ProfilingOptions.m_EnableProfiling = True + options.m_ProfilingOptions.m_OutgoingCaptureFile = "/tmp/outgoing.txt" + options.m_ProfilingOptions.m_IncomingCaptureFile = "/tmp/incoming.txt" + options.m_ProfilingOptions.m_TimelineEnabled = True + options.m_ProfilingOptions.m_CapturePeriod = 1000 + options.m_ProfilingOptions.m_FileFormat = "JSON" + + runtime = ann.IRuntime(options) + + assert runtime is not None + +def test_create_runtime_with_external_profiling_enabled_invalid_options(): + + options = ann.CreationOptions() + + options.m_ProfilingOptions.m_FileOnly = True + options.m_ProfilingOptions.m_EnableProfiling = False + options.m_ProfilingOptions.m_OutgoingCaptureFile = "/tmp/outgoing.txt" + options.m_ProfilingOptions.m_IncomingCaptureFile = "/tmp/incoming.txt" + options.m_ProfilingOptions.m_TimelineEnabled = True + options.m_ProfilingOptions.m_CapturePeriod = 1000 + options.m_ProfilingOptions.m_FileFormat = "JSON" + + with pytest.raises(RuntimeError) as err: + runtime = ann.IRuntime(options) + + expected_error_message = "It is not possible to enable timeline reporting without profiling being enabled" + assert expected_error_message in str(err.value) + def test_load_network_properties_provided(random_runtime): preferred_backends = random_runtime[0] -- cgit v1.2.1