Skip to content

Commit

Permalink
test: added "update wiki" action
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Oct 31, 2022
1 parent 578283d commit ce19f67
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/update_wiki.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Update Wiki

on:
push:
paths:
- 'wiki/**'
branches:
- develop
jobs:
update-wiki:
runs-on: ubuntu-latest
name: Update wiki
steps:
- uses: OrlovM/Wiki-Action@v1
with:
path: 'wiki'
token: ${{ secrets.GITHUB_TOKEN }}
82 changes: 82 additions & 0 deletions wiki/DiscoPoP-Explorer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# DiscoPoP graph analyzer
DiscoPoP profiler is accompanied by a Python framework, specifically designed to analyze the profiler output files, generate a CU graph, detect potential parallel patterns, and suggest OpenMP parallelizations.
Currently, the following five patterns can be detected:
* Reduction
* Do-All
* Pipeline
* Geometric Decomposition
* Task Parallelism

## Getting started
We assume that you have already run the DiscoPoP profiler on the target sequential application, and the following files are created in the current working directory:
* `Data.xml` (CU information in XML format created by *CUGeneration* pass)
* `<app_name>_dep.txt` (Data dependences created by *DPInstrumentation* pass)
* `reduction.txt` and `loop_counter_output.txt` (Reduction operations and loop iteration data identified by *DPReduction* pass)

In case any of the files mentioned above are missing, please follow the [DiscoPoP manual](../README.md) to generate them.

In addition to the already mentioned files, a file named `<app_name>_CUInstResult.txt` is required for the task parallelism detection.
In order to generate it, the following sequence of commands can be used:
```
python3 -m discopop_explorer --path=<path> --cu-xml=<cuxml> --dep-file=<depfile> --loop-counter=<loopcount> --reduction=<reduction> --generate-data-cu-inst=<outputdir>
clang++ -S -emit-llvm -c -std=c++11 -g <DISCOPOP_PATH>/CUInstantiation/RT/CUInstantiation_iFunctions.cpp -o iFunctions_CUInst.ll
clang++ -g -O0 -emit-llvm -fno-discard-value-names -c <C_File> -o tmp_target_app.ll
<CLANG_BIN_DIR>/opt -S -load=<PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMCUInstantiation.so -CUInstantiation -input=Data_CUInst.txt tmp_target_app.ll -fm-path=FileMapping.txt -o tmp_target_app_instrumented.ll
clang++ tmp_target_app_instrumented.ll iFunctions_CUInst.ll -o <app_name>_cui -L$PATH_TO_DISCOPOP_BUILD_DIR/rtlib -lDiscoPoP_RT -lpthread -o <app_name>_cui
rm tmp_target_app.ll tmp_target_app_instrumented.ll iFunctions_CUInst.ll
./<app_name>_cui
```


### Pre-requisites
To use the graph analyzer tool, you need to have Python 3.6+ installed on your system. Further Python dependencies can be installed using the following command:
`pip install -r requirements.txt`

### Usage
To run the graph analyzer, you can use the following command:

`python3 -m discopop_explorer --path <path-to-your-output>`

You can specify the path to DiscoPoP output files. Then, the Python script searches within this path to find the required files. Nevertheless, if you are interested in passing a specific location to each file, here is the detailed usage:

`discopop_explorer [--path <path>] [--cu-xml <cuxml>] [--dep-file <depfile>] [--plugins <plugs>] [--loop-counter <loopcount>] [--reduction <reduction>] [--json <json>] [--fmap <fmap>] [--cu-inst-res <cuinstres>] [--llvm-cxxfilt-path <cxxfp>] [--generate-data-cu-inst <outputdir>]`

Options:
```
--path=<path> Directory with input data [default: ./]
--cu-xml=<cuxml> CU node xml file [default: Data.xml].
--dep-file=<depfile> Dependencies text file [default: dep.txt].
--loop-counter=<loopcount> Loop counter data [default: loop_counter_output.txt].
--reduction=<reduction> Reduction variables file [default: reduction.txt].
--cu-inst-res=<cuinstres> CU instantiation result file. Task Pattern Detector is executed if this option is set.
--llvm-cxxfilt-path=<cxxfp> Path to llvm-cxxfilt executable. Required for Task Pattern Detector
if non-standard path should be used.
--plugins=<plugs> Plugins to execute
--fmap=<fmap> File mapping [default: FileMapping.txt]
--json Output result as a json file to specified path
--generate-data-cu-inst=<outputdir> Generates Data_CUInst.txt file and stores it in the given directory.
Stops the regular execution of the discopop_explorer.
Requires --cu-xml, --dep-file, --loop-counter, --reduction.
-h --help Show this screen.
--version Show version.
```

