Following is the code:
__global__ void warmup(){
__half tmp = 3;
__half b = 1;
__half wacc = 0;
for(int i = 0; i < 75; i++) {
for(int j = 0; j < 16; j++) {
printf("index: %d, before: %f ", i, __half2float(wacc));
wacc = __hadd(wacc, __hmul(tmp, b));
printf("after: %f\n ", __half2float(wacc));
}
}
}
I expect the result to be 3600, however the fllowing is the output:
index: 74, before: 4072.000000 after: 4076.000000
index: 74, before: 4076.000000 after: 4080.000000
index: 74, before: 4080.000000 after: 4084.000000
index: 74, before: 4084.000000 after: 4088.000000
index: 74, before: 4088.000000 after: 4092.000000
index: 74, before: 4092.000000 after: 4096.000000
index: 74, before: 4096.000000 after: 4100.000000
index: 74, before: 4100.000000 after: 4104.000000
index: 74, before: 4104.000000 after: 4108.000000
index: 74, before: 4108.000000 after: 4112.000000
index: 74, before: 4112.000000 after: 4116.000000
so I guess the problem may have to do with the function __hadd or __hmul, the error is accumulated in the for cycle.
I also tried the __hfma: wacc = __hfma(tmp, b, wacc), replace the code:
wacc = __hadd(wacc, __hmul(tmp, b));
but the output is same as above.
so what can i do if I want to get the result: 3600 instead of the output above when I use the __half datatype? I really need someone’s help!