Skip to content

Commit c7e1e7a

Browse files
committed
Optional events for master and worksharing constructs.
Events are not used for AD and disabled by default. Support events for worksharing constructs in the macro backend. Merge branch 'feature/optionalEvents' into develop
2 parents 0602053 + 053d78b commit c7e1e7a

5 files changed

Lines changed: 53 additions & 12 deletions

File tree

.gitlab-ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ gcc-macro:
1616

1717
clang-macro:
1818
image: fedora:41
19+
parallel:
20+
matrix:
21+
- FLAGS: ["", "-DOPDI_BACKEND_GENERATE_MASTER_EVENTS=1 -DOPDI_BACKEND_GENERATE_WORK_EVENTS=1"]
1922
script:
2023
- dnf install -y diffutils binutils clang git
2124
- git clone --depth 1 --branch develop https://github.com/SciCompKL/CoDiPack.git
@@ -29,7 +32,7 @@ clang-ompt:
2932
image: fedora:41
3033
parallel:
3134
matrix:
32-
- FLAGS: ["-DOPDI_OMPT_BACKEND_IMPLICIT_TASK_END_SOURCE=1", "-DOPDI_OMPT_BACKEND_IMPLICIT_TASK_END_SOURCE=2"]
35+
- FLAGS: ["-DOPDI_OMPT_BACKEND_IMPLICIT_TASK_END_SOURCE=1", "-DOPDI_OMPT_BACKEND_IMPLICIT_TASK_END_SOURCE=2", "-DOPDI_BACKEND_GENERATE_MASTER_EVENTS=1 -DOPDI_BACKEND_GENERATE_WORK_EVENTS=1"]
3336
script:
3437
- dnf install -y diffutils binutils clang git
3538
- git clone --depth 1 --branch develop https://github.com/SciCompKL/CoDiPack.git

include/opdi/backend/macro/macros.hpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include <omp.h>
2929

30+
#include "../../config.hpp"
3031
#include "../../helpers/macros.hpp"
3132

3233
#include "implicitBarrierTools.hpp"
@@ -46,22 +47,33 @@
4647
opdi::logic->onParallelEnd(opdiInternalParallelData); \
4748
}
4849

50+
#if OPDI_BACKEND_GENERATE_WORK_EVENTS
51+
#define OPDI_WORK(type, endpoint) opdi::logic->onWork(kind, endpoint)
52+
#else
53+
#define OPDI_WORK(type, endpoint) /* empty */
54+
#endif
55+
4956
#define OPDI_FOR(...) \
5057
opdi::ImplicitBarrierTools::beginRegionWithImplicitBarrier(); \
58+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Loop, opdi::LogicInterface::ScopeEndpoint::Begin); \
5159
OPDI_PRAGMA(omp for __VA_ARGS__ private(opdi::internalLoopProbe))
5260

5361
#define OPDI_END_FOR \
62+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Loop, opdi::LogicInterface::ScopeEndpoint::End); \
5463
opdi::ImplicitBarrierTools::endRegionWithImplicitBarrier();
5564

5665
#define OPDI_SECTIONS(...) \
5766
opdi::ImplicitBarrierTools::beginRegionWithImplicitBarrier(); \
67+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Sections, opdi::LogicInterface::ScopeEndpoint::Begin); \
5868
OPDI_PRAGMA(omp sections private(opdi::internalSectionsProbe) __VA_ARGS__)
5969

6070
#define OPDI_END_SECTIONS \
71+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Sections, opdi::LogicInterface::ScopeEndpoint::End); \
6172
opdi::ImplicitBarrierTools::endRegionWithImplicitBarrier();
6273

6374
#define OPDI_SINGLE(...) \
6475
{ \
76+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Single, opdi::LogicInterface::ScopeEndpoint::Begin); \
6577
bool constexpr opdiInternalBarrierIndicator = true; \
6678
void* opdiInternalTapePosition1 = opdi::tool->allocPosition(); \
6779
opdi::tool->getTapePosition(opdi::tool->getThreadLocalTape(), opdiInternalTapePosition1); \
@@ -78,6 +90,7 @@
7890