By default, running the graph analyzer will print out the list of patterns along with OpenMP parallelization suggestions to the standard output. You can also obtain the results in JSON format by passing `--json` argument to the Python script.

### Walkthrough example
The **test/** folder contains a number of precomputed inputs for testing the tool, e.g., *atax* from Polybench benchmark suite.
You can try out this example workflow.

**test/reduction/** contains source code and precomputed DiscoPoP output for a simple reduction loop.
The loop itself sums up all numbers from 1 to n.

You can run DiscoPoP on **main.c** or just use included output.

After that, you can run **discopop_explorer**. The **--path** argument should point to the output of the DiscoPoP.

In this example, the output for reduction will point to the lines 6-9, and it will suggest **pragma omp parallel for** OpenMP directive for parallelizing the loop.
You will also find **i** classified as a private variable and **sum** as a reduction variable. Thus, the parallelization directive would be suggested as follows:

```#pragma omp parallel for private(i) reduction(+:sum)```

The suggested pattern is demonstrated in **mainp.c**
125 changes: 125 additions & 0 deletions wiki/DiscoPoP-Profiler.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
*Call clang++ with DiscoPoP LLVM passes.*

The DiscoPoP profiler consists of multiple LLVM libraries (CUGeneration,
DPInstrumentation and DPReduction) to be passed to clang++ at compilation, as
well as a runtime library for the instrumented code.

`discopop_profiler` wraps clang++ invocations to include the necessary compiler
and linker flags to make use of the DiscoPoP features. To use one of
the DiscoPoP passes, `discopop_profiler` is used *instead* of `clang++`, with
one of the option flags `--CUGeneration`, `--DPInstrumentation` or
`--DPReduction` to select the LLVM pass.

## Pre-requisites

`discopop_profiler` is included in the
[PyPI package `discopop`](https://pypi.org/project/discopop/). As such, it is
installed with

```
pip install discopop
```

It is required that the DiscoPoP profiler is installed (see
[DiscoPoP profiler installation](../README.md#discopop-profiler-installation))
and the environment variable `DISCOPOP_INSTALL` is set to the path where
DiscoPoP is installed.

```
export DISCOPOP_INSTALL=<PATH_TO_DISCOPOP_BUILD_DIRECTORY>
```

## Usage

```
usage: discopop_profiler [--verbose] [--clang CLANG]
(--CUGeneration | --DPInstrumentation | --DPReduction)
<clang++ arguments>
Call clang++ with DiscoPoP LLVM passes.
optional arguments:
-h, --help Show this help message and exit.
-V, --version Show version number and exit.
-v, --verbose Show additional information such as clang++
invocations.
--clang CLANG Path to clang++ executable.
--CUGeneration, --cugeneration
Obtain the computational unit (CU) graph of the target
application.
--DPInstrumentation, --dpinstrumentation
Instrument the target application to obtain data
dependences.
--DPReduction, --dpreduction
Instrument the target application to obtain the list
of reduction operations.
```

### CU generation

To obtain the computational unit (CU) graph of the target application, please
run the following command.

```
discopop_profiler --CUGeneration -c <C_File>
```

### Dependence profiling

To obtain data dependences, we need to instrument the target application.
Running the instrumented application will result in a text file containing all
the dependences that are located in the present working directory.

```
discopop_profiler --DPInstrumentation -c <C_File> -o out.o
discopop_profiler --DPInstrumentation out.o -o <APP_NAME>
./<APP_NAME>
```

### Identifying reduction operations

To obtain the list of reduction operations in the target application, we need to
instrument the target application. Running the instrumented application will
result in a text file containing all the reductions that are located in the
present working directory.

```
discopop_profiler --DPReduction -c <C_File> -o out.o
discopop_profiler --DPReduction out.o -o <APP_NAME>
./<APP_NAME>
```

### Usage with projects that use the CMake build system

Since `discopop_profiler` is invoked like a regular compiler, it is easy to run
DiscoPoP instrumentation on projects that use a build system such as CMake.

1. Configure CMake to use `discopop_profiler` as `CMAKE_CXX_COMPILER`:
```
cmake -DCMAKE_CXX_COMPILER="discopop_profiler" -DCMAKE_CXX_FLAGS="--DPInstrumentation" .
```
1. Build the project with DiscoPoP instrumentation applied on the code:
```
make
```

## Troubleshooting

### clang++ executable not found in PATH

`discopop_profiler` expects to find `clang++-8` or `clang++` in your system's `PATH`.
If clang is installed elsewhere, either add the installation location to your
`PATH`, or set the location to the `clang++` binary to be invoked with

```
discopop_profiler --clang=<PATH_TO_CLANG++_EXECUTABLE> ...
```

### Compiler invocation

`discopop_profiler` prints the exact flags passed to `clang++` if the `--verbose`
flag is set.

```
discopop_profiler --verbose ...
```
40 changes: 40 additions & 0 deletions wiki/Guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Walk-through example
The following walk-through example demonstrates how to use DiscoPoP to analyze a sequential sample application and identify its parallelization opportunities. In this example, we use the program `SimplePipeline`. As its name suggests, this program involves a pipeline pattern. We assume that you have successfully installed DiscoPoP. The following diagram depicts the whole workflow of obtaining the parallelization suggestions.

![DiscoPoP workflow diagram](/docs/img/DPWorkflow.svg)

First, switch to the `/test/simple_pipeline` folder that contains the program `SimplePipeline.c`. Then, please run the following commands step-by-step to obtain the desired results.

1) Run the `dp-fmap` script to obtain the list of files. The output will be written in a file named FileMapping.txt.

`<DISCOPOP_PATH>/scripts/dp-fmap`

2) To obtain the computational units (CU), please run the following command.

`clang++ -g -O0 -fno-discard-value-names -Xclang -load -Xclang <PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMCUGeneration.so -mllvm -fm-path -mllvm ./FileMapping.txt -c SimplePipeline.c`

The output is an XML file that contains all the CU nodes and their connections. You should be able to obtain an XML file as in [`Data.xml`](/test/simple_pipeline/data/Data.xml). Using the information in this file, we can generate a CU graph.

3) To obtain data dependences, we need to instrument the application and run it.
```
clang++ -g -O0 -fno-discard-value-names -Xclang -load -Xclang <PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMDPInstrumentation.so -mllvm -fm-path -mllvm ./FileMapping.txt -c SimplePipeline.c -o out.o
clang++ out.o -L<PATH_TO_DISCOPOP_BUILD_DIR>/rtlib -lDiscoPoP_RT -lpthread -o out
./out
```
The output is a text file that contains all the dependences. You should be able to obtain a CU graph as in [`dp_run_dep.txt`](/test/simple_pipeline/data/dp_run_dep.txt).

A data dependence is represented as a triple `<sink, type, source>`. `type` denotes the dependence type and can be any of `RAW`, `WAR` or `WAW`. Note that a special type `INIT` represents the first write operation to a memory address. `source` and `sink` are the source code locations of the former and the latter memory access, respectively. `sink` is further represented as a pair `<fileID:lineID>`, while source is represented as a triple `<fileID:lineID|variableName>`. The keyword `NOM` (short for "NORMAL") indicates that the source line specified by aggregated `sink` has no control-flow information. Otherwise, `BGN` and `END` represent the entry and exit points of a control region.

4) Although there is no reduction pattern in SimplePipeline, we strongly suggest that you run the reduction analysis to avoid missing any pattern and obtain necessary loop information. This pass instruments the target application and analyzes its loops to identify their iteration counts and obtain the list of potential reduction operations. Running the instrumented application will result in a text file that containins all the reductions located in the working directory.
```
clang++ -g -O0 -fno-discard-value-names -Xclang -load -Xclang <PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMDPReduction.so -mllvm -fm-path -mllvm ./FileMapping.txt -c SimplePipeline.c -o out.o
clang++ out.o -L<PATH_TO_DISCOPOP_BUILD_DIR>/rtlib -lDiscoPoP_RT -lpthread -o out
./out
```
Besides the list of reduction loops, this step generates two important files named `loop_counter_output.txt` and `loop_meta.txt`. The pattern analysis in the next step requires these files along with CU graph and dependences.

5) To obtain the list of patterns and OpenMP parallelization suggestions, run the Python application `discopop_explorer`:

`python3 -m discopop_explorer --cu-xml=Data.xml --dep-file=dp_run_dep.txt`

You should now be able to see the pipeline pattern that was found in the target application along with its stages plus suitable OpenMP constructs for parallelization. You can access a sample output in [simple_pipeline.json](/test/simple_pipeline.json). Using these hints, you can start parallelizing the target application.
70 changes: 70 additions & 0 deletions wiki/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# DiscoPoP - Discovery of Potential Parallelism
Hello World!
DiscoPoP is an open-source tool that helps software developers parallelize their programs with threads. It is a joint project of Technical University of Darmstadt and Iowa State University.

In a nutshell, DiscoPoP performs the following steps:
* detect parts of the code (computational units or CUs) with little to no internal parallelization potential,
* find data dependences among them,
* identify parallel patterns that can be used to parallelize a code region,
* and finally suggest corresponding OpenMP parallelization constructs and clauses to programmers.

DiscoPoP is built on top of LLVM. Therefore, DiscoPoP can perform the above-mentioned steps on any source code which can be transferred into the LLVM IR.

A more comprehensive overview of DiscoPoP can be found on our [project website](https://www.discopop.tu-darmstadt.de/).

## Getting started
### Pre-requisites
Before doing anything, you need a basic development setup. We have tested DiscoPoP on Ubuntu, and the prerequisite packages should be installed using the following command:

sudo apt-get install git build-essential cmake

Additionally, you need to install LLVM on your system. Currently, DiscoPoP only supports LLVM versions between 8.0 and 11.1. Due to API changes, which lead to compilation failures, it does not support lower and higher versions. Please follow the [installation tutorial](https://llvm.org/docs/GettingStarted.html), or install LLVM 11 via a package manager as shown in the following snippet, if you have not installed LLVM yet.

apt-get install libclang-11-dev clang-11 llvm-11

### DiscoPoP profiler installation
First, clone the source code into the designated folder. Then, create a build directory:

mkdir build; cd build;

Next, configure the project using CMake. The preferred LLVM installation path for DiscoPoP can be set using the -DLLVM_DIST_PATH=<PATH_TO_LLVM_BUILD_FOLDER> CMake variable.

cmake -DLLVM_DIST_PATH=<PATH_TO_LLVM_BUILD_FOLDER> ..

Once the configuration process is successfully finished, run `make` to compile and obtain the DiscoPoP libraries. All the shared objects will be stored in the build directory under a folder named as `libi/`.


### Running DiscoPoP
DiscoPoP contains different tools for analyzing the target sequential application, namely CUGeneration, DPInstrumentation, and DPReduction. In the following, we will explain how to run each of them. However, before executing anything, please run the `dp-fmap` script in the root folder of the target application to obtain the list of files. The output will be written in a file named `FileMapping.txt`.

<DISCOPOP_PATH>/scripts/dp-fmap

#### CU generation
To obtain the computational unit (CU) graph of the target application, please run the following command.

clang++ -g -O0 -fno-discard-value-names -Xclang -load -Xclang <PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMCUGeneration.so -mllvm -fm-path -mllvm ./FileMapping.txt -c <C_File>

#### Dependence profiling
To obtain data dependences, we need to instrument the target application. Running the instrumented application will result in a text file containing all the dependences that are located in the present working directory.

clang++ -g -O0 -fno-discard-value-names -Xclang -load -Xclang <PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMDPInstrumentation.so -mllvm -fm-path -mllvm ./FileMapping.txt -c <C_File> -o out.o
clang++ out.o -L<PATH_TO_DISCOPOP_BUILD_DIR>/rtlib -lDiscoPoP_RT -lpthread
./<APP_NAME>

#### Identifying reduction operations
To obtain the list of reduction operations in the target application, we need to instrument the target application. Running the instrumented application will result in a text file containing all the reductions that are located in the present working directory.

clang++ -g -O0 -fno-discard-value-names -Xclang -load -Xclang <PATH_TO_DISCOPOP_BUILD_DIR>/libi/LLVMDPReduction.so -mllvm -fm-path -mllvm ./FileMapping.txt -c <C_File> -o out.o
clang++ out.o -L<PATH_TO_DISCOPOP_BUILD_DIR>/rtlib -lDiscoPoP_RT -lpthread
./<APP_NAME>

*NOTE:* Please use the exact compiler flags that we used. Otherwise, you might not get the correct results, or the analysis might fail.

DiscoPoP also provides a wrapper [discopop_profiler](discopop_profiler/README.md) to
easily invoke clang with the DiscoPoP LLVM passes.

#### Pattern identfication
Once you have all the results generated by DiscoPoP passes, you can use them to identify possible parallel design patterns. To learn more, please read the pattern detection [README](/discopop_explorer/README.md), which explains how to run pattern identification in detail.

## Walk-through example
In the `test/` folder, we have provided sample programs to help you start using DiscoPoP. You can find the walk-through example [here](https://github.com/discopop-project/discopop/wiki/Tutorial).

0 comments on commit ce19f67

Please sign in to comment.