-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathompvv.h
More file actions
152 lines (133 loc) · 5.44 KB
/
ompvv.h
File metadata and controls
152 lines (133 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//===------ ompvv.h ------------------ OMPVV HEADER FILE ------------------===//
//
// Header file for OMP Validation and verification test suite
//
//===----------------------------------------------------------------------===//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
int _ompvv_isOffloadingOn = -1;
// Macro for output of information, warning and error messages
#ifdef VERBOSE_MODE
#define OMPVV_WARNING(message, ...) { \
printf("[OMPVV_WARNING: %s:%i] " message "\n", __FILENAME__, __LINE__, ##__VA_ARGS__); \
}
#define OMPVV_WARNING_IF(condition, message, ...) { \
if(condition) { \
printf("[OMPVV_WARNING: %s:%i] " message "\n", __FILENAME__, __LINE__, ##__VA_ARGS__); \
} \
}
#define OMPVV_ERROR(message, ...) { \
fprintf(stderr, "[OMPVV_ERROR: %s:%i] " message "\n", __FILENAME__, __LINE__, ##__VA_ARGS__); \
}
#define OMPVV_ERROR_IF(condition, message, ...) { \
if(condition) { \
fprintf(stderr, "[OMPVV_ERROR: %s:%i] " message "\n", __FILENAME__, __LINE__, ##__VA_ARGS__); \
} \
}
#define OMPVV_INFOMSG(message, ...) { \
printf("[OMPVV_INFO: %s:%i] " message "\n", __FILENAME__, __LINE__, ##__VA_ARGS__); \
}
#define OMPVV_INFOMSG_IF(condition, message, ...) { \
if(condition) { \
printf("[OMPVV_INFO: %s:%i] " message "\n", __FILENAME__, __LINE__, ##__VA_ARGS__); \
} \
}
#else
#define OMPVV_WARNING(message, ...) {}
#define OMPVV_WARNING_IF(message, ...) {}
#define OMPVV_ERROR(message, ...) {}
#define OMPVV_ERROR_IF(message, ...) {}
#define OMPVV_INFOMSG(message, ...) {}
#define OMPVV_INFOMSG_IF(message, ...) {}
#endif // END IF VERBOSE_MODE
#define OMPVV_TEST_OFFLOADING_PROBE \
_ompvv_isOffloadingOn = 0; \
_Pragma("omp target map (from: _ompvv_isOffloadingOn)") \
{ _ompvv_isOffloadingOn = !omp_is_initial_device(); }
// Macro for checking if offloading is enabled or not
#define OMPVV_TEST_OFFLOADING { \
OMPVV_TEST_OFFLOADING_PROBE \
OMPVV_INFOMSG("Test is running on %s.",(_ompvv_isOffloadingOn)? "device" : "host"); \
}
// Macro for checking if offloading is enabled or not and set a variable with the result
#define OMPVV_TEST_AND_SET_OFFLOADING(var2set) { \
OMPVV_TEST_OFFLOADING_PROBE \
OMPVV_INFOMSG("Test is running on %s.",(_ompvv_isOffloadingOn)? "device" : "host"); \
var2set = _ompvv_isOffloadingOn; \
}
// Macro for setting errors on condition
#define OMPVV_TEST_AND_SET(err, condition) { \
int _ompvv_conditionEval = condition; \
err += (_ompvv_conditionEval); \
}
// Macro for setting errors on condition and displaying an error if something went wrong
#define OMPVV_TEST_AND_SET_VERBOSE(err, condition) { \
int _ompvv_conditionEval = condition; \
err += (_ompvv_conditionEval); \
OMPVV_ERROR_IF(_ompvv_conditionEval, " Condition " #condition " failed "); \
}
// Macro for reporting results
#define OMPVV_REPORT(err) { \
OMPVV_INFOMSG("The value of " #err " is %d.", err); \
if (_ompvv_isOffloadingOn == -1) \
if (err == OMPVV_SKIPPED_EXIT_CODE) \
printf("[OMPVV_RESULT: %s] Test %s.\n", __FILENAME__, "skipped"); \
else \
printf("[OMPVV_RESULT: %s] Test %s.\n", __FILENAME__, ((err) == 0)? "passed":"failed"); \
else \
if (err == OMPVV_SKIPPED_EXIT_CODE) \
printf("[OMPVV_RESULT: %s] Test %s on the %s.\n", __FILENAME__, "skipped", (_ompvv_isOffloadingOn)? "device" : "host"); \
else \
printf("[OMPVV_RESULT: %s] Test %s on the %s.\n", __FILENAME__, ((err) == 0)? "passed":"failed", (_ompvv_isOffloadingOn)? "device" : "host"); \
}
// Macro for correct exit code
#define OMPVV_RETURN(err) { \
return err; \
}
// Macro for report and exit
#define OMPVV_REPORT_AND_RETURN(err) {\
OMPVV_REPORT(err); \
OMPVV_RETURN(err); \
}
// Macro to check if it is a shared data environment
#define OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \
int _ompvv_isSharedEnv = 0; \
_ompvv_isOffloadingOn = 0; \
_Pragma("omp target map (from: _ompvv_isOffloadingOn) map(to: _ompvv_isSharedEnv)") \
{ _ompvv_isOffloadingOn = !omp_is_initial_device(); \
_ompvv_isSharedEnv = 1; \
}
// Macro to report warning if it is a shared environment
#define OMPVV_TEST_SHARED_ENVIRONMENT {\
OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \
OMPVV_WARNING_IF((_ompvv_isOffloadingOn && _ompvv_isSharedEnv == 1),"This tests is running on a shared data environment between host and device. This may cause errors") \
}
// Macro to report warning if it is a shared environment and set a variable for further use
#define OMPVV_TEST_AND_SET_SHARED_ENVIRONMENT(var2set) {\
OMPVV_TEST_SHARED_ENVIRONMENT_PROBE \
OMPVV_WARNING_IF((_ompvv_isOffloadingOn && _ompvv_isSharedEnv == 1),"This tests is running on a shared data environment between host and device. This may cause errors") \
var2set = (_ompvv_isOffloadingOn && _ompvv_isSharedEnv == 1);\
}
// Macro for skipping a test
#define OMPVV_CHECK_TO_SKIP(condition) { \
int SKIPPED_EXIT_CODE = OMPVV_SKIPPED_EXIT_CODE; \
if (condition) {OMPVV_REPORT_AND_RETURN(SKIPPED_EXIT_CODE)}; \
}
// Macros to provide thread and team nums if they are not specified
#ifndef OMPVV_NUM_THREADS_DEVICE
#define OMPVV_NUM_THREADS_DEVICE 8
#endif
#ifndef OMPVV_NUM_TEAMS_DEVICE
#define OMPVV_NUM_TEAMS_DEVICE 8
#endif
#ifndef OMPVV_NUM_TEAMS_HOST
#define OMPVV_NUM_TEAMS_HOST 4
#endif
#ifndef OMPVV_NUM_THREADS_HOST
#define OMPVV_NUM_THREADS_HOST 8
#endif
#ifndef OMPVV_SKIPPED_EXIT_CODE
#define OMPVV_SKIPPED_EXIT_CODE -667
#endif