cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

viktor_klochkov
Journeyman III

Returning pointer to class(structure) field

Why I can't return pointer to class field?

class test{

public:

int* get_a () {return a;}

private:

  int a[2];

};

I have the error message:

"/tmp/OCL8Rwvmd.cl", line 30: error: type "__global int *" is not identical to

          nor covariant with return type "int *"

  int* get_a () {return a;}

                

"/tmp/OCL8Rwvmd.cl", line 30: error: type "__local int *" is not identical to

          nor covariant with return type "int *"

  int* get_a () {return a;}

0 Likes
4 Replies
dipak
Big Boss

Hi Viktor,

Standard OpenCL kernel code doesn't support C++ features. So, I assume you're using AMD's OpenCL Static C++ kernel language for your kernel code. Right?

Please can you share a simple test-case(host and kernel code) which manifests this problem? Please also let us know your system setup details: CPU, GPU, SDK, Driver, OS (Window/Linux) (32/64) etc.

Regards,

0 Likes
nou
Exemplar

I didn't work with AMD C++ extension for OpenCL. But in OpenCL you can't mix pointers from different spaces. I think when you specify int* get_a() it automatically assume __private address space. So I assume that you want call that method over instance which reside in global memory space. So you are trying cast pointer from global address space to private which is ilegal in OpenCL.

Thank you for your answer!

Is it mean that I can't create getter in OpenCL? Because I don't see a way to do it.

0 Likes

ok with little experimentation it seems like AMD OpenCL compiler is creating internally three version of each member function. it is creating method for __global, __local and __private variant of class instance. at least that is what it imply from compiler behaviour.

you can rewrite your example to this C code.


struct test


{


     int a;


}



int* test_get_a(test *this)


{


   return this->a;


}

because OpenCL have different address spaces it must create variant for each address space.


int* _g_test_get_a(__global test *this);


int* _l_test_get_a(__local test *this);


int* _p_test_get_a(__private test *this);


0 Likes