ArmNN
 21.02
tflite Namespace Reference

Functions

TfLiteDelegate * tflite_plugin_create_delegate (char **options_keys, char **options_values, size_t num_options, void(*report_error)(const char *))
 Create an ArmNN delegate plugin. More...
 
void tflite_plugin_destroy_delegate (TfLiteDelegate *delegate)
 Destroy a given delegate plugin. More...
 

Variables

std::vector< std::string > gpu_options
 This file defines two symbols that need to be exported to use the TFLite external delegate provider. More...
 

Function Documentation

◆ tflite_plugin_create_delegate()

TfLiteDelegate* tflite::tflite_plugin_create_delegate ( char **  options_keys,
char **  options_values,
size_t  num_options,
void(*)(const char *)  report_error 
)

Create an ArmNN delegate plugin.

Available options:

Option key: "backends"
Possible values: ["EthosNPU"/"GpuAcc"/"CpuAcc"/"CpuRef"]
Descriptions: A comma separated list without whitespaces of backends which should be used for execution. Falls back to next backend in list if previous doesn't provide support for operation. e.g. "GpuAcc,CpuAcc"

Option key: "logging-severity"
Possible values: ["trace"/"debug"/"info"/"warning"/"error"/"fatal"]
Description: Sets the logging severity level for ArmNN. Logging is turned off if this option is not provided.

Option key: "gpu-tuning-level"
Possible values: ["0"/"1"/"2"/"3"]
Description: 0=UseOnly(default), 1=RapidTuning, 2=NormalTuning, 3=ExhaustiveTuning. Requires option gpu-tuning-file. 1,2 and 3 will create a tuning-file, 0 will apply the tunings from an existing file

Option key: "gpu-tuning-file"
Possible values: [filenameString]
Description: File name for the tuning file.

Option key: "gpu-kernel-profiling-enabled"
Possible values: ["true"/"false"]
Description: Enables GPU kernel profiling

Option key: "reduce-fp32-to-fp16"
Possible values: ["true"/"false"]
Description: Reduce Fp32 data to Fp16 for faster processing

Option key: "reduce-fp32-to-bf16"
Possible values: ["true"/"false"]
Description: Reduce Fp32 data to Bf16 for faster processing

Option key: "debug-data"
Possible values: ["true"/"false"]
Description: Add debug data for easier troubleshooting

Option key: "memory-import"
Possible values: ["true"/"false"]
Description: Enable memory import

Parameters
[in]option_keysDelegate option names
[in]options_valuesDelegate option values
[in]num_optionsNumber of delegate options
[in,out]report_errorError callback function
Returns
An ArmNN delegate if it succeeds else NULL

Definition at line 89 of file armnn_external_delegate.cpp.

References DelegateOptions::AddBackendOption(), OptimizerOptions::m_Debug, OptimizerOptions::m_ImportEnabled, OptimizerOptions::m_ReduceFp32ToBf16, OptimizerOptions::m_ReduceFp32ToFp16, DelegateOptions::SetBackends(), DelegateOptions::SetLoggingSeverity(), DelegateOptions::SetOptimizerOptions(), armnnDelegate::TfLiteArmnnDelegateCreate(), and armnnDelegate::TfLiteArmnnDelegateOptionsDefault().

