Hello,
I am starting to getting more accustomed with pytorch source code but I’ve recently hit a wall. I don’t quite understand C <-> CUDA <-> Python bindings yet I guess and that’s my problem here.
I just couldn’t find the source code of torch.empty function. Probably the easiest way to find it out is to ask
For PyTorch 1.17 or 1.18, do you know how the ‘empty(…)’ implemented?
I just found :
Tensor empty(
IntArrayRef size,
at::optional<DimnameList> names,
const TensorOptions& options,
optional<MemoryFormat> optional_memory_format) {
if (!names.has_value()) {
return at::empty(size, options, optional_memory_format);
}
TORCH_CHECK(options.layout() == Layout::Strided,
"NYI: named tensors only support strided layout");
TORCH_CHECK(options.device().is_cpu() || options.device().is_cuda(),
"NYI: named tensors only support CPU and CUDA tensors");
auto result = at::empty(size, options, optional_memory_format);
internal_set_names_inplace(result, names);
return result;
}