libtorch 如何获取张量设备类型?

how does libtorch get tensor device type?

libtorch有没有获取张量或模型设备类型的方法

就像pytorch中的xxx.device一样?

import torch
tensor = torch.rand(3,4)
print(tensor.device)

libtorch 旨在提供与 python 中几乎完全相同的 C++ 功能,因此如有疑问,您可以尝试:

#include <torch/torch.h>
torch::Tensor tensor = torch::rand({3,4});
std::cout << tensor.device() << std::endl;

情节扭曲:有效\o/