Add KernelInfo string-array attribute APIs to the ORT C and C++ APIs#27599
Merged
Add KernelInfo string-array attribute APIs to the ORT C and C++ APIs#27599
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds public ORT C/C++ API support for reading repeated (array) string attributes from OrtKernelInfo, closing a gap vs. existing numeric attribute array APIs and unblocking scenarios like plugin EP kernels that depend on repeated string attributes.
Changes:
- Adds
OrtApi::KernelInfoGetAttributeArray_string(allocator-allocatedchar**+ per-string buffers) and wires it into the C API dispatch table. - Implements the new API in the custom-op/kernel-info API layer by reading
OpKernelInfo::GetAttrs<std::string>and copying results to allocator-owned C strings. - Extends the C++ wrapper to support
Ort::ConstKernelInfo::GetAttributes<std::string>(...)and adds new gtest coverage.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
include/onnxruntime/core/session/onnxruntime_c_api.h |
Declares the new C API entry point and documents usage/freeing semantics. |
onnxruntime/core/session/ort_apis.h |
Adds the OrtApis::KernelInfoGetAttributeArray_string declaration. |
onnxruntime/core/session/onnxruntime_c_api.cc |
Wires the new function into the v1–v25 OrtApi function table and adds an ABI offset assert. |
onnxruntime/core/session/custom_ops.cc |
Implements the new KernelInfo string-array accessor and allocation/copy helper. |
include/onnxruntime/core/session/onnxruntime_cxx_api.h |
Extends the C++ wrapper API surface to support string arrays in GetAttributes. |
include/onnxruntime/core/session/onnxruntime_cxx_inline.h |
Implements attr_utils::GetAttrs(..., std::vector<std::string>&) using the new C API. |
onnxruntime/test/framework/kernel_info_test.cc |
Adds unit tests for non-empty/empty/missing string-array attributes and C++ wrapper parity. |
Comments suppressed due to low confidence (1)
include/onnxruntime/core/session/onnxruntime_cxx_api.h:2892
- The template parameter
RforGetAttributesis the element type (e.g.,float,int64_t,std::string), not a vector type. The comment currently saysstd::vector<float>/etc., which is misleading—please update it to match theGetAttributecomment above.
template <typename R> // R is only implemented for std::vector<float>, std::vector<int64_t>, and std::vector<std::string>
std::vector<R> GetAttributes(const char* name) const {
std::vector<R> result;
attr_utils::GetAttrs(this->p_, name, result);
return result;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
adrianlizarraga
approved these changes
Mar 11, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR adds a new
OrtApientry point for reading repeated string attributes fromOrtKernelInfo:KernelInfoGetAttributeArray_stringIt also wires that support through the C++ wrapper so callers can use:
Ort::ConstKernelInfo::GetAttributes<std::string>(...)Problem
The existing kernel info APIs already support scalar and array attribute access for numeric types, but there was no C API for reading string-array attributes from
OrtKernelInfo.That created a gap for code paths that rely on repeated string attributes in kernel metadata, such as:
GetAttributes<std::string>to work end-to-endOne concrete case is CUDA plugin EP RNN support, where the RNN kernels read the
activationsattribute viaGetAttrs<std::string>("activations", ...). The adapter path needed a corresponding ORT C API to expose that data.Changes
C API
Added
OrtApi::KernelInfoGetAttributeArray_stringto fetch repeated string attributes fromOrtKernelInfo.Behavior:
out == nullptr, the API returns the attribute count insize.OrtAllocator.*outis set tonullptrand*sizeis set to0.Implementation
Added the implementation in the ORT session/custom-op API layer by:
OpKernelInfo::GetAttrs<std::string>C++ wrapper
Completed C++ wrapper support so
Ort::ConstKernelInfo::GetAttributes<std::string>(name)works through the new C API.The wrapper follows the standard two-call pattern:
std::vector<std::string>and release allocator-owned memoryTests
Added framework tests covering:
Ort::ConstKernelInfoFiles Changed
include/onnxruntime/core/session/onnxruntime_c_api.hinclude/onnxruntime/core/session/onnxruntime_cxx_api.hinclude/onnxruntime/core/session/onnxruntime_cxx_inline.honnxruntime/core/session/custom_ops.cconnxruntime/core/session/onnxruntime_c_api.cconnxruntime/core/session/ort_apis.honnxruntime/test/framework/kernel_info_test.ccWhy This Change
This closes a real API gap in kernel attribute access and makes the public API surface more consistent with the existing numeric attribute helpers.
It also unblocks plugin/adapter-based kernel code that depends on repeated string attributes without requiring those kernels to special-case plugin builds.
For example, porting rnn operator to cuda plugin EP will need this API.
Validation
Validated with new unit coverage in
kernel_info_test.ccfor:KernelInfoGetAttributeArray_stringwith populated attributesKernelInfoGetAttributeArray_stringwith empty attributesOrt::ConstKernelInfo::GetAttributes<std::string>parity with the C API