Conditional compilation of eventify

This commit is contained in:
Patrick Lipka 2024-12-16 14:51:38 +01:00
parent 3473ce65ee
commit b83b868e33
3 changed files with 29 additions and 13 deletions

View File

@ -1,12 +1,18 @@
CXX ?= g++ CXX ?= g++
OPTFLAGS ?= -O3 -march=native OPTFLAGS ?= -O3 -march=native
VECTOR_SIZE ?= 268435456 VECTOR_SIZE ?= 268435456
CPPFLAGS = -DVECTOR_SIZE=$(VECTOR_SIZE) ENABLE_EVENTIFY ?= YES
INCLUDES = -I./include -I$(EVENTIFY_ROOT)/include
CPPFLAGS = -DVECTOR_SIZE=$(VECTOR_SIZE)
INCLUDES = -I./include
CXXFLAGS = $(CPPFLAGS) -std=c++20 -fopenmp $(INCLUDES) $(OPTFLAGS) CXXFLAGS = $(CPPFLAGS) -std=c++20 -fopenmp $(INCLUDES) $(OPTFLAGS)
LDFLAGS = -fopenmp -L$(EVENTIFY_ROOT)/lib -leventify LDFLAGS = -fopenmp
ifeq ($(ENABLE_EVENTIFY), "YES")
CPPFLAGS += -DENABLE_EVENTIFY
INCLUDES += -I$(EVENTIFY_ROOT)/include
LDFLAGS += -L$(EVENTIFY_ROOT)/lib -leventify
endif
SRC_DIR = src SRC_DIR = src
INCLUDE_DIR = include INCLUDE_DIR = include

View File

@ -35,12 +35,10 @@ You may as well contact the author Patrick Lipka (patrick.lipka@sipearl.com).
- C++20 or higher - C++20 or higher
- OpenMP support (for OpenMP parallelization strategy) - OpenMP support (for OpenMP parallelization strategy)
- Eventify library (for Eventify parallelization strategy)
- Limitation: Providing installs for all implemented parallelization strategies is mandantory at this point. Selective compilation of strategies might be added later if needed.
### Dependencies: ### Dependencies:
- **Eventify**: Ensure that the Eventify library is properly installed and the environment variable `EVENTIFY_ROOT` points to the root directory of the Eventify installation. - **Eventify**: If you want to compiler with eventify (`ENABLE_EVENTIFY=YES`), ensure that the eventify library is properly installed and the environment variable `EVENTIFY_ROOT` points to the root directory of the Eventify installation.
## Building the Project ## Building the Project
@ -50,7 +48,13 @@ To build the project, run:
make make
``` ```
This will compile the source files and generate an executable called `benchmark` in the `bin/` directory. The default is to compile with eventify enabled `ENABLE_EVENTIFY=YES`. If you want to build without eventify, please done
```
ENABLE_EVENTIFY=NO make
```
The make command will compile the source files and generate an executable called `benchmark` in the `bin/` directory.
Similar to the STREAM benchmark´s Makefile, the vector sizes are defined by the preprocessor variable `VECTOR_SIZE` that can be set in the Makefile. Similar to the STREAM benchmark´s Makefile, the vector sizes are defined by the preprocessor variable `VECTOR_SIZE` that can be set in the Makefile.
### Clean Up ### Clean Up
@ -158,11 +162,11 @@ To add a new kernel to the project, follow these steps:
- Kernels must be registered with a **name** (e.g., `"vector_product"`) and should include the corresponding **allocations and data initialization** (`prepare`) and **kernel logic** (`execute`). - Kernels must be registered with a **name** (e.g., `"vector_product"`) and should include the corresponding **allocations and data initialization** (`prepare`) and **kernel logic** (`execute`).
- Kernels must consist out of an outer loop at least for now. - Kernels must consist out of an outer loop at least for now.
- The kernels execution should be parallelizable using all of the available strategies (`omp` (OpenMP) and `eventify` (Eventify) for now). You can add more strategies by extending the `strategy` namespace. - The kernels execution should be parallelizable using all of the available strategies (`omp` (OpenMP) and `eventify` (eventify tasking library) for now). You can add more strategies by extending the `strategy` namespace.
- The `VECTOR_SIZE` preprocessor variable defines the size of the input data and should be appropriate for the kernel you are implementing. - The `VECTOR_SIZE` preprocessor variable defines the size of the input data and should be appropriate for the kernel you are implementing.
## Known Isuues and Limitations ## Known Isuues and Limitations
- The instantiation of Eventify's `task_system` is inckluded in the kernel timing, leading to a constant overhead compared to OpenMP. On NVIDIA Grace, this is 2.8 ms. It's ongoning discussion whether to include it or not. - The instantiation of eventify's `task_system` is inckluded in the kernel timing, leading to a constant overhead compared to OpenMP. On NVIDIA Grace, this is 2.8 ms. It's ongoning discussion whether to include it or not.
## Contributing ## Contributing

View File

@ -2,11 +2,13 @@
#define STRATEGY_HPP #define STRATEGY_HPP
#include <omp.h> #include <omp.h>
#include <eventify/task_system.hxx>
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#ifdef ENABLE_EVENTIFY
#include <eventify/task_system.hxx>
#endif
// Parallelization strategies are defined here. Assumption for now: there is // Parallelization strategies are defined here. Assumption for now: there is
// always an outer loop than can be parallelized. The strategies are templates // always an outer loop than can be parallelized. The strategies are templates
// instanciated when adding kernels to the kernel registry. // instanciated when adding kernels to the kernel registry.
@ -35,6 +37,7 @@ void openmp_strategy(int kernel_start_idx, int kernel_end_idx, int n_threads,
} }
} }
#ifdef ENABLE_EVENTIFY
// for eventify, we calculate indices for evenly divided chunks of the outermost // for eventify, we calculate indices for evenly divided chunks of the outermost
// loop, create independent tasks and submit them to the tasking system // loop, create independent tasks and submit them to the tasking system
template <typename Func> template <typename Func>
@ -59,7 +62,8 @@ void eventify_strategy(int kernel_start_idx, int kernel_end_idx, int n_tasks,
task_system.submit(task); task_system.submit(task);
} }
} }
#endif //ENABLE_EVENTIFY
// parallelization strategy selector // parallelization strategy selector
template <typename Func> template <typename Func>
requires invocable_with_int<Func> requires invocable_with_int<Func>
@ -69,9 +73,11 @@ void execute_strategy(const std::string& strategy_name, int kernel_start_idx,
if (strategy_name == "omp") { if (strategy_name == "omp") {
openmp_strategy(kernel_start_idx, kernel_end_idx, num_threads_or_tasks, openmp_strategy(kernel_start_idx, kernel_end_idx, num_threads_or_tasks,
std::forward<Func>(loop_body)); std::forward<Func>(loop_body));
#ifdef ENABLE_EVENTIFY
} else if (strategy_name == "eventify") { } else if (strategy_name == "eventify") {
eventify_strategy(kernel_start_idx, kernel_end_idx, num_threads_or_tasks, eventify_strategy(kernel_start_idx, kernel_end_idx, num_threads_or_tasks,
std::forward<Func>(loop_body)); std::forward<Func>(loop_body));
#endif
} else { } else {
throw std::invalid_argument("Unknown strategy: " + strategy_name); throw std::invalid_argument("Unknown strategy: " + strategy_name);
} }