93 {
94  // Returning null indicates an error during delegate creation so we initialize with that
95  TfLiteDelegate* delegate = nullptr;
96  try
97  {
98  // (Initializes with CpuRef backend)
100  armnn::OptimizerOptions optimizerOptions;
101  for (size_t i = 0; i < num_options; ++i)
102  {
103  // Process backends
104  if (std::string(options_keys[i]) == std::string("backends"))
105  {
106  // The backend option is a comma separated string of backendIDs that needs to be split
107  std::vector<armnn::BackendId> backends;
108  char* pch;
109  pch = strtok(options_values[i],",");
110  while (pch != NULL)
111  {
112  backends.push_back(pch);
113  pch = strtok (NULL, ",");
114  }
115  options.SetBackends(backends);
116  }
117  // Process logging level
118  else if (std::string(options_keys[i]) == std::string("logging-severity"))
119  {
120  options.SetLoggingSeverity(options_values[i]);
121  }
122  // Process GPU backend options
123  else if (std::string(options_keys[i]) == std::string("gpu-tuning-level"))
124  {
125  armnn::BackendOptions option("GpuAcc", {{"TuningLevel", atoi(options_values[i])}});
126  options.AddBackendOption(option);
127  }
128  else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file"))
129  {
130  armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath", std::string(options_values[i])}});
131  options.AddBackendOption(option);
132  }
133  else if (std::string(options_keys[i]) == std::string("gpu-tuning-file"))
134  {
135  armnn::BackendOptions option("GpuAcc", {{"TuningFile", std::string(options_values[i])}});
136  options.AddBackendOption(option);
137  }
138  else if (std::string(options_keys[i]) == std::string("gpu-kernel-profiling-enabled"))
139  {
140  armnn::BackendOptions option("GpuAcc", {{"KernelProfilingEnabled", (*options_values[i] != '0')}});
141  options.AddBackendOption(option);
142  }
143  // Process reduce-fp32-to-fp16 option
144  else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-fp16"))
145  {
146  optimizerOptions.m_ReduceFp32ToFp16 = *options_values[i] != '0';
147  }
148  // Process reduce-fp32-to-bf16 option
149  else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-bf16"))
150  {
151  optimizerOptions.m_ReduceFp32ToBf16 = *options_values[i] != '0';
152  }
153  // Process debug-data
154  else if (std::string(options_keys[i]) == std::string("debug-data"))
155  {
156  optimizerOptions.m_Debug = *options_values[i] != '0';
157  }
158  // Process memory-import
159  else if (std::string(options_keys[i]) == std::string("memory-import"))
160  {
161  optimizerOptions.m_ImportEnabled = *options_values[i] != '0';
162  }
163  else
164  {
165  throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + std::string(options_keys[i]));
166  }
167  }
168  options.SetOptimizerOptions(optimizerOptions);
169  delegate = TfLiteArmnnDelegateCreate(options);
170  }
171  catch (const std::exception& ex)
172  {
173  if(report_error)
174  {
175  report_error(ex.what());
176  }
177  }
178  return delegate;
179 }
void SetLoggingSeverity(const armnn::LogSeverity &level)
Sets the severity level for logging within ArmNN that will be used on creation of the delegate...
Struct for the users to pass backend specific options.
TfLiteDelegate * TfLiteArmnnDelegateCreate(armnnDelegate::DelegateOptions options)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
void SetBackends(const std::vector< armnn::BackendId > &backends)
DelegateOptions TfLiteArmnnDelegateOptionsDefault()
void AddBackendOption(const armnn::BackendOptions &option)
Appends a backend option to the list of backend options.
void SetOptimizerOptions(const armnn::OptimizerOptions &optimizerOptions)

◆ tflite_plugin_destroy_delegate()

void tflite::tflite_plugin_destroy_delegate ( TfLiteDelegate *  delegate)

Destroy a given delegate plugin.

Parameters
[in]delegateDelegate to destruct

Definition at line 185 of file armnn_external_delegate.cpp.

References armnnDelegate::TfLiteArmnnDelegateDelete().

186 {
188 }
void TfLiteArmnnDelegateDelete(TfLiteDelegate *tfLiteDelegate)

Variable Documentation

◆ gpu_options

std::vector<std::string> gpu_options
Initial value:
{"gpu-tuning-level",
"gpu-tuning-file",
"gpu-kernel-profiling-enabled"}

This file defines two symbols that need to be exported to use the TFLite external delegate provider.

This is a plugin that can be used for fast integration of delegates into benchmark tests and other tools. It allows loading of a dynamic delegate library at runtime.

The external delegate also has Tensorflow Lite Python bindings. Therefore the dynamic external delegate can be directly used with Tensorflow Lite Python APIs.

See tensorflow/lite/delegates/external for details or visit the tensorflow guide here

Definition at line 28 of file armnn_external_delegate.cpp.