1

I have a buffer that I'm passing to an OpenCL kernel via cl_mem object that I want to interpret as different types depending on the region eg

kernel void do_something(global void * data) {
    global double * offset_ptr = data + 20;
    global uint * offset2_ptr = data + 40;

    offset_ptr[5] = 4.0;
    offset2_ptr[2] = 5;
}

My problem is with lines 2 and 3; I get this message from the compiler:

Bitcasts between pointers of different address spaces is not legal.Use AddrSpaceCast instead.
%26 = bitcast i8 addrspace(1)* %19 to i8*

or something similar. I can fix this with

... = (global) data + 20;

but I feel like this is papering over the problem and I'm misunderstanding something fundamental about address spaces. When I introduce another error into the program these same lines then give me this:

warning: incompatible integer to pointer conversion initializing '__global double *__attribute__((address_space(16776963)))' with an expression of type 'unsigned int'

What should I be doing here?

tauroid
  • 46
  • 4
  • 4
    It is probably related to void pointers. So you are adding offset to a void pointer, and a void pointer has unkown size. Casting it beforehand may solve it. `((global double *)data)+20;` – DarkZeros Mar 03 '16 at 13:44
  • okay, going with the messy looking workaround of `(global double *) ((global char *) data + 20)` seems to fix things. Can't cast straight to `double` if the `double` array doesn't start at a `double` sized offset. Thanks! – tauroid Mar 03 '16 at 15:36
  • 2
    If the `double` array does not start at an `double` sized offset, then you may encounter alignment errors or at least a performance penalty. – Martin Zabel Mar 03 '16 at 20:23
  • Is that true if everything's still aligned to 32 bytes? I'm shooting for that at minimum because I start with some int arrays but I can always change the order.. – tauroid Mar 10 '16 at 11:26

0 Answers0