mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/50843 AT_ASSERTM is deprecated and should be replaced by either TORCH_CHECK or TORCH_INTERNAL_ASSERT, depending on the situation. Test Plan: Imported from OSS Reviewed By: ailzhang Differential Revision: D26074365 Pulled By: ezyang fbshipit-source-id: 46e13588fad4e24828f3cc99635e9cb2223a6c2c
54 lines
1.7 KiB
C++
54 lines
1.7 KiB
C++
#include <c10/core/Allocator.h>
|
|
|
|
#include <c10/util/ThreadLocalDebugInfo.h>
|
|
|
|
namespace c10 {
|
|
|
|
static void deleteInefficientStdFunctionContext(void* ptr) {
|
|
delete static_cast<InefficientStdFunctionContext*>(ptr);
|
|
}
|
|
|
|
at::DataPtr InefficientStdFunctionContext::makeDataPtr(
|
|
void* ptr,
|
|
const std::function<void(void*)>& deleter,
|
|
Device device) {
|
|
return {ptr,
|
|
new InefficientStdFunctionContext({ptr, deleter}),
|
|
&deleteInefficientStdFunctionContext,
|
|
device};
|
|
}
|
|
|
|
C10_API at::Allocator* allocator_array[at::COMPILE_TIME_MAX_DEVICE_TYPES];
|
|
C10_API uint8_t allocator_priority[at::COMPILE_TIME_MAX_DEVICE_TYPES] = {0};
|
|
|
|
void SetAllocator(at::DeviceType t, at::Allocator* alloc, uint8_t priority) {
|
|
if (priority >= allocator_priority[static_cast<int>(t)]) {
|
|
allocator_array[static_cast<int>(t)] = alloc;
|
|
allocator_priority[static_cast<int>(t)] = priority;
|
|
}
|
|
}
|
|
|
|
at::Allocator* GetAllocator(const at::DeviceType& t) {
|
|
auto* alloc = allocator_array[static_cast<int>(t)];
|
|
TORCH_INTERNAL_ASSERT(alloc, "Allocator for ", t, " is not set.");
|
|
return alloc;
|
|
}
|
|
|
|
bool memoryProfilingEnabled() {
|
|
auto* reporter_ptr = static_cast<MemoryReportingInfoBase*>(
|
|
ThreadLocalDebugInfo::get(DebugInfoKind::PROFILER_STATE));
|
|
return reporter_ptr && reporter_ptr->memoryProfilingEnabled();
|
|
}
|
|
|
|
void reportMemoryUsageToProfiler(void* ptr, int64_t alloc_size, Device device) {
|
|
auto* reporter_ptr = static_cast<MemoryReportingInfoBase*>(
|
|
ThreadLocalDebugInfo::get(DebugInfoKind::PROFILER_STATE));
|
|
if (reporter_ptr) {
|
|
reporter_ptr->reportMemoryUsage(ptr, alloc_size, device);
|
|
}
|
|
}
|
|
|
|
MemoryReportingInfoBase::MemoryReportingInfoBase() {}
|
|
|
|
} // namespace c10
|