Skip to content

Commit 0e8a90f

Browse files
committed
[offload][OMPT] Add device tracing support to ompTest
Added all necessary infrastructure for device tracing * CTORs, equality operators, ... Added 'SyncPoint' event for TestCase use * Makes sure that all events have been processed Allowed to disable tests by prefixing name with 'DISABLED_' * These will still be compiled but not executed * Same behavior as GoogleTest Moved handling of device groups from Asserters into TestCase * Allows coherent state but needs to be protected from data races Minor refactorings, fixes and tweaks * For example: split OmptTesterStandalone.h and added .cpp Change-Id: I5e1260f6fb21e44455c3c4c5994671d9b552bad6
1 parent b02f223 commit 0e8a90f

19 files changed

+979
-330
lines changed

offload/test/ompTest/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ if(NOT ${LIBOMPTARGET_OMPT_SUPPORT})
88
return()
99
endif()
1010

11+
option(LIBOMPTEST_USE_GOOGLETEST "If set to 'ON' build ompTest upon GoogleTest, otherwise 'standalone'." OFF)
12+
1113
cmake_minimum_required(VERSION 3.22)
1214
project(omptest LANGUAGES CXX)
1315

14-
# Use LLVM-bundled GoogleTest
15-
include(GoogleTest)
16-
1716
set(OMPTEST_HEADERS
1817
./include/AssertMacros.h
1918
./include/InternalEvent.h
@@ -23,8 +22,7 @@ set(OMPTEST_HEADERS
2322
./include/OmptAssertEvent.h
2423
./include/OmptCallbackHandler.h
2524
./include/OmptTester.h
26-
./include/OmptTesterGoogleTest.h
27-
./include/OmptTesterStandalone.h
25+
./include/OmptTesterGlobals.h
2826
)
2927

3028
add_library(omptest
@@ -39,6 +37,21 @@ add_library(omptest
3937
./src/OmptTester.cpp
4038
)
4139

40+
if(NOT LIBOMPTEST_USE_GOOGLETEST)
41+
# Add 'standalone' source files
42+
target_sources(omptest
43+
PRIVATE
44+
./include/OmptTesterStandalone.h
45+
./src/OmptTesterStandalone.cpp)
46+
else()
47+
# Use LLVM-bundled GoogleTest
48+
include(GoogleTest)
49+
# Add GoogleTest-based header
50+
target_sources(omptest PRIVATE ./include/OmptTesterGoogleTest.h)
51+
# Add compile definition
52+
add_definitions(-DLIBOFFLOAD_LIBOMPTEST_USE_GOOGLETEST)
53+
endif()
54+
4255
target_include_directories(omptest
4356
PRIVATE
4457
${LIBOMPTARGET_INCLUDE_DIR}
Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,92 @@
11
#ifndef OPENMP_LIBOMPTARGET_TEST_OMPTEST_ASSERTMACROS_H
22
#define OPENMP_LIBOMPTARGET_TEST_OMPTEST_ASSERTMACROS_H
33

4-
#define OMPTEST_EXCLUDE_EVENT omptest::ObserveState::never
5-
#define OMPTEST_REQUIRE_EVENT omptest::ObserveState::always
4+
#define OMPTEST_EXCLUDED_EVENT omptest::ObserveState::never
5+
#define OMPTEST_REQUIRED_EVENT omptest::ObserveState::always
66

77
/// ASSERT MACROS TO BE USED BY THE USER
88

9-
// Not implemented yet
10-
#define OMPT_ASSERT_EVENT(Event, ...)
9+
#define OMPT_GENERATE_EVENTS(NumberOfCopies, EventMacro) \
10+
for (size_t i = 0; i < NumberOfCopies; ++i) { \
11+
EventMacro \
12+
}
1113

1214
// Handle a minimum unordered set of events
1315
// Required events
1416
#define OMPT_ASSERT_SET_EVENT(Name, Group, EventTy, ...) \
15-
SetAsserter.insert(OmptAssertEvent::EventTy( \
16-
Name, Group, OMPTEST_REQUIRE_EVENT, __VA_ARGS__));
17+
SetAsserter->insert(OmptAssertEvent::EventTy( \
18+
Name, Group, OMPTEST_REQUIRED_EVENT, __VA_ARGS__));
1719
#define OMPT_ASSERT_SET(EventTy, ...) \
1820
OMPT_ASSERT_SET_EVENT("", "", EventTy, __VA_ARGS__)
19-
#define OMPT_ASSERT_SET_GROUP(Group, EventTy, ...) \
21+
#define OMPT_ASSERT_SET_GROUPED(Group, EventTy, ...) \
2022
OMPT_ASSERT_SET_EVENT("", Group, EventTy, __VA_ARGS__)
2123
#define OMPT_ASSERT_SET_NAMED(Name, EventTy, ...) \
2224
OMPT_ASSERT_SET_EVENT(Name, "", EventTy, __VA_ARGS__)
2325
// Excluded ("NOT") events
2426
#define OMPT_ASSERT_SET_EVENT_NOT(Name, Group, EventTy, ...) \
25-
SetAsserter.insert(OmptAssertEvent::EventTy( \
26-
Name, Group, OMPTEST_EXCLUDE_EVENT, __VA_ARGS__));
27+
SetAsserter->insert(OmptAssertEvent::EventTy( \
28+
Name, Group, OMPTEST_EXCLUDED_EVENT, __VA_ARGS__));
2729
#define OMPT_ASSERT_SET_NOT(EventTy, ...) \
2830
OMPT_ASSERT_SET_EVENT_NOT("", "", EventTy, __VA_ARGS__)
29-
#define OMPT_ASSERT_SET_GROUP_NOT(Group, EventTy, ...) \
31+
#define OMPT_ASSERT_SET_GROUPED_NOT(Group, EventTy, ...) \
3032
OMPT_ASSERT_SET_EVENT_NOT("", Group, EventTy, __VA_ARGS__)
3133
#define OMPT_ASSERT_SET_NAMED_NOT(Name, EventTy, ...) \
3234
OMPT_ASSERT_SET_EVENT_NOT(Name, "", EventTy, __VA_ARGS__)
3335

3436
// Handle an exact sequence of events
3537
// Required events
3638
#define OMPT_ASSERT_SEQUENCE_EVENT(Name, Group, EventTy, ...) \
37-
SequenceAsserter.insert(OmptAssertEvent::EventTy( \
38-
Name, Group, OMPTEST_REQUIRE_EVENT, __VA_ARGS__));
39+
SequenceAsserter->insert(OmptAssertEvent::EventTy( \
40+
Name, Group, OMPTEST_REQUIRED_EVENT, __VA_ARGS__));
3941
#define OMPT_ASSERT_SEQUENCE(EventTy, ...) \
4042
OMPT_ASSERT_SEQUENCE_EVENT("", "", EventTy, __VA_ARGS__)
41-
#define OMPT_ASSERT_GROUPED_SEQUENCE(Group, EventTy, ...) \
43+
#define OMPT_ASSERT_SEQUENCE_GROUPED(Group, EventTy, ...) \
4244
OMPT_ASSERT_SEQUENCE_EVENT("", Group, EventTy, __VA_ARGS__)
43-
#define OMPT_ASSERT_NAMED_SEQUENCE(Name, EventTy, ...) \
45+
#define OMPT_ASSERT_SEQUENCE_NAMED(Name, EventTy, ...) \
4446
OMPT_ASSERT_SEQUENCE_EVENT(Name, "", EventTy, __VA_ARGS__)
4547
// Excluded ("NOT") events
4648
#define OMPT_ASSERT_SEQUENCE_EVENT_NOT(Name, Group, EventTy, ...) \
47-
SequenceAsserter.insert(OmptAssertEvent::EventTy( \
48-
Name, Group, OMPTEST_EXCLUDE_EVENT, __VA_ARGS__));
49+
SequenceAsserter->insert(OmptAssertEvent::EventTy( \
50+
Name, Group, OMPTEST_EXCLUDED_EVENT, __VA_ARGS__));
4951
#define OMPT_ASSERT_SEQUENCE_NOT(EventTy, ...) \
5052
OMPT_ASSERT_SEQUENCE_EVENT_NOT("", "", EventTy, __VA_ARGS__)
51-
#define OMPT_ASSERT_GROUPED_SEQUENCE_NOT(Group, EventTy, ...) \
53+
#define OMPT_ASSERT_SEQUENCE_GROUPED_NOT(Group, EventTy, ...) \
5254
OMPT_ASSERT_SEQUENCE_EVENT_NOT("", Group, EventTy, __VA_ARGS__)
53-
#define OMPT_ASSERT_NAMED_SEQUENCE_NOT(Name, EventTy, ...) \
55+
#define OMPT_ASSERT_SEQUENCE_NAMED_NOT(Name, EventTy, ...) \
5456
OMPT_ASSERT_SEQUENCE_EVENT_NOT(Name, "", EventTy, __VA_ARGS__)
5557
// Special command: suspend active assertion
58+
// The created event is not correlated to any observed event
5659
#define OMPT_ASSERT_SEQUENCE_SUSPEND() \
57-
SequenceAsserter.insert( \
58-
OmptAssertEvent::Asserter("", "", OMPTEST_REQUIRE_EVENT));
60+
SequenceAsserter->insert( \
61+
OmptAssertEvent::AssertionSuspend("", "", OMPTEST_EXCLUDED_EVENT));
5962
#define OMPT_ASSERT_SEQUENCE_ONLY(EventTy, ...) \
6063
OMPT_ASSERT_SEQUENCE_SUSPEND() \
6164
OMPT_ASSERT_SEQUENCE_EVENT("", "", EventTy, __VA_ARGS__) \
6265
OMPT_ASSERT_SEQUENCE_SUSPEND()
63-
#define OMPT_ASSERT_GROUPED_SEQUENCE_ONLY(Group, EventTy, ...) \
66+
#define OMPT_ASSERT_SEQUENCE_GROUPED_ONLY(Group, EventTy, ...) \
6467
OMPT_ASSERT_SEQUENCE_SUSPEND() \
6568
OMPT_ASSERT_SEQUENCE_EVENT("", Group, EventTy, __VA_ARGS__) \
6669
OMPT_ASSERT_SEQUENCE_SUSPEND()
67-
#define OMPT_ASSERT_NAMED_SEQUENCE_ONLY(Name, EventTy, ...) \
70+
#define OMPT_ASSERT_SEQUENCE_NAMED_ONLY(Name, EventTy, ...) \
6871
OMPT_ASSERT_SEQUENCE_SUSPEND() \
6972
OMPT_ASSERT_SEQUENCE_EVENT(Name, "", EventTy, __VA_ARGS__) \
7073
OMPT_ASSERT_SEQUENCE_SUSPEND()
7174

7275
// Enable / disable asserters entirely
73-
#define OMPT_ASSERTER_DISABLE(Asserter) Asserter.setActive(false);
74-
#define OMPT_ASSERTER_ENABLE(Asserter) Asserter.setActive(true);
76+
#define OMPT_ASSERTER_DISABLE(Asserter) Asserter->setActive(false);
77+
#define OMPT_ASSERTER_ENABLE(Asserter) Asserter->setActive(true);
7578
#define OMPT_ASSERT_SET_DISABLE() OMPT_ASSERTER_DISABLE(SetAsserter)
7679
#define OMPT_ASSERT_SET_ENABLE() OMPT_ASSERTER_ENABLE(SetAsserter)
77-
#define OMPT_REPORT_EVENT_DISABLE() OMPT_ASSERTER_DISABLE(EventReporter)
78-
#define OMPT_REPORT_EVENT_ENABLE() OMPT_ASSERTER_ENABLE(EventReporter)
7980
#define OMPT_ASSERT_SEQUENCE_DISABLE() OMPT_ASSERTER_DISABLE(SequenceAsserter)
8081
#define OMPT_ASSERT_SEQUENCE_ENABLE() OMPT_ASSERTER_ENABLE(SequenceAsserter)
82+
#define OMPT_REPORT_EVENT_DISABLE() OMPT_ASSERTER_DISABLE(EventReporter)
83+
#define OMPT_REPORT_EVENT_ENABLE() OMPT_ASSERTER_ENABLE(EventReporter)
8184

8285
// Enable / disable certain event types for asserters
8386
#define OMPT_ASSERTER_PERMIT_EVENT(Asserter, EventTy) \
84-
Asserter.permitEvent(EventTy);
87+
Asserter->permitEvent(EventTy);
8588
#define OMPT_ASSERTER_SUPPRESS_EVENT(Asserter, EventTy) \
86-
Asserter.suppressEvent(EventTy);
89+
Asserter->suppressEvent(EventTy);
8790
#define OMPT_PERMIT_EVENT(EventTy) \
8891
OMPT_ASSERTER_PERMIT_EVENT(SetAsserter, EventTy); \
8992
OMPT_ASSERTER_PERMIT_EVENT(EventReporter, EventTy); \
@@ -93,4 +96,8 @@
9396
OMPT_ASSERTER_SUPPRESS_EVENT(EventReporter, EventTy); \
9497
OMPT_ASSERTER_SUPPRESS_EVENT(SequenceAsserter, EventTy);
9598

96-
#endif // include guard
99+
#define OMPT_ASSERT_SYNC_POINT(SyncPointName) \
100+
flush_traced_devices(); \
101+
OmptCallbackHandler::get().handleAssertionSyncPoint(SyncPointName);
102+
103+
#endif

offload/test/ompTest/include/InternalEvent.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@
44
#include "InternalEventCommon.h"
55

66
#include <cstring>
7+
#include <limits>
8+
9+
#define expectedDefault(TypeName) std::numeric_limits<TypeName>::min()
710

811
namespace omptest {
912

1013
namespace internal {
1114
// clang-format off
12-
event_class_stub(Asserter)
15+
event_class_w_custom_body(AssertionSyncPoint, \
16+
AssertionSyncPoint(const std::string &Name) \
17+
: InternalEvent(EventTy::AssertionSyncPoint), Name(Name) {} \
18+
\
19+
const std::string Name; \
20+
)
21+
event_class_stub(AssertionSuspend)
1322
event_class_w_custom_body(ThreadBegin, \
1423
ThreadBegin(ompt_thread_t ThreadType) \
1524
: InternalEvent(EventTy::ThreadBegin), ThreadType(ThreadType) {} \

offload/test/ompTest/include/InternalEventCommon.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ namespace internal {
1212
/// Enum values are used for comparison of observed and asserted events
1313
/// List is based on OpenMP 5.2 specification, table 19.2 (page 447)
1414
enum class EventTy {
15-
None, // not part of OpenMP spec, used for implementation
16-
Asserter, // not part of OpenMP spec, used for implementation
15+
None, // not part of OpenMP spec, used for implementation
16+
AssertionSyncPoint, // not part of OpenMP spec, used for implementation
17+
AssertionSuspend, // not part of OpenMP spec, used for implementation
18+
BufferRecord, // not part of OpenMP spec, used for implementation
1719
ThreadBegin,
1820
ThreadEnd,
1921
ParallelBegin,
@@ -33,8 +35,7 @@ enum class EventTy {
3335
DeviceLoad,
3436
DeviceUnload,
3537
BufferRequest,
36-
BufferComplete,
37-
BufferRecord // not part of OpenMP spec, used for implementation
38+
BufferComplete
3839
};
3940

4041
struct InternalEvent {

offload/test/ompTest/include/OmptAliases.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ constexpr ompt_target_t ENTER_DATA_NOWAIT = ompt_target_enter_data_nowait;
3232
constexpr ompt_target_t EXIT_DATA_NOWAIT = ompt_target_exit_data_nowait;
3333
constexpr ompt_target_t UPDATE_NOWAIT = ompt_target_update_nowait;
3434

35-
#endif // include guard
35+
/// Aliases for enum: ompt_callbacks_t (partial)
36+
constexpr ompt_callbacks_t CB_TARGET = ompt_callback_target;
37+
constexpr ompt_callbacks_t CB_DATAOP = ompt_callback_target_data_op;
38+
constexpr ompt_callbacks_t CB_KERNEL = ompt_callback_target_submit;
39+
40+
#endif

0 commit comments

Comments
 (0)