Fix regression in CustomOpApi::GetTensorData (#13450)

- Reverts change to CustomOpApi::GetTensorData introduced by commit 5dae0c477d,
which causes infinite recursion.
- Moves EndsProfilingAllocated to non-const session implementation
(C++ API header).
This commit is contained in:
Adrian Lizarraga 2022-10-31 12:20:49 -07:00 committed by GitHub
parent 2ecd1d6622
commit 9d867a07c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View file

@ -603,13 +603,6 @@ struct ConstSessionImpl : Base<T> {
*/
AllocatedStringPtr GetOverridableInitializerNameAllocated(size_t index, OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionGetOverridableInitializerName
/** \brief Returns a copy of the profiling file name.
*
* \param allocator to allocate memory for the copy of the string returned
* \return a instance of smart pointer that would deallocate the buffer when out of scope.
* The OrtAllocator instances must be valid at the point of memory release.
*/
AllocatedStringPtr EndProfilingAllocated(OrtAllocator* allocator) const; ///< Wraps OrtApi::SessionEndProfiling
uint64_t GetProfilingStartTimeNs() const; ///< Wraps OrtApi::SessionGetProfilingStartTimeNs
ModelMetadata GetModelMetadata() const; ///< Wraps OrtApi::SessionGetModelMetadata
@ -650,6 +643,14 @@ struct SessionImpl : ConstSessionImpl<T> {
const char* const* output_names, Value* output_values, size_t output_count);
void Run(const RunOptions& run_options, const IoBinding&); ///< Wraps OrtApi::RunWithBinding
/** \brief End profiling and return a copy of the profiling file name.
*
* \param allocator to allocate memory for the copy of the string returned
* \return a instance of smart pointer that would deallocate the buffer when out of scope.
* The OrtAllocator instances must be valid at the point of memory release.
*/
AllocatedStringPtr EndProfilingAllocated(OrtAllocator* allocator); ///< Wraps OrtApi::SessionEndProfiling
};
} // namespace detail

View file

@ -747,13 +747,6 @@ inline AllocatedStringPtr ConstSessionImpl<T>::GetOverridableInitializerNameAllo
return AllocatedStringPtr(out, detail::AllocatedFree(allocator));
}
template <typename T>
inline AllocatedStringPtr ConstSessionImpl<T>::EndProfilingAllocated(OrtAllocator* allocator) const {
char* out;
ThrowOnError(GetApi().SessionEndProfiling(this->p_, allocator, &out));
return AllocatedStringPtr(out, detail::AllocatedFree(allocator));
}
template <typename T>
inline uint64_t ConstSessionImpl<T>::GetProfilingStartTimeNs() const {
uint64_t out;
@ -814,6 +807,13 @@ inline void SessionImpl<T>::Run(const RunOptions& run_options, const IoBinding&
ThrowOnError(GetApi().RunWithBinding(this->p_, run_options, io_binding));
}
template <typename T>
inline AllocatedStringPtr SessionImpl<T>::EndProfilingAllocated(OrtAllocator* allocator) {
char* out = nullptr;
ThrowOnError(GetApi().SessionEndProfiling(this->p_, allocator, &out));
return AllocatedStringPtr(out, detail::AllocatedFree(allocator));
}
} // namespace detail
inline SessionOptions::SessionOptions() {
@ -1555,7 +1555,9 @@ inline const OrtMemoryInfo* CustomOpApi::GetTensorMemoryInfo(_In_ const OrtValue
template <typename T>
inline const T* CustomOpApi::GetTensorData(_Inout_ const OrtValue* value) {
return GetTensorData<T>(value);
T* data = nullptr;
Ort::ThrowOnError(api_.GetTensorMutableData(const_cast<OrtValue*>(value), reinterpret_cast<void**>(&data)));
return data;
}
inline std::vector<int64_t> CustomOpApi::GetTensorShape(const OrtTensorTypeAndShapeInfo* info) {