[Lldb-commits] [lldb] [libc][libm][GPU] Added missing vendor entry points to `libm` for GPUs (PR #66031)

2023-09-11 Thread Anton Rydahl via lldb-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Fangrui Song
 ,Razvan Lupusoru ,Walter Erquinigo
 ,"Yaxun (Sam) Liu" ,Nico Weber
 ,Stella Laurenzo ,Lang Hames
 ,Matthias Braun ,Arthur Eubanks
 ,Nico Weber ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Vitaly Buka ,Fangrui Song
 ,Fangrui Song ,Fangrui Song 
,Fangrui
 Song ,erichkeane ,Amir Ayupov
 ,Amir Ayupov ,yinying-lisa-li
 <107574043+yinying-lisa...@users.noreply.github.com>,Christopher Di Bella
 ,Konstantin Varlamov ,Alexey Bader
 ,Vitaly Buka 


https://github.com/AntonRydahl review_requested 
https://github.com/llvm/llvm-project/pull/66031
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Added missing vendor entry points to `libm` for GPUs (PR #66031)

2023-09-11 Thread Anton Rydahl via lldb-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Fangrui Song
 ,Razvan Lupusoru ,Walter Erquinigo
 ,"Yaxun (Sam) Liu" ,Nico Weber
 ,Stella Laurenzo ,Lang Hames
 ,Matthias Braun ,Arthur Eubanks
 ,Nico Weber ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Vitaly Buka ,Fangrui Song
 ,Fangrui Song ,Fangrui Song 
,Fangrui
 Song ,erichkeane ,Amir Ayupov
 ,Amir Ayupov ,yinying-lisa-li
 <107574043+yinying-lisa...@users.noreply.github.com>,Christopher Di Bella
 ,Konstantin Varlamov ,Alexey Bader
 ,Vitaly Buka 


https://github.com/AntonRydahl review_requested 
https://github.com/llvm/llvm-project/pull/66031
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Added missing vendor entry points to `libm` for GPUs (PR #66031)

2023-09-11 Thread Anton Rydahl via lldb-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Fangrui Song
 ,Razvan Lupusoru ,Walter Erquinigo
 ,"Yaxun (Sam) Liu" ,Nico Weber
 ,Stella Laurenzo ,Lang Hames
 ,Matthias Braun ,Arthur Eubanks
 ,Nico Weber ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Vitaly Buka ,Fangrui Song
 ,Fangrui Song ,Fangrui Song 
,Fangrui
 Song ,erichkeane ,Amir Ayupov
 ,Amir Ayupov ,yinying-lisa-li
 <107574043+yinying-lisa...@users.noreply.github.com>,Christopher Di Bella
 ,Konstantin Varlamov ,Alexey Bader
 ,Vitaly Buka 


https://github.com/AntonRydahl review_requested 
https://github.com/llvm/llvm-project/pull/66031
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Added missing vendor entry points to `libm` for GPUs (PR #66031)

2023-09-11 Thread Anton Rydahl via lldb-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Fangrui Song
 ,Razvan Lupusoru ,Walter Erquinigo
 ,"Yaxun (Sam) Liu" ,Nico Weber
 ,Stella Laurenzo ,Lang Hames
 ,Matthias Braun ,Arthur Eubanks
 ,Nico Weber ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Vitaly Buka ,Fangrui Song
 ,Fangrui Song ,Fangrui Song 
,Fangrui
 Song ,erichkeane ,Amir Ayupov
 ,Amir Ayupov ,yinying-lisa-li
 <107574043+yinying-lisa...@users.noreply.github.com>,Christopher Di Bella
 ,Konstantin Varlamov ,Alexey Bader
 ,Vitaly Buka 


https://github.com/AntonRydahl labeled 
https://github.com/llvm/llvm-project/pull/66031
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Added missing vendor entry points to `libm` for GPUs (PR #66031)

2023-09-11 Thread Anton Rydahl via lldb-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Fangrui Song
 ,Razvan Lupusoru ,Walter Erquinigo
 ,"Yaxun (Sam) Liu" ,Nico Weber
 ,Stella Laurenzo ,Lang Hames
 ,Matthias Braun ,Arthur Eubanks
 ,Nico Weber ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Vitaly Buka ,Fangrui Song
 ,Fangrui Song ,Fangrui Song 
,Fangrui
 Song ,erichkeane ,Amir Ayupov
 ,Amir Ayupov ,yinying-lisa-li
 <107574043+yinying-lisa...@users.noreply.github.com>,Christopher Di Bella
 ,Konstantin Varlamov ,Alexey Bader
 ,Vitaly Buka 


https://github.com/AntonRydahl review_requested 
https://github.com/llvm/llvm-project/pull/66031
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Added missing vendor entry points to `libm` for GPUs (PR #66031)

2023-09-11 Thread Anton Rydahl via lldb-commits
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,MaheshRavishankar
 <1663364+maheshravishan...@users.noreply.github.com>,Fangrui Song
 ,Razvan Lupusoru ,Walter Erquinigo
 ,"Yaxun (Sam) Liu" ,Nico Weber
 ,Stella Laurenzo ,Lang Hames
 ,Matthias Braun ,Arthur Eubanks
 ,Nico Weber ,
Valentin Clement =?utf-8?b?KOODkOODrOODsw=?=,Vitaly Buka
 ,Vitaly Buka ,Fangrui Song
 ,Fangrui Song ,Fangrui Song 
,Fangrui
 Song ,erichkeane ,Amir Ayupov
 ,Amir Ayupov ,yinying-lisa-li
 <107574043+yinying-lisa...@users.noreply.github.com>,Christopher Di Bella
 ,Konstantin Varlamov ,Alexey Bader
 ,Vitaly Buka 


https://github.com/AntonRydahl closed 
https://github.com/llvm/llvm-project/pull/66031
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Add missing vendor entrypoints to the GPU version of `libm` (PR #66034)

2023-10-19 Thread Anton Rydahl via lldb-commits

AntonRydahl wrote:

> LG after fixing the header formatting.

Thanks a bunch! I don't know how I did not notice the misformatted headers. I 
have fixed those now.

https://github.com/llvm/llvm-project/pull/66034
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [libc][libm][GPU] Add missing vendor entrypoints to the GPU version of `libm` (PR #66034)

2023-10-19 Thread Anton Rydahl via lldb-commits

https://github.com/AntonRydahl closed 
https://github.com/llvm/llvm-project/pull/66034
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [mlir] [lldb] [libcxxabi] [clang] [compiler-rt] [llvm] [libcxx] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-11-02 Thread Anton Rydahl via lldb-commits


@@ -466,6 +466,114 @@ Unpoisoning may not be an option, if (for example) you 
are not maintaining the a
 * You are using allocator, which does not call destructor during deallocation.
 * You are aware that memory allocated with an allocator may be accessed, even 
when unused by container.
 
+Offloading C++ Parallel Algorithms to GPUs
+--
+
+Experimental support for GPU offloading has been added to ``libc++``. The
+implementation uses OpenMP target offloading to leverage GPU compute resources.
+The OpenMP PSTL backend can target both NVIDIA and AMD GPUs.
+However, the implementation only supports contiguous iterators, such as 
+iterators for ``std::vector`` or ``std::array``.
+To enable the OpenMP offloading backend it must be selected with
+``LIBCXX_PSTL_BACKEND=openmp`` when installing ``libc++``. Further, when
+compiling a program, the user must specify the command line options
+``-fopenmp -fexperimental-library -stdlib=libc++``. To install LLVM with OpenMP
+offloading enabled, please read
+`the LLVM OpenMP FAQ. `_ 
+You may also want to to visit
+`the OpenMP offloading command-line argument reference. 
`_
 
+
+Example
+~~~
+
+The following is an example of offloading vector addition to a GPU using our
+standard library extension.
+
+.. code-block:: cpp
+
+  #include 
+  #include 
+
+  template
+  void axpy(const T1 a,std::vector& x, std::vector& y)
+  {
+std::transform(std::execution::par_unseq,x.begin(),x.end(), y.begin(), 
y.begin(),
+  [=](T2 xi, T3 yi){ return a*xi + yi; });
+  }
+
+The execution policy ``std::execution::par_unseq`` states that the algorithm's
+execution may be parallelized, vectorized, and migrated across threads. This is
+the only execution mode that is safe to offload to GPUs, and for all other
+execution modes the algorithms will execute on the CPU.
+Special attention must be paid to the lambda captures when enabling GPU
+offloading. If the lambda captures by reference, the user must manually map the
+variables to the device. If capturing by reference, the above example could
+be implemented in the following way.
+
+.. code-block:: cpp
+
+  template
+  void axpy(const T1 a,std::vector& x, std::vector& y)
+  {
+  # pragma omp target data map(to:a)
+std::transform(std::execution::par_unseq,x.begin(),x.end(), y.begin(), 
y.begin(),

AntonRydahl wrote:

I think they are correct, but I will const qualify the x vector. It is reading 
from x and y and writing to y, just like the classical BLAS AXPY routine. That 
corresponds to 4) from https://en.cppreference.com/w/cpp/algorithm/transform.

https://github.com/llvm/llvm-project/pull/66968
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [llvm] [mlir] [compiler-rt] [lldb] [clang] [libcxxabi] [libcxx] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-11-06 Thread Anton Rydahl via lldb-commits


@@ -330,6 +330,23 @@ def getStdFlag(cfg, std):
 default=f"{shlex.quote(sys.executable)} 
{shlex.quote(str(Path(__file__).resolve().parent.parent.parent / 'run.py'))}",
 help="Custom executor to use instead of the configured default.",
 actions=lambda executor: [AddSubstitution("%{executor}", executor)],
+),
+Parameter(
+name="openmp_pstl_backend",
+choices=[True, False],
+type=bool,
+default=False,
+help="Enable the OpenMP compilation toolchain if the PSTL backend was 
set to OpenMP.",
+actions=lambda enabled: [
+AddCompileFlag("-fopenmp"),

AntonRydahl wrote:

I think there is unfortunately no better way of doing this at the moment, 
except for changing Clang. The problem is that OpenMP might already be shipped 
with the system, and then a lot of conflicts can happen if the wrong version of 
the OpenMP target library or the device runtime is picked up. But I agree that 
this is indeed not very user friendly and that it would be a lot nicer if Clang 
automatically did this.

https://github.com/llvm/llvm-project/pull/66968
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [libcxx] [clang] [compiler-rt] [llvm] [lldb] [libcxxabi] [mlir] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-11-06 Thread Anton Rydahl via lldb-commits


@@ -466,6 +466,114 @@ Unpoisoning may not be an option, if (for example) you 
are not maintaining the a
 * You are using allocator, which does not call destructor during deallocation.
 * You are aware that memory allocated with an allocator may be accessed, even 
when unused by container.
 
+Offloading C++ Parallel Algorithms to GPUs
+--
+
+Experimental support for GPU offloading has been added to ``libc++``. The
+implementation uses OpenMP target offloading to leverage GPU compute resources.
+The OpenMP PSTL backend can target both NVIDIA and AMD GPUs.
+However, the implementation only supports contiguous iterators, such as 
+iterators for ``std::vector`` or ``std::array``.
+To enable the OpenMP offloading backend it must be selected with
+``LIBCXX_PSTL_BACKEND=openmp`` when installing ``libc++``. Further, when
+compiling a program, the user must specify the command line options
+``-fopenmp -fexperimental-library -stdlib=libc++``. To install LLVM with OpenMP
+offloading enabled, please read
+`the LLVM OpenMP FAQ. `_ 
+You may also want to to visit
+`the OpenMP offloading command-line argument reference. 
`_
 
+
+Example
+~~~
+
+The following is an example of offloading vector addition to a GPU using our
+standard library extension.
+
+.. code-block:: cpp
+
+  #include 
+  #include 
+
+  template
+  void axpy(const T1 a,std::vector& x, std::vector& y)
+  {
+std::transform(std::execution::par_unseq,x.begin(),x.end(), y.begin(), 
y.begin(),
+  [=](T2 xi, T3 yi){ return a*xi + yi; });
+  }
+
+The execution policy ``std::execution::par_unseq`` states that the algorithm's
+execution may be parallelized, vectorized, and migrated across threads. This is
+the only execution mode that is safe to offload to GPUs, and for all other
+execution modes the algorithms will execute on the CPU.
+Special attention must be paid to the lambda captures when enabling GPU
+offloading. If the lambda captures by reference, the user must manually map the
+variables to the device. If capturing by reference, the above example could
+be implemented in the following way.
+
+.. code-block:: cpp
+
+  template
+  void axpy(const T1 a,std::vector& x, std::vector& y)
+  {
+  # pragma omp target data map(to:a)
+std::transform(std::execution::par_unseq,x.begin(),x.end(), y.begin(), 
y.begin(),
+  [&](T2 xi, T3 yi){ return a*xi + yi; });
+  }
+
+However, if unified shared memory, USM, is enabled, no additional data mapping
+is necessary when capturing y reference.
+
+Compiling functions for GPUs with OpenMP
+
+
+The C++ standard defines that all accesses to memory are inside a single 
address
+space. However, discrete GPU systems have distinct address spaces. A single
+address space can be emulated if your system supports unified shared memory.
+However, many discrete GPU systems do not, and in those cases it is important 
to
+pass device function pointers to the parallel algorithms. Below is an example 
of
+how the OpenMP `declare target` directive can be used to mark that a function
+should be compiled for both host and device. The device address of a function
+pointer can be obtained with `target map(from:)`.
+
+.. code-block:: cpp
+
+  // Declare that the function must be compiled for both host and device
+  #pragma omp declare target
+  void cube(int& n) {n*=n*n; };
+  #pragma omp end declare target
+
+  int main()
+  {
+int * a =  new int[LEN];
+// Initialize the array to 2 on the device
+std::fill(std::execution::par_unseq,a, a+LEN,2);
+// Get the device pointer for cube
+void (*dcube)(int& n);
+#pragma omp target map(from:dcube)
+dcube = &cube;

AntonRydahl wrote:

@jdoerfert just made it possible to make the mapping automatically. If 
https://github.com/llvm/llvm-project/pull/71462 lands, we just need to use 
`#pragma omp declare target indirect to()`.

https://github.com/llvm/llvm-project/pull/66968
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [mlir] [compiler-rt] [libcxx] [libcxxabi] [clang] [llvm] [lldb] Adding Separate OpenMP Offloading Backend to `libcxx/include/__algorithm/pstl_backends` (PR #66968)

2023-11-06 Thread Anton Rydahl via lldb-commits

https://github.com/AntonRydahl edited 
https://github.com/llvm/llvm-project/pull/66968
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits