Skip to content

Commit c270fcc

Browse files
committed
Add offload-tblgen tests
1 parent 633e432 commit c270fcc

File tree

15 files changed

+276
-24
lines changed

15 files changed

+276
-24
lines changed

offload/cmake/OpenMPTesting.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ function(find_standalone_test_dependencies)
3737
return()
3838
endif()
3939

40+
find_program(OFFLOAD_TBLGEN_EXECUTABLE
41+
NAMES offload-tblgen
42+
PATHS ${OPENMP_LLVM_TOOLS_DIR})
43+
if (NOT OFFLOAD_TBLGEN_EXECUTABLE)
44+
message(STATUS "Cannot find 'offload-tblgen'.")
45+
message(STATUS "Please put 'not' in your PATH, set OFFLOAD_TBLGEN_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
46+
message(WARNING "The check targets will not be available!")
47+
set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
48+
return()
49+
endif()
50+
4051
find_program(OPENMP_NOT_EXECUTABLE
4152
NAMES not
4253
PATHS ${OPENMP_LLVM_TOOLS_DIR})
@@ -73,6 +84,7 @@ else()
7384
set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
7485
endif()
7586
set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)
87+
set(OFFLOAD_TBLGEN_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/offload-tblgen)
7688

7789
# Macro to extract information about compiler from file. (no own scope)
7890
macro(extract_test_compiler_information lang file)

offload/new-api/include/offload_exports

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ global:
1010
offloadDeviceGet;
1111
offloadDeviceGetInfo;
1212
offloadDeviceGetInfoSize;
13+
offloadInitWithCodeLoc;
14+
offloadShutDownWithCodeLoc;
15+
offloadPlatformGetWithCodeLoc;
16+
offloadPlatformGetCountWithCodeLoc;
17+
offloadPlatformGetInfoWithCodeLoc;
18+
offloadPlatformGetInfoSizeWithCodeLoc;
19+
offloadDeviceGetCountWithCodeLoc;
20+
offloadDeviceGetWithCodeLoc;
21+
offloadDeviceGetInfoWithCodeLoc;
22+
offloadDeviceGetInfoSizeWithCodeLoc;
1323
local:
1424
*;
1525
};

offload/new-api/include/offload_funcs.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,15 @@ OFFLOAD_FUNC(offloadDeviceGetCount)
2020
OFFLOAD_FUNC(offloadDeviceGet)
2121
OFFLOAD_FUNC(offloadDeviceGetInfo)
2222
OFFLOAD_FUNC(offloadDeviceGetInfoSize)
23+
OFFLOAD_FUNC(offloadInitWithCodeLoc)
24+
OFFLOAD_FUNC(offloadShutDownWithCodeLoc)
25+
OFFLOAD_FUNC(offloadPlatformGetWithCodeLoc)
26+
OFFLOAD_FUNC(offloadPlatformGetCountWithCodeLoc)
27+
OFFLOAD_FUNC(offloadPlatformGetInfoWithCodeLoc)
28+
OFFLOAD_FUNC(offloadPlatformGetInfoSizeWithCodeLoc)
29+
OFFLOAD_FUNC(offloadDeviceGetCountWithCodeLoc)
30+
OFFLOAD_FUNC(offloadDeviceGetWithCodeLoc)
31+
OFFLOAD_FUNC(offloadDeviceGetInfoWithCodeLoc)
32+
OFFLOAD_FUNC(offloadDeviceGetInfoSizeWithCodeLoc)
2333

2434
#undef OFFLOAD_FUNC

offload/new-api/include/offload_print.hpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ inline std::ostream &operator<<(std::ostream &os,
290290
return os;
291291
}
292292

