Skip to content

Commit aac5ccf

Browse files
authored
[SYCLomatic] Add query-api-mapping for 44 thrust APIs (#2903)
Signed-off-by: chenwei.sun <chenwei.sun@intel.com>
1 parent a14a8ca commit aac5ccf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1973
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <thrust/device_vector.h>
2+
#include <thrust/host_vector.h>
3+
#include <thrust/logical.h>
4+
#include <thrust/functional.h>
5+
#include <thrust/adjacent_difference.h>
6+
#include <thrust/gather.h>
7+
#include <thrust/scatter.h>
8+
#include <thrust/execution_policy.h>
9+
#include <thrust/remove.h>
10+
#include <thrust/sort.h>
11+
#include <thrust/unique.h>
12+
13+
void adjacent_difference_test() {
14+
// clang-format off
15+
// Start
16+
float *host_ptr_A;
17+
float *host_ptr_R;
18+
float *device_ptr_A;
19+
float *device_ptr_R;
20+
/*1*/ thrust::adjacent_difference(thrust::device, device_ptr_A, device_ptr_A+10, device_ptr_R);
21+
/*2*/ thrust::adjacent_difference(host_ptr_A, host_ptr_A+10, host_ptr_R, thrust::minus<float>());
22+
/*3*/ thrust::adjacent_difference(thrust::device, device_ptr_A, device_ptr_A+10, device_ptr_R, thrust::minus<float>());
23+
/*4*/ thrust::adjacent_difference(host_ptr_A, host_ptr_A+10, host_ptr_R);
24+
// End
25+
// clang-format on
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <thrust/device_vector.h>
2+
#include <thrust/host_vector.h>
3+
#include <thrust/logical.h>
4+
#include <thrust/functional.h>
5+
#include <thrust/adjacent_difference.h>
6+
#include <thrust/execution_policy.h>
7+
#include <thrust/remove.h>
8+
9+
void any_of_test() {
10+
// clang-format off
11+
// Start
12+
struct greater_than_zero {
13+
__host__ __device__ bool operator()(int x) const { return x > 0; }
14+
};
15+
greater_than_zero pred;
16+
thrust::device_vector<int> A(4);
17+
thrust::device_vector<int> B(4);
18+
/*1*/ thrust::any_of(A.begin(), A.end(), pred);
19+
/*2*/ thrust::any_of(thrust::device, B.begin(), B.end(), pred);
20+
// End
21+
// clang-format on
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <vector>
2+
3+
#include <thrust/binary_search.h>
4+
#include <thrust/copy.h>
5+
#include <thrust/device_malloc.h>
6+
#include <thrust/device_vector.h>
7+
#include <thrust/execution_policy.h>
8+
#include <thrust/extrema.h>
9+
#include <thrust/find.h>
10+
#include <thrust/functional.h>
11+
#include <thrust/gather.h>
12+
#include <thrust/host_vector.h>
13+
#include <thrust/inner_product.h>
14+
#include <thrust/mismatch.h>
15+
#include <thrust/random.h>
16+
#include <thrust/reduce.h>
17+
#include <thrust/remove.h>
18+
#include <thrust/replace.h>
19+
#include <thrust/reverse.h>
20+
#include <thrust/set_operations.h>
21+
#include <thrust/sort.h>
22+
#include <thrust/tabulate.h>
23+
#include <thrust/transform_scan.h>
24+
#include <thrust/unique.h>
25+
26+
27+
void binary_search_test() {
28+
// clang-format off
29+
// Start
30+
std::vector<int> v, v2, v3, v4;
31+
auto bp = [](int x, int y) -> bool { return x < y; };
32+
/*1*/ thrust::binary_search(thrust::seq, v.begin(), v.end(), v2.begin(), v2.end(), v3.begin());
33+
/*2*/ thrust::binary_search(v.begin(), v.end(), v2.begin(), v2.end(), v3.begin());
34+
/*3*/ thrust::binary_search(thrust::seq, v.begin(), v.end(), v2.begin(), v2.end(), v3.begin(), bp);
35+
/*4*/ thrust::binary_search(v.begin(), v.end(), v2.begin(), v2.end(), v3.begin(), bp);
36+
// End
37+
// clang-format on
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <thrust/device_vector.h>
2+
#include <thrust/host_vector.h>
3+
#include <thrust/copy.h>
4+
#include <thrust/execution_policy.h>
5+
6+
void copy_test() {
7+
// clang-format off
8+
// Start
9+
const char data[] = "abc";
10+
const size_t N = (sizeof(data) / sizeof(char)) - 1;
11+
char dst_data[N];
12+
thrust::device_vector<char> input(data, data + N);
13+
thrust::device_vector<char> dst(data, data + N);
14+
/*1*/ thrust::copy(data, data + N, dst_data);
15+
/*2*/ thrust::copy(thrust::device, input.begin(), input.begin() + N, dst.begin());
16+
// End
17+
// clang-format on
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <thrust/device_vector.h>
2+
#include <thrust/host_vector.h>
3+
#include <thrust/copy.h>
4+
#include <thrust/execution_policy.h>
5+
6+
void copy_if() {
7+
// clang-format off
8+
// Start
9+
auto is_even = [] __host__ __device__(int v) { return (v % 2) == 0; };
10+
const int N = 4;
11+
int vec_host_in[N] = {-1, 0, 1, 2};
12+
int vec_host_out[N];
13+
int *vec_devic_in;
14+
int *vec_devic_out;
15+
thrust::device_vector<int> dVecIn(vec_host_in, vec_host_in + N);
16+
thrust::device_vector<int> dVecOut(N);
17+
/*1*/ thrust::copy_if(vec_host_in, vec_host_in + N, vec_host_out, is_even);
18+
/*2*/ thrust::copy_if(thrust::device, vec_devic_in, vec_devic_in + N, vec_devic_out, is_even);
19+
/*3*/ thrust::copy_if(thrust::host, vec_host_in, vec_host_in + N,vec_host_out, is_even);
20+
/*4*/ thrust::copy_if(dVecIn.begin(), dVecIn.end(), dVecOut.begin(), is_even);
21+
// End
22+
// clang-format on
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <thrust/device_vector.h>
2+
#include <thrust/host_vector.h>
3+
#include <thrust/copy.h>
4+
#include <thrust/execution_policy.h>
5+
6+
void copy_n() {
7+
// clang-format off
8+
// Start
9+
const char data[] = "abc";
10+
const size_t N = (sizeof(data) / sizeof(char)) - 1;
11+
char dst_data[N];
12+
thrust::device_vector<char> input(data, data + N);
13+
thrust::device_vector<char> dst(data, data + N);
14+
/*1*/ thrust::copy_n(data, N, dst_data);
15+
/*2*/ thrust::copy_n(thrust::device, input.begin(), N, dst.begin());
16+
// End
17+
// clang-format on
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <thrust/copy.h>
2+
#include <thrust/count.h>
3+
#include <thrust/device_ptr.h>
4+
#include <thrust/device_vector.h>
5+
#include <thrust/execution_policy.h>
6+
#include <thrust/extrema.h>
7+
#include <thrust/gather.h>
8+
#include <thrust/host_vector.h>
9+
#include <thrust/inner_product.h>
10+
#include <thrust/scatter.h>
11+
#include <thrust/tuple.h>
12+
13+
void count_if_test() {
14+
15+
// clang-format off
16+
// Start
17+
std::vector<thrust::device_vector<int>> d(10);
18+
auto t = thrust::make_counting_iterator(0);
19+
int ret = thrust::count_if(t, t + 10, [=] __device__(int idx) { return true;});
20+
// End
21+
// clang-format on
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <thrust/copy.h>
2+
#include <thrust/count.h>
3+
#include <thrust/device_ptr.h>
4+
#include <thrust/device_vector.h>
5+
#include <thrust/execution_policy.h>
6+
#include <thrust/extrema.h>
7+
#include <thrust/gather.h>
8+
#include <thrust/host_vector.h>
9+
#include <thrust/inner_product.h>
10+
#include <thrust/scatter.h>
11+
#include <thrust/tuple.h>
12+
13+
void exclusive_scan_test() {
14+
// clang-format off
15+
// Start
16+
std::vector<int> v, v2, v3, v4;
17+
thrust::maximum<int> binary_op;
18+
thrust::device_vector<int> tv, tv2, tv3, tv4;
19+
/*1*/ thrust::exclusive_scan(thrust::device, tv.begin(), tv.end(), tv2.begin());
20+
/*2*/ thrust::exclusive_scan(tv.begin(), tv.end(), tv2.begin());
21+
/*3*/ thrust::exclusive_scan(thrust::device, tv.begin(), tv.end(), tv2.begin(), 4);
22+
/*4*/ thrust::exclusive_scan(tv.begin(), tv.end(), tv2.begin(), 4);
23+
/*5*/ thrust::exclusive_scan(thrust::device, tv.begin(), tv.end(), tv2.begin(), 1, binary_op);
24+
/*6*/ thrust::exclusive_scan(tv.begin(), tv.end(), tv2.begin(), 1, binary_op);
25+
// End
26+
// clang-format on
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <thrust/copy.h>
2+
#include <thrust/count.h>
3+
#include <thrust/device_ptr.h>
4+
#include <thrust/device_vector.h>
5+
#include <thrust/execution_policy.h>
6+
#include <thrust/extrema.h>
7+
#include <thrust/gather.h>
8+
#include <thrust/host_vector.h>
9+
#include <thrust/inner_product.h>
10+
#include <thrust/scatter.h>
11+
#include <thrust/tuple.h>
12+
13+
void exclusive_scan_by_key_test() {
14+
// clang-format off
15+
// Start
16+
std::vector<int> v, v2, v3, v4;
17+
auto bp = [](int x, int y) -> bool { return x < y; };
18+
thrust::device_vector<int> tv, tv2, tv3, tv4;
19+
/*1*/ thrust::exclusive_scan_by_key(thrust::seq, v.begin(), v.end(), v2.begin(), v3.begin());
20+
/*2*/ thrust::exclusive_scan_by_key(v.begin(), v.end(), v2.begin(), v3.begin());
21+
/*3*/ thrust::exclusive_scan_by_key(thrust::seq, v.begin(), v.end(), v2.begin(), v3.begin(), 1);
22+
/*4*/ thrust::exclusive_scan_by_key(v.begin(), v.end(), v2.begin(), v3.begin(), 1);
23+
/*5*/ thrust::exclusive_scan_by_key(thrust::seq, v.begin(), v.end(), v2.begin(), v3.begin(), 1, bp);
24+
/*6*/ thrust::exclusive_scan_by_key(v.begin(), v.end(), v2.begin(), v3.begin(), 1, bp);
25+
// End
26+
// clang-format on
27+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <thrust/copy.h>
2+
#include <thrust/count.h>
3+
#include <thrust/device_ptr.h>
4+
#include <thrust/device_vector.h>
5+
#include <thrust/execution_policy.h>
6+
#include <thrust/extrema.h>
7+
#include <thrust/gather.h>
8+
#include <thrust/host_vector.h>
9+
10+
void fill_test() {
11+
// clang-format off
12+
// Start
13+
float *_de = NULL;
14+
float fill_value = 0.0;
15+
thrust::device_ptr<float> dev_ptr = thrust::device_pointer_cast(static_cast<float *>(&_de[0]));
16+
thrust::fill(dev_ptr, dev_ptr + 10, fill_value);
17+
// End
18+
// clang-format on
19+
}

0 commit comments

Comments
 (0)