Skip to content

Commit a2015d3

Browse files
Merge pull request #3 from Durganshu/develop
Restructuring and bug fixes in Mitosrun and OpenMP hooks
2 parents b9a8d68 + 948a930 commit a2015d3

24 files changed

+1006
-1247
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ cscope.out
88
build/
99
cmake-build-debug/
1010
.idea/
11+
inst-dir/
12+
.vscode/

CMakeLists.txt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ set(MITOS_MAJOR_VERSION 0)
99
set(MITOS_MINOR_VERSION 8)
1010
set(MITOS_PATCH_VERSION 1)
1111
set(MITOS_VERSION ${MITOS_MAJOR_VERSION}.${MITOS_MINOR_VERSION}.${MITOS_PATCH_VERSION})
12-
set(IBS_TYPE "OFF" "IBS_FETCH" "IBS_OP" CACHE STRING "Enabling Instruction-Based Sampling")
1312
option(MITOSHOOKS_OPEN_MP "Enable Mitoshooks OpenMP-Routing" OFF)
13+
14+
# IBS (AMD) and PEBS (Intel) related options
15+
set(IBS_TYPE "OFF" "IBS_FETCH" "IBS_OP" CACHE STRING "Enabling Instruction-Based Sampling")
1416
set_property(CACHE IBS_TYPE PROPERTY STRINGS
1517
"OFF" "IBS_FETCH" "IBS_OP")
1618

