[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / openmp / libomptarget / test / libc / host_call.c
blob11260cc285765d7ad66222e7f7b470c4a5afe2cc
1 // RUN: %libomptarget-compile-run-and-check-generic
3 // REQUIRES: libc
5 #include <assert.h>
6 #include <omp.h>
7 #include <stdio.h>
9 #pragma omp begin declare variant match(device = {kind(gpu)})
10 // Extension provided by the 'libc' project.
11 void rpc_host_call(void *fn, void *args, size_t size);
12 #pragma omp declare target to(rpc_host_call) device_type(nohost)
13 #pragma omp end declare variant
15 #pragma omp begin declare variant match(device = {kind(cpu)})
16 // Dummy host implementation to make this work for all targets.
17 void rpc_host_call(void *fn, void *args, size_t size) {
18 ((void (*)(void *))fn)(args);
20 #pragma omp end declare variant
22 typedef struct args_s {
23 int thread_id;
24 int block_id;
25 } args_t;
27 // CHECK-DAG: Thread: 0, Block: 0
28 // CHECK-DAG: Thread: 1, Block: 0
29 // CHECK-DAG: Thread: 0, Block: 1
30 // CHECK-DAG: Thread: 1, Block: 1
31 // CHECK-DAG: Thread: 0, Block: 2
32 // CHECK-DAG: Thread: 1, Block: 2
33 // CHECK-DAG: Thread: 0, Block: 3
34 // CHECK-DAG: Thread: 1, Block: 3
35 void foo(void *data) {
36 assert(omp_is_initial_device() && "Not executing on host?");
37 args_t *args = (args_t *)data;
38 printf("Thread: %d, Block: %d\n", args->thread_id, args->block_id);
41 void *fn_ptr = NULL;
42 #pragma omp declare target to(fn_ptr)
44 int main() {
45 fn_ptr = (void *)&foo;
46 #pragma omp target update to(fn_ptr)
48 #pragma omp target teams num_teams(4)
49 #pragma omp parallel num_threads(2)
51 args_t args = {omp_get_thread_num(), omp_get_team_num()};
52 rpc_host_call(fn_ptr, &args, sizeof(args_t));