diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_api.h b/include/onnxruntime/core/session/onnxruntime_cxx_api.h index 1c48a68aa7..2d5461346f 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_api.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_api.h @@ -403,13 +403,6 @@ struct ModelMetadata : Base { explicit ModelMetadata(std::nullptr_t) {} ///< Create an empty ModelMetadata object, must be assigned a valid one to be used explicit ModelMetadata(OrtModelMetadata* p) : Base{p} {} ///< Used for interop with the C API - /** \deprecated use GetProducerNameAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetProducerName(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetProducerName - /** \brief Returns a copy of the producer name. * * \param allocator to allocate memory for the copy of the name returned @@ -418,13 +411,6 @@ struct ModelMetadata : Base { */ AllocatedStringPtr GetProducerNameAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetProducerName - /** \deprecated use GetGraphNameAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetGraphName(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetGraphName - /** \brief Returns a copy of the graph name. * * \param allocator to allocate memory for the copy of the name returned @@ -433,13 +419,6 @@ struct ModelMetadata : Base { */ AllocatedStringPtr GetGraphNameAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetGraphName - /** \deprecated use GetDomainAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetDomain(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetDomain - /** \brief Returns a copy of the domain name. * * \param allocator to allocate memory for the copy of the name returned @@ -448,13 +427,6 @@ struct ModelMetadata : Base { */ AllocatedStringPtr GetDomainAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetDomain - /** \deprecated use GetDescriptionAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetDescription(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetDescription - /** \brief Returns a copy of the description. * * \param allocator to allocate memory for the copy of the string returned @@ -463,13 +435,6 @@ struct ModelMetadata : Base { */ AllocatedStringPtr GetDescriptionAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetDescription - /** \deprecated use GetGraphDescriptionAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetGraphDescription(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetGraphDescription - /** \brief Returns a copy of the graph description. * * \param allocator to allocate memory for the copy of the string returned @@ -478,22 +443,14 @@ struct ModelMetadata : Base { */ AllocatedStringPtr GetGraphDescriptionAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetGraphDescription - /** \deprecated use GetCustomMetadataMapKeysAllocated() - * [[deprecated]] - * This interface produces multiple pointers that must be released - * by the specified allocator and is often leaked. Not exception safe. + /** \brief Returns a vector of copies of the custom metadata keys. + * + * \param allocator to allocate memory for the copy of the string returned + * \return a instance std::vector of smart pointers that would deallocate the buffers when out of scope. + * The OrtAllocator instance must be valid at the point of memory release. */ - char** GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const; ///< Wraps OrtApi::ModelMetadataGetCustomMetadataMapKeys - std::vector GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataGetCustomMetadataMapKeys - /** \deprecated use LookupCustomMetadataMapAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const; ///< Wraps OrtApi::ModelMetadataLookupCustomMetadataMap - /** \brief Looks up a value by a key in the Custom Metadata map * * \param key zero terminated string key to lookup @@ -551,13 +508,6 @@ struct Session : Base { size_t GetOutputCount() const; ///< Returns the number of model outputs size_t GetOverridableInitializerCount() const; ///< Returns the number of inputs that have defaults that can be overridden - /** \deprecated use GetInputNameAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetInputName(size_t index, OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionGetInputName - /** \brief Returns a copy of input name at the specified index. * * \param index must less than the value returned by GetInputCount() @@ -567,13 +517,6 @@ struct Session : Base { */ AllocatedStringPtr GetInputNameAllocated(size_t index, OrtAllocator* allocator) const; - /** \deprecated use GetOutputNameAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetOutputName(size_t index, OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionGetOutputName - /** \brief Returns a copy of output name at then specified index. * * \param index must less than the value returned by GetOutputCount() @@ -583,13 +526,6 @@ struct Session : Base { */ AllocatedStringPtr GetOutputNameAllocated(size_t index, OrtAllocator* allocator) const; - /** \deprecated use GetOverridableInitializerNameAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* GetOverridableInitializerName(size_t index, OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionGetOverridableInitializerName - /** \brief Returns a copy of the overridable initializer name at then specified index. * * \param index must less than the value returned by GetOverridableInitializerCount() @@ -599,13 +535,6 @@ struct Session : Base { */ AllocatedStringPtr GetOverridableInitializerNameAllocated(size_t index, OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionGetOverridableInitializerName - /** \deprecated use EndProfilingAllocated() - * [[deprecated]] - * This interface produces a pointer that must be released - * by the specified allocator and is often leaked. Not exception safe. - */ - char* EndProfiling(OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionEndProfiling - /** \brief Returns a copy of the profiling file name. * * \param allocator to allocate memory for the copy of the string returned diff --git a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h index e47c43c4a5..f9e20bc57a 100644 --- a/include/onnxruntime/core/session/onnxruntime_cxx_inline.h +++ b/include/onnxruntime/core/session/onnxruntime_cxx_inline.h @@ -650,18 +650,6 @@ inline size_t Session::GetOverridableInitializerCount() const { return out; } -inline char* Session::GetInputName(size_t index, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionGetInputName(p_, index, allocator, &out)); - return out; -} - -inline char* Session::GetOutputName(size_t index, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionGetOutputName(p_, index, allocator, &out)); - return out; -} - inline AllocatedStringPtr Session::GetInputNameAllocated(size_t index, OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().SessionGetInputName(p_, index, allocator, &out)); @@ -674,24 +662,12 @@ inline AllocatedStringPtr Session::GetOutputNameAllocated(size_t index, OrtAlloc return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* Session::GetOverridableInitializerName(size_t index, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionGetOverridableInitializerName(p_, index, allocator, &out)); - return out; -} - inline AllocatedStringPtr Session::GetOverridableInitializerNameAllocated(size_t index, OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().SessionGetOverridableInitializerName(p_, index, allocator, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* Session::EndProfiling(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().SessionEndProfiling(p_, allocator, &out)); - return out; -} - inline AllocatedStringPtr Session::EndProfilingAllocated(OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().SessionEndProfiling(p_, allocator, &out)); @@ -710,84 +686,42 @@ inline ModelMetadata Session::GetModelMetadata() const { return ModelMetadata{out}; } -inline char* ModelMetadata::GetProducerName(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetProducerName(p_, allocator, &out)); - return out; -} - inline AllocatedStringPtr ModelMetadata::GetProducerNameAllocated(OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().ModelMetadataGetProducerName(p_, allocator, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* ModelMetadata::GetGraphName(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetGraphName(p_, allocator, &out)); - return out; -} - inline AllocatedStringPtr ModelMetadata::GetGraphNameAllocated(OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().ModelMetadataGetGraphName(p_, allocator, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* ModelMetadata::GetDomain(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetDomain(p_, allocator, &out)); - return out; -} - inline AllocatedStringPtr ModelMetadata::GetDomainAllocated(OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().ModelMetadataGetDomain(p_, allocator, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* ModelMetadata::GetDescription(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetDescription(p_, allocator, &out)); - return out; -} - inline AllocatedStringPtr Ort::ModelMetadata::GetDescriptionAllocated(OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().ModelMetadataGetDescription(p_, allocator, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* ModelMetadata::GetGraphDescription(OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataGetGraphDescription(p_, allocator, &out)); - return out; -} - inline AllocatedStringPtr ModelMetadata::GetGraphDescriptionAllocated(OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().ModelMetadataGetGraphDescription(p_, allocator, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char* ModelMetadata::LookupCustomMetadataMap(const char* key, OrtAllocator* allocator) const { - char* out; - ThrowOnError(GetApi().ModelMetadataLookupCustomMetadataMap(p_, allocator, key, &out)); - return out; -} - inline AllocatedStringPtr ModelMetadata::LookupCustomMetadataMapAllocated(const char* key, OrtAllocator* allocator) const { char* out; ThrowOnError(GetApi().ModelMetadataLookupCustomMetadataMap(p_, allocator, key, &out)); return AllocatedStringPtr(out, detail::AllocatedFree(allocator)); } -inline char** ModelMetadata::GetCustomMetadataMapKeys(OrtAllocator* allocator, _Out_ int64_t& num_keys) const { - char** out; - ThrowOnError(GetApi().ModelMetadataGetCustomMetadataMapKeys(p_, allocator, &out, &num_keys)); - return out; -} - inline std::vector ModelMetadata::GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const { auto deletor = detail::AllocatedFree(allocator); std::vector result; diff --git a/js/node/src/inference_session_wrap.cc b/js/node/src/inference_session_wrap.cc index 2ead506583..78f32ec092 100644 --- a/js/node/src/inference_session_wrap.cc +++ b/js/node/src/inference_session_wrap.cc @@ -83,7 +83,8 @@ Napi::Value InferenceSessionWrap::LoadModel(const Napi::CallbackInfo &info) { size_t count = session_->GetInputCount(); inputNames_.reserve(count); for (size_t i = 0; i < count; i++) { - inputNames_.emplace_back(session_->GetInputName(i, allocator)); + auto inp_name = session_->GetInputNameAllocated(i, allocator); + inputNames_.emplace_back(inp_name.get()); auto typeInfo = session_->GetInputTypeInfo(i); auto onnxType = typeInfo.GetONNXType(); inputTypes_.emplace_back(onnxType); @@ -95,7 +96,8 @@ Napi::Value InferenceSessionWrap::LoadModel(const Napi::CallbackInfo &info) { count = session_->GetOutputCount(); outputNames_.reserve(count); for (size_t i = 0; i < count; i++) { - outputNames_.emplace_back(session_->GetOutputName(i, allocator)); + auto out_name = session_->GetOutputNameAllocated(i, allocator); + outputNames_.emplace_back(out_name.get()); auto typeInfo = session_->GetOutputTypeInfo(i); auto onnxType = typeInfo.GetONNXType(); outputTypes_.emplace_back(onnxType); diff --git a/js/react_native/ios/OnnxruntimeModule.mm b/js/react_native/ios/OnnxruntimeModule.mm index ab56fd3438..fe7bf48c74 100644 --- a/js/react_native/ios/OnnxruntimeModule.mm +++ b/js/react_native/ios/OnnxruntimeModule.mm @@ -12,9 +12,10 @@ struct SessionInfo { std::unique_ptr session; - std::vector allocations; std::vector inputNames; + std::vector inputNames_ptrs; std::vector outputNames; + std::vector outputNames_ptrs; }; static Ort::Env *ortEnv = new Ort::Env(ORT_LOGGING_LEVEL_INFO, "Default"); @@ -90,16 +91,16 @@ RCT_EXPORT_METHOD(run sessionInfo->inputNames.reserve(sessionInfo->session->GetInputCount()); for (size_t i = 0; i < sessionInfo->session->GetInputCount(); ++i) { - auto inputName = sessionInfo->session->GetInputName(i, ortAllocator); - sessionInfo->allocations.emplace_back(ortAllocator, inputName, strlen(inputName) + 1); - sessionInfo->inputNames.emplace_back(inputName); + auto inputName = sessionInfo->session->GetInputNameAllocated(i, ortAllocator); + sessionInfo->inputNames.emplace_back(inputName.get()); + sessionInfo->inputNames_ptrs.emplace_back(std::move(inputName)); } sessionInfo->outputNames.reserve(sessionInfo->session->GetOutputCount()); for (size_t i = 0; i < sessionInfo->session->GetOutputCount(); ++i) { - auto outputName = sessionInfo->session->GetOutputName(i, ortAllocator); - sessionInfo->allocations.emplace_back(ortAllocator, outputName, strlen(outputName) + 1); - sessionInfo->outputNames.emplace_back(outputName); + auto outputName = sessionInfo->session->GetOutputNameAllocated(i, ortAllocator); + sessionInfo->outputNames.emplace_back(outputName.get()); + sessionInfo->outputNames_ptrs.emplace_back(std::move(outputName)); } value = [NSValue valueWithPointer:(void *)sessionInfo]; diff --git a/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm b/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm index 08621360c7..ad7606c7f8 100644 --- a/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm +++ b/js/react_native/ios/OnnxruntimeModuleTest/TensorHelperTest.mm @@ -5,6 +5,7 @@ #import #import +#include @interface TensorHelperTest : XCTestCase @@ -142,27 +143,29 @@ static void testCreateOutputTensorT(const std::array &outValues, std::func NSBundle *bundle = [NSBundle bundleForClass:[TensorHelperTest class]]; NSString *dataPath = [bundle pathForResource:testDataFileName ofType:testDataFileExtension]; - std::unique_ptr ortEnv{new Ort::Env(ORT_LOGGING_LEVEL_INFO, "Default")}; + Ort::Env ortEnv{ORT_LOGGING_LEVEL_INFO, "Default"}; Ort::SessionOptions sessionOptions; - std::unique_ptr session{new Ort::Session(*ortEnv, [dataPath UTF8String], sessionOptions)}; + Ort::Session session{ortEnv, [dataPath UTF8String], sessionOptions}; Ort::AllocatorWithDefaultOptions ortAllocator; - std::vector allocations; + std::vector names; + + names.reserve(session.GetInputCount() + session.GetOutputCount()); std::vector inputNames; - inputNames.reserve(session->GetInputCount()); - for (size_t i = 0; i < session->GetInputCount(); ++i) { - auto inputName = session->GetInputName(i, ortAllocator); - allocations.emplace_back(ortAllocator, inputName, strlen(inputName) + 1); - inputNames.emplace_back(inputName); + inputNames.reserve(session.GetInputCount()); + for (size_t i = 0; i < session.GetInputCount(); ++i) { + auto inputName = session.GetInputNameAllocated(i, ortAllocator); + inputNames.emplace_back(inputName.get()); + names.emplace_back(std::move(inputName)); } std::vector outputNames; - outputNames.reserve(session->GetOutputCount()); - for (size_t i = 0; i < session->GetOutputCount(); ++i) { - auto outputName = session->GetOutputName(i, ortAllocator); - allocations.emplace_back(ortAllocator, outputName, strlen(outputName) + 1); - outputNames.emplace_back(outputName); + outputNames.reserve(session.GetOutputCount()); + for (size_t i = 0; i < session.GetOutputCount(); ++i) { + auto outputName = session.GetOutputNameAllocated(i, ortAllocator); + outputNames.emplace_back(outputName.get()); + names.emplace_back(std::move(outputName)); } NSMutableDictionary *inputTensorMap = [NSMutableDictionary dictionary]; @@ -185,7 +188,7 @@ static void testCreateOutputTensorT(const std::array &outValues, std::func NSString *dataEncoded = [byteBufferRef base64EncodedStringWithOptions:0]; inputTensorMap[@"data"] = dataEncoded; - + std::vector allocations; Ort::Value inputTensor = [TensorHelper createInputTensor:inputTensorMap ortAllocator:ortAllocator allocations:allocations]; @@ -194,8 +197,8 @@ static void testCreateOutputTensorT(const std::array &outValues, std::func feeds.emplace_back(std::move(inputTensor)); Ort::RunOptions runOptions; - auto output = session->Run(runOptions, inputNames.data(), feeds.data(), inputNames.size(), outputNames.data(), - outputNames.size()); + auto output = session.Run(runOptions, inputNames.data(), feeds.data(), inputNames.size(), outputNames.data(), + outputNames.size()); NSDictionary *resultMap = [TensorHelper createOutputTensor:outputNames values:output]; diff --git a/objectivec/src/ort_session.mm b/objectivec/src/ort_session.mm index f801740f15..f23c5367fb 100644 --- a/objectivec/src/ort_session.mm +++ b/objectivec/src/ort_session.mm @@ -168,25 +168,21 @@ NS_ASSUME_NONNULL_BEGIN auto getName = [&session = *_session, namedValueType](size_t i, OrtAllocator* allocator) { if (namedValueType == NamedValueType::Input) { - return session.GetInputName(i, allocator); + return session.GetInputNameAllocated(i, allocator); } else if (namedValueType == NamedValueType::OverridableInitializer) { - return session.GetOverridableInitializerName(i, allocator); + return session.GetOverridableInitializerNameAllocated(i, allocator); } else { - return session.GetOutputName(i, allocator); + return session.GetOutputNameAllocated(i, allocator); } }; const size_t nameCount = getCount(); Ort::AllocatorWithDefaultOptions allocator; - auto deleter = [ortAllocator = static_cast(allocator)](void* p) { - ortAllocator->Free(ortAllocator, p); - }; - NSMutableArray* result = [NSMutableArray arrayWithCapacity:nameCount]; for (size_t i = 0; i < nameCount; ++i) { - auto name = std::unique_ptr{getName(i, allocator), deleter}; + auto name = getName(i, allocator); NSString* nameNsstr = [NSString stringWithUTF8String:name.get()]; NSAssert(nameNsstr != nil, @"nameNsstr must not be nil"); [result addObject:nameNsstr]; diff --git a/onnxruntime/python/tools/tensorrt/perf/mem_test/main.cpp b/onnxruntime/python/tools/tensorrt/perf/mem_test/main.cpp index 74ee766190..6f3468f88d 100644 --- a/onnxruntime/python/tools/tensorrt/perf/mem_test/main.cpp +++ b/onnxruntime/python/tools/tensorrt/perf/mem_test/main.cpp @@ -67,6 +67,7 @@ void run_ort_trt2() { // print number of model input nodes size_t num_input_nodes = session.GetInputCount(); + std::vector input_node_names_ptr; std::vector input_node_names(num_input_nodes); std::vector input_node_dims; // simplify... this model has only 1 input node {1, 3, 224, 224}. // Otherwise need vector> @@ -76,9 +77,10 @@ void run_ort_trt2() { // iterate over all input nodes for (int i = 0; i < num_input_nodes; i++) { // print input node names - char* input_name = session.GetInputName(i, allocator); - printf("Input %d : name=%s\n", i, input_name); - input_node_names[i] = input_name; + auto input_name = session.GetInputNameAllocated(i, allocator); + printf("Input %d : name=%s\n", i, input_name.get()); + input_node_names[i] = input_name.get(); + input_node_names_ptr.push_back(std::move(input_name)); // print input node types Ort::TypeInfo type_info = session.GetInputTypeInfo(i); @@ -192,6 +194,7 @@ void ort_trt_run_with_default_options() { // print number of model input nodes size_t num_input_nodes = session.GetInputCount(); + std::vector input_node_names_ptr; std::vector input_node_names(num_input_nodes); std::vector input_node_dims; // simplify... this model has only 1 input node {1, 3, 224, 224}. // Otherwise need vector> @@ -201,9 +204,10 @@ void ort_trt_run_with_default_options() { // iterate over all input nodes for (int i = 0; i < num_input_nodes; i++) { // print input node names - char* input_name = session.GetInputName(i, allocator); - printf("Input %d : name=%s\n", i, input_name); - input_node_names[i] = input_name; + auto input_name = session.GetInputNameAllocated(i, allocator); + printf("Input %d : name=%s\n", i, input_name.get()); + input_node_names[i] = input_name.get(); + input_node_names_ptr.push_back(std::move(input_name)); // print input node types Ort::TypeInfo type_info = session.GetInputTypeInfo(i); @@ -308,6 +312,7 @@ void run_ort_trt() { // print number of model input nodes size_t num_input_nodes = session.GetInputCount(); + std::vector input_node_names_ptr; std::vector input_node_names(num_input_nodes); std::vector input_node_dims; // simplify... this model has only 1 input node {1, 3, 224, 224}. // Otherwise need vector> @@ -317,9 +322,10 @@ void run_ort_trt() { // iterate over all input nodes for (int i = 0; i < num_input_nodes; i++) { // print input node names - char* input_name = session.GetInputName(i, allocator); - printf("Input %d : name=%s\n", i, input_name); - input_node_names[i] = input_name; + auto input_name = session.GetInputNameAllocated(i, allocator); + printf("Input %d : name=%s\n", i, input_name.get()); + input_node_names[i] = input_name.get(); + input_node_names_ptr.push_back(std::move(input_name)); // print input node types Ort::TypeInfo type_info = session.GetInputTypeInfo(i); diff --git a/onnxruntime/test/fuzzing/include/OnnxPrediction.h b/onnxruntime/test/fuzzing/include/OnnxPrediction.h index 687614af91..02ae9fa48b 100644 --- a/onnxruntime/test/fuzzing/include/OnnxPrediction.h +++ b/onnxruntime/test/fuzzing/include/OnnxPrediction.h @@ -155,10 +155,14 @@ class OnnxPrediction { // std::vector input_names; + std::vector input_names_ptrs; + // Stores the output names // std::vector output_names; + std::vector output_names_ptrs; + // Create a list of output values // std::vector output_values{}; diff --git a/onnxruntime/test/fuzzing/src/OnnxPrediction.cpp b/onnxruntime/test/fuzzing/src/OnnxPrediction.cpp index fa52089f71..ce1e66cc7d 100644 --- a/onnxruntime/test/fuzzing/src/OnnxPrediction.cpp +++ b/onnxruntime/test/fuzzing/src/OnnxPrediction.cpp @@ -145,7 +145,8 @@ void OnnxPrediction::init() { // for (int i = 0; i < ptr_session->GetInputCount(); i++) { // TODO Use push_back on input_names instead of assignment - input_names[i] = ptr_session->GetInputName(i, alloc); + input_names_ptrs.push_back(ptr_session->GetInputNameAllocated(i, alloc)); + input_names[i] = input_names_ptrs.back().get(); input_values.emplace_back(nullptr); } @@ -153,7 +154,8 @@ void OnnxPrediction::init() { // for (int i = 0; i < ptr_session->GetOutputCount(); i++) { // TODO Use push_back on output_names instead of assignment - output_names[i] = ptr_session->GetOutputName(i, alloc); + output_names_ptrs.push_back(ptr_session->GetOutputNameAllocated(i, alloc)); + output_names[i] = output_names_ptrs.back().get(); output_values.emplace_back(nullptr); } }