@@ -21,13 +23,14 @@ set_property(CACHE IBS_SAMPLING_MODE PROPERTY STRINGS
2123
if ((IBS_TYPE STREQUAL "IBS_FETCH") OR (IBS_TYPE STREQUAL "IBS_OP"))
2224
# define sampling mode for IBS
2325
if (IBS_SAMPLING_MODE STREQUAL "ALL_ON")
24-
message(STATUS "IBS Sampling Mode ALL_ON Selected: Monitor all cores")
26+
message(STATUS "IBS (AMD) Sampling Mode ALL_ON Selected: Monitor all cores")
2527
add_definitions(-DUSE_IBS_ALL_ON)
2628
elseif (IBS_SAMPLING_MODE STREQUAL "THREAD_MIGRATION")
27-
message(STATUS "IBS Sampling Mode THREAD_MIGRATION Selected: Monitor one thread; Migrate sampler at runtime from one core to another")
29+
message(STATUS "IBS (AMD) Sampling Mode THREAD_MIGRATION Selected: Monitor one thread; Migrate sampler at runtime from one core to another")
2830
add_definitions(-DUSE_IBS_THREAD_MIGRATION)
29-
else()
30-
message(STATUS "IBS not set")
31+
# if no IBS options are selected, use PEBS
32+
else()
33+
message(STATUS "Using PEBS (Intel)")
3134
endif ()
3235
endif ()
3336

@@ -37,8 +40,9 @@ if (IBS_TYPE STREQUAL "IBS_FETCH")
3740
elseif (IBS_TYPE STREQUAL "IBS_OP")
3841
message(STATUS "Switch IBS_OP On")
3942
add_definitions(-DUSE_IBS_OP)
40-
else()
41-
message(STATUS "IBS not set")
43+
# If no IBS sampling mode is set, use PEBS
44+
else()
45+
message(STATUS "Using PEBS (Intel)")
4246
endif ()
4347

4448

@@ -66,6 +70,7 @@ endif()
6670
# C-Defines for non-essential packages
6771
if(MPI_FOUND)
6872
add_definitions(-DUSE_MPI)
73+
message(STATUS "Mitoshooks MPI Enabled")
6974
endif()
7075

7176

@@ -97,4 +102,4 @@ export(PACKAGE Mitos)
97102

98103
# Install cmake export
99104
install(EXPORT mitos-targets DESTINATION lib/Mitos)
100-
install(FILES mitos-config.cmake DESTINATION lib/Mitos)
105+
install(FILES mitos-config.cmake DESTINATION lib/Mitos)

README.md

Lines changed: 80 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Mitos requires:
1616
sampling. This originated in the 3.10 Linux kernel, but is backported
1717
to some versions of [RHEL6.6](https://www.redhat.com/promo/Red_Hat_Enterprise_Linux6/).
1818

19-
* [Dyninst](http://www.dyninst.org) version 8.2 or higher.
19+
* [Dyninst](http://www.dyninst.org) version 12.3.0 or higher.
2020

2121
* [hwloc](http://www.open-mpi.org/projects/hwloc/)
2222

@@ -26,11 +26,11 @@ Mitos requires:
2626
`CMAKE_PREFIX_PATH` environment variable.
2727

2828
2. Run the following commands from the root of the MemAxes source:
29-
```
30-
mkdir build && cd build
31-
cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/location ..
32-
make
33-
make install
29+
```bash
30+
$> mkdir build && cd build
31+
$> cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/location ..
32+
$> make
33+
$> make install
3434
```
3535

3636
## Running
@@ -40,18 +40,25 @@ Mitos requires:
4040
1. Find the `mitosrun` command in the `bin` directory in the install
4141
directory.
4242

43-
2. Run any binary with `mitosrun` like this to generate a folder of
44-
mitos output data. For example:
43+
2. Make sure that the path to the installation location of `mitos` and `Dyninst` is added to the `LD_LIBRARY_PATH`. For example:
4544

45+
```bash
46+
$> export LD_LIBRARY_PATH=/path/to/mitos/install/location/lib/
47+
$> export LD_LIBRARY_PATH=/path/to/dyninst/lib/:$LD_LIBRARY_PATH
4648
```
47-
mitosrun ./examples/matmul
49+
50+
3. Run any binary with `mitosrun` like this to generate a folder of
51+
mitos output data. For example:
52+
53+
```bash
54+
$> mitosrun ./examples/matmul
4855
```
4956

5057
The above command will run the matmul example and create a folder
5158
called mitos_###, where ### is the number of seconds since the
5259
epoch. The folder will contain:
5360

54-
```
61+
```bash
5562
mitos_###/
5663
data/
5764
samples.csv
@@ -67,18 +74,20 @@ Mitos requires:
6774

6875
`mitosrun` can also be fine-tuned with the following parameters:
6976

70-
```
77+
```bash
7178
[options]:
7279
-b sample buffer size (default 4096)
7380
-p sample period (default 4000)
7481
-t sample latency threshold (default 10)
82+
-s top folder of source code to copy
7583
```
84+
**See the section on `Source Code Attribution` below for more details on how to save the source code information with the samples collected while running your application.**
7685

77-
## IBS Configuration
78-
1. Configure CMAKE with IBS depending on the chosen executable and configure environment variables if necessary:
86+
## IBS (AMD) Configuration
87+
The default installation of `mitos` will be configured for Intel based Precise Event Based Sampling (PEBS). Additionally, `mitos` supports AMD based Instruction Based Sampling (IBS). Configure CMAKE with IBS depending on the chosen executable and configure environment variables if necessary:
7988
* `IBS_TYPE`
8089
* Use IBS_FETCH or IBS_OP depending on the profiling use case (requires AMD processor with IBS support)
81-
* IBS is not supported on Intel processors, therefore set variable to OFF
90+
* IBS is not supported on Intel processors. By default, the variable is set to OFF.
8291
* `IBS_SAMPLING_MODE`
8392
* Mitosrun (with or without OpenMP): `IBS_ALL_ON` or `IBS_THREAD_MIGRATION`
8493
* Mitoshooks with OpenMP:
@@ -90,19 +99,63 @@ Mitos requires:
9099
* NOTE: `IBS_ALL_ON` might also work, but this sampling method is not recommended.
91100

92101
## Mitoshooks with OpenMP Usage
93-
1. Requirements
94-
* Compiler with OMPT support such as Clang (OpenMP feature since version 5.0)
95-
2. CMake Configuration
96-
* OpenMP found
97-
* `MITOSHOOKS_OPEN_MP`: ON
98-
3. Compilation
99-
* Compilation of Mitoshooks library
100-
* Compilation of OpenMP-application
101-
4. Execution
102-
* Configuration of environment variable `OMP_TOOL_LIBRARIES` that points to mitoshooks-library:
103-
* e.g. for omp_example.cpp: OMP_TOOL_LIBRARIES=./../src/libmitoshooks.so
104-
* Launch OpenMP-application
105-
* ./omp_example
102+
### 1. Requirements
103+
104+
Compiler with OMPT support such as Clang (OpenMP feature since version 5.0) is required. if clang is not the default compiler:
105+
106+
```bash
107+
$> export CC=/path/to/clang*
108+
$> export CXX=/path/to/clang++*
109+
```
110+
### 2. CMake Configuration
111+
112+
OpenMP (version 5.0 and later) must be installed. If OpenMP is not installed at the default loaction, make sure to specify the paths so that `cmake` finds it.
113+
114+
Enable `MITOSHOOKS_OPEN_MP` option by `-DMITOSHOOKS_OPEN_MP=ON`
115+
116+
### 3. Compilation
117+
* Build and install `mitos` and `mitoshooks`
118+
* Depending on the build method (cmake/make/command-line), link the application with `mitos` and `mitoshooks` by specifying their paths.
119+
* See the section on `Source Code Attribution` below for more details on how to save the source code information with the samples collected while running your application.
120+
121+
### 4. Execution
122+
123+
Mitoshooks uses the OMPT interface to collect samples while each thread runs. Configure the environment variable `OMP_TOOL_LIBRARIES` that points to mitoshooks-library and use one of these methods to launch the OpenMP-application.
124+
125+
**Recommended method:**
126+
```bash
127+
$> env OMP_TOOL_LIBRARIES=/path/to/mitos-inst-dir/lib/libmitoshooks.so ./omp_example
128+
```
129+
***The following method should also work but is not recommended. Exporting the variable `OMP_TOOL_LIBRARIES` for the global enviornment may break other OpenMP applications that do not intend to use hooks.***
130+
```bash
131+
$> export OMP_TOOL_LIBRARIES=/path/to/mitos-inst-dir/lib/libmitoshooks.so
132+
133+
$> ./omp_example
134+
```
135+
`Mitoshooks` can be fine-tuned by setting these parameters:
136+
137+
```bash
138+
env MITOS_SAMPLING_PERIOD=1000 MITOS_LATENCY_THRESHOLD=10
139+
```
140+
Default value of sampling period is 4000 and that of sample latency threshold is 3. When setting these values, the application can be executed by:
141+
142+
```bash
143+
$> env OMP_TOOL_LIBRARIES=/path/to/mitos-inst-dir/lib/libmitoshooks.so MITOS_SAMPLING_PERIOD=1000 MITOS_LATENCY_THRESHOLD=10 ./omp_example
144+
```
145+
146+
# Source Code Attribution
147+
148+
## Requirements
149+
* [Dyninst](http://www.dyninst.org) version 12.3.0 or higher.
150+
* The application must be compiled in Debug mode (only `-g` compiler flag sufficient).
151+
152+
## Saving the virtual address
153+
154+
The source code of the executable must save the virtual addess offset when the executable starts runnnig. This can be done by including the [virtual_address_writer.h](src/virtual_address_writer.h) and calling the function [save_virtual_address_offset("virt_address.txt")](src/virtual_address_writer.h#L18).
155+
156+
See [matmul.cpp](examples/matmul.cpp) for reference.
157+
158+
This saves the virtual address offset to `/tmp/virt_address.txt`. Dyninst will access this file and attribute the source code information when the samples are saved.
106159

107160
# Authors
108161

examples/CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ set(CMAKE_BUILD_TYPE Debug)
66
add_executable(api_test api_test.cpp)
77
add_executable(matmul matmul.cpp)
88

9-
target_link_libraries(api_test mitos)
10-
target_link_libraries(matmul dl)
9+
target_link_libraries(api_test mitos mitoshooks)
10+
target_link_libraries(matmul mitos mitoshooks dl)
1111

1212
if(Dyninst_FOUND)
1313
include_directories(${DYNINST_INCLUDE_DIR})
@@ -16,13 +16,16 @@ endif()
1616
if(MPI_FOUND)
1717
include_directories(${MPI_INCLUDE_PATH})
1818
add_executable(mpi_matmul mpi_matmul.cpp)
19+
add_executable(mpi_jacobi mpi_jacobi.cpp)
1920
target_link_libraries(mpi_matmul mitos mitoshooks ${MPI_LIBRARIES})
21+
target_link_libraries(mpi_jacobi mitos mitoshooks ${MPI_LIBRARIES})
2022
endif()
2123

2224
if(OpenMP_CXX_FOUND)
2325
# env OMP_TOOL_LIBRARIES=$(PWD)/libinit.so
2426
# OMP_TOOL_LIBRARIES=./../src/libmitoshooks.so
2527
include_directories(./../src)
28+
message(STATUS "Linking examples with mitos, mitoshooks and OpenMP")
2629
add_executable(omp_example omp_example.cpp)
2730
target_link_libraries(omp_example mitos mitoshooks OpenMP::OpenMP_CXX)
2831
endif ()

examples/api_test.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <cstdlib>
55

66
#include "../src/Mitos.h"
7+
#include "src/virtual_address_writer.h"
78

89
mitos_output mout;
910

@@ -25,7 +26,9 @@ void init_matrices(int N, double **a, double **b, double **c)
2526
*b = new double[N*N];
2627
*c = new double[N*N];
2728

28-
size_t dims[2] = {N,N};
29+
size_t dims[2];
30+
dims[0] = N; //static_cast<size_t>(N);
31+
dims[1] = N; //static_cast<size_t>(N);
2932
Mitos_add_symbol("a",*a,sizeof(double),dims,2);
3033
Mitos_add_symbol("b",*b,sizeof(double),dims,2);
3134
Mitos_add_symbol("c",*c,sizeof(double),dims,2);
@@ -62,6 +65,7 @@ void matmul(int N, double *a, double *b, double *c)
6265

6366
int main(int argc, char **argv)
6467
{
68+
save_virtual_address_offset("virt_address.txt");
6569
int N = (argc == 2) ? atoi(argv[1]) : 1024;
6670

6771
double *a,*b,*c;
@@ -74,9 +78,18 @@ int main(int argc, char **argv)
7478
Mitos_set_sample_latency_threshold(3);
7579
Mitos_set_sample_time_frequency(4000);
7680

77-
//Mitos_begin_sampler();
81+
Mitos_begin_sampler();
7882
matmul(N,a,b,c);
79-
//Mitos_end_sampler();
80-
81-
Mitos_post_process(argv[0],&mout);
82-
}
83+
Mitos_end_sampler();
84+
std::set<std::string> src_files;
85+
Mitos_add_offsets("", &mout);
86+
if(Mitos_openFile(argv[0], &mout))
87+
{
88+
std::cerr << "Error opening binary file!" << std::endl;
89+
return 1;
90+
}
91+
if(Mitos_post_process(argv[0],&mout, src_files)){
92+
std::cerr << "Error post processing!" << std::endl;
93+
return 1;
94+
}
95+
}

0 commit comments

Comments
 (0)