annotate openmp/docs/SupportAndFAQ.rst @ 240:ca573705d418

merge
author matac
date Fri, 28 Jul 2023 20:50:09 +0900
parents c4bab56944e8
children 1f2b6ac9f198
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 Support, Getting Involved, and FAQ
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 ==================================
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
4 Please do not hesitate to reach out to us on the `Discourse forums (Runtimes - OpenMP) <https://discourse.llvm.org/c/runtimes/openmp/35>`_ or join
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 one of our :ref:`regular calls <calls>`. Some common questions are answered in
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 the :ref:`faq`.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 .. _calls:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 Calls
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 -----
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 OpenMP in LLVM Technical Call
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 - Development updates on OpenMP (and OpenACC) in the LLVM Project, including Clang, optimization, and runtime work.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 - Join `OpenMP in LLVM Technical Call <https://bluejeans.com/544112769//webrtc>`__.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 - Time: Weekly call on every Wednesday 7:00 AM Pacific time.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 - Meeting minutes are `here <https://docs.google.com/document/d/1Tz8WFN13n7yJ-SCE0Qjqf9LmjGUw0dWO9Ts1ss4YOdg/edit>`__.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 - Status tracking `page <https://openmp.llvm.org/docs>`__.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 OpenMP in Flang Technical Call
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 - Development updates on OpenMP and OpenACC in the Flang Project.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 - Join `OpenMP in Flang Technical Call <https://bit.ly/39eQW3o>`_
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 - Time: Weekly call on every Thursdays 8:00 AM Pacific time.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 - Meeting minutes are `here <https://docs.google.com/document/d/1yA-MeJf6RYY-ZXpdol0t7YoDoqtwAyBhFLr5thu5pFI>`__.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 - Status tracking `page <https://docs.google.com/spreadsheets/d/1FvHPuSkGbl4mQZRAwCIndvQx9dQboffiD-xD0oqxgU0/edit#gid=0>`__.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 .. _faq:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 FAQ
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 ---
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 .. note::
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 The FAQ is a work in progress and most of the expected content is not
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 yet available. While you can expect changes, we always welcome feedback and
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
40 additions. Please post on the `Discourse forums (Runtimes - OpenMP) <https://discourse.llvm.org/c/runtimes/openmp/35>`__.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 Q: How to contribute a patch to the webpage or any other part?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 All patches go through the regular `LLVM review process
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 <https://llvm.org/docs/Contributing.html#how-to-submit-a-patch>`_.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 .. _build_offload_capable_compiler:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 Q: How to build an OpenMP GPU offload capable compiler?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 To build an *effective* OpenMP offload capable compiler, only one extra CMake
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 option, `LLVM_ENABLE_RUNTIMES="openmp"`, is needed when building LLVM (Generic
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
56 information about building LLVM is available `here
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
57 <https://llvm.org/docs/GettingStarted.html>`__.). Make sure all backends that
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
58 are targeted by OpenMP to be enabled. By default, Clang will be built with all
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
59 backends enabled. When building with `LLVM_ENABLE_RUNTIMES="openmp"` OpenMP
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
60 should not be enabled in `LLVM_ENABLE_PROJECTS` because it is enabled by
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
61 default.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
63 For Nvidia offload, please see :ref:`build_nvidia_offload_capable_compiler`.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
64 For AMDGPU offload, please see :ref:`build_amdgpu_offload_capable_compiler`.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 .. note::
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 The compiler that generates the offload code should be the same (version) as
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 the compiler that builds the OpenMP device runtimes. The OpenMP host runtime
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 can be built by a different compiler.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 .. _advanced_builds: https://llvm.org//docs/AdvancedBuilds.html
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 .. _build_nvidia_offload_capable_compiler:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 Q: How to build an OpenMP NVidia offload capable compiler?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 The Cuda SDK is required on the machine that will execute the openmp application.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 If your build machine is not the target machine or automatic detection of the
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 available GPUs failed, you should also set:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 - `CLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_XX` where `XX` is the architecture of your GPU, e.g, 80.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 - `LIBOMPTARGET_NVPTX_COMPUTE_CAPABILITIES=YY` where `YY` is the numeric compute capacity of your GPU, e.g., 75.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 .. _build_amdgpu_offload_capable_compiler:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 Q: How to build an OpenMP AMDGPU offload capable compiler?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
90 A subset of the `ROCm <https://github.com/radeonopencompute>`_ toolchain is
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 required to build the LLVM toolchain and to execute the openmp application.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 Either install ROCm somewhere that cmake's find_package can locate it, or
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 build the required subcomponents ROCt and ROCr from source.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
95 The two components used are ROCT-Thunk-Interface, roct, and ROCR-Runtime, rocr.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
96 Roct is the userspace part of the linux driver. It calls into the driver which
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
97 ships with the linux kernel. It is an implementation detail of Rocr from
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
98 OpenMP's perspective. Rocr is an implementation of `HSA
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
99 <http://www.hsafoundation.com>`_.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
100
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
101 .. code-block:: text
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
103 SOURCE_DIR=same-as-llvm-source # e.g. the checkout of llvm-project, next to openmp
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
104 BUILD_DIR=somewhere
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
105 INSTALL_PREFIX=same-as-llvm-install
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
106
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
107 cd $SOURCE_DIR
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
108 git clone git@github.com:RadeonOpenCompute/ROCT-Thunk-Interface.git -b roc-4.2.x \
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
109 --single-branch
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
110 git clone git@github.com:RadeonOpenCompute/ROCR-Runtime.git -b rocm-4.2.x \
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
111 --single-branch
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
112
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
113 cd $BUILD_DIR && mkdir roct && cd roct
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
114 cmake $SOURCE_DIR/ROCT-Thunk-Interface/ -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
115 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
116 make && make install
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
118 cd $BUILD_DIR && mkdir rocr && cd rocr
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
119 cmake $SOURCE_DIR/ROCR-Runtime/src -DIMAGE_SUPPORT=OFF \
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
120 -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_BUILD_TYPE=Release \
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
121 -DBUILD_SHARED_LIBS=ON
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
122 make && make install
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
124 ``IMAGE_SUPPORT`` requires building rocr with clang and is not used by openmp.
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
125
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 Provided cmake's find_package can find the ROCR-Runtime package, LLVM will
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
127 build a tool ``bin/amdgpu-arch`` which will print a string like ``gfx906`` when
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 run if it recognises a GPU on the local system. LLVM will also build a shared
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 library, libomptarget.rtl.amdgpu.so, which is linked against rocr.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 With those libraries installed, then LLVM build and installed, try:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
133 .. code-block:: shell
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
134
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 clang -O2 -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa example.c -o example && ./example
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 Q: What are the known limitations of OpenMP AMDGPU offload?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
139 LD_LIBRARY_PATH or rpath/runpath are required to find libomp.so and libomptarget.so
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
141 There is no libc. That is, malloc and printf do not exist. Libm is implemented in terms
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
142 of the rocm device library, which will be searched for if linking with '-lm'.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 Some versions of the driver for the radeon vii (gfx906) will error unless the
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 environment variable 'export HSA_IGNORE_SRAMECC_MISREPORT=1' is set.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 It is a recent addition to LLVM and the implementation differs from that which
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 has been shipping in ROCm and AOMP for some time. Early adopters will encounter
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 bugs.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
151 Q: What are the LLVM components used in offloading and how are they found?
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
152 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
153 The libraries used by an executable compiled for target offloading are:
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
154
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
155 - ``libomp.so`` (or similar), the host openmp runtime
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
156 - ``libomptarget.so``, the target-agnostic target offloading openmp runtime
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
157 - plugins loaded by libomptarget.so:
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
158
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
159 - ``libomptarget.rtl.amdgpu.so``
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
160 - ``libomptarget.rtl.cuda.so``
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
161 - ``libomptarget.rtl.x86_64.so``
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
162 - ``libomptarget.rtl.ve.so``
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
163 - and others
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
164
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
165 - dependencies of those plugins, e.g. cuda/rocr for nvptx/amdgpu
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
166
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
167 The compiled executable is dynamically linked against a host runtime, e.g.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
168 ``libomp.so``, and against the target offloading runtime, ``libomptarget.so``. These
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
169 are found like any other dynamic library, by setting rpath or runpath on the
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
170 executable, by setting ``LD_LIBRARY_PATH``, or by adding them to the system search.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
171
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
172 ``libomptarget.so`` has rpath or runpath (whichever the system default is) set to
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
173 ``$ORIGIN``, and the plugins are located next to it, so it will find the plugins
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
174 without any environment variables set. If ``LD_LIBRARY_PATH`` is set, whether it
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
175 overrides which plugin is found depends on whether your system treats ``-Wl,-rpath``
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
176 as RPATH or RUNPATH.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
177
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
178 The plugins will try to find their dependencies in plugin-dependent fashion.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
179
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
180 The cuda plugin is dynamically linked against libcuda if cmake found it at
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
181 compiler build time. Otherwise it will attempt to dlopen ``libcuda.so``. It does
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
182 not have rpath set.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
183
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
184 The amdgpu plugin is linked against ROCr if cmake found it at compiler build
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
185 time. Otherwise it will attempt to dlopen ``libhsa-runtime64.so``. It has rpath
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
186 set to ``$ORIGIN``, so installing ``libhsa-runtime64.so`` in the same directory is a
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
187 way to locate it without environment variables.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
188
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
189 In addition to those, there is a compiler runtime library called deviceRTL.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
190 This is compiled from mostly common code into an architecture specific
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
191 bitcode library, e.g. ``libomptarget-nvptx-sm_70.bc``.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
192
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
193 Clang and the deviceRTL need to match closely as the interface between them
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
194 changes frequently. Using both from the same monorepo checkout is strongly
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
195 recommended.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
196
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
197 Unlike the host side which lets environment variables select components, the
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
198 deviceRTL that is located in the clang lib directory is preferred. Only if
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
199 it is absent, the ``LIBRARY_PATH`` environment variable is searched to find a
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
200 bitcode file with the right name. This can be overridden by passing a clang
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
201 flag, ``--libomptarget-nvptx-bc-path`` or ``--libomptarget-amdgcn-bc-path``. That
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
202 can specify a directory or an exact bitcode file to use.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
203
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
204
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 Q: Does OpenMP offloading support work in pre-packaged LLVM releases?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 For now, the answer is most likely *no*. Please see :ref:`build_offload_capable_compiler`.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 Q: Does OpenMP offloading support work in packages distributed as part of my OS?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 For now, the answer is most likely *no*. Please see :ref:`build_offload_capable_compiler`.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 .. _math_and_complex_in_target_regions:
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 Q: Does Clang support `<math.h>` and `<complex.h>` operations in OpenMP target on GPUs?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
219 Yes, LLVM/Clang allows math functions and complex arithmetic inside of OpenMP
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
220 target regions that are compiled for GPUs.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 Clang provides a set of wrapper headers that are found first when `math.h` and
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 `complex.h`, for C, `cmath` and `complex`, for C++, or similar headers are
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 included by the application. These wrappers will eventually include the system
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225 version of the corresponding header file after setting up a target device
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 specific environment. The fact that the system header is included is important
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 because they differ based on the architecture and operating system and may
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 contain preprocessor, variable, and function definitions that need to be
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 available in the target region regardless of the targeted device architecture.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 However, various functions may require specialized device versions, e.g.,
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 `sin`, and others are only available on certain devices, e.g., `__umul64hi`. To
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 provide "native" support for math and complex on the respective architecture,
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 Clang will wrap the "native" math functions, e.g., as provided by the device
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 vendor, in an OpenMP begin/end declare variant. These functions will then be
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 picked up instead of the host versions while host only variables and function
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 definitions are still available. Complex arithmetic and functions are support
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 through a similar mechanism. It is worth noting that this support requires
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 `extensions to the OpenMP begin/end declare variant context selector
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 <https://clang.llvm.org/docs/AttributeReference.html#pragma-omp-declare-variant>`__
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 that are exposed through LLVM/Clang to the user as well.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 Q: What is a way to debug errors from mapping memory to a target device?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
245 An experimental way to debug these errors is to use :ref:`remote process
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 offloading <remote_offloading_plugin>`.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247 By using ``libomptarget.rtl.rpc.so`` and ``openmp-offloading-server``, it is
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 possible to explicitly perform memory transfers between processes on the host
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 CPU and run sanitizers while doing so in order to catch these errors.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 Q: Why does my application say "Named symbol not found" and abort when I run it?
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 This is most likely caused by trying to use OpenMP offloading with static
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 libraries. Static libraries do not contain any device code, so when the runtime
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 attempts to execute the target region it will not be found and you will get an
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 an error like this.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 .. code-block:: text
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 CUDA error: Loading '__omp_offloading_fd02_3231c15__Z3foov_l2' Failed
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 CUDA error: named symbol not found
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 Libomptarget error: Unable to generate entries table for device id 0.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 Currently, the only solution is to change how the application is built and avoid
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 the use of static libraries.
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
268 Q: Can I use dynamically linked libraries with OpenMP offloading?
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
269 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 Dynamically linked libraries can be only used if there is no device code split
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 between the library and application. Anything declared on the device inside the
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 shared library will not be visible to the application when it's linked.
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
274
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
275 Q: How to build an OpenMP offload capable compiler with an outdated host compiler?
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
276 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
277
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
278 Enabling the OpenMP runtime will perform a two-stage build for you.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
279 If your host compiler is different from your system-wide compiler, you may need
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
280 to set the CMake variable `GCC_INSTALL_PREFIX` so clang will be able to find the
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
281 correct GCC toolchain in the second stage of the build.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
282
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
283 For example, if your system-wide GCC installation is too old to build LLVM and
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
284 you would like to use a newer GCC, set the CMake variable `GCC_INSTALL_PREFIX`
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
285 to inform clang of the GCC installation you would like to use in the second stage.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
286
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
287 Q: How can I include OpenMP offloading support in my CMake project?
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
288 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
289
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
290 Currently, there is an experimental CMake find module for OpenMP target
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
291 offloading provided by LLVM. It will attempt to find OpenMP target offloading
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
292 support for your compiler. The flags necessary for OpenMP target offloading will
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
293 be loaded into the ``OpenMPTarget::OpenMPTarget_<device>`` target or the
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
294 ``OpenMPTarget_<device>_FLAGS`` variable if successful. Currently supported
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
295 devices are ``AMDGPU`` and ``NVPTX``.
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
296
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
297 To use this module, simply add the path to CMake's current module path and call
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
298 ``find_package``. The module will be installed with your OpenMP installation by
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
299 default. Including OpenMP offloading support in an application should now only
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
300 require a few additions.
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
301
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
302 .. code-block:: cmake
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
303
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
304 cmake_minimum_required(VERSION 3.13.4)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
305 project(offloadTest VERSION 1.0 LANGUAGES CXX)
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
306
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
307 list(APPEND CMAKE_MODULE_PATH "${PATH_TO_OPENMP_INSTALL}/lib/cmake/openmp")
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
308
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
309 find_package(OpenMPTarget REQUIRED NVPTX)
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
310
223
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
311 add_executable(offload)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
312 target_link_libraries(offload PRIVATE OpenMPTarget::OpenMPTarget_NVPTX)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
313 target_sources(offload PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp)
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
314
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
315 Using this module requires at least CMake version 3.13.4. Supported languages
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
316 are C and C++ with Fortran support planned in the future. Compiler support is
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
317 best for Clang but this module should work for other compiler vendors such as
5f17cb93ff66 LLVM13 (2021/7/18)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 221
diff changeset
318 IBM, GNU.
236
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
319
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
320 Q: What does 'Stack size for entry function cannot be statically determined' mean?
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
321 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
322
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
323 This is a warning that the Nvidia tools will sometimes emit if the offloading
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
324 region is too complex. Normally, the CUDA tools attempt to statically determine
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
325 how much stack memory each thread. This way when the kernel is launched each
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
326 thread will have as much memory as it needs. If the control flow of the kernel
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
327 is too complex, containing recursive calls or nested parallelism, this analysis
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
328 can fail. If this warning is triggered it means that the kernel may run out of
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
329 stack memory during execution and crash. The environment variable
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
330 ``LIBOMPTARGET_STACK_SIZE`` can be used to increase the stack size if this
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
331 occurs.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
332
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
333 Q: Can OpenMP offloading compile for multiple architectures?
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
334 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
335
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
336 Since LLVM version 15.0, OpenMP offloading supports offloading to multiple
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
337 architectures at once. This allows for executables to be run on different
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
338 targets, such as offloading to AMD and NVIDIA GPUs simultaneously, as well as
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
339 multiple sub-architectures for the same target. Additionally, static libraries
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
340 will only extract archive members if an architecture is used, allowing users to
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
341 create generic libraries.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
342
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
343 The architecture can either be specified manually using ``--offload-arch=``. If
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
344 ``--offload-arch=`` is present no ``-fopenmp-targets=`` flag is present then the
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
345 targets will be inferred from the architectures. Conversely, if
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
346 ``--fopenmp-targets=`` is present with no ``--offload-arch`` then the target
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
347 architecture will be set to a default value, usually the architecture supported
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
348 by the system LLVM was built on.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
349
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
350 For example, an executable can be built that runs on AMDGPU and NVIDIA hardware
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
351 given that the necessary build tools are installed for both.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
352
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
353 .. code-block:: shell
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
354
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
355 clang example.c -fopenmp --offload-arch=gfx90a --offload-arch=sm_80
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
356
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
357 If just given the architectures we should be able to infer the triples,
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
358 otherwise we can specify them manually.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
359
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
360 .. code-block:: shell
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
361
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
362 clang example.c -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa,nvptx64-nvidia-cuda \
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
363 -Xopenmp-target=amdgcn-amd-amdhsa --offload-arch=gfx90a \
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
364 -Xopenmp-target=nvptx64-nvidia-cuda --offload-arch=sm_80
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
365
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
366 When linking against a static library that contains device code for multiple
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
367 architectures, only the images used by the executable will be extracted.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
368
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
369 .. code-block:: shell
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
370
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
371 clang example.c -fopenmp --offload-arch=gfx90a,gfx90a,sm_70,sm_80 -c
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
372 llvm-ar rcs libexample.a example.o
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
373 clang app.c -fopenmp --offload-arch=gfx90a -o app
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
374
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
375 The supported device images can be viewed using the ``--offloading`` option with
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
376 ``llvm-objdump``.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
377
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
378 .. code-block:: shell
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
379
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
380 clang example.c -fopenmp --offload-arch=gfx90a --offload-arch=sm_80 -o example
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
381 llvm-objdump --offloading example
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
382
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
383 a.out: file format elf64-x86-64
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
384
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
385 OFFLOADING IMAGE [0]:
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
386 kind elf
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
387 arch gfx90a
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
388 triple amdgcn-amd-amdhsa
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
389 producer openmp
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
390
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
391 OFFLOADING IMAGE [1]:
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
392 kind elf
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
393 arch sm_80
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
394 triple nvptx64-nvidia-cuda
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
395 producer openmp
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
396
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
397 Q: Can I link OpenMP offloading with CUDA or HIP?
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
398 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
399
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
400 OpenMP offloading files can currently be experimentally linked with CUDA and HIP
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
401 files. This will allow OpenMP to call a CUDA device function or vice-versa.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
402 However, the global state will be distinct between the two images at runtime.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
403 This means any global variables will potentially have different values when
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
404 queried from OpenMP or CUDA.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
405
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
406 Linking CUDA and HIP currently requires enabling a different compilation mode
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
407 for CUDA / HIP with ``--offload-new-driver`` and to link using
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
408 ``--offload-link``. Additionally, ``-fgpu-rdc`` must be used to create a
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
409 linkable device image.
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
410
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
411 .. code-block:: shell
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
412
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
413 clang++ openmp.cpp -fopenmp --offload-arch=sm_80 -c
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
414 clang++ cuda.cu --offload-new-driver --offload-arch=sm_80 -fgpu-rdc -c
c4bab56944e8 LLVM 16
kono
parents: 232
diff changeset
415 clang++ openmp.o cuda.o --offload-link -o app