Files
pytorch/torch/csrc/Storage.cpp
Vitaly Fedyunin 5653a914f7 Implement reference counting for shared IPC CUDA tensors (#16854)
Summary:
This is to fix #16141 and similar issues.

The idea is to track a reference to every shared CUDA Storage and deallocate memory only after a consumer process deallocates received Storage.

ezyang Done with cleanup. Same (insignificantly better) performance as in file-per-share solution, but handles millions of shared tensors easily. Note [ ] documentation in progress.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16854

Differential Revision: D13994490

Pulled By: VitalyFedyunin

fbshipit-source-id: 565148ec3ac4fafb32d37fde0486b325bed6fbd1
2019-03-25 10:24:38 -07:00

36 lines
803 B
C++

#define __STDC_FORMAT_MACROS
#include <torch/csrc/python_headers.h>
#ifdef _MSC_VER
#include <Windows.h>
#endif
#include <structmember.h>
#define THP_HOST_HALF
#include <TH/TH.h>
// See Note [TH abstraction violation]
// - Used to get at the allocator associated with a storage
#include <TH/THStorageFunctions.hpp>
#include <libshm.h>
#include <torch/csrc/THP.h>
#include <torch/csrc/copy_utils.h>
#include <torch/csrc/DynamicTypes.h>
#include <torch/csrc/CudaIPCTypes.h>
#include <torch/csrc/generic/Storage.cpp>
#include <TH/THGenerateAllTypes.h>
#include <torch/csrc/generic/Storage.cpp>
#include <TH/THGenerateHalfType.h>
#include <torch/csrc/generic/Storage.cpp>
#include <TH/THGenerateBoolType.h>
template<>
void THPPointer<THStorage>::free() {
if (ptr) {
THStorage_free(ptr);
}
}