|
22 | 22 | #include "core/graph/model.h" |
23 | 23 | #include "core/graph/model_saving_options.h" |
24 | 24 | #include "core/session/onnxruntime_session_options_config_keys.h" |
| 25 | +#include "core/session/onnxruntime_ep_device_ep_metadata_keys.h" |
25 | 26 |
|
26 | 27 | // uncomment this line to count non-CUDA ops in ONNX domain |
27 | 28 | // #define COUNT_NON_CUDA_OPS |
@@ -909,6 +910,34 @@ static Status CreateEpContextModel(const ExecutionProviders& execution_providers |
909 | 910 | } |
910 | 911 | } |
911 | 912 |
|
| 913 | + // Generate EP compatibility strings for OrtEp types and add to model metadata |
| 914 | + // At this point, the graph has been populated with all the EPContext nodes |
| 915 | + { |
| 916 | + ORT_RETURN_IF_ERROR(ep_graph.Resolve()); |
| 917 | + const GraphViewer graph_viewer(ep_graph); |
| 918 | + for (const auto& ep : execution_providers) { |
| 919 | + try { |
| 920 | + // Generate the compatibility string for this EP |
| 921 | + std::string compatibility_string = ep->GetCompiledModelCompatibilityInfo(graph_viewer); |
| 922 | + if (!compatibility_string.empty()) { |
| 923 | + // Create a unique key for this EP's compatibility info |
| 924 | + // Use format: "ep_compatibility_info.<EP_TYPE>" |
| 925 | + // All EPs in a session must have a unique Type() value, so this will be unique for the generated model |
| 926 | + std::string metadata_key = std::string(kOrtModelMetadata_EpCompatibilityInfoPrefix) + ep->Type(); |
| 927 | + auto& model_metadata = ep_context_model.MetaData(); |
| 928 | + auto [it, was_inserted] = |
| 929 | + model_metadata.insert_or_assign(metadata_key, compatibility_string); |
| 930 | + if (!was_inserted) { |
| 931 | + LOGS(logger, WARNING) << "Overwriting existing EP compatibility info for key: " << metadata_key << " (EP: " << ep->Type() << ")"; |
| 932 | + } |
| 933 | + LOGS(logger, VERBOSE) << "Added EP compatibility info for " << ep->Type() << " with key: " << metadata_key; |
| 934 | + } |
| 935 | + } catch (const std::exception& ex) { |
| 936 | + LOGS(logger, WARNING) << "Failed to generate compatibility string for EP " << ep->Type() << ": " << ex.what(); |
| 937 | + } |
| 938 | + } |
| 939 | + } |
| 940 | + |
912 | 941 | size_t ini_size_threshold = ep_context_gen_options.output_external_initializer_size_threshold; |
913 | 942 | std::filesystem::path external_ini_path = ep_context_gen_options.output_external_initializers_file_path; |
914 | 943 | bool force_embed_external_ini = false; |
|
0 commit comments