-
Notifications
You must be signed in to change notification settings - Fork 4k
Add EPContext data I/O callbacks #28529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fd16c94
Add EPContext data I/O callbacks
06486e1
Add EPContext data callback test coverage
6d887dd
Document EPContext data callback contracts
7f59d8c
Apply lint formatting fixes
0588dc0
Fix EPContext config release API docs
ed119fb
Fix EPContext read callback failure output handling
Copilot 3726211
Refine EPContext callback regression naming
Copilot 7db2cb6
Clarify non-null sentinel in EPContext regression test
Copilot b0158c7
Simplify EPContext callback allocation status check
Copilot c31257b
Adjust EPContext regression call-site formatting
Copilot 9de0928
Apply EPContext test formatting fix
6dc0110
Address review feedback: C++ EpContextConfig wrapper, path-traversal …
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -593,6 +593,62 @@ typedef OrtStatus*(ORT_API_CALL* OrtWriteBufferFunc)(_In_ void* state, | |
| _In_ const void* buffer, | ||
| _In_ size_t buffer_num_bytes); | ||
|
|
||
| /** \brief Function called to write EPContext binary data during compilation. | ||
| * | ||
| * This function is called synchronously by OrtEpApi::WriteEpContextData on the calling thread. ORT does not retain | ||
| * buffer after the callback returns, does not reorder callback invocations, and does not serialize invocations made by | ||
| * different EP instances or EP worker threads. | ||
| * | ||
| * Each callback invocation represents one complete write operation for file_name. The callback signature does not | ||
| * provide an offset, sequence number, or final-chunk marker, so EPs that need chunked streaming must define their own | ||
| * ordering and completion contract with the application. EPs should prefer a single callback invocation per EPContext | ||
| * binary unless chunking semantics are documented by that EP. | ||
| * | ||
| * The application's implementation can process the data in any way (e.g., encrypt and store, upload to cloud storage, | ||
| * or compress) before persisting it. | ||
| * | ||
| * \param[in] state Opaque pointer holding the user's state. ORT does not own or manage this pointer. The application | ||
| * must keep it valid for the duration of any compile operation that may invoke this callback and must | ||
| * provide any synchronization required if it can be used concurrently. | ||
| * \param[in] file_name The intended EPContext binary file name as a null-terminated UTF-8 string. | ||
| * \param[in] buffer The buffer containing EPContext binary data to write. | ||
| * \param[in] buffer_num_bytes The size of the buffer in bytes. | ||
| * | ||
| * \return OrtStatus* Write status. Return nullptr on success. | ||
| * Use CreateStatus to provide error info with ORT_FAIL as the error code. | ||
| * ORT will release the OrtStatus* if not null. | ||
| */ | ||
| typedef OrtStatus*(ORT_API_CALL* OrtWriteEpContextDataFunc)(_In_ void* state, | ||
| _In_ const char* file_name, | ||
| _In_ const void* buffer, | ||
| _In_ size_t buffer_num_bytes); | ||
|
|
||
| /** \brief Function called by ORT to read EPContext binary data during session load. | ||
| * | ||
| * The application reads, processes (e.g., decrypts, decompresses, downloads), and returns the EPContext binary data. | ||
| * ORT provides an allocator so the application can allocate the output buffer directly. The callback is called | ||
| * synchronously by OrtEpApi::ReadEpContextData on the calling thread. ORT does not serialize invocations made by | ||
| * different EP instances or EP worker threads. | ||
| * | ||
| * \param[in] state Opaque pointer holding the user's state. ORT does not own or manage this pointer. The application | ||
| * must keep it valid while any session or EP created from the associated OrtSessionOptions may invoke | ||
| * this callback and must provide any synchronization required if it can be used concurrently. | ||
| * \param[in] file_name The EPContext binary file name as a null-terminated UTF-8 string. | ||
| * \param[in] allocator ORT-provided allocator. The application must use this to allocate the output buffer. | ||
| * \param[out] buffer Set by the implementation to the allocated buffer containing the output data. | ||
| * \param[out] data_size Set by the implementation to the size of the output data in bytes. | ||
| * | ||
| * \return OrtStatus* Read status. Return nullptr on success. | ||
| * On failure, ORT ignores callback outputs and treats buffer/data_size as unset. | ||
| * Use CreateStatus to provide error info with ORT_FAIL as the error code. | ||
| * ORT will release the OrtStatus* if not null. | ||
| */ | ||
| typedef OrtStatus*(ORT_API_CALL* OrtReadEpContextDataFunc)(_In_ void* state, | ||
| _In_ const char* file_name, | ||
| _In_ OrtAllocator* allocator, | ||
| _Outptr_ void** buffer, | ||
| _Out_ size_t* data_size); | ||
|
|
||
| /** \brief Function called by ORT to allow user to specify how an initializer should be saved, that is, either | ||
| * written to an external file or stored within the model. ORT calls this function for every initializer when | ||
| * generating a model. | ||
|
|
@@ -7486,6 +7542,26 @@ struct OrtApi { | |
| * \since Version 1.27. | ||
| */ | ||
| ORT_API2_STATUS(SessionReleaseCapturedGraph, _In_ OrtSession* session, _In_ int graph_annotation_id); | ||
|
|
||
| /** \brief Registers a callback to provide EPContext binary data during session load. | ||
| * | ||
| * When loading a compiled model with external (non-embedded) EPContext binary data, an execution provider can use | ||
| * OrtEpApi::ReadEpContextData to call this callback instead of reading the binary data from disk. | ||
| * | ||
| * The state pointer is stored as-is and is not owned by ORT. It must remain valid while any session or EP created | ||
| * from these options may call the callback. If the same state may be used by multiple EPs or threads, the application | ||
| * is responsible for synchronization. | ||
| * | ||
| * \param[in] options The OrtSessionOptions instance. | ||
| * \param[in] read_func The OrtReadEpContextDataFunc callback. | ||
| * \param[in] state Opaque state passed to read_func. Can be NULL. | ||
| * | ||
| * \snippet{doc} snippets.dox OrtStatus Return Value | ||
| * | ||
| * \since Version 1.27. | ||
| */ | ||
| ORT_API2_STATUS(SessionOptions_SetEpContextDataReadFunc, _Inout_ OrtSessionOptions* options, | ||
| _In_ OrtReadEpContextDataFunc read_func, _In_opt_ void* state); | ||
|
Comment on lines
+7546
to
+7564
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1.27 has not been released yet, so the new |
||
| }; | ||
|
|
||
| /* | ||
|
|
@@ -8307,6 +8383,27 @@ struct OrtCompileApi { | |
| ORT_API2_STATUS(ModelCompilationOptions_SetInputModel, | ||
| _In_ OrtModelCompilationOptions* model_compile_options, | ||
| _In_ const OrtModel* model); | ||
|
|
||
| /** \brief Sets a callback for writing EPContext binary data during compilation. | ||
| * | ||
| * When EPContext embed mode is disabled, execution providers can use OrtEpApi::WriteEpContextData to call this | ||
| * callback instead of writing EPContext binary data directly to disk. | ||
| * | ||
| * The state pointer is stored as-is and is not owned by ORT. It must remain valid for the duration of the compile | ||
| * operation that may call the callback. If the same state may be used by multiple EPs or threads, the application is | ||
| * responsible for synchronization. | ||
| * | ||
| * \param[in] model_compile_options The OrtModelCompilationOptions instance. | ||
| * \param[in] write_func The OrtWriteEpContextDataFunc called to write EPContext bytes. | ||
| * \param[in] state Opaque state passed to write_func. Can be NULL. | ||
| * | ||
| * \snippet{doc} snippets.dox OrtStatus Return Value | ||
| * | ||
| * \since Version 1.27. | ||
| */ | ||
| ORT_API2_STATUS(ModelCompilationOptions_SetEpContextDataWriteFunc, | ||
| _In_ OrtModelCompilationOptions* model_compile_options, | ||
| _In_ OrtWriteEpContextDataFunc write_func, _In_opt_ void* state); | ||
| }; | ||
|
|
||
| /** | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.