cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Franchute13
Journeyman III

cannot be assigned to an entity of type

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,y); k2=f(t + 0.5*h,y + 0.5*k1*h); k3=f(t+0.5*h,y+0.5*k2*h); k4=f(t+h,y+k3*h); y[i+1]=y+(1./6.)*(k1+2.*k2+2.*k3+k4)*h; t[i+1]=t+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); } }

0 Likes
6 Replies
pulec
Journeyman III

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.

0 Likes

yes taht error say that you assing __private pointer to __global one. this is illegal.

another error (as pulec pointed) is that you return pointer on y which is after end of function no longer valid.

this big array is definitly stored in RAM and not in registers.

0 Likes

Thanks for the replies.
My mistake is to think that * is an array and not a pointer.

Question, how do I return an array of a method?


Example in java:
Variable: float vari[];

public float[] metodo(){
   bla bla
    bla
        return vari;
 }

 

Try putting a

float [] calculated (....
           float temp []....
return temp;

It does not work

 

 

thx for you reply

0 Likes

in C array == pointer

only difference between array is method of creating.

//this is normal C code not kernel code
float a1[10];
float *a2 = (float*)malloc(10*sizeof(float));//this is in kernel for example global buffers
//from this point a1 and a2 is equal
a1[5];//sixth element
*(a2+5);//equal. pointer is address. so add five element to start address and return value.
//but oposite is possible too
*(a1+6);
a2[6];

i recomend read some C tutorials. in OpenCL kernels it is the same.

 

void calc(float *array) { //fill array for(int i=01;i<10;i++)array = i; } __kernel void ker() { float a[10]; calc(a); }

0 Likes

DELETED

EDIT: I can seen nou has answered it meanwhile

0 Likes

thank both

0 Likes