6 Replies Latest reply on Dec 19, 2010 6:17 PM by Franchute13

    cannot be assigned to an entity of type

    Franchute13

      Hello.

      I am a beginner and I come from Java.

      I do not understand how to pass arrays between methods. The following code gives me the error:

      error: a value of type
                "float *" cannot be assigned to an entity of type "global float *"
                x = calcu(datos, j);
                  ^


      How do you fix ?

      I apologize for my English.

      Thx

      //#pragma OPENCL EXTENSION cl_khr_fp64 : enable //#pragma OPENCL EXTENSION cl_khr_fp16 : enable float f(float t, float y){ //float funcion= y; //float funcion= y*sin(t); float funcion= y*sin(t); return funcion; } float* calcu(__local float *datos, int j){ float x[1000],y[1000],t[1000],h,k1,k2,k3,k4,l1,l2,l3,l4; t[0]=0; //x[0]=1; x[0]=0; //y[0]=0; y[0]=datos[2*j]; h=datos[2*j+1]; int i=0; while (i<1000) { //int i = get_global_id(0); k1=f(t[i],y[i]); k2=f(t[i] + 0.5*h,y[i] + 0.5*k1*h); k3=f(t[i]+0.5*h,y[i]+0.5*k2*h); k4=f(t[i]+h,y[i]+k3*h); y[i+1]=y[i]+(1./6.)*(k1+2.*k2+2.*k3+k4)*h; t[i+1]=t[i]+h; //h=h*(i+1); x[i+1]=h*(i+1); i++; } return y; } __kernel void rk4(__local float *datos,__global float *x,__global float *y) { int j = get_global_id(0); while (j<get_global_size (0)){ x = calcu(datos, j); } }

        • cannot be assigned to an entity of type
          pulec

          I am also no OpenCL expert, but I'll try to answer

          First of all, you return from calcu pointer to array y defined inside this function, which is suspicious even in standard C. (I am no sure where are the data actually placed, when not specified, probably in registers, but can be also in global/local memory. I'd be glad if someone clarifies this.). Try to think it out - the array doesn't exist outside of calcu, so the pointer points to the place, where has the array been, but probably not any more. It could be a little strange if you use Java, but you will definitely need to understand it.

          What concerns your error - it simply says that you are assigning between pointers pointing perhaps to the different address spaces (__global and some else). The theoretical solution would be define the returned pointer and data as __global. This would probably compile, _BUT_ it will be semantically incorrect in you code, as I've tryied to explain in first paragraph.