================
@@ -176,3 +176,34 @@ Predefined Macros
    * - ``HIP_API_PER_THREAD_DEFAULT_STREAM``
      - Alias to ``__HIP_API_PER_THREAD_DEFAULT_STREAM__``. Deprecated.
 
+C++20 Concepts with HIP and CUDA
+--------------------------------
+
+In Clang, when working with HIP or CUDA, it's important to note that all 
constraints in C++20 concepts are assumed to be for the host side only. This 
behavior is consistent across both programming models, and developers should be 
aware of this assumption when writing code that utilizes C++20 concepts.
+
+Example:
+.. code-block:: c++
+
+   template <class T>
+   concept MyConcept = requires(T& obj) {
+     my_function(obj);  // Assumed to be a host-side requirement
----------------
yxsamliu wrote:

> If I understand correctly, normally a template is usable from either host or 
> device (depending on whether it ends up calling any host-only or device-only 
> function). 

No. template function in CUDA/HIP is subject to the same availability check 
regarding host/device attributes. e.g https://godbolt.org/z/ccTxhEhfo

constexpr template functions can be called by both host and device functions 
not because they are template functions, but because host device attributes are 
added to them implicitly. They are still subject to host/device availability 
checks.

https://github.com/llvm/llvm-project/pull/67721
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to