MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / alloc

Method alloc

csrc/pin_memory/deepspeed_pin_tensor.cpp:42–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42torch::Tensor deepspeed_pin_tensor_t::alloc(const int64_t num_elem,
43 const torch::TensorOptions& options)
44{
45 const auto scalar_dtype = torch::typeMetaToScalarType(options.dtype());
46 const auto num_bytes = num_elem * torch::elementSize(scalar_dtype);
47 auto pinned_buffer = ds_page_aligned_alloc(num_bytes, true);
48 assert(nullptr != pinned_buffer);
49
50 {
51 std::lock_guard<std::mutex> guard(_mutex);
52 _locked_tensors[pinned_buffer] = num_bytes;
53 }
54
55 return at::from_blob(pinned_buffer, static_cast<int64_t>(num_elem), options);
56}
57
58torch::Tensor deepspeed_pin_tensor_t::alloc(const int64_t num_elem, const at::ScalarType& elem_type)
59{

Callers 3

new_cpu_locked_tensorMethod · 0.80
_alloc_bounce_bufferMethod · 0.80
new_cpu_locked_tensorMethod · 0.80

Calls 3

ds_page_aligned_allocFunction · 0.85
dtypeMethod · 0.45
deviceMethod · 0.45

Tested by

no test coverage detected