Skip to content

Commit 5a583f9

Browse files
committed
Merge branch 'master' into sync_msft_31072025
2 parents 420ec3a + eade5fe commit 5a583f9

39 files changed

+1599
-433
lines changed

cmake/external/onnxruntime_external_deps.cmake

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,23 @@ if (CPUINFO_SUPPORTED)
367367
set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "")
368368
set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "")
369369
if (onnxruntime_target_platform STREQUAL "ARM64EC" OR onnxruntime_target_platform STREQUAL "ARM64")
370-
message(STATUS "Applying a patch for Windows ARM64/ARM64EC in cpuinfo")
371-
onnxruntime_fetchcontent_declare(
372-
pytorch_cpuinfo
373-
URL ${DEP_URL_pytorch_cpuinfo}
374-
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
375-
EXCLUDE_FROM_ALL
376-
PATCH_COMMAND ${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/9bb12d342fd9479679d505d93a478a6f9cd50a47.patch
377-
FIND_PACKAGE_ARGS NAMES cpuinfo
378-
)
370+
message(STATUS "Applying a patch for Windows ARM64/ARM64EC in cpuinfo")
371+
onnxruntime_fetchcontent_declare(
372+
pytorch_cpuinfo
373+
URL ${DEP_URL_pytorch_cpuinfo}
374+
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
375+
EXCLUDE_FROM_ALL
376+
PATCH_COMMAND ${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/patch_cpuinfo_h_for_arm64ec.patch
377+
FIND_PACKAGE_ARGS NAMES cpuinfo
378+
)
379379
else()
380-
onnxruntime_fetchcontent_declare(
381-
pytorch_cpuinfo
382-
URL ${DEP_URL_pytorch_cpuinfo}
383-
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
384-
EXCLUDE_FROM_ALL
385-
FIND_PACKAGE_ARGS NAMES cpuinfo
386-
)
380+
onnxruntime_fetchcontent_declare(
381+
pytorch_cpuinfo
382+
URL ${DEP_URL_pytorch_cpuinfo}
383+
URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo}
384+
EXCLUDE_FROM_ALL
385+
FIND_PACKAGE_ARGS NAMES cpuinfo
386+
)
387387
endif()
388388
set(ONNXRUNTIME_CPUINFO_PROJ pytorch_cpuinfo)
389389
onnxruntime_fetchcontent_makeavailable(${ONNXRUNTIME_CPUINFO_PROJ})
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/include/cpuinfo.h b/include/cpuinfo.h
2-
index 6eb4b8c..4346a5a 100644
2+
index f1d35d4..9e454d2 100644
33
--- a/include/cpuinfo.h
44
+++ b/include/cpuinfo.h
55
@@ -18,7 +18,7 @@
@@ -20,16 +20,3 @@ index 6eb4b8c..4346a5a 100644
2020
#define CPUINFO_ARCH_ARM64 1
2121
#endif
2222

23-
diff --git a/src/arm/windows/init.c b/src/arm/windows/init.c
24-
index de2f6cc..c3a7835 100644
25-
--- a/src/arm/windows/init.c
26-
+++ b/src/arm/windows/init.c
27-
@@ -175,7 +175,7 @@ static struct woa_chip_info* get_system_info_from_registry(void) {
28-
if (chip_info == NULL) {
29-
/* No match was found, so print a warning and assign the unknown
30-
* case. */
31-
- cpuinfo_log_error(
32-
+ cpuinfo_log_debug(
33-
"Unknown chip model name '%ls'.\nPlease add new Windows on Arm SoC/chip support to arm/windows/init.c!",
34-
text_buffer);
35-
} else {

csharp/src/Microsoft.ML.OnnxRuntime/Exceptions.shared.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ internal enum ErrorCode
2323
ModelLoaded = 8,
2424
NotImplemented = 9,
2525
InvalidGraph = 10,
26-
ShapeInferenceNotRegistered = 11,
27-
RequirementNotRegistered = 12,
26+
ShapeInferenceNotRegistered = 11, // TODO: should be ORT_EP_FAIL
27+
RequirementNotRegistered = 12, // TODO: should be ORT_MODEL_LOAD_CANCELED
2828
}
2929

3030
/// <summary>

include/onnxruntime/core/common/status.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum StatusCode {
4646
EP_FAIL = 11,
4747
MODEL_LOAD_CANCELED = 12,
4848
MODEL_REQUIRES_COMPILATION = 13,
49+
NOT_FOUND = 14,
4950
};
5051

5152
constexpr const char* StatusCodeToString(StatusCode status) noexcept {
@@ -78,6 +79,8 @@ constexpr const char* StatusCodeToString(StatusCode status) noexcept {
7879
return "MODEL_LOAD_CANCELED";
7980
case StatusCode::MODEL_REQUIRES_COMPILATION:
8081
return "MODEL_REQUIRES_COMPILATION";
82+
case StatusCode::NOT_FOUND:
83+
return "NOT_FOUND";
8184
default:
8285
return "GENERAL ERROR";
8386
}
@@ -114,6 +117,8 @@ constexpr HRESULT StatusCodeToHRESULT(StatusCode status) noexcept {
114117
return HRESULT_FROM_WIN32(ERROR_CANCELLED);
115118
case StatusCode::MODEL_REQUIRES_COMPILATION:
116119
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
120+
case StatusCode::NOT_FOUND:
121+
return HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
117122
default:
118123
return E_FAIL;
119124
}

include/onnxruntime/core/providers/utils/ort_graph_to_proto.h

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static Ort::Status GetOrtValueInfoTensorTypeShape(const OrtValueInfo& ort_value_
232232
/*out*/ std::vector<int64_t>& dims,
233233
/*out*/ std::vector<std::string>& symbolic_dims);
234234
static Ort::Status OrtValueInfoToProto(const OrtValueInfo& ort_value_info, onnx::ValueInfoProto& value_info_proto);
235-
static Ort::Status OrtOpAttrToProto(const OrtOpAttr& ort_attr, onnx::AttributeProto& attr_proto);
235+
static Ort::Status OrtOpAttrToProto(const OrtNode& ort_node, const OrtOpAttr& ort_attr, onnx::AttributeProto& attr_proto);
236236

237237
Ort::Status OrtGraphToProto(const OrtGraph& ort_graph,
238238
onnx::GraphProto& graph_proto,
@@ -379,7 +379,7 @@ Ort::Status OrtGraphToProto(const OrtGraph& ort_graph,
379379
}
380380

381381
onnx::AttributeProto* attr_proto = node_proto->add_attribute();
382-
ORT_EP_UTILS_CXX_RETURN_IF_ERROR(OrtOpAttrToProto(*ort_attr, *attr_proto));
382+
ORT_EP_UTILS_CXX_RETURN_IF_ERROR(OrtOpAttrToProto(*ort_node, *ort_attr, *attr_proto));
383383
}
384384
}
385385

@@ -652,7 +652,7 @@ static Ort::Status OrtValueInfoToProto(const OrtValueInfo& ort_value_info,
652652
return Ort::Status{nullptr};
653653
}
654654

655-
static Ort::Status OrtOpAttrToProto(const OrtOpAttr& ort_attr, onnx::AttributeProto& attr_proto) {
655+
static Ort::Status OrtOpAttrToProto(const OrtNode& ort_node, const OrtOpAttr& ort_attr, onnx::AttributeProto& attr_proto) {
656656
const OrtApi& ort_api = Ort::GetApi();
657657

658658
const char* attr_name = nullptr;
@@ -758,6 +758,103 @@ static Ort::Status OrtOpAttrToProto(const OrtOpAttr& ort_attr, onnx::AttributePr
758758

759759
break;
760760
}
761+
case OrtOpAttrType::ORT_OP_ATTR_TENSOR: {
762+
attr_proto.set_type(onnx::AttributeProto_AttributeType_TENSOR);
763+
764+
onnx::TensorProto tensor_proto;
765+
766+
// TensorProto as an attribute value doesn't require a name.
767+
768+
OrtValue* ort_value = nullptr;
769+
ORT_EP_UTILS_C_RETURN_IF_ERROR(ort_api.Node_GetTensorAttributeAsOrtValue(&ort_node, &ort_attr, &ort_value));
770+
771+
Ort::Value tensor(ort_value);
772+
773+
// Get tensor type and shape info
774+
Ort::TensorTypeAndShapeInfo type_shape_info = tensor.GetTensorTypeAndShapeInfo();
775+
776+
// Get tensor type
777+
ONNXTensorElementDataType element_type = type_shape_info.GetElementType();
778+
779+
size_t element_size = 0;
780+
switch (element_type) {
781+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT: {
782+
tensor_proto.set_data_type(onnx::TensorProto_DataType_FLOAT);
783+
element_size = sizeof(float);
784+
break;
785+
}
786+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT8: {
787+
tensor_proto.set_data_type(onnx::TensorProto_DataType_UINT8);
788+
element_size = sizeof(uint8_t);
789+
break;
790+
}
791+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT8: {
792+
tensor_proto.set_data_type(onnx::TensorProto_DataType_INT8);
793+
element_size = sizeof(int8_t);
794+
break;
795+
}
796+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT16: {
797+
tensor_proto.set_data_type(onnx::TensorProto_DataType_UINT16);
798+
element_size = sizeof(uint16_t);
799+
break;
800+
}
801+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT16: {
802+
tensor_proto.set_data_type(onnx::TensorProto_DataType_INT16);
803+
element_size = sizeof(int16_t);
804+
break;
805+
}
806+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32: {
807+
tensor_proto.set_data_type(onnx::TensorProto_DataType_INT32);
808+
element_size = sizeof(int32_t);
809+
break;
810+
}
811+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64: {
812+
tensor_proto.set_data_type(onnx::TensorProto_DataType_INT64);
813+
element_size = sizeof(int64_t);
814+
break;
815+
}
816+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_BOOL: {
817+
tensor_proto.set_data_type(onnx::TensorProto_DataType_BOOL);
818+
element_size = sizeof(bool);
819+
break;
820+
}
821+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_DOUBLE: {
822+
tensor_proto.set_data_type(onnx::TensorProto_DataType_DOUBLE);
823+
element_size = sizeof(double);
824+
break;
825+
}
826+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT32: {
827+
tensor_proto.set_data_type(onnx::TensorProto_DataType_UINT32);
828+
element_size = sizeof(uint32_t);
829+
break;
830+
}
831+
case ONNX_TENSOR_ELEMENT_DATA_TYPE_UINT64: {
832+
tensor_proto.set_data_type(onnx::TensorProto_DataType_UINT64);
833+
element_size = sizeof(uint64_t);
834+
break;
835+
}
836+
default: {
837+
std::string err_msg = "Unexpected ONNXTensorElementDataType with value " + std::to_string(static_cast<int>(element_type));
838+
return Ort::Status(err_msg.c_str(), ORT_FAIL);
839+
}
840+
}
841+
842+
auto shape = type_shape_info.GetShape();
843+
844+
for (auto& dim : shape) {
845+
tensor_proto.add_dims(dim);
846+
}
847+
848+
size_t element_count = type_shape_info.GetElementCount();
849+
size_t data_bytes = element_count * element_size;
850+
const void* data = tensor.GetTensorData<void>();
851+
852+
// Copy the Ortvalue to TensorProto as raw data
853+
tensor_proto.set_raw_data(data, data_bytes);
854+
855+
*(attr_proto.mutable_t()) = std::move(tensor_proto);
856+
break;
857+
}
761858
default: {
762859
std::string err_msg = "Unexpected OrtOpAttrType with value " + std::to_string(static_cast<int>(attr_type));
763860
return Ort::Status(err_msg.c_str(), ORT_FAIL);

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ typedef enum OrtErrorCode {
264264
ORT_EP_FAIL,
265265
ORT_MODEL_LOAD_CANCELED,
266266
ORT_MODEL_REQUIRES_COMPILATION,
267+
ORT_NOT_FOUND,
267268
} OrtErrorCode;
268269

269270
typedef enum OrtOpAttrType {
@@ -275,6 +276,7 @@ typedef enum OrtOpAttrType {
275276
ORT_OP_ATTR_STRING,
276277
ORT_OP_ATTR_STRINGS,
277278
ORT_OP_ATTR_GRAPH,
279+
ORT_OP_ATTR_TENSOR,
278280
} OrtOpAttrType;
279281

280282
//! @}
@@ -6031,6 +6033,11 @@ struct OrtApi {
60316033
* Typical usage sets this to the result of Node_GetNumAttributes(). An error status is
60326034
* returned if `num_attributes` is less than the number of node attributes.
60336035
*
6036+
* \note ONNX Runtime automatically sets optional (unset) attributes to their default values if the default value
6037+
* is a constant expression that does not depend on other tensor/model characteristics. Conv's 'kernel_shape'
6038+
* attribute is an example of an optional attribute that does not have a constant default value. This function
6039+
* does not provide any unset optional attributes without a constant default value.
6040+
*
60346041
* \snippet{doc} snippets.dox OrtStatus Return Value
60356042
*
60366043
* \since Version 1.23.
@@ -6042,14 +6049,36 @@ struct OrtApi {
60426049
*
60436050
* \param[in] node The OrtNode instance.
60446051
* \param[in] attribute_name The name of the attribute
6045-
* \param[out] attribute Output the attribute if its name matches 'attribute_name', otherwise output nullptr.
6052+
* \param[out] attribute Output parameter set to the OrtOpAttr instance if an attribute by the given name exists.
6053+
* For an unset optional attribute, `attribute` is set to NULL and a non-error status is
6054+
* returned. For an invalid attribute name, `attribute` is set to NULL and an error status with
6055+
* code ORT_NOT_FOUND is returned.
6056+
*
6057+
* \note ONNX Runtime automatically sets optional (unset) attributes to their default values if the default value
6058+
* is a constant expression that does not depend on other tensor/model characteristics. Conv's 'kernel_shape'
6059+
* attribute is an example of an optional attribute that does not have a constant default value. This function
6060+
* does not provide any unset optional attributes without a constant default value.
60466061
*
60476062
* \snippet{doc} snippets.dox OrtStatus Return Value
60486063
*
60496064
* \since Version 1.23.
60506065
*/
60516066
ORT_API2_STATUS(Node_GetAttributeByName, _In_ const OrtNode* node, _In_ const char* attribute_name,
6052-
_Outptr_ const OrtOpAttr** attribute);
6067+
_Outptr_result_maybenull_ const OrtOpAttr** attribute);
6068+
6069+
/** \brief Get the OrtNode's 'TENSOR' attribute as an OrtValue.
6070+
*
6071+
* \param[in] node The OrtNode instance.
6072+
* \param[in] attribute The OrtOpAttr instance.
6073+
* \param[out] attr_tensor If successful, contains the 'TENSOR' attribute as a newly created OrtValue.
6074+
Must be freed with OrtApi::ReleaseValue.
6075+
*
6076+
* \snippet{doc} snippets.dox OrtStatus Return Value
6077+
*
6078+
* \since Version 1.23.
6079+
*/
6080+
ORT_API2_STATUS(Node_GetTensorAttributeAsOrtValue, _In_ const OrtNode* node, _In_ const OrtOpAttr* attribute,
6081+
_Outptr_result_maybenull_ OrtValue** attr_tensor);
60536082

60546083
/** \brief Get the attribute type as OrtOpAttrType from an OrtOpAttr.
60556084
*

java/src/main/java/ai/onnxruntime/OrtException.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ public enum OrtErrorCode {
8181
/** The ONNX graph is invalid. */
8282
ORT_INVALID_GRAPH(10),
8383
/** The ORT execution provider failed. */
84-
ORT_EP_FAIL(11);
84+
ORT_EP_FAIL(11),
85+
/** Model load was canceled. */
86+
ORT_MODEL_LOAD_CANCELED(12),
87+
/** Model requires compilation. */
88+
ORT_MODEL_REQUIRES_COMPILATION(13),
89+
/** Item was not found. */
90+
ORT_NOT_FOUND(14);
8591

8692
private final int value;
8793

88-
private static final OrtErrorCode[] values = new OrtErrorCode[12];
94+
private static final OrtErrorCode[] values = new OrtErrorCode[15];
8995

9096
static {
9197
for (OrtErrorCode ot : OrtErrorCode.values()) {

java/src/main/native/OrtJniUtil.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,12 @@ jint convertErrorCode(OrtErrorCode code) {
10511051
return 10;
10521052
case ORT_EP_FAIL:
10531053
return 11;
1054+
case ORT_MODEL_LOAD_CANCELED:
1055+
return 12;
1056+
case ORT_MODEL_REQUIRES_COMPILATION:
1057+
return 13;
1058+
case ORT_NOT_FOUND:
1059+
return 14;
10541060
default:
10551061
return -1; // Unknown error code
10561062
}

onnxruntime/contrib_ops/webgpu/bert/attention_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct WebgpuAttentionParameters {
5050
v_hidden_size_(parameters.kv_hidden_size),
5151
v_head_size_(parameters.kv_hidden_size / parameters.kv_num_heads),
5252
num_heads_(parameters.num_heads),
53+
is_unidirectional_(true),
5354
do_rotary_(parameters.do_rotary),
5455
scale_(parameters.scale),
5556
seqlen_past_kv_cache_(parameters.seqlen_past_kv_cache),

0 commit comments

Comments
 (0)