| 1 |
/* { dg-additional-options "-fdump-tree-gimple" } */ |
| 2 |
|
| 3 |
#if __cplusplus >= 201103L |
| 4 |
# define __GOMP_UINTPTR_T_ENUM : __UINTPTR_TYPE__ |
| 5 |
#else |
| 6 |
# define __GOMP_UINTPTR_T_ENUM |
| 7 |
#endif |
| 8 |
|
| 9 |
typedef enum omp_interop_t __GOMP_UINTPTR_T_ENUM |
| 10 |
{ |
| 11 |
omp_interop_none = 0, |
| 12 |
__omp_interop_t_max__ = __UINTPTR_MAX__ |
| 13 |
} omp_interop_t; |
| 14 |
|
| 15 |
typedef enum omp_interop_fr_t |
| 16 |
{ |
| 17 |
omp_ifr_cuda = 1, |
| 18 |
omp_ifr_cuda_driver = 2, |
| 19 |
omp_ifr_opencl = 3, |
| 20 |
omp_ifr_sycl = 4, |
| 21 |
omp_ifr_hip = 5, |
| 22 |
omp_ifr_level_zero = 6, |
| 23 |
omp_ifr_hsa = 7, |
| 24 |
omp_ifr_last = omp_ifr_hsa |
| 25 |
} omp_interop_fr_t; |
| 26 |
|
| 27 |
|
| 28 |
extern int flag; |
| 29 |
|
| 30 |
void g1(int, const char *, int *, int *, omp_interop_t, omp_interop_t) { } |
| 31 |
void g2(int, const char *, int *, int *, omp_interop_t, omp_interop_t) { } |
| 32 |
#pragma omp declare variant(g1) \ |
| 33 |
match(construct={dispatch}, user={condition(flag==1)}) \ |
| 34 |
append_args(interop(target,prefer_type( {fr("cuda") }, {fr(omp_ifr_hsa)} , {attr("ompx_a") } , {fr(omp_ifr_hip) }), targetsync), \ |
| 35 |
interop(targetsync, prefer_type("cuda", "hsa"))) \ |
| 36 |
adjust_args(need_device_ptr : y, k) |
| 37 |
#pragma omp declare variant(g2) \ |
| 38 |
match(construct={dispatch}, user={condition(flag==2)}) \ |
| 39 |
append_args(interop(target,prefer_type( {fr("cuda") }, {fr(omp_ifr_hsa)} , {attr("ompx_a") } , {fr(omp_ifr_hip) }), targetsync), \ |
| 40 |
interop(targetsync, prefer_type("cuda", "hsa"))) \ |
| 41 |
adjust_args(need_device_ptr : y) |
| 42 |
void f(int x, const char *y, int *, int *k) { } |
| 43 |
|
| 44 |
|
| 45 |
void gvar1(int, const char *, int *, int *, omp_interop_t, omp_interop_t, ...) { } |
| 46 |
void gvar2(int, const char *, int *, int *, omp_interop_t, omp_interop_t, ...) { } |
| 47 |
#pragma omp declare variant(gvar1) \ |
| 48 |
match(construct={dispatch}, user={condition(flag==3)}) \ |
| 49 |
append_args(interop(target,prefer_type( {fr("cuda") }, {fr(omp_ifr_hsa)} , {attr("ompx_a") } , {fr(omp_ifr_hip) }), targetsync), \ |
| 50 |
interop(targetsync, prefer_type("cuda", "hsa"))) \ |
| 51 |
adjust_args(need_device_ptr : y, k) |
| 52 |
#pragma omp declare variant(gvar2) \ |
| 53 |
match(construct={dispatch}, user={condition(flag==4)}) \ |
| 54 |
append_args(interop(target,prefer_type( {fr("cuda") }, {fr(omp_ifr_hsa)} , {attr("ompx_a") } , {fr(omp_ifr_hip) }), targetsync), \ |
| 55 |
interop(targetsync, prefer_type("cuda", "hsa"))) \ |
| 56 |
adjust_args(need_device_ptr : y) |
| 57 |
void fvar(int x, const char *y, int *, int *k, ...) { } |
| 58 |
|
| 59 |
void foo(const char *cp1, const char *cp2, int *a, int *b, int *c) |
| 60 |
{ |
| 61 |
omp_interop_t obj1, obj2, obj3, obj4; |
| 62 |
obj1 = obj2 = obj3 = obj4 = omp_interop_none; |
| 63 |
|
| 64 |
#pragma omp dispatch device(5) interop(obj1,obj2) is_device_ptr(cp1) |
| 65 |
f(3, cp1, a, b); |
| 66 |
|
| 67 |
#pragma omp dispatch device(4) interop(obj3,obj4) is_device_ptr(a,b,c) |
| 68 |
fvar(99, cp2, a, b, c, a, b, c, a, b, c); |
| 69 |
} |
| 70 |
|
| 71 |
/* Since the selectors are dynamic, there must be calls to all the variants as |
| 72 |
well as the base functions. */ |
| 73 |
/* { dg-final { scan-tree-dump "f \\(3, cp1, a, b\\)" "gimple" } } */ |
| 74 |
/* { dg-final { scan-tree-dump "g1 \\(3, cp1, a, D\.\[0-9\]+, obj1, obj2\\)" "gimple" } } */ |
| 75 |
/* { dg-final { scan-tree-dump "g2 \\(3, cp1, a, b, obj1, obj2\\)" "gimple" } } */ |
| 76 |
/* { dg-final { scan-tree-dump "fvar \\(99, cp2, a, b, c, a, b, c, a, b, c\\)" "gimple" } } */ |
| 77 |
/* { dg-final { scan-tree-dump "gvar1 \\(99, D\.\[0-9\]+, a, b, obj3, obj4, c, a, b, c, a, b, c\\)" "gimple" } } */ |
| 78 |
/* { dg-final { scan-tree-dump "gvar2 \\(99, D\.\[0-9\]+, a, b, obj3, obj4, c, a, b, c, a, b, c\\)" "gimple" } } */ |
| 79 |
|
| 80 |
/* Check that the condition tests appear in the output, too. */ |
| 81 |
/* { dg-final { scan-tree-dump "if \\(flag.\[0-9\]+ == 1\\)" "gimple" } } */ |
| 82 |
/* { dg-final { scan-tree-dump "if \\(flag.\[0-9\]+ == 2\\)" "gimple" } } */ |
| 83 |
/* { dg-final { scan-tree-dump "if \\(flag.\[0-9\]+ == 3\\)" "gimple" } } */ |
| 84 |
/* { dg-final { scan-tree-dump "if \\(flag.\[0-9\]+ == 4\\)" "gimple" } } */ |
| 85 |
|
| 86 |
/* There should be one call to map the pointer b for the call to f's variant |
| 87 |
g1; g2 doesn't have a need_device_ptr on this parameter. */ |
| 88 |
/* { dg-final { scan-tree-dump-times "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(b," 1 "gimple" } } */ |
| 89 |
|
| 90 |
/* Both variants for fvar need to map pointer cp2. */ |
| 91 |
/* { dg-final { scan-tree-dump-times "D\.\[0-9\]+ = __builtin_omp_get_mapped_ptr \\(cp2," 2 "gimple" } } */ |
| 92 |
|
| 93 |
|
| 94 |
|