|
1 |
| -Examples |
2 |
| -======== |
| 1 | +Compiler Examples |
| 2 | +================= |
3 | 3 |
|
4 | 4 | The LLVM compiler supports several accelerated programming models
|
5 | 5 | including OpenMP, HIP, opencl, stdpar, hipfort, raja, and kokkos.
|
6 | 6 | Acceleration with OpenMP is available for FORTRAN, c, and C++.
|
7 |
| -These examples demonstrate how to use the LLVM compiler to compile and execute |
8 |
| -applications using these different programming models and various utilities to |
9 |
| -support development. |
| 7 | +These Compiler examples demonstrate how to use the LLVM compiler to compile, |
| 8 | +link, and execute applications using different programming models and |
| 9 | +various utilities to support development. Each Compiler example uses |
| 10 | +'make' to clearly show the full commands to compile, link, and execute |
| 11 | +an application. The execution of make will also show any supporting commands |
| 12 | +and environment variable settings needed to support the example. |
10 | 13 |
|
11 |
| -The examples are divided into categories. These categories are: |
| 14 | +## Compiler Example Categories |
| 15 | + |
| 16 | +The Compiler examples are divided into categories: |
12 | 17 |
|
13 | 18 | - [OpenMP](openmp/README.md) C++ and c examples of OpenMP target offload
|
14 | 19 | - [FORTRAN](fortran) FORTRAN examples of OpenMP target offload
|
15 | 20 | - [HIP](hip/README.md) Acceleration with HIP
|
| 21 | +- [stdpar](stdpar) C++ stdpar examples |
16 | 22 | - [Raja](raja/README.md) Examples that use the RAJA programming model
|
17 | 23 | - [Kokkos](kokkos) Examples that use the kokkos programming model
|
18 | 24 | - [tools](tools) Examples on how to use profiling, debug, and address sanitizer tools
|
19 |
| -- [stress](stress) Examples that are complex or stress resources |
| 25 | +- [stress](stress) Examples that are complex or stress resources. CI is not run on these examples |
| 26 | +- [hipfort](hipfort) FORTRAN examples that use FORTRAN HIP bindings |
20 | 27 |
|
21 | 28 | Eventually we will add these categories:
|
22 | 29 |
|
23 |
| -- [stdpar](stdpar) C++ stdpar examples |
24 | 30 | - [opencl](opencl) Examples of offloading with OpenCL
|
25 |
| -- [hipfort](hipfort) FORTRAN examples that use FORTRAN HIP bindings |
26 | 31 |
|
27 | 32 | Each category is a directory and each example is a subdirectory of the category directory.
|
28 |
| -Typically there is a Makefile for each example. That Makefile can be executed with either update |
29 |
| -access to the example directory or in a different directory since examples typically exist in a |
30 |
| -read-only installation directory. These commands show how to run an example from |
31 |
| -a writable tmp directory. |
| 33 | + |
| 34 | + |
| 35 | +## Using Compiler Example Makefiles |
| 36 | + |
| 37 | +There is a Makefile for each Compiler example. The Makefile(s) can be executed |
| 38 | +with update access to the example directory where the Makefile and sources are |
| 39 | +found, "in-tree", OR from a different directory, "out-of-tree". |
| 40 | +These commands demonstrate how to test the example "in-tree": |
| 41 | +``` |
| 42 | +cd openmp/veccopy |
| 43 | +make run |
| 44 | +
|
| 45 | +``` |
| 46 | +An "out-of-tree" test is useful when examples are stored in a read-only |
| 47 | +directory such as the ROCm installation directory. For example, to run the |
| 48 | +veccopy example "out-of-tree" from a new /tmp directory run these commands: |
32 | 49 | ```
|
33 | 50 | mkdir /tmp/demo ; cd /tmp/demo
|
34 |
| -EXROOT=/opt/rocm/share/openmp-extras/examples # The examples base directory. |
| 51 | +EXROOT=/opt/rocm/share/examples/Compiler # The examples base directory. |
35 | 52 | make -f $EXROOT/openmp/veccopy/Makefile run
|
36 | 53 | ```
|
37 | 54 | The above will compile and execute the openmp/veccopy example.
|
38 |
| -The Makefile will print the compile and execute commands to your console. |
| 55 | +The Makefile will print the compile and execute commands to the console. |
| 56 | + |
| 57 | +If you plan to copy the sources for these examples, be sure to copy |
| 58 | +the entire Compiler examples directory. For example: |
| 59 | +``` |
| 60 | +EXROOT=/opt/rocm/share/examples/Compiler # The examples base directory. |
| 61 | +cp -rp $EXROOT /tmp |
| 62 | +cd /tmp/Compiler/openmp/veccopy |
| 63 | +make run |
| 64 | +``` |
| 65 | +## Setting LLVM_INSTALL_DIR and LLVM_GPU_ARCH |
39 | 66 |
|
40 |
| -Each Makefile typically includes the common Makefile helper file |
41 |
| -[Makefile.find_gpu_and_install_dir](Makefile.find_gpu_and_install_dir). |
42 |
| -This include file finds the LLVM compiler and sets the environment |
43 |
| -variable `LLVM_INSTALL_DIR` if not already preset by the user. |
44 |
| -If not preset, or the value of `LLVM_INSTALL_DIR` specifies a nonexistant directory, |
45 |
| -the Makefile searches this list of directories: |
| 67 | +Each Makefile includes the common Makefile helper file |
| 68 | +[inc/find_gpu_and_install_dir.mk](inc/find_gpu_and_install_dir.mk). |
| 69 | +This "include-file" finds the LLVM compiler and sets environment |
| 70 | +variable `LLVM_INSTALL_DIR`, if not already preset by the user. |
| 71 | +If not preset, or `LLVM_INSTALL_DIR` specifies a nonexistant directory, |
| 72 | +the include-file searches this list of directories to set 'LLVM_INSTALL_DIR': |
46 | 73 |
|
47 | 74 | ```
|
48 | 75 | /opt/rocm/lib/llvm /usr/lib/aomp ./../../../llvm ~/rocm/aomp
|
49 | 76 | ```
|
| 77 | +If no LLVM installation is found, all Compile examples will fail. |
| 78 | +Therefore, it is recommended that users of these examples preset `LLVM_INSTALL_DIR` |
| 79 | +to use a compiler other than the last installed ROCm compiler typically |
| 80 | +found at /opt/rocm/lib/llvm. |
50 | 81 |
|
51 |
| -The Makefile sets `LLVM_INSTALL_DIR` to the first directory it finds in the above list. |
52 |
| -It is recommended that users of these examples preset `LLVM_INSTALL_DIR` |
53 |
| -if they want to demo the compiler with something other than the last |
54 |
| -installed ROCm compiler. |
55 |
| - |
56 |
| -The include file then determines if there is an active GPU and |
57 |
| -the GPU architecture (eg. gfx940, sm_70, etc). |
58 |
| -It first checks for an active amdgpu kernel module |
59 |
| -If there is an active amdgpu kernel, the LLVM compiler utility |
60 |
| -`$(LLVM_INSTALL_DIR)/bin/amdgpu-arch` is used to set |
61 |
| -the value `LLVM_GPU_ARCH` which instructs the compiler which GPU to compile for. |
| 82 | +The include-file then searches for an active GPU to set `LLVM_GPU_ARCH` |
| 83 | +(e.g. gfx90a, gfx940, sm_70, etc). |
| 84 | +Each example uses the value of `LLVM_GPU_ARCH` to instruct the compiler |
| 85 | +which GPU to use for compilation. If `LLVM_GPU_ARCH` is not preset, |
| 86 | +the include-file first checks for an active amdgpu kernel module. |
| 87 | +If there is an active amdgpu kernel module, the include-file calls the LLVM compiler utility |
| 88 | +`$(LLVM_INSTALL_DIR)/bin/amdgpu-arch` to set the value of `LLVM_GPU_ARCH`. |
62 | 89 | If no active amdgpu kernel module is found, the include file looks for an nvidia PCI
|
63 |
| -device and then uses the compiler utility `$(LLVM_INSTALL_DIR)/bin/amdgpu-arch` |
| 90 | +device and then uses the compiler utility `$(LLVM_INSTALL_DIR)/bin/nvptx-arch` |
64 | 91 | to set the value `LLVM_GPU_ARCH`.
|
| 92 | +If there are no active GPUs or the examples are being run for compile-only, |
| 93 | +users may preset `LLVM_GPU_ARCH` to avoid this search. |
| 94 | + |
| 95 | +If `LLVM_GPU_ARCH` is not preset and no GPUs are found, all Compile examples will fail. |
| 96 | + |
| 97 | +## Makefile Targets |
65 | 98 |
|
66 |
| -If no LLVM installation or GPU could be found, the example Makefile will fail. |
67 |
| -So if you want to demo the compiler with something other than the last |
68 |
| -installed ROCm compiler (which is typically found at /opt/rocm/lib/llvm), |
69 |
| -then it is recommended that users preset LLVM_INSTALL_DIR. |
| 99 | +The default for each Makefile is to compile and link the example binary. |
| 100 | +The target "run" will compile, link, and execute the example. |
| 101 | +The target "clean" will remove all generated files by the Makefile. |
70 | 102 |
|
71 |
| -There are often other make targets to show different ways to build the binary. |
| 103 | +There are often other make targets. To show different ways to build the binary. |
72 | 104 | E.g. to run with some debug output set `OFFLOAD_DEBUG` variable:
|
73 | 105 |
|
74 | 106 | ```
|
75 | 107 | env OFFLOAD_DEBUG=1 make
|
76 | 108 | env OFFLOAD_DEBUG=1 make run
|
77 | 109 | ```
|
78 | 110 |
|
79 |
| -Run ```make help``` to see all the possible demos of each example. |
| 111 | +Run ```make help``` to see various demos of each example. |
| 112 | + |
| 113 | +## Hierarchical Makefiles |
| 114 | + |
| 115 | +Each category has a Makefile that will build and run all the examples for that category. |
| 116 | +For example the Makefile for openmp is [openmp/Makefile](here). |
| 117 | +To test all the openmp examples with the AOMP compiler run these commands: |
| 118 | +``` |
| 119 | +EXROOT=~/git/rocm-examples/Compiler # The examples base directory. |
| 120 | +cd $EXROOT/openmp |
| 121 | +env LLVM_INSTALL_DIR=$AOMP make run |
| 122 | +``` |
| 123 | +The Compiler Examples has a root [Makefile](Makefile) that can be used to build and run all examples. |
| 124 | +To test all Compiler Examples with the AOMP compiler run these commands: |
| 125 | +``` |
| 126 | +EXROOT=~/git/rocm-examples/Compiler # The examples base directory. |
| 127 | +cd $EXROOT |
| 128 | +env LLVM_INSTALL_DIR=$AOMP make run |
| 129 | +``` |
| 130 | + |
| 131 | + |
| 132 | +## Contributions |
| 133 | + |
| 134 | +If you want to contribute a Compiler example, please read these [rules](inc/contribute_rules.md). |
0 commit comments