19
19
#include " openvino/runtime/device_id_parser.hpp"
20
20
#include " openvino/runtime/internal_properties.hpp"
21
21
#include " openvino/runtime/iremote_context.hpp"
22
+ #include " openvino/runtime/compilation_context.hpp"
23
+ #include " openvino/util/file_util.hpp"
22
24
#include " plugin.hpp"
23
25
#include " auto_schedule.hpp"
24
26
#include " auto_compiled_model.hpp"
@@ -78,7 +80,6 @@ namespace auto_plugin {
78
80
std::shared_ptr<std::mutex> Plugin::m_mtx = std::make_shared<std::mutex>();
79
81
std::shared_ptr<std::map<unsigned int , std::list<std::string>>> Plugin::m_priority_map =
80
82
std::make_shared<std::map<unsigned int , std::list<std::string>>>();
81
-
82
83
ov::SoPtr<ov::IRemoteContext> Plugin::create_context (const ov::AnyMap& remote_properties) const {
83
84
OPENVINO_NOT_IMPLEMENTED;
84
85
}
@@ -304,14 +305,17 @@ ov::Any Plugin::get_property(const std::string& name, const ov::AnyMap& argument
304
305
} else if (name == ov::device::full_name) {
305
306
return decltype (ov::device::full_name)::value_type {get_device_name ()};
306
307
} else if (name == ov::device::capabilities.name ()) {
307
- std::vector<std::string> device_list = arguments.count (ov::device::priorities.name ())
308
- ? m_plugin_config.parse_priorities_devices (
309
- arguments.at (ov::device::priorities.name ()).as <std::string>())
308
+ if (arguments.count (ov::device::priorities.name ())) {
309
+ // By default, all devices are assumed to support caching ability when Core checks caching ability for AUTO.
310
+ return std::vector<std::string>{ov::device::capability::EXPORT_IMPORT};
311
+ }
312
+ std::string priorities = m_plugin_config.get_property (ov::device::priorities.name ()).as <std::string>();
313
+ std::vector<std::string> device_list = !priorities.empty ()
314
+ ? m_plugin_config.parse_priorities_devices (priorities)
310
315
: get_core ()->get_available_devices ();
316
+
311
317
std::vector<std::string> capabilities;
312
318
for (auto const & device : device_list) {
313
- if (device[0 ] == ' -' )
314
- continue ;
315
319
try {
316
320
auto dev_capabilities = get_core ()->get_property (device, ov::device::capabilities);
317
321
capabilities.insert (capabilities.end (), dev_capabilities.begin (), dev_capabilities.end ());
@@ -409,7 +413,16 @@ std::shared_ptr<ov::ICompiledModel> Plugin::compile_model_impl(const std::string
409
413
// and set filter configure
410
414
auto auto_s_context = std::make_shared<ScheduleContext>();
411
415
ov::AnyMap filter_property;
412
- auto str_devices = get_device_list (full_property);
416
+ auto str_devices = get_device_list (full_property, model, model_path);
417
+ // in case startup or runtime fallback is set caused by cache blob checking, we need to set the property
418
+ if (full_property.count (ov::intel_auto::enable_startup_fallback.name ())) {
419
+ load_config.set_property (ov::intel_auto::enable_startup_fallback (
420
+ full_property.at (ov::intel_auto::enable_startup_fallback.name ()).as <bool >()));
421
+ }
422
+ if (full_property.count (ov::intel_auto::enable_runtime_fallback.name ())) {
423
+ load_config.set_property (ov::intel_auto::enable_runtime_fallback (
424
+ full_property.at (ov::intel_auto::enable_runtime_fallback.name ()).as <bool >()));
425
+ }
413
426
// fill in the context for auto
414
427
if (load_config.get_property (ov::enable_profiling)) {
415
428
filter_property.insert ({ov::enable_profiling (true )});
@@ -694,7 +707,9 @@ void Plugin::register_priority(const unsigned int& priority, const std::string&
694
707
}
695
708
}
696
709
697
- std::string Plugin::get_device_list (const ov::AnyMap& properties) const {
710
+ std::string Plugin::get_device_list (ov::AnyMap& properties,
711
+ const std::shared_ptr<const ov::Model>& model,
712
+ const std::string& model_path) const {
698
713
std::string all_devices;
699
714
std::string device_architecture;
700
715
auto device_list_config = properties.find (ov::device::priorities.name ());
@@ -708,10 +723,56 @@ std::string Plugin::get_device_list(const ov::AnyMap& properties) const {
708
723
return " " ;
709
724
};
710
725
std::vector<std::string> devices_merged;
726
+ bool enable_startup_cpu = properties.count (ov::intel_auto::enable_startup_fallback.name ())
727
+ ? properties.at (ov::intel_auto::enable_startup_fallback.name ()).as <bool >()
728
+ : true ;
729
+ bool enable_runtime_cpu = properties.count (ov::intel_auto::enable_runtime_fallback.name ())
730
+ ? properties.at (ov::intel_auto::enable_runtime_fallback.name ()).as <bool >()
731
+ : true ;
732
+ bool is_cumulative_tput =
733
+ get_device_name () != " AUTO" ||
734
+ (properties.count (ov::hint::performance_mode.name ()) &&
735
+ properties.at (ov::hint::performance_mode.name ()).as <std::string>() == " CUMULATIVE_THROUGHPUT" );
711
736
if (device_list_config != properties.end () && !(device_list_config->second .as <std::string>().empty ())) {
712
737
auto priorities = device_list_config->second ;
713
738
// parsing the string and splitting the comma-separated tokens
714
- std::vector<std::string> devices_to_be_merged = m_plugin_config.parse_priorities_devices (priorities.as <std::string>());
739
+ std::vector<std::string> devices_to_be_merged =
740
+ m_plugin_config.parse_priorities_devices (priorities.as <std::string>());
741
+ std::size_t num_blob_files = 0 ;
742
+ std::string cache_dir = properties.count (ov::cache_dir.name ())
743
+ ? properties.at (ov::cache_dir.name ()).as <std::string>()
744
+ : get_core ()->get_property (" " , ov::cache_dir);
745
+ bool if_need_cache_check =
746
+ !is_cumulative_tput && enable_startup_cpu && (model || !model_path.empty ()) && !cache_dir.empty ();
747
+ if (if_need_cache_check) {
748
+ for (auto && device : devices_to_be_merged) {
749
+ ov::DeviceIDParser parsed{device};
750
+ if (parsed.get_device_name ().find (" CPU" ) != std::string::npos)
751
+ continue ;
752
+ // check if cached model exists for other devices
753
+ auto dev_properties = get_core ()->get_supported_property (parsed.get_device_name (), properties);
754
+ dev_properties = get_core ()->create_compile_config (parsed.get_device_name (), dev_properties);
755
+ std::string blobId;
756
+
757
+ if (model)
758
+ blobId = ov::ModelCache::compute_hash (std::const_pointer_cast<const ov::Model>(model),
759
+ dev_properties);
760
+ else
761
+ blobId = ov::ModelCache::compute_hash (model_path, dev_properties);
762
+ std::string cached_model_path = ov::util::make_path (cache_dir, blobId + " .blob" );
763
+ bool is_blob_file_exist = ov::util::file_exists (cached_model_path);
764
+ num_blob_files += is_blob_file_exist;
765
+ LOG_DEBUG_TAG (" device: %s %s cached blob: %s " ,
766
+ device.c_str (),
767
+ is_blob_file_exist ? " found" : " not found" ,
768
+ cached_model_path.c_str ());
769
+ }
770
+
771
+ if (enable_startup_cpu && num_blob_files) {
772
+ LOG_DEBUG_TAG (" Disabling CPU fallback as a cached blob file was found for a device in the candidate "
773
+ " list. AUTO will work as pass-through mode." );
774
+ }
775
+ }
715
776
std::vector<std::string> devices_to_be_deleted (devices_to_be_merged.size ());
716
777
const auto & iterDel = std::copy_if (devices_to_be_merged.begin (),
717
778
devices_to_be_merged.end (),
@@ -765,17 +826,16 @@ std::string Plugin::get_device_list(const ov::AnyMap& properties) const {
765
826
std::vector<std::string> device_list = {};
766
827
try {
767
828
if (parsed.get_device_name ().find (" CPU" ) != std::string::npos) {
768
- bool enable_startup_cpu =
769
- properties.count (ov::intel_auto::enable_startup_fallback.name ())
770
- ? properties.at (ov::intel_auto::enable_startup_fallback.name ()).as <bool >()
771
- : true ;
772
- bool enable_runtime_cpu =
773
- properties.count (ov::intel_auto::enable_runtime_fallback.name ())
774
- ? properties.at (ov::intel_auto::enable_runtime_fallback.name ()).as <bool >()
775
- : true ;
776
- // Skip to load CPU device if both startup and runtime fallback are disabled
777
- if (!enable_startup_cpu && !enable_runtime_cpu)
829
+ // Disable CPU if any blob files found
830
+ if (num_blob_files) {
831
+ properties[ov::intel_auto::enable_startup_fallback.name ()] = false ;
832
+ properties[ov::intel_auto::enable_runtime_fallback.name ()] = false ;
833
+ continue ;
834
+ }
835
+ // Disable CPU if enable_startup_cpu and enable_runtime_cpu are both disabled
836
+ if (!enable_startup_cpu && !enable_runtime_cpu) {
778
837
continue ;
838
+ }
779
839
}
780
840
auto device_id_list = get_core ()
781
841
->get_property (parsed.get_device_name (), ov::available_devices.name (), {})
0 commit comments