Sunday, February 12, 2012 10:59 PMI've got a problem domain on the CPU right now which takes and returns an array of T and U. Both T and U meet the requirements for AMP use, and the function isn't very complex (meets the requirements), and it can be called several thousand or more times on a given run, so it seemed like an ideal candidate for GPU parallelisation. Unfortunately, I can't seem to find any means in AMP which effectively takes, or returns, an array. Any suggestions or is this too much to expect from the GPU?
Monday, February 13, 2012 1:06 AM
First of all, a host side function (restrict(cpu) function) can take and return concurrency::array. However, please be aware that copy operation for concurrency::array is a deep copy, just like STL containers (e.g. std::vector). It effectively allocate and create a new array and copy the content from the old array. It's very costly. Also any computation performed on the new array will not take effect on old array, as expected. So in most cases, you probably never want to do something like this. So normally, you'd want pass by reference instead of by value.
Since the copy semantics invovles an allocation of new array container, which could not be achieved on GPU. The copy constructor and assignment operator of concurrency::array are intentionally not allowed in restrict(amp). So on GPU (restrict(amp) world), you could never take/return an array.
Wednesday, February 15, 2012 2:23 AMOwner
This question has been answered by Weirong, and I just wanted to add that you can also use array_view objects, in addition to the option fo passing references of arrays.
- Marked As Answer by DanielMothMicrosoft Employee, Owner Friday, April 06, 2012 7:26 AM