How can I interpret an at::Tensor as a different datatype? I’m doing RL, and I need to get quite a few tensors onto the GPU. Before, I could create one long empty float32 tensor in pinned memory, send it to the GPU when needed, and slice it, but this doesn’t work when mixing datatypes.
Basically, my question is how can I do this:
auto x = torch::empty({16}, torch::dtype(torch::kByte));
char *x_ptr = x.data_ptr<char>();
// write to x_ptr using other tensors...
auto x_gpu = x.to(torch::kCUDA);
auto a = x_gpu.slice(0, 0, 8)./* interpret as */(torch::kFloat16);
auto b = x_gpu.slice(0, 8, 16)./* interpret as */(torch::kFloat32);