none
Functions that can take and return arrays

    Întrebare

  • I'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?
    12 februarie 2012 22:59

Răspunsuri

  • Hi DeadMG

    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.

    Thanks,

    Weirong

    13 februarie 2012 01:06
  • 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.

    Cheers

    Daniel


    http://www.danielmoth.com/Blog/

    15 februarie 2012 02:23

Toate mesajele

  • Hi DeadMG

    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.

    Thanks,

    Weirong

    13 februarie 2012 01:06
  • 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.

    Cheers

    Daniel


    http://www.danielmoth.com/Blog/

    15 februarie 2012 02:23