Anastasia created this revision. Anastasia added a reviewer: mantognini. Herald added subscribers: ebevhan, yaxunl. Anastasia requested review of this revision.
Started a new doc section about the OpenCL experimental features and described ongoing work on C++ libraries e.g. type traits. https://reviews.llvm.org/D94188 Files: clang/docs/OpenCLSupport.rst Index: clang/docs/OpenCLSupport.rst =================================================================== --- clang/docs/OpenCLSupport.rst +++ clang/docs/OpenCLSupport.rst @@ -96,3 +96,56 @@ +------------------------------+--------------------------------------------------------------+----------------------+---------------------------------------------------------------------------+ | New functionality | Atomic mem scopes: subgroup, all devices including functions | :part:`worked on` | https://reviews.llvm.org/D92004 (functions only) | +------------------------------+--------------------------------------------------------------+----------------------+---------------------------------------------------------------------------+ + +Experimental features +===================== + +Clang provides the following new WIP features for the developers to experiment +with and provide early feedback or contribute with further improvements. +Feel free to contact us on `cfe-dev +<https://lists.llvm.org/mailman/listinfo/cfe-dev>`_ or via `Bugzilla +<https://bugs.llvm.org/>`_. + +C++ libraries for OpenCL +------------------------ + +There is ongoing work to support C++ standard libraries from `LLVM's libcxx +<https://libcxx.llvm.org/>`_ in OpenCL kernel code using C++ for OpenCL mode. + +It is currently possible to use `type_traits` from C++17 in the kernel sources +if the following clang extensions are enabled ``__cl_clang_function_pointers`` +and ``__cl_clang_variadic_functions``, see :doc:`LanguageExtensions` for more +details. The use of non-conformant features enabled by the extensions does not +expose non-conformant behavior beyond the compilation i.e. does not get +generated in IR or binary. The extension only appear in metaprogramming +mechanism to identify or verify the properties of types. This allows to provide +the full C++ functionality without a loss of portability. To avoid unsafe use +of the extensions it is recommended that the extensions are disabled directly +after the header include. + +**Example of Use**: + +The example of kernel code with `type_traits` is illustrated here. + +.. code-block:: c++ + + #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable + #pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable + #include "type_traits" + #pragma OPENCL EXTENSION __cl_clang_function_pointers : disable + #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable + + typedef std::make_signed<unsigned int>::type sint_t; + + __kernel void foo() { + static_assert(!std::is_same<sint_t, unsigned int>::value); + } + +The possible clang invocation to compile the example is as follows: + + .. code-block:: console + + $ clang -cl-std=clc++ -I<path to libcxx checkout or installation>/include test.cl + +Note that `type_traits` is a header only library and therefore no extra +linking step for the standard libraries is required.
Index: clang/docs/OpenCLSupport.rst =================================================================== --- clang/docs/OpenCLSupport.rst +++ clang/docs/OpenCLSupport.rst @@ -96,3 +96,56 @@ +------------------------------+--------------------------------------------------------------+----------------------+---------------------------------------------------------------------------+ | New functionality | Atomic mem scopes: subgroup, all devices including functions | :part:`worked on` | https://reviews.llvm.org/D92004 (functions only) | +------------------------------+--------------------------------------------------------------+----------------------+---------------------------------------------------------------------------+ + +Experimental features +===================== + +Clang provides the following new WIP features for the developers to experiment +with and provide early feedback or contribute with further improvements. +Feel free to contact us on `cfe-dev +<https://lists.llvm.org/mailman/listinfo/cfe-dev>`_ or via `Bugzilla +<https://bugs.llvm.org/>`_. + +C++ libraries for OpenCL +------------------------ + +There is ongoing work to support C++ standard libraries from `LLVM's libcxx +<https://libcxx.llvm.org/>`_ in OpenCL kernel code using C++ for OpenCL mode. + +It is currently possible to use `type_traits` from C++17 in the kernel sources +if the following clang extensions are enabled ``__cl_clang_function_pointers`` +and ``__cl_clang_variadic_functions``, see :doc:`LanguageExtensions` for more +details. The use of non-conformant features enabled by the extensions does not +expose non-conformant behavior beyond the compilation i.e. does not get +generated in IR or binary. The extension only appear in metaprogramming +mechanism to identify or verify the properties of types. This allows to provide +the full C++ functionality without a loss of portability. To avoid unsafe use +of the extensions it is recommended that the extensions are disabled directly +after the header include. + +**Example of Use**: + +The example of kernel code with `type_traits` is illustrated here. + +.. code-block:: c++ + + #pragma OPENCL EXTENSION __cl_clang_function_pointers : enable + #pragma OPENCL EXTENSION __cl_clang_variadic_functions : enable + #include "type_traits" + #pragma OPENCL EXTENSION __cl_clang_function_pointers : disable + #pragma OPENCL EXTENSION __cl_clang_variadic_functions : disable + + typedef std::make_signed<unsigned int>::type sint_t; + + __kernel void foo() { + static_assert(!std::is_same<sint_t, unsigned int>::value); + } + +The possible clang invocation to compile the example is as follows: + + .. code-block:: console + + $ clang -cl-std=clc++ -I<path to libcxx checkout or installation>/include test.cl + +Note that `type_traits` is a header only library and therefore no extra +linking step for the standard libraries is required.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits