PyTorch C++ Extensions: Accessing data for Half Tensors
I'm trying to write a C++/CUDA extension for PyTorch using the C++ Tensor API, and I would like my code to work with both float32 and float16 (half precision). I'm not sure how to access the data pointer for half tensors coming from Python.

Here's how I do it for float tensors:

// Access data pointer for float Tensor A
torch::Tensor A;
float* ptr = A.data&lt;float&gt;();


Here's what I've tried for half tensors:

// CUDA float 16 type
// undefined symbol: _ZNK2at6Tensor4dataI6__halfEEPT_v
A.data&lt;__half&gt;();

// PyTorch float16 type
// error: no instance of function template "at::Tensor::data" 
A.data&lt;torch::ScalarType::Half&gt;();

// Casting to __half*
// This compiles but throws and error if the requested pointer type doesn't match the Tensor type:
// RuntimeError: expected scalar type Float but found Half
(__half*)(A.data&lt;float&gt;());


I tried looking into the C++ api source code, but couldn't find anything else that looks like a float16 type.

System information:
Python 3.6.2
PyTorch 1.0.1

The correct type turned out to be at::Half.
