mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-22 22:01:08 +00:00
Fix memory leak when a Python list passed as a feed. Create a custom allocator that can take ownership of python arrays that are created inside pybind. Allow direct memory use if continuous array is a copy because we now can take ownership of it by the allocator.
40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#pragma once
|
|
|
|
#include <pybind11/iostream.h>
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/stl.h>
|
|
|
|
#include "core/common/logging/logging.h"
|
|
#include "core/common/logging/sinks/clog_sink.h"
|
|
#include "core/common/logging/sinks/cerr_sink.h"
|
|
#include "core/framework/allocatormgr.h"
|
|
#include "core/session/environment.h"
|
|
#include "core/framework/ml_value.h"
|
|
#include "core/session/inference_session.h"
|
|
|
|
namespace onnxruntime {
|
|
namespace python {
|
|
|
|
namespace py = pybind11;
|
|
|
|
int OnnxRuntimeTensorToNumpyType(const DataTypeImpl* tensor_type);
|
|
|
|
MLDataType NumpyTypeToOnnxRuntimeType(int numpy_type);
|
|
|
|
void CreateGenericMLValue(const onnxruntime::InputDefList* input_def_list, const AllocatorPtr& alloc, const std::string& name_input,
|
|
py::object& value, OrtValue* p_mlvalue);
|
|
|
|
template <class T>
|
|
struct DecRefFn {
|
|
void operator()(T* pyobject) const {
|
|
Py_XDECREF(pyobject);
|
|
}
|
|
};
|
|
|
|
template <class T>
|
|
using UniqueDecRefPtr = std::unique_ptr<T, DecRefFn<T>>;
|
|
} // namespace python
|
|
} // namespace onnxruntime
|