Problems with Stream Wrapper Object

Discussion created by gentiradentes on Sep 10, 2009
Latest reply on Sep 12, 2009 by gaurav.garg

I've recently written a wrapper object for Brook+ streams that makes the process of performing simple data parallel operations easier. The wrapper provides overloaded operators that work with streams, which makes porting SISD code to the GPU much easier than ever before.


Here is the code: (This is GPLv3 licensed, by the way.


StreamOperations Header

StreamOperations Source

The problem I'm having is that I need to return a streamOperations object for each call of an overloaded operator which contains the results of the operation. I need the "stream" and "result" streams to be accessible and constant throughout the class, so I create pointers to them and dynamically allocate the streams during the construction of the object.

This is causing me problems because for some reason, attempting to delete the streams in the destructor causes the application to crash. If I don't delete the streams, a memory leak appears on the GPU side, and graphics memory is consumed until the application crashes. (This happens in seconds) Besides these problems, the wrapper works great.

If anyone can help me solve this problem, I'd be very grateful. This code, like I said, is licensed under the GNU GPLv3, so if I can fix this, you'd not only be helping me, you'd also be helping anyone else who would benefit from this code.


//Here's an example of how the wrapper is used: int size = 4096; int* input = new int[size]; int* output = new int[size]; for(int i = 0; i < size; i++) { input[i] = i; } //CPU Code: for(int i = 0; i < size; i++) output[i] = input[i] + input[i]; //GPU Code: (using streamOperations wrapper) streamOperations ops(size); ops.writeStream(input); ops += ops; ops.readStream(output);