7991
#define OPDI_SINGLE_NOWAIT(...) \
8092
{ \
93+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Single, opdi::LogicInterface::ScopeEndpoint::Begin); \
8194
bool constexpr opdiInternalBarrierIndicator = false; \
8295
void* opdiInternalTapePosition1 = opdi::tool->allocPosition(); \
8396
void* opdiInternalTapePosition2 = opdi::tool->allocPosition(); /* for consistency with the end macro */ \
@@ -100,6 +113,7 @@
100113
} \
101114
opdi::tool->freePosition(opdiInternalTapePosition1); \
102115
opdi::tool->freePosition(opdiInternalTapePosition2); \
116+
OPDI_WORK(opdi::LogicInterface::WorksharingKind::Single, opdi::LogicInterface::ScopeEndpoint::End); \
103117
opdi::ImplicitBarrierTools::implicitBarrierStack.top() = opdiInternalBarrierIndicator; \
104118
opdi::ImplicitBarrierTools::endRegionWithImplicitBarrier(); \
105119
}
@@ -144,14 +158,21 @@
144158

145159
#define OPDI_END_SECTION
146160

147-
#define OPDI_MASTER(...) \
148-
OPDI_PRAGMA(omp master __VA_ARGS__) \
149-
{ \
150-
opdi::logic->onMaster(opdi::LogicInterface::ScopeEndpoint::Begin);
161+
#if OPDI_BACKEND_GENERATE_MASTER_EVENTS
162+
#define OPDI_MASTER(...) \
163+
OPDI_PRAGMA(omp master __VA_ARGS__) \
164+
{ \
165+
opdi::logic->onMaster(opdi::LogicInterface::ScopeEndpoint::Begin);
151166

152-
#define OPDI_END_MASTER \
153-
opdi::logic->onMaster(opdi::LogicInterface::ScopeEndpoint::End); \
154-
}
167+
#define OPDI_END_MASTER \
168+
opdi::logic->onMaster(opdi::LogicInterface::ScopeEndpoint::End); \
169+
}
170+
#else
171+
#define OPDI_MASTER(...) \
172+
OPDI_PRAGMA(omp master __VA_ARGS__) \
173+
174+
#define OPDI_END_MASTER /* empty */
175+
#endif
155176

156177
// standalone macros
157178

include/opdi/backend/ompt/masterCallbacks.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#pragma once
2727

28+
#include "../../config.hpp"
2829
#include "../../helpers/exceptions.hpp"
2930
#include "../../helpers/macros.hpp"
3031
#include "../../logic/logicInterface.hpp"

include/opdi/backend/ompt/omptBackend.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ namespace opdi {
101101
// initialize callback structures
102102
ParallelCallbacks::init();
103103
ImplicitTaskCallbacks::init();
104-
WorkCallbacks::init();
104+
#if OPDI_BACKEND_GENERATE_WORK_EVENTS
105+
WorkCallbacks::init();
106+
#endif
105107
SyncRegionCallbacks::init();
106108
MutexCallbacks::init();
107109
ReductionCallbacks::init();
108-
MasterCallbacks::init();
110+
#if OPDI_BACKEND_GENERATE_MASTER_EVENTS
111+
MasterCallbacks::init();
112+
#endif
109113

110114
return 1; // success
111115
}
@@ -115,11 +119,15 @@ namespace opdi {
115119
OPDI_UNUSED(toolData);
116120

117121
// finalize callback structures
118-
MasterCallbacks::finalize();
122+
#if OPDI_BACKEND_GENERATE_MASTER_EVENTS
123+
MasterCallbacks::finalize();
124+
#endif
119125
ReductionCallbacks::finalize();
120126
MutexCallbacks::finalize();
121127
SyncRegionCallbacks::finalize();
122-
WorkCallbacks::finalize();
128+
#if OPDI_BACKEND_GENERATE_WORK_EVENTS
129+
WorkCallbacks::finalize();
130+
#endif
123131
ImplicitTaskCallbacks::finalize();
124132
ParallelCallbacks::finalize();
125133
}

include/opdi/config.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@
4646

4747
/* ----- backend configuration ----- */
4848

49+
#ifndef OPDI_BACKEND_GENERATE_MASTER_EVENTS
50+
#define OPDI_BACKEND_GENERATE_MASTER_EVENTS 0
51+
#endif
52+
53+
#ifndef OPDI_BACKEND_GENERATE_WORK_EVENTS
54+
#define OPDI_BACKEND_GENERATE_WORK_EVENTS 0
55+
#endif
56+
4957
#ifndef OPDI_OMPT_BACKEND_IMPLICIT_TASK_END_SOURCE
5058
#define OPDI_OMPT_BACKEND_IMPLICIT_TASK_END_SOURCE OPDI_OMPT_IMPLICIT_TASK_END
5159
#endif

0 commit comments

Comments
 (0)