[C++ AMP] I would like to have intrinsics for converting between 32-bit float and 16-bit float (a.k.a. half float) RRS feed

  • Question

  • Hi,

    Recently, I have evaluated some GPGPU programming models including C++ AMP, CUDA, and OpenCL in terms of several key requirements such as portability, performance, and productivity. Of such programming models, I have found that C++ AMP is consistently better than or at least comparable to any other programming model. Also, I have found C++ AMP reliable in the sense that I have found few bugs in the C++ AMP compiler/runtime as well as the back end drivers from GPU vendors. Since I am primarily interested in development under native Windows environments, I am not very concerned about that C++ AMP is backed by DX11, which restricts the portability within Windows. That said, I am also interested in open source projects like HCC (formerly known as Kalmar or clamp) that expand the C++ AMP platforms to UNIX OSs.

    Although some people have expressed a concern regarding the C++ AMP development recently, I am less worried about it because, I think, after having had some active development and stabilizing phases, we are now in the adoption phase of C++ AMP by more general programmers. Indeed, the blog articles posted some time ago as well as the C++ AMP book still remain extremely valuable sources of information for such programmers. Having read some blog articles, I am impressed by Microsoft's attitude that they are open to suggestions. Actually, there have been already quite a bunch of suggestions proposed by many people.

    Unfortunately, they have however missed one thing that I would really like to have, that is, intrinsics for converting between 32-bit float and 16-bit (half) float. Some use cases and discussions include:

    • Although float textures support half float as an underlying data type, arrays do not; we cannot natively read/write half floats from/to arrays (without the proposed intrinsics). I say this because there exist use cases where we want to use arrays (instead of textures) even for images, which allow us to use CPU/GPU shared memory, for example. Besides that, arrays are more flexible than textures (e.g., in terms of the element's type) and my experiments have also shown that, on modern GPUs, arrays are as fast as (or sometimes faster than) textures because read-only arrays can be cached into the L1 cache if there is no aliasing so that  SRV is used as the underlying DX11 buffer type. (By the way, other programming models like CUDA require the explicit __restrict__ qualification to global memory pointers for the L1 cache to work.) Other than the above use case, we sometimes simply want to use half float matrices to reduce global memory traffic at the expense of precision; CUDA 7.5 has introduced half float data types and conversion intrinsics for this reason.
    • Although the C++ AMP open specification has a mention of supporting half float as an extension, this extension has not been implemented in Microsoft's C++ AMP (as of Visual Studio 2015 Update 1). A full spec implementation of the half float data type would be exciting, but simple conversion intrinsics suffice for me and, probably, for most other programmers. Since we have the corresponding HLSL intrinsics, it must be relatively straightforward to expose them as C++ AMP intrinsics (in the concurrency::direct3d namespace).
    • Since Intel "Ivy Bridge" and AMD "Piledriver", even CPUs support such conversion instructions called F16C. There also exist a software implementation. Even with the current implementation of C++ AMP, it is possible to implement such conversion functions using some integer bit manipulation. Provided that we do not require strict IEEE 754 conformance (e.g., the "round to nearest, ties to even" rounding behavior and correct handling of NaN and denormals), we can implement such conversion functions more efficiently. However, native intrinsics are preferable in terms of speed and precision.

    I would appreciate it if you consider my suggestion for future improvement of C++ AMP.

    Thank you.

    Yousuke Takada

    Friday, February 12, 2016 3:05 AM