Skip to content

Commit 44a1f08

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

File tree

5 files changed

+96
-0
lines changed

5 files changed

+96
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <thrust/device_malloc.h>
2+
#include <thrust/device_vector.h>
3+
#include <thrust/execution_policy.h>
4+
#include <thrust/functional.h>
5+
#include <thrust/host_vector.h>
6+
#include <thrust/logical.h>
7+
#include <thrust/partition.h>
8+
#include <thrust/set_operations.h>
9+
#include <thrust/sort.h>
10+
#include <thrust/unique.h>
11+
12+
void count_test() {
13+
// clang-format off
14+
// Start
15+
std::vector<int> v;
16+
/*1*/ thrust::count(thrust::seq, v.begin(), v.end(), 23);
17+
/*2*/ thrust::count(v.begin(), v.end(), 23);
18+
// End
19+
// clang-format on
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <thrust/device_delete.h>
2+
#include <thrust/device_malloc.h>
3+
#include <thrust/device_new.h>
4+
#include <thrust/device_vector.h>
5+
#include <thrust/execution_policy.h>
6+
#include <thrust/memory.h>
7+
8+
void get_temporary_buffer_test() {
9+
10+
// clang-format off
11+
// Start
12+
const int N = 100;
13+
typedef thrust::pair<thrust::pointer<int, thrust::device_system_tag>, std::ptrdiff_t> ptr_and_size_t;
14+
thrust::device_system_tag device_sys;
15+
ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer<int>(device_sys, N);
16+
// End
17+
// clang-format on
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <thrust/device_vector.h>
2+
#include <thrust/execution_policy.h>
3+
#include <thrust/functional.h>
4+
#include <thrust/host_vector.h>
5+
#include <thrust/partition.h>
6+
#include <thrust/set_operations.h>
7+
#include <thrust/sort.h>
8+
#include <thrust/unique.h>
9+
10+
void sort_test() {
11+
// clang-format off
12+
// Start
13+
thrust::host_vector<int> h_vec(10);
14+
thrust::device_vector<int> d_vec(10);
15+
/*1*/ thrust::sort(h_vec.begin(), h_vec.end());
16+
/*2*/ thrust::sort(thrust::device, d_vec.begin(), d_vec.end());
17+
// End
18+
// clang-format on
19+
}

clang/test/dpct/query_api_mapping/Thrust/thrust_api_test_p3.cu

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,39 @@
267267
// thrust_make_zip_iterator-NEXT: typedef dpct::device_vector<float>::iterator float_iterator;
268268
// thrust_make_zip_iterator-NEXT: typedef std::tuple<int_iterator, float_iterator> iterator_tuple;
269269
// thrust_make_zip_iterator-NEXT: dpct::zip_iterator<iterator_tuple> ret = oneapi::dpl::make_zip_iterator(std::make_tuple(int_in.begin(), float_in.begin()));
270+
271+
// RUN: dpct --cuda-include-path="%cuda-path/include" --query-api-mapping=thrust::count --extra-arg="-std=c++14"| FileCheck %s -check-prefix=thrust_count
272+
// thrust_count: CUDA API:
273+
// thrust_count-NEXT: std::vector<int> v;
274+
// thrust_count-NEXT: /*1*/ thrust::count(thrust::seq, v.begin(), v.end(), 23);
275+
// thrust_count-NEXT: /*2*/ thrust::count(v.begin(), v.end(), 23);
276+
// thrust_count-NEXT: Is migrated to:
277+
// thrust_count-NEXT: std::vector<int> v;
278+
// thrust_count-NEXT: /*1*/ std::count(oneapi::dpl::execution::seq, v.begin(), v.end(), 23);
279+
// thrust_count-NEXT: /*2*/ std::count(oneapi::dpl::execution::seq, v.begin(), v.end(), 23);
280+
281+
// RUN: dpct --cuda-include-path="%cuda-path/include" --query-api-mapping=thrust::sort --extra-arg="-std=c++14"| FileCheck %s -check-prefix=thrust_sort
282+
// thrust_sort: CUDA API:
283+
// thrust_sort-NEXT: thrust::host_vector<int> h_vec(10);
284+
// thrust_sort-NEXT: thrust::device_vector<int> d_vec(10);
285+
// thrust_sort-NEXT: /*1*/ thrust::sort(h_vec.begin(), h_vec.end());
286+
// thrust_sort-NEXT: /*2*/ thrust::sort(thrust::device, d_vec.begin(), d_vec.end());
287+
// thrust_sort-NEXT: Is migrated to:
288+
// thrust_sort-NEXT: std::vector<int> h_vec(10);
289+
// thrust_sort-NEXT: dpct::device_vector<int> d_vec(10);
290+
// thrust_sort-NEXT: /*1*/ oneapi::dpl::sort(oneapi::dpl::execution::seq, h_vec.begin(), h_vec.end());
291+
// thrust_sort-NEXT: /*2*/ oneapi::dpl::sort(oneapi::dpl::execution::make_device_policy(q_ct1), d_vec.begin(), d_vec.end());
292+
293+
// RUN: dpct --cuda-include-path="%cuda-path/include" --query-api-mapping=thrust::get_temporary_buffer --extra-arg="-std=c++14"| FileCheck %s -check-prefix=thrust_get_temporary_buffer
294+
// thrust_get_temporary_buffer: CUDA API:
295+
// thrust_get_temporary_buffer-NEXT: const int N = 100;
296+
// thrust_get_temporary_buffer-NEXT: typedef thrust::pair<thrust::pointer<int, thrust::device_system_tag>, std::ptrdiff_t> ptr_and_size_t;
297+
// thrust_get_temporary_buffer-NEXT: thrust::device_system_tag device_sys;
298+
// thrust_get_temporary_buffer-NEXT: ptr_and_size_t ptr_and_size = thrust::get_temporary_buffer<int>(device_sys, N);
299+
// thrust_get_temporary_buffer-NEXT: Is migrated to:
300+
// thrust_get_temporary_buffer-NEXT: const int N = 100;
301+
// thrust_get_temporary_buffer-NEXT: typedef std::pair<dpct::tagged_pointer<int, dpct::device_sys_tag>, std::ptrdiff_t> ptr_and_size_t;
302+
// thrust_get_temporary_buffer-NEXT: dpct::device_sys_tag device_sys;
303+
// thrust_get_temporary_buffer-NEXT: ptr_and_size_t ptr_and_size = dpct::get_temporary_allocation<int>(device_sys, N);
304+
305+

clang/test/dpct/query_api_mapping/test_all.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,7 @@
24242424
// CHECK-NEXT: thrust::copy_n
24252425
// CHECK-NEXT: thrust::cos
24262426
// CHECK-NEXT: thrust::cosh
2427+
// CHECK-NEXT: thrust::count
24272428
// CHECK-NEXT: thrust::count_if
24282429
// CHECK-NEXT: thrust::device_delete
24292430
// CHECK-NEXT: thrust::device_free
@@ -2450,6 +2451,7 @@
24502451
// CHECK-NEXT: thrust::generate
24512452
// CHECK-NEXT: thrust::generate_n
24522453
// CHECK-NEXT: thrust::get
2454+
// CHECK-NEXT: thrust::get_temporary_buffer
24532455
// CHECK-NEXT: thrust::inclusive_scan
24542456
// CHECK-NEXT: thrust::inclusive_scan_by_key
24552457
// CHECK-NEXT: thrust::inner_product
@@ -2513,6 +2515,7 @@
25132515
// CHECK-NEXT: thrust::set_union_by_key
25142516
// CHECK-NEXT: thrust::sin
25152517
// CHECK-NEXT: thrust::sinh
2518+
// CHECK-NEXT: thrust::sort
25162519
// CHECK-NEXT: thrust::sort_by_key
25172520
// CHECK-NEXT: thrust::sqrt
25182521
// CHECK-NEXT: thrust::stable_partition

0 commit comments

Comments
 (0)