llvm-project/offload/test/api/omp_host_call.c
Nick Sarnie 78ff5b55fd
[offload][lit] Enable/disable tests on Level Zero when using DeviceRTL (#182128)
Since we can now build the DeviceRTL with SPIR-V, redo the
`XFAIL/UNSUPPORTED` specifications for the tests we see passing/failing
on the Level Zero backend with the DeviceRTL being used.

The tests marked `UNSUPPORTED` hang or sporadically fail and those are
tracked in https://github.com/llvm/llvm-project/issues/182119.

This change will allow us to enable CI testing with the DeviceRTL.

Here are the full test results with this change applied, running only
the `spirv64-intel` `check-offload` tests:

```
Total Discovered Tests: 453
  Unsupported      : 206 (45.47%)
  Passed           : 141 (31.13%)
  Expectedly Failed: 106 (23.40%)
```

31% is not a bad start.

---------

Signed-off-by: Nick Sarnie <nick.sarnie@intel.com>
2026-02-18 21:53:19 +00:00

65 lines
1.8 KiB
C

// RUN: %libomptarget-compile-run-and-check-generic
// https://github.com/llvm/llvm-project/issues/182119
// UNSUPPORTED: intelgpu
#include <assert.h>
#include <omp.h>
#include <stdio.h>
#pragma omp begin declare variant match(device = {kind(gpu)})
// Extension provided by the 'libc' project.
unsigned long long __llvm_omp_host_call(void *fn, void *args, size_t size);
#pragma omp declare target to(__llvm_omp_host_call) device_type(nohost)
#pragma omp end declare variant
#pragma omp begin declare variant match(device = {kind(cpu)})
// Dummy host implementation to make this work for all targets.
unsigned long long __llvm_omp_host_call(void *fn, void *args, size_t size) {
return ((unsigned long long (*)(void *))fn)(args);
}
#pragma omp end declare variant
typedef struct args_s {
int thread_id;
int block_id;
} args_t;
// CHECK-DAG: Thread: 0, Block: 0
// CHECK-DAG: Thread: 1, Block: 0
// CHECK-DAG: Thread: 0, Block: 1
// CHECK-DAG: Thread: 1, Block: 1
// CHECK-DAG: Thread: 0, Block: 2
// CHECK-DAG: Thread: 1, Block: 2
// CHECK-DAG: Thread: 0, Block: 3
// CHECK-DAG: Thread: 1, Block: 3
unsigned long long foo(void *data) {
assert(omp_is_initial_device() && "Not executing on host?");
args_t *args = (args_t *)data;
printf("Thread: %d, Block: %d\n", args->thread_id, args->block_id);
return 42;
}
void *fn_ptr = NULL;
#pragma omp declare target to(fn_ptr)
int main() {
fn_ptr = (void *)&foo;
#pragma omp target update to(fn_ptr)
int failed = 0;
#pragma omp target teams num_teams(4) map(tofrom : failed)
#pragma omp parallel num_threads(2)
{
args_t args = {omp_get_thread_num(), omp_get_team_num()};
unsigned long long res =
__llvm_omp_host_call(fn_ptr, &args, sizeof(args_t));
if (res != 42)
#pragma omp atomic write
failed = 1;
}
// CHECK: PASS
if (!failed)
printf("PASS\n");
}