Wednesday, July 04, 2012 10:07 AM
It appears from the blogs that there are three ways of passing constant data to the GPU, possibly exposed via different AMP interfaces:
- ShaderResourceView - via const array<T> or array_view<const T>
- Constant memory - via capturing T variable
- Textures - via concurrency::graphics::texture
Am i correct about the interfaces for 1 & 2?
Clearly there are various memory and other constraints on the use of each of these.
Do you have a view on the relative performance of each?
It might be handy to summarise the usage, constraints and performance comparison in one place.
Thursday, July 05, 2012 6:26 PM
Constant memory should be used to hold constants that will be accessed by all the threads, so threads normall read the same value. array/array_view/texture is used to supply inputs for computation, where threads normally read different portion of the resource. So for example, if you are doing a computation like
C[i] = A[i] + e * B[i];
Assume "e" is a constant. You will want to put "e" to the constant buffer, while putting A and B to array/array_view/texture.
Now, about the choice between array/array_view and texture. A texture could be the choice when graphics interop is required (the resource for both rendering and computing is a texture) or for the purpose of sub-word packing of data. For the general computing scenario, it's less clear on which is better and it's usually very application, algorithm, and hardware specific. If your GPU algorithm uses coalesced global memory access (we will blog about this soon) or effectively uses the programmable cache (tile_static memory), using texture probably would not result in any major performance gains (compared to array). GPU hardware has texture caches optimized for 2D locality (however, the 2D caching scheme is proprietary, so there is no clear description on how it works, it could be different from vendor to vendor, and from generation to generation). If your algorithm has irregular memory access pattern that you cannot take advantage of coalesced memory access, and it has data re-use for 2D locality, you may see perf improvement using textures. However, you should always measure and quantify the performance improvements when you make such choices.
Friday, July 06, 2012 9:22 AMOne more question about constant memory: does this support arrays too?
Friday, July 06, 2012 5:13 PM
I assume your question is about whether you can pass a constant C array (e.g., int x) to constant memory. If that's your question, please read this blog post: http://blogs.msdn.com/b/nativeconcurrency/archive/2012/01/11/using-constant-memory-in-c-amp.aspx