cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

berathebrain
Journeyman III

Stream class limited capability

If I have code:

::brook::Stream<float>* divG;

which has some data and I want to make temp variable that has the same data. How can I do this? If I write

::brook::Stream<float> *temp=new ::brook::Stream<float>(*divG);

which I thought is a copy constructor, then I cant use this temp variable in a call like this:

calculate_and_add_divergence_gpu_ati(cols,rows,*Gx,*Gy,*temp,*divG)

where divG is output stream. The runtime reports the error: "Input stream is the same as the output stream."

I get the same error even after the code like this:

temp->assign(divG);

or

*temp=*divG;

If I could just get the dimension of divG I could make a temp variable like

::brook::Stream<float> *temp=new ::brook::Stream<float>(1,&dimension); And then use assign method.

Here is the kernel which I am calling:

kernel void calculate_and_add_divergence_gpu_ati(int cols,int rows,float Gx[],float Gy[],float temp<>, out float divG<>{
    float divGx, divGy;
    int idx=instance().x;
    int ky = idx % cols;
    int kx=idx-ky*cols;
   
    if(kx == 0)
        divGx = Gx[idx];
    else   
        divGx = Gx[idx] - Gx[idx-1];

    if(ky == 0)
        divGy = Gy[idx];
    else   
        divGy = Gy[idx] - Gy[idx - cols];           

    divG = temp + divGx + divGy;
}

Thank you for your help.

0 Likes
4 Replies
gaurav_garg
Adept I

Both copy constructor and assign operator use shallow copy with ref counting, so internally the GPU buffer used is same, and you can not use the same buffer as input and output.

0 Likes

I know that when I make temp like:

::brook::Stream *temp=new ::brook::Stream(1,&dimension);

then I can use assign method and everything would be alright.

The only thing that bothers me is that I can't get dimensions from Stream class.

0 Likes

So I see that there is StreamImpl class that has getDimensions but how can I get StreamImpl from Stream object. There is an operator *() that returns StreamImpl* object from Stream but if I do this then I get the error:

use of undefined type 'StreamImpl'

from the compiler. Even if I declare it on the top of the file like so:

class StreamImpl;

There is no StreamImpl.h that I could include in my project.

Thank you for your help.

0 Likes

OK, nevermind. I added the method getDimenions() to class Stream myself.

It works fine.

0 Likes