mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Pull Request resolved: https://github.com/pytorch/pytorch/pull/155134 Approved by: https://github.com/kwen2501 Co-authored-by: Ke Wen <kw2501@meta.com>
31 lines
1.2 KiB
C++
31 lines
1.2 KiB
C++
#include <torch/csrc/python_headers.h>
|
|
|
|
#include <torch/csrc/jit/python/pybind_utils.h>
|
|
#include <torch/csrc/utils/device_lazy_init.h>
|
|
#include <torch/csrc/utils/pybind.h>
|
|
|
|
#include <c10/cuda/CUDACachingAllocator.h>
|
|
|
|
template <typename T>
|
|
using shared_ptr_class_ = py::class_<T, std::shared_ptr<T>>;
|
|
|
|
// NOLINTNEXTLINE(misc-use-internal-linkage)
|
|
void THCPMemPool_init(PyObject* module) {
|
|
auto torch_C_m = py::handle(module).cast<py::module>();
|
|
shared_ptr_class_<::c10::cuda::MemPool>(torch_C_m, "_MemPool")
|
|
.def(
|
|
py::init([](c10::cuda::CUDACachingAllocator::CUDAAllocator* allocator,
|
|
bool is_user_created,
|
|
bool use_on_oom,
|
|
bool symmetric) {
|
|
torch::utils::device_lazy_init(at::kCUDA);
|
|
return std::make_shared<::c10::cuda::MemPool>(
|
|
allocator, is_user_created, use_on_oom, symmetric);
|
|
}))
|
|
.def_property_readonly("id", &::c10::cuda::MemPool::id)
|
|
.def_property_readonly(
|
|
"is_symmetric", &::c10::cuda::MemPool::is_symmetric)
|
|
.def_property_readonly("allocator", &::c10::cuda::MemPool::allocator)
|
|
.def("use_count", &::c10::cuda::MemPool::use_count);
|
|
}
|