How to Convert OpenCL code from FP32 to FP16?

1k views Asked by At

Is there a way to automatically convert a code that has been written to do FP32 calculations on a FP32 GPU, so it can do always FP16 calculations instead of FP32?

What I'm trying to achieve is to run a code for an old GPU (that doesn't support HALF Type), to run on a newer GPU that does - but without going through the code myself.

If not possible, please show me what documentations I should read to do it myself.

(New GPU is Radeon Vega Frontier, driver is ROCm 1.9.1, OS is Ubuntu 18.04)
(the code is extensive and composed by different modules. So I won't be posting it here, unless asked to)

1

There are 1 answers

2
Dithermaster On

No, there is no standard flag to say "treat float as half". You have to change float to half. Also, your device must support fp16 calculations (many don't, just fp16 storage that converts to/from fp32 when you load/store). The cl_khr_fp16 extension adds support for half scalar and vector types as built-in types that can be used for arithmetic operations. You'll need a #pragma in any kernels that use it.