diff --git a/cmake/onnxruntime_java.cmake b/cmake/onnxruntime_java.cmake index 07e40ad809..1567ef92e5 100644 --- a/cmake/onnxruntime_java.cmake +++ b/cmake/onnxruntime_java.cmake @@ -75,6 +75,12 @@ endif() if (onnxruntime_USE_NUPHAR) target_compile_definitions(onnxruntime4j_jni PRIVATE USE_NUPHAR=1) endif() +if (onnxruntime_USE_ACL) + target_compile_definitions(onnxruntime4j_jni PRIVATE USE_ACL=1) +endif() +if (onnxruntime_USE_DML) + target_compile_definitions(onnxruntime4j_jni PRIVATE USE_DIRECTML=1) +endif() # depend on java sources. if they change, the JNI should recompile add_dependencies(onnxruntime4j_jni onnxruntime4j) diff --git a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs index 86d9af68a8..d99dce3508 100644 --- a/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs +++ b/csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs @@ -1836,4 +1836,44 @@ namespace Microsoft.ML.OnnxRuntime.Tests } } + + // A Disposable list is a list of IDisposable objects. All elements will be disposed when the container is disposed. + internal class DisposableList : List, IDisposableReadOnlyCollection + where T : IDisposable + { + public DisposableList() { } + public DisposableList(int count) : base(count) { } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + for (int i = 0; i < this.Count; i++) + { + this[i]?.Dispose(); + } + this.Clear(); + } + + disposedValue = true; + } + } + + ~DisposableList() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion + } } diff --git a/include/onnxruntime/core/session/onnxruntime_c_api.h b/include/onnxruntime/core/session/onnxruntime_c_api.h index 4f78b464fa..a7a7240006 100644 --- a/include/onnxruntime/core/session/onnxruntime_c_api.h +++ b/include/onnxruntime/core/session/onnxruntime_c_api.h @@ -7,7 +7,7 @@ #include // This value is used in structures passed to ORT so that a newer version of ORT will still work with them -#define ORT_API_VERSION 2 +#define ORT_API_VERSION 3 #ifdef __cplusplus extern "C" { @@ -772,6 +772,16 @@ struct OrtApi { ORT_CLASS_RELEASE(ThreadingOptions); + /** + * \param num_keys contains the number of keys in the custom metadata map + * \param keys is an array of null terminated strings (array count = num_keys) allocated using 'allocator'. + * The caller is responsible for freeing each string and the pointer array. + * 'keys' will be a nullptr if custom metadata map is empty. + */ + OrtStatus*(ORT_API_CALL* ModelMetadataGetCustomMetadataMapKeys)(_In_ const OrtModelMetadata* model_metadata, + _Inout_ OrtAllocator* allocator, + _Outptr_ char*** keys, _Out_ int64_t* num_keys)NO_EXCEPTION; + // Override symbolic dimensions (by specific name strings) with actual values if known at session initialization time to enable // optimizations that can take advantage of fixed values (such as memory planning, etc) OrtStatus*(ORT_API_CALL* AddFreeDimensionOverrideByName)(_Inout_ OrtSessionOptions* options, diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h index cd132b1628..de6886bcdd 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h @@ -199,6 +199,7 @@ struct ModelMetadata : Base { char* GetGraphName(OrtAllocator* allocator) const; char* GetDomain(OrtAllocator* allocator) const; char* GetDescription(OrtAllocator* allocator) const; + char** GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const; char* LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const; int64_t GetVersion() const; }; diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h index 258b2bc490..49d8c61af7 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h @@ -324,6 +324,12 @@ inline char* ModelMetadata::LookupCustomMetadataMap(const char* key, OrtAllocato return out; } +inline char** ModelMetadata::GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const { + char** out; + ThrowOnError(Global::api_.ModelMetadataGetCustomMetadataMapKeys(p_, allocator, &out, &num_keys)); + return out; +} + inline int64_t ModelMetadata::GetVersion() const { int64_t out; ThrowOnError(Global::api_.ModelMetadataGetVersion(p_, &out)); diff --git a/java/src/main/java/ai/onnxruntime/OrtSession.java b/java/src/main/java/ai/onnxruntime/OrtSession.java index 2cd21cd3bf..f9136a1d3b 100644 --- a/java/src/main/java/ai/onnxruntime/OrtSession.java +++ b/java/src/main/java/ai/onnxruntime/OrtSession.java @@ -548,6 +548,26 @@ public class OrtSession implements AutoCloseable { addNuphar(OnnxRuntime.ortApiHandle, nativeHandle, allowUnalignedBuffers ? 1 : 0, settings); } + /** + * Adds DirectML as an execution backend. + * + * @param deviceId The id of the DirectML device. + * @throws OrtException If there was an error in native code. + */ + public void addDirectML(int deviceId) throws OrtException { + addDirectML(OnnxRuntime.ortApiHandle, nativeHandle, deviceId); + } + + /** + * Adds the ARM Compute Library as an execution backend. + * + * @param useArena If true use the arena memory allocator. + * @throws OrtException If there was an error in native code. + */ + public void addACL(boolean useArena) throws OrtException { + addACL(OnnxRuntime.ortApiHandle, nativeHandle, useArena ? 1 : 0); + } + private native void setExecutionMode(long apiHandle, long nativeHandle, int mode) throws OrtException; @@ -601,6 +621,11 @@ public class OrtSession implements AutoCloseable { private native void addNuphar( long apiHandle, long nativeHandle, int allowUnalignedBuffers, String settings) throws OrtException; + + private native void addDirectML(long apiHandle, long nativeHandle, int deviceId) + throws OrtException; + + private native void addACL(long apiHandle, long nativeHandle, int useArena) throws OrtException; } /** diff --git a/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c b/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c index c3a5d16a3b..739ab68357 100644 --- a/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c +++ b/java/src/main/native/ai_onnxruntime_OrtSession_SessionOptions.c @@ -17,6 +17,10 @@ #include "onnxruntime/core/providers/nuphar/nuphar_provider_factory.h" #include "onnxruntime/core/providers/openvino/openvino_provider_factory.h" #include "onnxruntime/core/providers/tensorrt/tensorrt_provider_factory.h" +#include "onnxruntime/core/providers/acl/acl_provider_factory.h" +#ifdef USE_DIRECTML +#include "onnxruntime/core/providers/dml/dml_provider_factory.h" +#endif /* * Class: ai_onnxruntime_OrtSession_SessionOptions @@ -233,8 +237,7 @@ JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addNna /* * Class: ai_onnxruntime_OrtSession_SessionOptions * Method: addNuphar - * Signature: (JILjava/lang/String { - })V + * Signature: (JILjava/lang/String)V */ JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addNuphar (JNIEnv * jniEnv, jobject jobj, jlong apiHandle, jlong handle, jint allowUnalignedBuffers, jstring settingsString) { @@ -248,3 +251,35 @@ JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addNup throwOrtException(jniEnv,convertErrorCode(ORT_INVALID_ARGUMENT),"This binary was not compiled with Nuphar support."); #endif } + +/* + * Class: ai_onnxruntime_OrtSession_SessionOptions + * Method: addDirectML + * Signature: (JJI)V + */ +JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addDirectML + (JNIEnv * jniEnv, jobject jobj, jlong apiHandle, jlong handle, jint deviceID) { + (void)jobj; + #ifdef USE_DIRECTML + checkOrtStatus(jniEnv,(const OrtApi*)apiHandle,OrtSessionOptionsAppendExecutionProvider_DML((OrtSessionOptions*) handle, deviceID)); + #else + (void)apiHandle;(void)handle;(void)deviceID; // Parameters used when DirectML is defined. + throwOrtException(jniEnv,convertErrorCode(ORT_INVALID_ARGUMENT),"This binary was not compiled with DirectML support."); + #endif +} + +/* + * Class: ai_onnxruntime_OrtSession_SessionOptions + * Method: addACL + * Signature: (JJI)V + */ +JNIEXPORT void JNICALL Java_ai_onnxruntime_OrtSession_00024SessionOptions_addACL + (JNIEnv * jniEnv, jobject jobj, jlong apiHandle, jlong handle, jint useArena) { + (void)jobj; + #ifdef USE_ACL + checkOrtStatus(jniEnv,(const OrtApi*)apiHandle,OrtSessionOptionsAppendExecutionProvider_ACL((OrtSessionOptions*) handle,useArena)); + #else + (void)apiHandle;(void)handle;(void)useArena; // Parameters used when ACL is defined. + throwOrtException(jniEnv,convertErrorCode(ORT_INVALID_ARGUMENT),"This binary was not compiled with ACL support."); + #endif +} diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index 393c05fd29..5da9ee0111 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -13,6 +13,7 @@ #include "core/common/logging/logging.h" #include "core/common/status.h" +#include "core/common/safeint.h" #include "core/graph/graph.h" #include "core/framework/allocator.h" #include "core/framework/tensor.h" @@ -755,6 +756,37 @@ ORT_API_STATUS_IMPL(OrtApis::ModelMetadataLookupCustomMetadataMap, API_IMPL_END } +ORT_API_STATUS_IMPL(OrtApis::ModelMetadataGetCustomMetadataMapKeys, + _In_ const OrtModelMetadata* model_metadata, + _Inout_ OrtAllocator* allocator, _Outptr_ char*** keys, _Out_ int64_t* num_keys) { + API_IMPL_BEGIN + const auto& custom_metadata_map = + reinterpret_cast(model_metadata)->custom_metadata_map; + + auto count = custom_metadata_map.size(); + if (count == 0) { + *keys = nullptr; + } else { + // To guard against overflow in the next step where we compute bytes to allocate + SafeInt alloc_count(count); + + // alloc_count * sizeof(...) will throw if there was an overflow which will be caught in API_IMPL_END + // and be returned to the user as a status + *keys = reinterpret_cast(allocator->Alloc(allocator, alloc_count * sizeof(char*))); + + auto map_iter = custom_metadata_map.cbegin(); + int64_t i = 0; + while (map_iter != custom_metadata_map.cend()) { + *keys[i++] = StrDup(map_iter->first, allocator); + ++map_iter; + } + } + + *num_keys = static_cast(count); + return nullptr; + API_IMPL_END +} + ORT_API_STATUS_IMPL(OrtApis::ModelMetadataGetVersion, _In_ const OrtModelMetadata* model_metadata, _Out_ int64_t* value) { @@ -1516,6 +1548,7 @@ static constexpr OrtApi ort_api_1_to_3 = { &OrtApis::DisablePerSessionThreads, &OrtApis::CreateThreadingOptions, &OrtApis::ReleaseThreadingOptions, + &OrtApis::ModelMetadataGetCustomMetadataMapKeys, &OrtApis::AddFreeDimensionOverrideByName}; // Assert to do a limited check to ensure Version 1 of OrtApi never changes (will detect an addition or deletion but not if they cancel out each other) diff --git a/onnxruntime/core/session/ort_apis.h b/onnxruntime/core/session/ort_apis.h index 472e34e162..e06b837f99 100644 --- a/onnxruntime/core/session/ort_apis.h +++ b/onnxruntime/core/session/ort_apis.h @@ -186,6 +186,10 @@ ORT_API_STATUS_IMPL(DisablePerSessionThreads, _In_ OrtSessionOptions* options); ORT_API_STATUS_IMPL(CreateThreadingOptions, _Outptr_ OrtThreadingOptions** out); ORT_API(void, ReleaseThreadingOptions, _Frees_ptr_opt_ OrtThreadingOptions*); +ORT_API_STATUS_IMPL(ModelMetadataGetCustomMetadataMapKeys, _In_ const OrtModelMetadata* model_metadata, + _Inout_ OrtAllocator* allocator, _Outptr_ char*** keys, _Out_ int64_t* num_keys); + + ORT_API_STATUS_IMPL(AddFreeDimensionOverrideByName, _Inout_ OrtSessionOptions* options, _In_ const char* dim_name, _In_ int64_t dim_value); } // namespace OrtApis diff --git a/onnxruntime/featurizers_ops/cpu/cat_imputer_transformer.cc b/onnxruntime/featurizers_ops/cpu/cat_imputer_transformer.cc index 0e7d4b14f4..f57c6c5ae7 100644 --- a/onnxruntime/featurizers_ops/cpu/cat_imputer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/cat_imputer_transformer.cc @@ -36,7 +36,7 @@ struct CatImputerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::CatImputerTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/count_vectorizer_transfromer.cc b/onnxruntime/featurizers_ops/cpu/count_vectorizer_transfromer.cc index 28828572c8..40b9df4743 100644 --- a/onnxruntime/featurizers_ops/cpu/count_vectorizer_transfromer.cc +++ b/onnxruntime/featurizers_ops/cpu/count_vectorizer_transfromer.cc @@ -19,7 +19,7 @@ void CountVectorizerTransformerImpl(OpKernelContext* ctx) { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::CountVectorizerTransformer(archive); }()); @@ -28,8 +28,10 @@ void CountVectorizerTransformerImpl(OpKernelContext* ctx) { const std::string* input_data = input_tensor->template Data(); // Prepare the callback that would output directly to output memory std::function)> callback; - callback = [ctx](NS::Featurizers::SparseVectorEncoding result) { + bool callback_allow = true; + callback = [ctx, callback_allow](NS::Featurizers::SparseVectorEncoding result) { // Prepare output + ORT_ENFORCE(callback_allow, "callback function can only be called during execute() and special flush() when needed"); ORT_ENFORCE(result.NumElements < static_cast(std::numeric_limits::max()), "NumElements in SparseVectorEncoding is GE than max(int64)"); auto* output_tensor = ctx->Output(0, TensorShape{static_cast(result.NumElements)}); @@ -40,6 +42,9 @@ void CountVectorizerTransformerImpl(OpKernelContext* ctx) { } }; transformer.execute(*input_data, callback); + // The flush() does nothing but shows Featurizers concept + callback_allow = false; + transformer.flush(callback); }; class CountVectorizerTransformer final : public OpKernel { diff --git a/onnxruntime/featurizers_ops/cpu/date_time_transformer.cc b/onnxruntime/featurizers_ops/cpu/date_time_transformer.cc index 8a5c4310d6..15c9712ac3 100644 --- a/onnxruntime/featurizers_ops/cpu/date_time_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/date_time_transformer.cc @@ -24,7 +24,7 @@ class DateTimeTransformer final : public OpKernel { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::DateTimeTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/forecasting_pivot_transformer.cc b/onnxruntime/featurizers_ops/cpu/forecasting_pivot_transformer.cc index 24575c2021..514a059550 100644 --- a/onnxruntime/featurizers_ops/cpu/forecasting_pivot_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/forecasting_pivot_transformer.cc @@ -24,7 +24,7 @@ struct ForecastingPivotTransformerImpl { //Get the transformer const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); TransformerT transformer(archive); // Get the Number of Rows @@ -59,9 +59,10 @@ struct ForecastingPivotTransformerImpl { std::tuple info_tuple(input_data, input_dim_1, input_dim_2); dataPtrMap.insert(std::pair>(index, info_tuple)); } - const T* input_data(std::get<0>(dataPtrMap.at(index))); - const int64_t input_dim_1(std::get<1>(dataPtrMap.at(index))); - const int64_t input_dim_2(std::get<2>(dataPtrMap.at(index))); + std::tuple &inputTuple(dataPtrMap.at(index)); + const T* input_data(std::get<0>(inputTuple)); + const int64_t input_dim_1(std::get<1>(inputTuple)); + const int64_t input_dim_2(std::get<2>(inputTuple)); input.push_back(typename InputType::value_type(input_data, input_dim_1, input_dim_2)); //Increment data pointer input_data += input_dim_1 * input_dim_2; diff --git a/onnxruntime/featurizers_ops/cpu/from_string_transformer.cc b/onnxruntime/featurizers_ops/cpu/from_string_transformer.cc index da3c63705c..0a237b8409 100644 --- a/onnxruntime/featurizers_ops/cpu/from_string_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/from_string_transformer.cc @@ -21,7 +21,7 @@ struct FromStringTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::FromStringTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/hash_one_hot_vectorizer_transformer.cc b/onnxruntime/featurizers_ops/cpu/hash_one_hot_vectorizer_transformer.cc index c06157fba2..44f880728c 100644 --- a/onnxruntime/featurizers_ops/cpu/hash_one_hot_vectorizer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/hash_one_hot_vectorizer_transformer.cc @@ -21,7 +21,7 @@ struct HashOneHotVectorizerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::HashOneHotVectorizerTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/imputation_marker_transformer.cc b/onnxruntime/featurizers_ops/cpu/imputation_marker_transformer.cc index 2630badc17..478dbf20f5 100644 --- a/onnxruntime/featurizers_ops/cpu/imputation_marker_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/imputation_marker_transformer.cc @@ -27,7 +27,7 @@ struct ImputationMarkerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::ImputationMarkerTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/label_encoder_transformer.cc b/onnxruntime/featurizers_ops/cpu/label_encoder_transformer.cc index ed5bf1b9cc..a6843f0780 100644 --- a/onnxruntime/featurizers_ops/cpu/label_encoder_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/label_encoder_transformer.cc @@ -21,7 +21,7 @@ struct LabelEncoderTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::LabelEncoderTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/laglead_operator_transformer.cc b/onnxruntime/featurizers_ops/cpu/laglead_operator_transformer.cc index 7535b0eef3..703c6068e7 100644 --- a/onnxruntime/featurizers_ops/cpu/laglead_operator_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/laglead_operator_transformer.cc @@ -28,7 +28,7 @@ struct LagLeadOperatorTransformerImpl { //Get the transformer const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); typename EstimatorT::TransformerType transformer(archive); // Get the Grains @@ -52,8 +52,8 @@ struct LagLeadOperatorTransformerImpl { bool has_allocate_output_data = false; std::function callback_fn; callback_fn = [ctx, &output_grains_data, &output_data, &has_allocate_output_data, output_dim_0](OutputType value) -> void { - GrainT & output_grains(std::get(value)); - const OutputMatrixType & output_matrix(std::get(value)); + GrainT & output_grains(std::get<0>(value)); + const OutputMatrixType & output_matrix(std::get<1>(value)); //Allocate tensor memory after first output is generated if (!has_allocate_output_data) { TensorShape output_shape({output_dim_0, output_matrix.rows(), output_matrix.cols()}); diff --git a/onnxruntime/featurizers_ops/cpu/max_abs_scaler_transformer.cc b/onnxruntime/featurizers_ops/cpu/max_abs_scaler_transformer.cc index af5b004157..8cb9ddd781 100644 --- a/onnxruntime/featurizers_ops/cpu/max_abs_scaler_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/max_abs_scaler_transformer.cc @@ -44,7 +44,7 @@ struct MaxAbsScalerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::MaxAbsScalerTransformer::type>(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/mean_imputer_transformer.cc b/onnxruntime/featurizers_ops/cpu/mean_imputer_transformer.cc index 884da425e0..073f21608d 100644 --- a/onnxruntime/featurizers_ops/cpu/mean_imputer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/mean_imputer_transformer.cc @@ -36,7 +36,7 @@ struct MeanImputerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return MeanImputerTransformerT(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/median_imputer_transformer.cc b/onnxruntime/featurizers_ops/cpu/median_imputer_transformer.cc index 6b3aa5bd73..bcd5602dfb 100644 --- a/onnxruntime/featurizers_ops/cpu/median_imputer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/median_imputer_transformer.cc @@ -50,7 +50,7 @@ struct MedianImputerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return MedianImputerTransformerT(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/min_max_imputer_transformer.cc b/onnxruntime/featurizers_ops/cpu/min_max_imputer_transformer.cc index 7e7f0b3c79..94a6e399ce 100644 --- a/onnxruntime/featurizers_ops/cpu/min_max_imputer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/min_max_imputer_transformer.cc @@ -45,7 +45,7 @@ struct MinMaxImputerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return MinMaxImputerTransformerT(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/min_max_scaler_transformer.cc b/onnxruntime/featurizers_ops/cpu/min_max_scaler_transformer.cc index 6d9ae46186..25d1e6c74f 100644 --- a/onnxruntime/featurizers_ops/cpu/min_max_scaler_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/min_max_scaler_transformer.cc @@ -21,7 +21,7 @@ struct MinMaxScalerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::MinMaxScalerTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/missing_dummies_transformer.cc b/onnxruntime/featurizers_ops/cpu/missing_dummies_transformer.cc index 908855a17d..465b58e9f0 100644 --- a/onnxruntime/featurizers_ops/cpu/missing_dummies_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/missing_dummies_transformer.cc @@ -27,7 +27,7 @@ struct MissingDummiesTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::MissingDummiesTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/mode_imputer_transformer.cc b/onnxruntime/featurizers_ops/cpu/mode_imputer_transformer.cc index c310d05ca0..6b8e39ca63 100644 --- a/onnxruntime/featurizers_ops/cpu/mode_imputer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/mode_imputer_transformer.cc @@ -45,7 +45,7 @@ struct ModeImputerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return ModeImputerTransformerT(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/normalize_transformer.cc b/onnxruntime/featurizers_ops/cpu/normalize_transformer.cc index 1337623ae6..41c809aec7 100644 --- a/onnxruntime/featurizers_ops/cpu/normalize_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/normalize_transformer.cc @@ -23,7 +23,7 @@ struct NormalizeTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Transformer(archive); }()); @@ -43,7 +43,9 @@ struct NormalizeTransformerImpl { std::vector result; std::function)> callback; - callback = [&result](std::vector val) mutable { + bool callback_allow = true; + callback = [&result, callback_allow](std::vector val) { + ORT_ENFORCE(callback_allow, "callback function can only be called during execute() and special flush() when needed"); result = std::move(val); }; @@ -58,6 +60,9 @@ struct NormalizeTransformerImpl { std::copy(result.cbegin(), result.cend(), output_data); output_data += row_size; } + // The flush() does nothing but shows Featurizers concept + callback_allow = false; + transformer.flush(callback); } }; diff --git a/onnxruntime/featurizers_ops/cpu/numericalize_transformer.cc b/onnxruntime/featurizers_ops/cpu/numericalize_transformer.cc index cd9e32f056..710654fbe0 100644 --- a/onnxruntime/featurizers_ops/cpu/numericalize_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/numericalize_transformer.cc @@ -21,7 +21,7 @@ struct NumericalizeTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::NumericalizeTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/one_hot_encoder_transformer.cc b/onnxruntime/featurizers_ops/cpu/one_hot_encoder_transformer.cc index 0231fc9ec8..54c94622b0 100644 --- a/onnxruntime/featurizers_ops/cpu/one_hot_encoder_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/one_hot_encoder_transformer.cc @@ -21,7 +21,7 @@ struct OneHotEncoderTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::OneHotEncoderTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/pca_transformer.cc b/onnxruntime/featurizers_ops/cpu/pca_transformer.cc index 03a07b01f4..2dd644fa35 100644 --- a/onnxruntime/featurizers_ops/cpu/pca_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/pca_transformer.cc @@ -25,7 +25,7 @@ struct PCATransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::PCATransformer(archive); }()); @@ -47,10 +47,15 @@ struct PCATransformerImpl { Eigen::Map output_matrix(output_data, dim_0, dim_1); std::function callback; - callback = [&output_matrix](MatrixT val) { + bool callback_allow = true; + callback = [&output_matrix, callback_allow](MatrixT val) { + ORT_ENFORCE(callback_allow, "callback function can only be called during execute() and special flush() when needed"); output_matrix = val; }; transformer.execute(input_matrix, callback); + // The flush() does nothing but shows Featurizers concept + callback_allow = false; + transformer.flush(callback); } }; diff --git a/onnxruntime/featurizers_ops/cpu/robust_scaler_transformer.cc b/onnxruntime/featurizers_ops/cpu/robust_scaler_transformer.cc index 608f1c338a..4d67b86c3e 100644 --- a/onnxruntime/featurizers_ops/cpu/robust_scaler_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/robust_scaler_transformer.cc @@ -44,7 +44,7 @@ struct RobustScalerTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::RobustScalerTransformer::type>(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/rolling_window_transformer.cc b/onnxruntime/featurizers_ops/cpu/rolling_window_transformer.cc index 4ee900f7cd..6fbe055ab4 100644 --- a/onnxruntime/featurizers_ops/cpu/rolling_window_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/rolling_window_transformer.cc @@ -24,7 +24,7 @@ struct RollingWindowTransformerImpl { //Get the transformer const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); typename EstimatorT::TransformerType transformer(archive); // Get the Grains @@ -69,6 +69,7 @@ struct RollingWindowTransformerImpl { target_data++; grains_data += grains_num; } + transformer.flush(callback_fn); } }; diff --git a/onnxruntime/featurizers_ops/cpu/short_grain_dropper_transformer.cc b/onnxruntime/featurizers_ops/cpu/short_grain_dropper_transformer.cc index cda8ca2e13..7cfc34fad2 100644 --- a/onnxruntime/featurizers_ops/cpu/short_grain_dropper_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/short_grain_dropper_transformer.cc @@ -19,7 +19,7 @@ void ShortGrainDropperTransformerImpl(OpKernelContext* ctx) { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::ShortGrainDropperTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/standard_scale_wrapper_transformer.cc b/onnxruntime/featurizers_ops/cpu/standard_scale_wrapper_transformer.cc index c0918f0cad..ed0213d1e0 100644 --- a/onnxruntime/featurizers_ops/cpu/standard_scale_wrapper_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/standard_scale_wrapper_transformer.cc @@ -21,7 +21,7 @@ struct StandardScaleWrapperTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::StandardScalerTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/string_transformer.cc b/onnxruntime/featurizers_ops/cpu/string_transformer.cc index 60a2c70106..ac9342e0f7 100644 --- a/onnxruntime/featurizers_ops/cpu/string_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/string_transformer.cc @@ -21,7 +21,7 @@ struct StringTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::StringTransformer(archive); }()); diff --git a/onnxruntime/featurizers_ops/cpu/tfidf_vectorizer_transformer.cc b/onnxruntime/featurizers_ops/cpu/tfidf_vectorizer_transformer.cc index 4b7b54c1bd..9365c3742c 100644 --- a/onnxruntime/featurizers_ops/cpu/tfidf_vectorizer_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/tfidf_vectorizer_transformer.cc @@ -19,7 +19,7 @@ void TfidfVectorizerTransformerImpl(OpKernelContext* ctx) { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::TfidfVectorizerTransformer(archive); }()); @@ -29,8 +29,10 @@ void TfidfVectorizerTransformerImpl(OpKernelContext* ctx) { // Prepare the callback that would output directly to output memory std::function)> callback; - callback = [ctx](NS::Featurizers::SparseVectorEncoding result) { + bool callback_allow = true; + callback = [ctx, callback_allow](NS::Featurizers::SparseVectorEncoding result) { // Prepare output + ORT_ENFORCE(callback_allow, "callback function can only be called during execute() and special flush() when needed"); ORT_ENFORCE(result.NumElements < static_cast(std::numeric_limits::max()), "NumElements in SparseVectorEncoding is GE than max(int64)"); auto* output_tensor = ctx->Output(0, TensorShape{static_cast(result.NumElements)}); @@ -41,6 +43,9 @@ void TfidfVectorizerTransformerImpl(OpKernelContext* ctx) { } }; transformer.execute(*input_data, callback); + // The flush() does nothing but shows Featurizers concept + callback_allow = false; + transformer.flush(callback); } class TfidfVectorizerTransformer final : public OpKernel { diff --git a/onnxruntime/featurizers_ops/cpu/truncated_svd_transformer.cc b/onnxruntime/featurizers_ops/cpu/truncated_svd_transformer.cc index 5e1a805523..f707bbdf91 100644 --- a/onnxruntime/featurizers_ops/cpu/truncated_svd_transformer.cc +++ b/onnxruntime/featurizers_ops/cpu/truncated_svd_transformer.cc @@ -25,7 +25,7 @@ struct TruncatedSVDTransformerImpl { const auto* state_tensor(ctx->Input(0)); const uint8_t* const state_data(state_tensor->Data()); - Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().GetDims()[0]); + Microsoft::Featurizer::Archive archive(state_data, state_tensor->Shape().Size()); return Microsoft::Featurizer::Featurizers::TruncatedSVDTransformer(archive); }()); @@ -47,10 +47,15 @@ struct TruncatedSVDTransformerImpl { Eigen::Map output_matrix(output_data, dim_0, dim_1); std::function callback; - callback = [&output_matrix](MatrixT val) { + bool callback_allow = true; + callback = [&output_matrix, callback_allow](MatrixT val) { + ORT_ENFORCE(callback_allow, "callback function can only be called during execute() and special flush() when needed"); output_matrix = val; }; transformer.execute(input_matrix, callback); + // The flush() does nothing but shows Featurizers concept + callback_allow = false; + transformer.flush(callback); } }; diff --git a/onnxruntime/test/onnx/main.cc b/onnxruntime/test/onnx/main.cc index 9d1b76969b..332e083cc0 100644 --- a/onnxruntime/test/onnx/main.cc +++ b/onnxruntime/test/onnx/main.cc @@ -662,6 +662,18 @@ int real_main(int argc, char* argv[], Ort::Env& env) { broken_tests.insert({"dynamic_slice_end_out_of_bounds", "This model uses contrib ops."}); broken_tests.insert({"dynamic_slice_neg", "This model uses contrib ops."}); broken_tests.insert({"mvn", "This model uses contrib ops.", {"onnx130"}}); + broken_tests.insert({"cdist_float32_euclidean_1000_2000_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float32_euclidean_1000_2000_500", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float32_euclidean_1_1_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float32_sqeuclidean_1000_2000_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float32_sqeuclidean_1000_2000_500", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float32_sqeuclidean_1_1_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float64_euclidean_1000_2000_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float64_euclidean_1000_2000_500", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float64_euclidean_1_1_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float64_sqeuclidean_1000_2000_1", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float64_sqeuclidean_1000_2000_500", "This model uses contrib ops."}); + broken_tests.insert({"cdist_float64_sqeuclidean_1_1_1", "This model uses contrib ops."}); #endif int result = 0; diff --git a/onnxruntime/test/python/onnx_backend_test_series.py b/onnxruntime/test/python/onnx_backend_test_series.py index fb1eafca2c..c9469f86cf 100644 --- a/onnxruntime/test/python/onnx_backend_test_series.py +++ b/onnxruntime/test/python/onnx_backend_test_series.py @@ -172,7 +172,8 @@ def create_backend_test(testname=None): '^test_resize_downsample_scales_cubic_align_corners_cpu', # results mismatch with onnx tests '^test_resize_downsample_scales_linear_align_corners_cpu' # results mismatch with onnx tests ] - + if platform.architecture()[0] == '32bit': + current_failing_tests += ['^test_vgg19', '^test_zfnet512', '^test_bvlc_alexnet_cpu'] # Example of how to disable tests for a specific provider. # if c2.supports_device('NGRAPH'): # current_failing_tests.append('^test_operator_repeat_dim_overflow_cpu') diff --git a/onnxruntime/test/shared_lib/test_inference.cc b/onnxruntime/test/shared_lib/test_inference.cc index 51294e5dc0..37f1e68485 100644 --- a/onnxruntime/test/shared_lib/test_inference.cc +++ b/onnxruntime/test/shared_lib/test_inference.cc @@ -346,7 +346,7 @@ TEST(CApiTest, DISABLED_test_custom_op_library) { #elif defined(__APPLE__) lib_name = "libcustom_op_library.dylib"; #else - lib_name = "libcustom_op_library.so"; + lib_name = "./libcustom_op_library.so"; #endif TestInference(*ort_env, CUSTOM_OP_LIBRARY_TEST_MODEL_URI, inputs, "output", expected_dims_y, expected_values_y, 0, nullptr, lib_name.c_str()); @@ -509,37 +509,71 @@ TEST(CApiTest, end_profiling) { } TEST(CApiTest, model_metadata) { - Ort::MemoryInfo info("Cpu", OrtDeviceAllocator, 0, OrtMemTypeDefault); auto allocator = onnxruntime::make_unique(); - - // Create session - Ort::SessionOptions session_options; - Ort::Session session(*ort_env, MODEL_WITH_CUSTOM_MODEL_METADATA, session_options); - - // Fetch model metadata // The following all tap into the c++ APIs which internally wrap over C APIs - auto model_metadata = session.GetModelMetadata(); - char* producer_name = model_metadata.GetProducerName(allocator.get()); - ASSERT_TRUE(strcmp("Hari", producer_name) == 0); + // The following section tests a model containing all metadata supported via the APIs + { + Ort::SessionOptions session_options; + Ort::Session session(*ort_env, MODEL_WITH_CUSTOM_MODEL_METADATA, session_options); - char* graph_name = model_metadata.GetGraphName(allocator.get()); - ASSERT_TRUE(strcmp("matmul test", graph_name) == 0); + // Fetch model metadata + auto model_metadata = session.GetModelMetadata(); - char* domain = model_metadata.GetDomain(allocator.get()); - ASSERT_TRUE(strcmp("", domain) == 0); + char* producer_name = model_metadata.GetProducerName(allocator.get()); + ASSERT_TRUE(strcmp("Hari", producer_name) == 0); + allocator.get()->Free(producer_name); - char* description = model_metadata.GetDescription(allocator.get()); - ASSERT_TRUE(strcmp("This is a test model with a valid ORT config Json", description) == 0); + char* graph_name = model_metadata.GetGraphName(allocator.get()); + ASSERT_TRUE(strcmp("matmul test", graph_name) == 0); + allocator.get()->Free(graph_name); - int64_t version = model_metadata.GetVersion(); - ASSERT_TRUE(version == 1); + char* domain = model_metadata.GetDomain(allocator.get()); + ASSERT_TRUE(strcmp("", domain) == 0); + allocator.get()->Free(domain); - char* lookup_value = model_metadata.LookupCustomMetadataMap("ort_config", allocator.get()); - ASSERT_TRUE(strcmp(lookup_value, - "{\"session_options\": {\"inter_op_num_threads\": 5, \"intra_op_num_threads\": 2, \"graph_optimization_level\": 99, \"enable_profiling\": 1}}") == 0); + char* description = model_metadata.GetDescription(allocator.get()); + ASSERT_TRUE(strcmp("This is a test model with a valid ORT config Json", description) == 0); + allocator.get()->Free(description); - // key doesn't exist in custom metadata map - lookup_value = model_metadata.LookupCustomMetadataMap("key_doesnt_exist", allocator.get()); - ASSERT_TRUE(lookup_value == nullptr); + int64_t version = model_metadata.GetVersion(); + ASSERT_TRUE(version == 1); + + int64_t num_keys_in_custom_metadata_map; + char** custom_metadata_map_keys = model_metadata.GetCustomMetadataMapKeys(allocator.get(), num_keys_in_custom_metadata_map); + ASSERT_TRUE(num_keys_in_custom_metadata_map == 1); + ASSERT_TRUE(strcmp(custom_metadata_map_keys[0], "ort_config") == 0); + allocator.get()->Free(custom_metadata_map_keys[0]); + allocator.get()->Free(custom_metadata_map_keys); + + char* lookup_value = model_metadata.LookupCustomMetadataMap("ort_config", allocator.get()); + ASSERT_TRUE(strcmp(lookup_value, + "{\"session_options\": {\"inter_op_num_threads\": 5, \"intra_op_num_threads\": 2, \"graph_optimization_level\": 99, \"enable_profiling\": 1}}") == 0); + allocator.get()->Free(lookup_value); + + // key doesn't exist in custom metadata map + lookup_value = model_metadata.LookupCustomMetadataMap("key_doesnt_exist", allocator.get()); + ASSERT_TRUE(lookup_value == nullptr); + } + + // The following section tests a model with some missing metadata info + // Adding this just to make sure the API implementation is able to handle empty/missing info + { + Ort::SessionOptions session_options; + Ort::Session session(*ort_env, MODEL_URI, session_options); + + // Fetch model metadata + auto model_metadata = session.GetModelMetadata(); + + // Model description is empty + char* description = model_metadata.GetDescription(allocator.get()); + ASSERT_TRUE(strcmp("", description) == 0); + allocator.get()->Free(description); + + // Model does not contain custom metadata map + int64_t num_keys_in_custom_metadata_map; + char** custom_metadata_map_keys = model_metadata.GetCustomMetadataMapKeys(allocator.get(), num_keys_in_custom_metadata_map); + ASSERT_TRUE(num_keys_in_custom_metadata_map == 0); + ASSERT_TRUE(custom_metadata_map_keys == nullptr); + } } diff --git a/tools/ci_build/github/azure-pipelines/azure-pipelines-py-packaging.yml b/tools/ci_build/github/azure-pipelines/azure-pipelines-py-packaging.yml index 57b0c96972..36998f5f17 100644 --- a/tools/ci_build/github/azure-pipelines/azure-pipelines-py-packaging.yml +++ b/tools/ci_build/github/azure-pipelines/azure-pipelines-py-packaging.yml @@ -1,8 +1,11 @@ -parameters: -- name: is_featurizers_build - displayName: "Is Featurizers Build" - type: boolean - default: false +# Note that any variable set in this file overrides a value set within the Azure pipeline UX. +# Therefore, do not set default values here, but instead do it within a template script. +# +# parameters: +# - name: is_featurizers_build +# displayName: "Is Featurizers Build" +# type: boolean +# default: false jobs: - job: Manylinux2010_py_Wheels @@ -36,7 +39,7 @@ jobs: - template: templates/set-featurizer-build-flag-step.yml parameters: - is_featurizers_build: ${{ parameters.is_featurizers_build }} + is_featurizers_build: $(is_featurizers_build) - task: CmdLine@2 displayName: 'Download azcopy' @@ -111,7 +114,7 @@ jobs: - template: templates/set-featurizer-build-flag-step.yml parameters: - is_featurizers_build: ${{ parameters.is_featurizers_build }} + is_featurizers_build: $(is_featurizers_build) - task: CmdLine@2 displayName: 'Download azcopy' @@ -193,7 +196,7 @@ jobs: - template: templates/set-featurizer-build-flag-step.yml parameters: - is_featurizers_build: ${{ parameters.is_featurizers_build }} + is_featurizers_build: $(is_featurizers_build) - task: BatchScript@1 displayName: 'setup env' @@ -284,7 +287,7 @@ jobs: - template: templates/set-featurizer-build-flag-step.yml parameters: - is_featurizers_build: ${{ parameters.is_featurizers_build }} + is_featurizers_build: $(is_featurizers_build) - task: PythonScript@0 displayName: 'Download test data' @@ -336,6 +339,10 @@ jobs: clean: true submodules: recursive + - template: templates/set-featurizer-build-flag-step.yml + parameters: + is_featurizers_build: $(is_featurizers_build) + - task: UsePythonVersion@0 displayName: 'Use Python' inputs: @@ -344,7 +351,7 @@ jobs: - script: | sudo python -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt' sudo xcode-select --switch /Applications/Xcode_10.app/Contents/Developer - ./build.sh --config Release --skip_submodule_sync --parallel --build_wheel --use_openmp + ./build.sh --config Release --skip_submodule_sync --parallel --build_wheel --use_openmp $(FeaturizerBuildFlag) displayName: 'Command Line Script' - task: CopyFiles@2 diff --git a/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml index 12d301481c..d38d683bce 100644 --- a/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-ci-pipeline.yml @@ -38,6 +38,15 @@ jobs: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' + - powershell: | + $Env:USE_MSVC_STATIC_RUNTIME=1 + $Env:ONNX_ML=1 + $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" + python setup.py bdist_wheel + Get-ChildItem -Path dist/*.whl | foreach {pip install --upgrade $_.fullname} + workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + displayName: 'Install ONNX' + - task: NuGetToolInstaller@0 displayName: Use Nuget 4.9 inputs: diff --git a/tools/ci_build/github/azure-pipelines/win-nocontribops-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-nocontribops-ci-pipeline.yml index 8eeb6592d0..1e2c0853ce 100644 --- a/tools/ci_build/github/azure-pipelines/win-nocontribops-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-nocontribops-ci-pipeline.yml @@ -37,7 +37,16 @@ jobs: python -m pip install -q pyopenssl setuptools wheel numpy workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - + + - powershell: | + $Env:USE_MSVC_STATIC_RUNTIME=1 + $Env:ONNX_ML=1 + $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" + python setup.py bdist_wheel + Get-ChildItem -Path dist/*.whl | foreach {pip install --upgrade $_.fullname} + workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + displayName: 'Install ONNX' + - task: PythonScript@0 displayName: 'Generate cmake config' inputs: diff --git a/tools/ci_build/github/azure-pipelines/win-x86-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-x86-ci-pipeline.yml index 8e2930315f..000c90aa0a 100644 --- a/tools/ci_build/github/azure-pipelines/win-x86-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-x86-ci-pipeline.yml @@ -38,6 +38,15 @@ jobs: workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' + - powershell: | + $Env:USE_MSVC_STATIC_RUNTIME=1 + $Env:ONNX_ML=1 + $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" + python setup.py bdist_wheel + Get-ChildItem -Path dist/*.whl | foreach {pip install --upgrade $_.fullname} + workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + displayName: 'Install ONNX' + - task: PythonScript@0 displayName: 'Generate cmake config' inputs: diff --git a/tools/ci_build/github/azure-pipelines/win-x86-nocontribops-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/win-x86-nocontribops-ci-pipeline.yml index 8a866e9f8b..7824f33bdf 100644 --- a/tools/ci_build/github/azure-pipelines/win-x86-nocontribops-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/win-x86-nocontribops-ci-pipeline.yml @@ -37,7 +37,16 @@ jobs: python -m pip install -q pyopenssl setuptools wheel numpy workingDirectory: '$(Build.BinariesDirectory)' displayName: 'Install python modules' - + + - powershell: | + $Env:USE_MSVC_STATIC_RUNTIME=1 + $Env:ONNX_ML=1 + $Env:CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=OFF -DProtobuf_USE_STATIC_LIBS=ON -DONNX_USE_LITE_PROTO=ON -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=$(buildArch)-windows-static" + python setup.py bdist_wheel + Get-ChildItem -Path dist/*.whl | foreach {pip install --upgrade $_.fullname} + workingDirectory: '$(Build.SourcesDirectory)\cmake\external\onnx' + displayName: 'Install ONNX' + - task: PythonScript@0 displayName: 'Generate cmake config' inputs: