It’s a bit clunky, but I believe simply: *reinterpret_cast<__half*>(&myathalf);
and *reinterpret_cast<at::Half*>(&myhalf);
would work. To convert pointers you would simply drop the dereference.
Thanks for your advice. Actually, we want to create atomicMax just in normal .cu file without at::Half defination. So, are there some ways to correctly replace at::Half by __half in above function?
I am not familiar with pytorch/Half.h at master but simple replacement would bring error class "__half" has no member "x"
unsigned int *address_as_ui = (unsigned int *)((char *)address - ((size_t)address & 2));
unsigned int old = *address_as_ui;
unsigned int assumed;
do {
assumed = old;
__half hsum;
hsum = reinterpret_cast<size_t>(address) & 2 ? (old >> 16) : (old & 0xffff);
hsum = __float2half(fmaxf(__half2float(hsum), __half2float(val)));
old = (size_t)address & 2 ? (old & 0xffff) | (hsum << 16)
: (old & 0xffff0000) | hsum;
old = atomicCAS(address_as_ui, assumed, old);
} while (assumed != old);
The error appears in two hsum in old calculation:
test.cu(57): error: more than one conversion function from "__half" to a built-in type applies:
function "__half::operator short() const"
/cuda-11.4/include/cuda_fp16.hpp(222): here
function "__half::operator unsigned short() const"
/cuda-11.4/include/cuda_fp16.hpp(225): here
function "__half::operator int() const"
/cuda-11.4/include/cuda_fp16.hpp(228): here
function "__half::operator unsigned int() const"
/cuda-11.4/include/cuda_fp16.hpp(231): here
function "__half::operator long long() const"
/cuda-11.4/include/cuda_fp16.hpp(234): here
function "__half::operator unsigned long long() const"
/cuda-11.4/include/cuda_fp16.hpp(237): here
function "__half::operator __nv_bool() const"
/cuda-11.4/include/cuda_fp16.hpp(241): here