locked
Pack two short into a single int RRS feed

  • Question

  • I want to pack two signed shorts into an int in order to reduce a memory bottleneck when passing data between two kernels.

    I've read the C++ AMP: It's got character, but no char! post and based my implementation on that.

    template <typename T>
    int read_s16(T& arr, int idx) restrict(amp, cpu)
    {
    	return static_cast<int>((arr[idx/2] >> ((idx % 2) * 16)) << 16) >> 16;
    }
    	
    template<typename T>
    void write_s16(T& arr, int idx, int val) restrict(amp)
    {
    	// NOTE: arr is zero initialized
    	concurrency::atomic_fetch_or(&arr[idx/2], (val & 0xFFFF) << ((idx % 2) * 16));
    }

    However it is rather complicated, I would like to suggest that something like __half2float be added to C++ AMP.


    • Edited by Dragon89 Friday, August 31, 2012 8:45 PM
    Friday, August 31, 2012 7:12 PM

Answers

  • Hi Dragon89,

    C++ AMP currently supports subword packing through textures as described in this blog post. Does this suit your requirement?

    -Amit


    Amit K Agarwal

    • Marked as answer by Dragon89 Wednesday, September 12, 2012 7:10 PM
    Wednesday, September 12, 2012 6:50 PM
    Moderator

All replies

  • Take a look to the MAKELONG macro defined in windef.h file shipped in Windows SDK. However, that implementation can confuse also ))

    Sergey

    Tuesday, September 4, 2012 12:24 PM
  • Hi Dragon89,

    C++ AMP currently supports subword packing through textures as described in this blog post. Does this suit your requirement?

    -Amit


    Amit K Agarwal

    • Marked as answer by Dragon89 Wednesday, September 12, 2012 7:10 PM
    Wednesday, September 12, 2012 6:50 PM
    Moderator