Open LeiWang1999 opened 2 years ago
Currently I rewrite the cuda::BatchNormNCHW::emit_function_body()
to solve this problem, But I think there's another solution, to reference cutlass code, implement operator overload of half datatype, for example:
https://github1s.com/NVIDIA/cutlass/blob/HEAD/include/cutlass/half.h#L805
CUTLASS_HOST_DEVICE
half_t operator/(half_t const& lhs, half_t const& rhs) {
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 530)
return half_t(__hdiv(lhs.to_half(), rhs.to_half()));
#else
return half_t(float(lhs) / float(rhs));
#endif
}
CUTLASS_HOST_DEVICE
half_t& operator+=(half_t & lhs, half_t const& rhs) {
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 530)
lhs = half_t(__hadd(lhs.to_half(), rhs.to_half()));
#else
lhs = half_t(float(lhs) + float(rhs));
#endif
return lhs;
}
CUTLASS_HOST_DEVICE
half_t& operator-=(half_t & lhs, half_t const& rhs) {
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 530)
lhs = half_t(__hsub(lhs.to_half(), rhs.to_half()));
#else
lhs = half_t(float(lhs) - float(rhs));
#endif
return lhs;
}
🐛 build cuda_codegen of densenet161-fp16.onnx failed
Now I can generate densenet161-fp32 and densenet161-fp16 cudacode and have a correct output, but for fp16, I got a builded failed issue, and the message is :
According to my research, this was caused by that cuda does't implement operator overload for datatype half :
It worked when I reconstruct the expression to below:
I'm now trying to figure it out.