@@ -72,8 +72,8 @@ Status ModelCompilationOptions::SetOutputModelPath(const std::string& output_mod
7272 if (log_manager != nullptr && log_manager->HasDefaultLogger ()) {
7373 const logging::Logger& logger = log_manager->DefaultLogger ();
7474 LOGS (logger, WARNING) << " Output model path length (" << ep_context_gen_options.output_model_file_path .size ()
75- << " ) exceeds limit of " << ConfigOptions::kMaxKeyLength << " characters."
76- << " ORT will still generated the expected output file, but EPs will see an empty "
75+ << " ) exceeds limit of " << ConfigOptions::kMaxValueLength << " characters."
76+ << " ORT will still generate the expected output file, but EPs will see an empty "
7777 << " output model path in SessionOption's ConfigOptions." ;
7878 }
7979 }
@@ -98,6 +98,36 @@ Status ModelCompilationOptions::SetOutputModelBuffer(onnxruntime::AllocatorPtr a
9898 return Status::OK ();
9999}
100100
101+ Status ModelCompilationOptions::SetEpContextBinaryInformation (const std::string& output_directory,
102+ const std::string& model_name) {
103+ if (output_directory.empty () || model_name.empty ()) {
104+ return ORT_MAKE_STATUS (ONNXRUNTIME, INVALID_ARGUMENT, " output_dir or model_name is empty." );
105+ }
106+
107+ std::filesystem::path output_dir_path (output_directory);
108+ if (output_dir_path.has_filename () && output_dir_path.extension () == " " ) {
109+ return ORT_MAKE_STATUS (ONNXRUNTIME, INVALID_ARGUMENT, " output_dir is not a valid directory." );
110+ }
111+
112+ std::filesystem::path ctx_model_path = output_directory / std::filesystem::path (model_name);
113+
114+ if (ctx_model_path.string ().size () <= ConfigOptions::kMaxValueLength ) {
115+ ORT_RETURN_IF_ERROR (session_options_.value .config_options .AddConfigEntry (kOrtSessionOptionEpContextFilePath ,
116+ ctx_model_path.string ().c_str ()));
117+ } else {
118+ logging::LoggingManager* log_manager = env_.GetLoggingManager ();
119+ if (log_manager != nullptr && log_manager->HasDefaultLogger ()) {
120+ const logging::Logger& logger = log_manager->DefaultLogger ();
121+ LOGS (logger, WARNING) << " output_directory length with model_name length together exceeds limit of "
122+ << ConfigOptions::kMaxValueLength << " characters."
123+ << " ORT will still generate the expected output file, but EPs will see an empty "
124+ << " output path in SessionOption's ConfigOptions." ;
125+ }
126+ }
127+
128+ return Status::OK ();
129+ }
130+
101131Status ModelCompilationOptions::SetEpContextEmbedMode (bool embed_ep_context_in_model) {
102132 ORT_RETURN_IF_ERROR (session_options_.value .config_options .AddConfigEntry (
103133 kOrtSessionOptionEpContextEmbedMode , embed_ep_context_in_model ? " 1" : " 0" ));
@@ -146,7 +176,7 @@ Status ModelCompilationOptions::ResetOutputModelSettings() {
146176 ep_context_gen_options.output_model_buffer_ptr = nullptr ;
147177 ep_context_gen_options.output_model_buffer_size_ptr = nullptr ;
148178 ep_context_gen_options.output_model_buffer_allocator = nullptr ;
149- return session_options_. value . config_options . AddConfigEntry ( kOrtSessionOptionEpContextFilePath , " " );
179+ return Status::OK ( );
150180}
151181
152182Status ModelCompilationOptions::CheckInputModelSettings () const {
0 commit comments