FrodoTheGiant

How costly are type casts?

Discussion created by FrodoTheGiant on Dec 6, 2010
Latest reply on Dec 7, 2010 by himanshu.gautam

Hi,

I have a kernel that is using data from a lookup table to initialize an array.

Output data has to be of type float.

To save __constant memory I use type "char" for the data in the lookup table (is OK since the values only go from -16 to +16).

 

__constant char lookup_table[16] = {-12, 2, 9, -7, ...};

__kernel void lookup(__global int* in, __global float* out){
    uint tid = get_global_id(0);
    out[tid] = (float)lookup_table[in[tid]];
}

 

My question: How costly are type casts? Would it be better to use type "float" for the lookup_table?

 

Outcomes