Skip to content

Commit

Permalink
Remove previously deprecated API (microsoft#12935)
Browse files Browse the repository at this point in the history
Remove previously deprecated API
Format JS code, address review comments
NPM Formatting
  • Loading branch information
yuslepukhin authored Sep 14, 2022
1 parent 1ef1029 commit bc2df1b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 186 deletions.
81 changes: 5 additions & 76 deletions include/onnxruntime/core/session/onnxruntime_cxx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,6 @@ struct ModelMetadata : Base<OrtModelMetadata> {
explicit ModelMetadata(std::nullptr_t) {} ///< Create an empty ModelMetadata object, must be assigned a valid one to be used
explicit ModelMetadata(OrtModelMetadata* p) : Base<OrtModelMetadata>{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
Expand All @@ -418,13 +411,6 @@ struct ModelMetadata : Base<OrtModelMetadata> {
*/
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
Expand All @@ -433,13 +419,6 @@ struct ModelMetadata : Base<OrtModelMetadata> {
*/
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
Expand All @@ -448,13 +427,6 @@ struct ModelMetadata : Base<OrtModelMetadata> {
*/
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
Expand All @@ -463,13 +435,6 @@ struct ModelMetadata : Base<OrtModelMetadata> {
*/
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
Expand All @@ -478,22 +443,14 @@ struct ModelMetadata : Base<OrtModelMetadata> {
*/
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<AllocatedStringPtr> 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
Expand Down Expand Up @@ -551,13 +508,6 @@ struct Session : Base<OrtSession> {
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()
Expand All @@ -567,13 +517,6 @@ struct Session : Base<OrtSession> {
*/
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()
Expand All @@ -583,13 +526,6 @@ struct Session : Base<OrtSession> {
*/
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()
Expand All @@ -599,13 +535,6 @@ struct Session : Base<OrtSession> {
*/
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
Expand Down
66 changes: 0 additions & 66 deletions include/onnxruntime/core/session/onnxruntime_cxx_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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<AllocatedStringPtr> ModelMetadata::GetCustomMetadataMapKeysAllocated(OrtAllocator* allocator) const {
auto deletor = detail::AllocatedFree(allocator);
std::vector<AllocatedStringPtr> result;
Expand Down
6 changes: 4 additions & 2 deletions js/node/src/inference_session_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions js/react_native/ios/OnnxruntimeModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ @implementation OnnxruntimeModule

struct SessionInfo {
std::unique_ptr<Ort::Session> session;
std::vector<Ort::MemoryAllocation> allocations;
std::vector<const char *> inputNames;
std::vector<Ort::AllocatedStringPtr> inputNames_ptrs;
std::vector<const char *> outputNames;
std::vector<Ort::AllocatedStringPtr> outputNames_ptrs;
};

static Ort::Env *ortEnv = new Ort::Env(ORT_LOGGING_LEVEL_INFO, "Default");
Expand Down Expand Up @@ -90,16 +91,16 @@ - (NSDictionary *)loadModel:(NSString *)modelPath options:(NSDictionary *)option

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];
Expand Down
Loading

0 comments on commit bc2df1b

Please sign in to comment.