[SOLVED] C++ example for OpenCL float16 calculation on Mali-T860

I convert the model and params to float16 format,

and set some parameters for float16 calculation.

int dtype_code = kDLFloat;
int dtype_bits = 16;
int dtype_lanes = 1;
int device_type = kDLOpenCL;
int device_id = 0;

then uses float2half and half2float for data conversion,

TVMArrayCopyFromBytes(x, data_x, total_inputsizeof(uint16_t));
TVMArrayCopyToBytes(y, data_y, total_output
sizeof(uint16_t));

float32 results are verified according to the example but the float16 results by above settings are wrong.

Could you have some guides?Thanks!

The correctness of fp16 in python is verified here https://github.com/merrymercy/tvm-mali/issues/3#issuecomment-371849500.

@qhou also verified fp16 on mali (in C++ API?). Maybe he can share some thoughts.

Yes, I also verified the correctness of our fp16 models in python.
We also need C++ API for deployment

It works now, there is something wrong with my float/half conversion functions.

Nice, you can also use these functions for float/half conversion.

We implemented float32 to float16 in assembly for aarch64. It works well.

@merrymercy Hi, can you elaborate how to call this function in C++? I have a float* a, and I assigned values to it. How should I copy these float32 data to a float16 DLTensor?

many thanks if there any help

you can use the function like:

        out[indexOut] = (int)(__gnu_h2f_ieee(*(outputData + indexOutputData)));