|
| 1 | +// UNSUPPORTED: cuda-8.0 |
| 2 | +// UNSUPPORTED: v8.0 |
| 3 | +// RUN: dpct -out-root %T/thrust_gather %s --cuda-include-path="%cuda-path/include" --usm-level=none |
| 4 | +// RUN: FileCheck --input-file %T/thrust_gather/thrust_gather.dp.cpp --match-full-lines %s |
| 5 | + |
| 6 | +#include <thrust/gather.h> |
| 7 | +#include <thrust/device_vector.h> |
| 8 | +#include <thrust/host_vector.h> |
| 9 | +#include <thrust/execution_policy.h> |
| 10 | +struct is_less_than_zero |
| 11 | +{ |
| 12 | + __host__ __device__ |
| 13 | + bool operator()(int x) const |
| 14 | + { |
| 15 | + return x < 0; |
| 16 | + } |
| 17 | +}; |
| 18 | + |
| 19 | +int main(void) { |
| 20 | + |
| 21 | + thrust::device_vector<int> AD(4); |
| 22 | + thrust::device_vector<int> BD(4); |
| 23 | + thrust::device_vector<int> SD(4); |
| 24 | + thrust::device_vector<int> RD(4); |
| 25 | + thrust::host_vector<int> AH(4); |
| 26 | + thrust::host_vector<int> BH(4); |
| 27 | + thrust::host_vector<int> SH(4); |
| 28 | + thrust::host_vector<int> RH(4); |
| 29 | + |
| 30 | + is_less_than_zero pred; |
| 31 | + |
| 32 | + int *h_ptr; |
| 33 | + int *d_ptr; |
| 34 | + |
| 35 | + h_ptr = (int*)std::malloc(20 * sizeof(int)); |
| 36 | + cudaMalloc(&d_ptr, 20 * sizeof(int)); |
| 37 | + |
| 38 | +/******************************************************************************************* |
| 39 | + 1. Test gather_if |
| 40 | + 2. Test four VERSIONs (with/without exec argument with/without predicate) |
| 41 | + 3. Test each VERSION with (device_vector/host_vector/malloc-ed memory/cudaMalloc-ed memory) |
| 42 | + *******************************************************************************************/ |
| 43 | + |
| 44 | +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 45 | +// CHECK:dpct::gather_if(oneapi::dpl::execution::seq, AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin(), pred); |
| 46 | +// CHECK-NEXT:dpct::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin(), pred); |
| 47 | +// CHECK-NEXT:if (dpct::is_device_ptr(h_ptr + 4)) { |
| 48 | +// CHECK-NEXT: dpct::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), dpct::device_pointer<int>(h_ptr), dpct::device_pointer<int>(h_ptr + 4), dpct::device_pointer<>(SH.begin()), dpct::device_pointer<>(BH.begin()), dpct::device_pointer<>(RH.begin()), pred); |
| 49 | +// CHECK-NEXT:} else { |
| 50 | +// CHECK-NEXT: dpct::gather_if(oneapi::dpl::execution::seq, h_ptr, h_ptr + 4, SH.begin(), BH.begin(), RH.begin(), pred); |
| 51 | +// CHECK-NEXT:}; |
| 52 | + // VERSION first last stencil input result pred |
| 53 | + thrust::gather_if( AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin(), pred); |
| 54 | + thrust::gather_if( AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin(), pred); |
| 55 | + thrust::gather_if( h_ptr, h_ptr+4, SH.begin(), BH.begin(), RH.begin(), pred); |
| 56 | + // Overload not supported with thrust |
| 57 | + // thrust::gather_if( d_ptr, d_ptr+4, SD.begin(), BD.begin(), RD.begin(), pred); |
| 58 | + |
| 59 | +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 60 | +// CHECK:dpct::gather_if(oneapi::dpl::execution::seq, AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin(), pred); |
| 61 | +// CHECK-NEXT:dpct::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin(), pred); |
| 62 | +// CHECK-NEXT:if (dpct::is_device_ptr(h_ptr)) { |
| 63 | +// CHECK-NEXT: dpct::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), dpct::device_pointer<int>(h_ptr), dpct::device_pointer<int>(h_ptr + 4), dpct::device_pointer<>(SH.begin()), dpct::device_pointer<>(BH.begin()), dpct::device_pointer<>(RH.begin()), pred); |
| 64 | +// CHECK-NEXT:} else { |
| 65 | +// CHECK-NEXT: dpct::gather_if(oneapi::dpl::execution::seq, h_ptr, h_ptr + 4, SH.begin(), BH.begin(), RH.begin(), pred); |
| 66 | +// CHECK-NEXT:}; |
| 67 | +// CHECK-NEXT:if (dpct::is_device_ptr(d_ptr)) { |
| 68 | +// CHECK-NEXT: dpct::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), dpct::device_pointer<int>(d_ptr), dpct::device_pointer<int>(d_ptr + 4), dpct::device_pointer<>(SD.begin()), dpct::device_pointer<>(BD.begin()), dpct::device_pointer<>(RD.begin()), pred); |
| 69 | +// CHECK-NEXT:} else { |
| 70 | +// CHECK-NEXT: dpct::gather_if(oneapi::dpl::execution::seq, d_ptr, d_ptr + 4, SD.begin(), BD.begin(), RD.begin(), pred); |
| 71 | +// CHECK-NEXT:}; |
| 72 | + // VERSION exec first last stencil input result pred |
| 73 | + thrust::gather_if(thrust::host, AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin(), pred); |
| 74 | + thrust::gather_if(thrust::device, AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin(), pred); |
| 75 | + thrust::gather_if(thrust::host, h_ptr, h_ptr+4, SH.begin(), BH.begin(), RH.begin(), pred); |
| 76 | + thrust::gather_if(thrust::device, d_ptr, d_ptr+4, SD.begin(), BD.begin(), RD.begin(), pred); |
| 77 | + |
| 78 | +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 | + |
| 80 | +// CHECK: /* |
| 81 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 82 | +// CHECK-NEXT: */ |
| 83 | +// CHECK-NEXT: thrust::gather_if(AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin()); |
| 84 | +// CHECK-NEXT: /* |
| 85 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 86 | +// CHECK-NEXT: */ |
| 87 | +// CHECK-NEXT: thrust::gather_if(AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin()); |
| 88 | +// CHECK-NEXT: /* |
| 89 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 90 | +// CHECK-NEXT: */ |
| 91 | +// CHECK-NEXT: thrust::gather_if(h_ptr, h_ptr + 4, SH.begin(), BH.begin(), RH.begin()); |
| 92 | + // VERSION first last stencil input result |
| 93 | + thrust::gather_if( AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin()); |
| 94 | + thrust::gather_if( AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin()); |
| 95 | + thrust::gather_if( h_ptr, h_ptr+4, SH.begin(), BH.begin(), RH.begin()); |
| 96 | + // Overload not supported with thrust |
| 97 | + // thrust::gather_if( d_ptr, d_ptr+4, SD.begin(), BD.begin(), RD.begin()); |
| 98 | + |
| 99 | +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 | + |
| 101 | +// CHECK: /* |
| 102 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 103 | +// CHECK-NEXT: */ |
| 104 | +// CHECK-NEXT: thrust::gather_if(oneapi::dpl::execution::seq, AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin()); |
| 105 | +// CHECK-NEXT: /* |
| 106 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 107 | +// CHECK-NEXT: */ |
| 108 | +// CHECK-NEXT: thrust::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin()); |
| 109 | +// CHECK-NEXT: /* |
| 110 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 111 | +// CHECK-NEXT: */ |
| 112 | +// CHECK-NEXT: thrust::gather_if(oneapi::dpl::execution::seq, h_ptr, h_ptr + 4, SH.begin(), BH.begin(), RH.begin()); |
| 113 | +// CHECK-NEXT: /* |
| 114 | +// CHECK-NEXT: DPCT1107:{{[0-9]+}}: Migration for this overload of thrust::gather_if is not supported. |
| 115 | +// CHECK-NEXT: */ |
| 116 | +// CHECK-NEXT: thrust::gather_if(oneapi::dpl::execution::make_device_policy(q_ct1), d_ptr, d_ptr + 4, SD.begin(), BD.begin(), RD.begin()); |
| 117 | + // VERSION exec first last stencil input result |
| 118 | + thrust::gather_if(thrust::host, AH.begin(), AH.end(), SH.begin(), BH.begin(), RH.begin()); |
| 119 | + thrust::gather_if(thrust::device, AD.begin(), AD.end(), SD.begin(), BD.begin(), RD.begin()); |
| 120 | + thrust::gather_if(thrust::host, h_ptr, h_ptr+4, SH.begin(), BH.begin(), RH.begin()); |
| 121 | + thrust::gather_if(thrust::device, d_ptr, d_ptr+4, SD.begin(), BD.begin(), RD.begin()); |
| 122 | + |
| 123 | + return 0; |
| 124 | +} |
0 commit comments