293-
inline std::ostream &operator<<(
294-
std::ostream &os,
295-
[[maybe_unused]] const struct offload_platform_get_params_t *params) {
293+
inline std::ostream &
294+
operator<<(std::ostream &os,
295+
const struct offload_platform_get_params_t *params) {
296296
os << ".NumEntries = ";
297297
os << *params->pNumEntries;
298298
os << ", ";
@@ -308,17 +308,17 @@ inline std::ostream &operator<<(
308308
return os;
309309
}
310310

311-
inline std::ostream &operator<<(
312-
std::ostream &os,
313-
[[maybe_unused]] const struct offload_platform_get_count_params_t *params) {
311+
inline std::ostream &
312+
operator<<(std::ostream &os,
313+
const struct offload_platform_get_count_params_t *params) {
314314
os << ".NumPlatforms = ";
315315
printPtr(os, *params->pNumPlatforms);
316316
return os;
317317
}
318318

319-
inline std::ostream &operator<<(
320-
std::ostream &os,
321-
[[maybe_unused]] const struct offload_platform_get_info_params_t *params) {
319+
inline std::ostream &
320+
operator<<(std::ostream &os,
321+
const struct offload_platform_get_info_params_t *params) {
322322
os << ".Platform = ";
323323
printPtr(os, *params->pPlatform);
324324
os << ", ";
@@ -335,8 +335,7 @@ inline std::ostream &operator<<(
335335

336336
inline std::ostream &
337337
operator<<(std::ostream &os,
338-
[[maybe_unused]] const struct offload_platform_get_info_size_params_t
339-
*params) {
338+
const struct offload_platform_get_info_size_params_t *params) {
340339
os << ".Platform = ";
341340
printPtr(os, *params->pPlatform);
342341
os << ", ";
@@ -348,9 +347,9 @@ operator<<(std::ostream &os,
348347
return os;
349348
}
350349

351-
inline std::ostream &operator<<(
352-
std::ostream &os,
353-
[[maybe_unused]] const struct offload_device_get_count_params_t *params) {
350+
inline std::ostream &
351+
operator<<(std::ostream &os,
352+
const struct offload_device_get_count_params_t *params) {
354353
os << ".Platform = ";
355354
printPtr(os, *params->pPlatform);
356355
os << ", ";
@@ -360,8 +359,7 @@ inline std::ostream &operator<<(
360359
}
361360

362361
inline std::ostream &
363-
operator<<(std::ostream &os,
364-
[[maybe_unused]] const struct offload_device_get_params_t *params) {
362+
operator<<(std::ostream &os, const struct offload_device_get_params_t *params) {
365363
os << ".Platform = ";
366364
printPtr(os, *params->pPlatform);
367365
os << ", ";
@@ -380,9 +378,9 @@ operator<<(std::ostream &os,
380378
return os;
381379
}
382380

383-
inline std::ostream &operator<<(
384-
std::ostream &os,
385-
[[maybe_unused]] const struct offload_device_get_info_params_t *params) {
381+
inline std::ostream &
382+
operator<<(std::ostream &os,
383+
const struct offload_device_get_info_params_t *params) {
386384
os << ".Device = ";
387385
printPtr(os, *params->pDevice);
388386
os << ", ";
@@ -399,8 +397,7 @@ inline std::ostream &operator<<(
399397

400398
inline std::ostream &
401399
operator<<(std::ostream &os,
402-
[[maybe_unused]] const struct offload_device_get_info_size_params_t
403-
*params) {
400+
const struct offload_device_get_info_size_params_t *params) {
404401
os << ".Device = ";
405402
printPtr(os, *params->pDevice);
406403
os << ", ";

offload/test/lit.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def evaluate_bool_env(env):
6666
config.name = 'libomptarget :: ' + config.libomptarget_current_target
6767

6868
# suffixes: A list of file extensions to treat as test files.
69-
config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu']
69+
config.suffixes = ['.c', '.cpp', '.cc', '.f90', '.cu', '.td']
7070

7171
# excludes: A list of directories to exclude from the testuites.
7272
config.excludes = ['Inputs']
@@ -418,3 +418,4 @@ config.substitutions.append(("%flags", config.test_flags))
418418
config.substitutions.append(("%not", config.libomptarget_not))
419419
config.substitutions.append(("%offload-device-info",
420420
config.offload_device_info))
421+
config.substitutions.append(("%offload-tblgen", config.offload_tblgen))

offload/test/lit.site.cfg.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ config.libomptarget_debug = @LIBOMPTARGET_DEBUG@
2828
config.has_libomptarget_ompt = @LIBOMPTARGET_OMPT_SUPPORT@
2929
config.libomptarget_has_libc = @LIBOMPTARGET_GPU_LIBC_SUPPORT@
3030
config.libomptarget_test_pgo = @LIBOMPTARGET_TEST_GPU_PGO@
31+
config.offload_tblgen = "@OFFLOAD_TBLGEN_EXECUTABLE@"
3132
# Let the main config do the real work.
3233
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
2+
// RUN: %offload-tblgen -gen-entry-points -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-VALIDATION
3+
4+
// Check implicit returns are included in documentation and the validation
5+
// wrappers where applicable
6+
7+
include "APIDefs.td"
8+
9+
def : Handle {
10+
let name = "offload_foo_handle_t";
11+
let desc = "Example handle type";
12+
}
13+
14+
def : Function {
15+
let name = "FunctionA";
16+
let desc = "Function A description";
17+
let details = [ "Function A detailed information" ];
18+
let params = [
19+
Param<"uint32_t", "ParamValue", "A plain value parameter">,
20+
Param<"offload_foo_handle_t", "ParamHandle", "A handle parameter">,
21+
Param<"uint32_t*", "ParamPointer", "A pointer parameter">,
22+
Param<"uint32_t*", "ParamPointerOpt", "An optional pointer parameter", PARAM_OUT_OPTIONAL>
23+
];
24+
let returns = [];
25+
}
26+
27+
// CHECK-API: /// @returns
28+
// CHECK-API: OFFLOAD_RESULT_SUCCESS
29+
// CHECK-API: OFFLOAD_ERRC_INVALID_NULL_HANDLE
30+
// CHECK-API-NEXT: `NULL == ParamHandle`
31+
// CHECK-API: OFFLOAD_ERRC_INVALID_NULL_POINTER
32+
// CHECK-API-NEXT: `NULL == ParamPointer`
33+
// CHECK-API-NOT: `NULL == ParamPointerOpt`
34+
35+
// CHECK-VALIDATION: FunctionA_val
36+
// CHECK-VALIDATION: if (NULL == ParamHandle)
37+
// CHECK-VALIDATION-NEXT: return OFFLOAD_ERRC_INVALID_NULL_HANDLE;
38+
// CHECK-VALIDATION: if (NULL == ParamPointer)
39+
// CHECK-VALIDATION-NEXT: return OFFLOAD_ERRC_INVALID_NULL_POINTER;
40+
// CHECK-VALIDATION-NOT: if (NULL == ParamPointerOpt)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %offload-tblgen -gen-entry-points -I %S/../../../new-api/API %s | %fcheck-generic
2+
3+
// Check entry point wrapper functions are generated correctly
4+
5+
include "APIDefs.td"
6+
7+
def : Function {
8+
let name = "FunctionA";
9+
let desc = "Function A description";
10+
let details = [ "Function A detailed information" ];
11+
let params = [
12+
Param<"uint32_t", "ParamA", "Parameter A description">,
13+
Param<"uint32_t*", "ParamB", "Parameter B description">,
14+
];
15+
let returns = [
16+
Return<"OFFLOAD_ERRC_INVALID_VALUE", ["When a value is invalid"]>
17+
];
18+
}
19+
20+
21+
// The validation function should call the implementation function
22+
// CHECK: FunctionA_val
23+
// CHECK: return FunctionA_impl(ParamA, ParamB);
24+
25+
// CHECK: offload_result_t{{.*}} FunctionA(
26+
27+
// The entry point should print tracing output if enabled
28+
// CHECK: if (offloadConfig().TracingEnabled) {
29+
// CHECK-NEXT: "---> FunctionA";
30+
31+
// CHECK: Result = FunctionA_val(ParamA, ParamB);
32+
33+
// Tracing should construct a param struct for printing
34+
// CHECK: if (offloadConfig().TracingEnabled) {
35+
// CHECK: function_a_params_t Params = {&ParamA, &ParamB};
36+
37+
// CHECK: return Result;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
2+
// RUN: %offload-tblgen -gen-exports -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-EXPORTS
3+
// RUN: %offload-tblgen -gen-func-names -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-FUNC-MACRO
4+
5+
// Check basic support for API functions
6+
7+
include "APIDefs.td"
8+
9+
def : Function {
10+
let name = "FunctionA";
11+
let desc = "Function A description";
12+
let details = [ "Function A detailed information" ];
13+
let params = [
14+
Param<"uint32_t", "ParamA", "Parameter A description">,
15+
Param<"uint32_t*", "ParamB", "Parameter B description">,
16+
];
17+
let returns = [
18+
Return<"OFFLOAD_ERRC_INVALID_VALUE", ["When a value is invalid"]>
19+
];
20+
}
21+
22+
// CHECK-API: /// @brief Function A description
23+
// CHECK-API: /// @details
24+
// CHECK-API-NEXT: Function A detailed information
25+
// CHECK-API: /// @returns
26+
// CHECK-API: OFFLOAD_ERRC_INVALID_VALUE
27+
// CHECK-API-NEXT: When a value is invalid
28+
29+
// CHECK-API: offload_result_t
30+
// CHECK-API-SAME: FunctionA
31+
32+
// CHECK-API: // Parameter A description
33+
// CHECK-API-NEXT: uint32_t ParamA
34+
// CHECK-API: // Parameter B description
35+
// CHECK-API-NEXT: uint32_t* ParamB
36+
37+
// CHECK-EXPORTS: FunctionA
38+
39+
// CHECK-FUNC-MACRO: OFFLOAD_FUNC(FunctionA)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %offload-tblgen -gen-api -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-API
2+
// RUN: %offload-tblgen -gen-exports -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-EXPORTS
3+
// RUN: %offload-tblgen -gen-func-names -I %S/../../../new-api/API %s | %fcheck-generic --check-prefix=CHECK-FUNC-MACRO
4+
5+
// Check that the function variant with code location information is generated
6+
// and is otherwise the same as the regular function
7+
8+
include "APIDefs.td"
9+
10+
def : Function {
11+
let name = "FunctionA";
12+
let desc = "Function A description";
13+
let details = [ "Function A detailed information" ];
14+
let params = [
15+
Param<"uint32_t", "ParamA", "Parameter A description">,
16+
Param<"uint32_t*", "ParamB", "Parameter B description">,
17+
];
18+
let returns = [
19+
Return<"OFFLOAD_ERRC_INVALID_VALUE", ["When a value is invalid"]>
20+
];
21+
}
22+
23+
// CHECK-API-DAG: offload_result_t{{.*}} FunctionA
24+
// CHECK-API-DAG: offload_result_t{{.*}} FunctionAWithCodeLoc
25+
// CHECK-EXPORTS: FunctionAWithCodeLoc
26+
// CHECK-FUNC-MACRO: OFFLOAD_FUNC(FunctionAWithCodeLoc)

0 commit comments

Comments
 (0)