3535#include " litert/cc/litert_expected.h"
3636#include " litert/cc/litert_macros.h"
3737#include " litert/cc/litert_model.h"
38+ #include " litert/cc/options/litert_intel_openvino_options.h"
3839#include " litert/vendors/c/litert_compiler_plugin.h"
40+ #include " litert/vendors/cc/options_helper.h"
3941#include " litert/vendors/intel_openvino/compiler/graph_iterator.h"
42+
4043namespace {
4144
4245constexpr char kPluginManufacturer [] = " IntelOpenVINO" ;
@@ -216,17 +219,35 @@ LiteRtStatus LiteRtCompiledResultNumByteCodeModules(
216219// Plugin Definition
217220// / \brief Define Compiler plugin APIs
218221struct LiteRtCompilerPluginT {
219- LiteRtEnvironmentOptions env;
220- LiteRtOptions options;
222+ using IntelOpenVinoOptions = ::litert::intel_openvino::IntelOpenVinoOptions;
223+
224+ LiteRtCompilerPluginT (LiteRtEnvironmentOptions env, LiteRtOptions options) {
225+ std::tie (env_, opts_, opq_, intel_openvino_opts_) =
226+ litert::ParseOptions<IntelOpenVinoOptions>(env, options);
227+ }
228+
229+ const ::litert::Expected<IntelOpenVinoOptions>& GetIntelOpenVinoOptions () const {
230+ return intel_openvino_opts_;
231+ }
232+
233+ const ::litert::Expected<litert::OpaqueOptions>& GetOpaqueOptions () const { return opq_; }
234+
235+ private:
236+ litert::Expected<litert::EnvironmentOptions> env_ = litert::Error(
237+ kLiteRtStatusErrorInvalidArgument , " Null environment options" );
238+ litert::Expected<litert::Options> opts_ =
239+ litert::Error (kLiteRtStatusErrorInvalidArgument , " Null options" );
240+ litert::Expected<litert::OpaqueOptions> opq_ =
241+ litert::Error (kLiteRtStatusErrorInvalidArgument , " Null opaque options" );
242+ litert::Expected<IntelOpenVinoOptions> intel_openvino_opts_ =
243+ litert::Error (kLiteRtStatusErrorInvalidArgument , " Null Intel OpenVINO options" );
221244};
222245
223246LiteRtStatus LiteRtCreateCompilerPlugin (LiteRtCompilerPlugin *compiler_plugin,
224247 LiteRtEnvironmentOptions env,
225248 LiteRtOptions options) {
226249 LiteRtSetMinLoggerSeverity (LiteRtGetDefaultLogger (), LITERT_INFO);
227- auto *plugin = new LiteRtCompilerPluginT;
228- plugin->env = env;
229- plugin->options = options;
250+ auto *plugin = new LiteRtCompilerPluginT (env, options);
230251 *compiler_plugin = plugin;
231252 return kLiteRtStatusOk ;
232253}
@@ -273,13 +294,77 @@ LiteRtStatus LiteRtCompilerPluginCompile(
273294 auto model = litert::Model::CreateFromNonOwnedHandle (partitions);
274295 const auto num_partitions = model.NumSubgraphs ();
275296
297+ // Configure device and OpenVINO settings from Intel OpenVINO options
298+ std::string device = " NPU" ; // Default device
299+ ov::AnyMap configs_map;
300+
301+ if (compiler_plugin->GetIntelOpenVinoOptions ().HasValue ()) {
302+ const auto & intel_opts = compiler_plugin->GetIntelOpenVinoOptions ().Value ();
303+
304+ // Configure device type
305+ auto device_type = intel_opts.GetDeviceType ();
306+ switch (device_type) {
307+ case kLiteRtIntelOpenVinoDeviceTypeCPU :
308+ device = " CPU" ;
309+ break ;
310+ case kLiteRtIntelOpenVinoDeviceTypeGPU :
311+ device = " GPU" ;
312+ break ;
313+ case kLiteRtIntelOpenVinoDeviceTypeNPU :
314+ device = " NPU" ;
315+ break ;
316+ case kLiteRtIntelOpenVinoDeviceTypeAUTO :
317+ device = " AUTO" ;
318+ break ;
319+ }
320+
321+ LITERT_LOG (LITERT_INFO, " Using Intel OpenVINO device: %s" , device.c_str ());
322+
323+ auto performance_mode = intel_opts.GetPerformanceMode ();
324+
325+ // Add custom configuration options
326+ int num_custom_options = intel_opts.GetNumConfigsMapOptions ();
327+ for (int i = 0 ; i < num_custom_options; ++i) {
328+ auto [key, value] = intel_opts.GetConfigsMapOption (i);
329+ if (!key.empty ()) { // Valid config option
330+ configs_map[key] = value;
331+ LITERT_LOG (LITERT_INFO, " Custom config: %s = %s" , key.c_str (), value.c_str ());
332+ }
333+ }
334+
335+ // Configure performance mode (can be overridden by custom options)
336+ switch (performance_mode) {
337+ case kLiteRtIntelOpenVinoPerformanceModeLatency :
338+ if (configs_map.find (ov::hint::performance_mode.name ()) == configs_map.end ()) {
339+ configs_map[ov::hint::performance_mode.name ()] = ov::hint::PerformanceMode::LATENCY;
340+ LITERT_LOG (LITERT_INFO, " Performance mode: LATENCY" );
341+ }
342+ break ;
343+ case kLiteRtIntelOpenVinoPerformanceModeThroughput :
344+ if (configs_map.find (ov::hint::performance_mode.name ()) == configs_map.end ()) {
345+ configs_map[ov::hint::performance_mode.name ()] = ov::hint::PerformanceMode::THROUGHPUT;
346+ LITERT_LOG (LITERT_INFO, " Performance mode: THROUGHPUT" );
347+ }
348+ break ;
349+ case kLiteRtIntelOpenVinoPerformanceModeCumulativeThroughput :
350+ if (configs_map.find (ov::hint::performance_mode.name ()) == configs_map.end ()) {
351+ configs_map[ov::hint::performance_mode.name ()] = ov::hint::PerformanceMode::CUMULATIVE_THROUGHPUT;
352+ LITERT_LOG (LITERT_INFO, " Performance mode: CUMULATIVE_THROUGHPUT" );
353+ }
354+ break ;
355+ }
356+ } else {
357+ // Default configuration if no options provided
358+ configs_map[ov::hint::performance_mode.name ()] = ov::hint::PerformanceMode::LATENCY;
359+ LITERT_LOG (LITERT_INFO, " Using default configuration (LATENCY mode)" );
360+ }
361+
276362 auto result = std::make_unique<LiteRtCompiledResultT>();
277363 result->byte_code .resize (num_partitions);
278364 result->graph_names .resize (num_partitions);
279365 auto tflite_fe =
280366 std::make_shared<ov::frontend::tensorflow_lite::FrontEnd>();
281- // TODO: Update this hard coded path to an env option passed from LiteRT
282- // framework
367+
283368 ov::Core core;
284369 for (int partition_idx = 0 ; partition_idx < num_partitions;
285370 ++partition_idx) {
@@ -295,10 +380,9 @@ LiteRtStatus LiteRtCompilerPluginCompile(
295380 LITERT_LOG (LITERT_INFO, " Model loaded" );
296381 auto model = tflite_fe->convert (input_model);
297382
298- // TODO: pass the device string from env options
299- std::string device = " NPU" ;
383+ // Use device and configs_map from Intel OpenVINO options
300384 std::ostringstream oss;
301- auto compiled_model = core.compile_model (model, device);
385+ auto compiled_model = core.compile_model (model, device, configs_map );
302386 compiled_model.export_model (oss);
303387 LITERT_LOG (LITERT_INFO, " Model export done" );
304388 result->byte_code [partition_idx] = oss.str ();
0 commit comments