Operator new for class

Hi, i have the following situation:

class A

{

    int n;

};

__global__ void func()

{

    A *a = new A;

}

Where is “n” located? Local memory? Device?

Another example:

class A

{

    int n;

__device__ A():n(6){}

    __device__ A(const A& a):n(a.n){}

};

class B

{

    int data;

    A *a;

__device__ B()

    {

         data = 5;

         a = new A;

    }

__device__ B(const B& b)

    {

         data=b.data;

         a = new A(b.a);

    }

};

void func()

{

    B b;

    global_func<<<120,2>>>(b);

}

Where is “n” located now? Shared? Device?

Then “b” passes as argument to global function, shared copy of “b” is created by copying constructor, right? That’s why pointer “a” is shared, but what about instance “*a”?

I need to locate “n” in shared memory in this case for fast using by any thread, please, help me.

In the first example, A is located in per-thread heap, which is stored in global memory on the device.

The second example will fail for a few reasons. You are instantiating b in the host, but it has no host constructor, and then trying to pass a host memory class instance as an argument to a kernel function. It both shouldn’t compile and wouldn’t work even if it did.

Thank for reply. Of course, I mean “host device” instead of “device”.

How can memory be allocated as shared by operator new?

And in this case:

class A 

{ 

    int n; 

__device__ __host__ A():n(6){} 

    __device__ __host__ A(const A& a):n(a.n){} 

}; 

class B 

{ 

    int data; 

    A a; 

__device__ __host__ B():a()

    { 

         data = 5;  

    } 

__device__ __host__ B(const B& b):a(b.a) 

    { 

         data=b.data; 

    } 

}; 

void func() 

{ 

    B b; 

    global_func<<<120,2>>>(b); 

}

Where is “b.a.n” in “global_func”? I hope in shared memory, is it?

Sorry, if there are some errors in code, i can’t check it now.