-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCLomatic] Add query-api-mapping support for 26 thrust APIs (#1945)
Signed-off-by: chenwei.sun <[email protected]>
- Loading branch information
Showing
30 changed files
with
1,622 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <thrust/device_delete.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_new.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/memory.h> | ||
|
||
void device_delete_test() { | ||
const int N = 137; | ||
int val = 46; | ||
thrust::device_ptr<int> d_mem = thrust::device_malloc<int>(N); | ||
thrust::device_ptr<int> d_array1 = thrust::device_new<int>(d_mem, N); | ||
|
||
// Start | ||
thrust::device_delete(d_array1, N); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <thrust/device_delete.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_new.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/memory.h> | ||
|
||
void device_new_test() { | ||
const int N = 137; | ||
int val = 46; | ||
|
||
thrust::device_ptr<int> d_mem = thrust::device_malloc<int>(N); | ||
|
||
// Start | ||
/*1*/ thrust::device_ptr<int> d_array1 = thrust::device_new<int>(d_mem, N); | ||
/*2*/ thrust::device_ptr<int> d_array2 = | ||
thrust::device_new<int>(d_mem, val, N); | ||
/*3*/ thrust::device_ptr<int> d_array3 = thrust::device_new<int>(N); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <algorithm> | ||
#include <thrust/copy.h> | ||
#include <thrust/device_ptr.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/extrema.h> | ||
#include <thrust/gather.h> | ||
#include <thrust/host_vector.h> | ||
#include <thrust/inner_product.h> | ||
#include <thrust/random.h> | ||
#include <thrust/reduce.h> | ||
#include <thrust/scatter.h> | ||
#include <thrust/tuple.h> | ||
// for cuda 12.0 | ||
#include <thrust/count.h> | ||
#include <thrust/iterator/constant_iterator.h> | ||
#include <thrust/sort.h> | ||
#include <thrust/unique.h> | ||
|
||
void device_pointer_cast_test(void) { | ||
int data[10]; | ||
|
||
// Start | ||
thrust::device_ptr<int> begin = thrust::device_pointer_cast(&data[0]); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <thrust/device_delete.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_new.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/memory.h> | ||
|
||
void device_ptr_test() { | ||
const int N = 137; | ||
int val = 46; | ||
|
||
// Start | ||
thrust::device_ptr<int> d_mem = thrust::device_malloc<int>(N); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <vector> | ||
|
||
#include <thrust/binary_search.h> | ||
#include <thrust/copy.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/extrema.h> | ||
#include <thrust/find.h> | ||
#include <thrust/functional.h> | ||
#include <thrust/gather.h> | ||
#include <thrust/host_vector.h> | ||
#include <thrust/inner_product.h> | ||
#include <thrust/mismatch.h> | ||
#include <thrust/random.h> | ||
#include <thrust/reduce.h> | ||
#include <thrust/remove.h> | ||
#include <thrust/replace.h> | ||
#include <thrust/reverse.h> | ||
#include <thrust/set_operations.h> | ||
#include <thrust/sort.h> | ||
#include <thrust/tabulate.h> | ||
#include <thrust/transform_scan.h> | ||
#include <thrust/unique.h> | ||
|
||
// CHECK: #include <oneapi/dpl/memory> | ||
#include <thrust/equal.h> | ||
#include <thrust/uninitialized_copy.h> | ||
|
||
// for cuda 12.0 | ||
#include <thrust/iterator/constant_iterator.h> | ||
#include <thrust/partition.h> | ||
#include <thrust/scatter.h> | ||
|
||
struct add_functor { | ||
__host__ __device__ void operator()(int &x) { x++; } | ||
}; | ||
void for_each_n_test() { | ||
const int N = 3; | ||
int A[N] = {0, 1, 2}; | ||
thrust::host_vector<int> h_V(A, A + N); | ||
thrust::device_vector<int> d_V(A, A + N); | ||
|
||
// Start | ||
/*1*/ thrust::for_each_n(thrust::host, h_V.begin(), h_V.size(), | ||
add_functor()); | ||
/*2*/ thrust::for_each_n(h_V.begin(), h_V.size(), add_functor()); | ||
/*3*/ thrust::for_each_n(thrust::device, d_V.begin(), d_V.size(), | ||
add_functor()); | ||
/*4*/ thrust::for_each_n(d_V.begin(), d_V.size(), add_functor()); | ||
/*5*/ thrust::for_each_n(thrust::host, A, N, add_functor()); | ||
/*6*/ thrust::for_each_n(A, N, add_functor()); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include <vector> | ||
|
||
#include <thrust/binary_search.h> | ||
#include <thrust/copy.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/extrema.h> | ||
#include <thrust/find.h> | ||
#include <thrust/functional.h> | ||
#include <thrust/gather.h> | ||
#include <thrust/host_vector.h> | ||
#include <thrust/inner_product.h> | ||
#include <thrust/mismatch.h> | ||
#include <thrust/random.h> | ||
#include <thrust/reduce.h> | ||
#include <thrust/remove.h> | ||
#include <thrust/replace.h> | ||
#include <thrust/reverse.h> | ||
#include <thrust/set_operations.h> | ||
#include <thrust/sort.h> | ||
#include <thrust/tabulate.h> | ||
#include <thrust/transform_scan.h> | ||
#include <thrust/unique.h> | ||
|
||
// CHECK: #include <oneapi/dpl/memory> | ||
#include <thrust/equal.h> | ||
#include <thrust/uninitialized_copy.h> | ||
|
||
// for cuda 12.0 | ||
#include <thrust/iterator/constant_iterator.h> | ||
#include <thrust/partition.h> | ||
#include <thrust/scatter.h> | ||
|
||
void is_sorted_test() { | ||
const int N = 6; | ||
int datas[N] = {1, 4, 2, 8, 5, 7}; | ||
|
||
thrust::host_vector<int> h_v(datas, datas + N); | ||
thrust::device_vector<int> d_v(datas, datas + N); | ||
thrust::greater<int> comp; | ||
|
||
// Start | ||
/*1*/ thrust::is_sorted(thrust::host, h_v.begin(), h_v.end()); | ||
/*2*/ thrust::is_sorted(h_v.begin(), h_v.end()); | ||
/*3*/ thrust::is_sorted(thrust::host, h_v.begin(), h_v.end(), comp); | ||
/*4*/ thrust::is_sorted(h_v.begin(), h_v.end(), comp); | ||
/*5*/ thrust::is_sorted(h_v.begin(), h_v.end(), comp); | ||
/*6*/ thrust::is_sorted(thrust::device, d_v.begin(), d_v.end()); | ||
/*7*/ thrust::is_sorted(thrust::device, d_v.begin(), d_v.end(), comp); | ||
/*8*/ thrust::is_sorted(d_v.begin(), d_v.end(), comp); | ||
/*9*/ thrust::is_sorted(thrust::host, datas, datas + N); | ||
/*10*/ thrust::is_sorted(datas, datas + N); | ||
/*11*/ thrust::is_sorted(thrust::host, datas, datas + N, comp); | ||
/*12*/ thrust::is_sorted(datas, datas + N, comp); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <thrust/device_delete.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_new.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/memory.h> | ||
|
||
void malloc_test() { | ||
const int N = 137; | ||
int val = 46; | ||
|
||
thrust::device_system_tag device_sys; | ||
|
||
// Start | ||
/*1*/ thrust::pointer<int, thrust::device_system_tag> ptr = | ||
thrust::malloc<int>(device_sys, N); | ||
/*2*/ thrust::pointer<void, thrust::device_system_tag> void_ptr = | ||
thrust::malloc(device_sys, N); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <vector> | ||
|
||
#include <thrust/binary_search.h> | ||
#include <thrust/copy.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/extrema.h> | ||
#include <thrust/find.h> | ||
#include <thrust/functional.h> | ||
#include <thrust/gather.h> | ||
#include <thrust/host_vector.h> | ||
#include <thrust/inner_product.h> | ||
#include <thrust/mismatch.h> | ||
#include <thrust/partition.h> | ||
#include <thrust/random.h> | ||
#include <thrust/reduce.h> | ||
#include <thrust/remove.h> | ||
#include <thrust/replace.h> | ||
#include <thrust/reverse.h> | ||
#include <thrust/set_operations.h> | ||
#include <thrust/sort.h> | ||
#include <thrust/tabulate.h> | ||
#include <thrust/transform_scan.h> | ||
#include <thrust/unique.h> | ||
|
||
struct compare_key_value { | ||
__host__ __device__ bool operator()(int lhs, int rhs) const { | ||
return lhs < rhs; | ||
} | ||
}; | ||
|
||
void minmax_element_test() { | ||
const int N = 6; | ||
int data[N] = {1, 0, 2, 2, 1, 3}; | ||
thrust::host_vector<int> h_values(data, data + N); | ||
thrust::device_vector<int> d_values(data, data + N); | ||
// Start | ||
/*1*/ thrust::minmax_element(thrust::host, h_values.begin(), h_values.end()); | ||
/*2*/ thrust::minmax_element(h_values.begin(), h_values.end()); | ||
/*3*/ thrust::minmax_element(thrust::host, h_values.begin(), | ||
h_values.begin() + 4, compare_key_value()); | ||
/*4*/ thrust::minmax_element(h_values.begin(), h_values.begin() + 4, | ||
compare_key_value()); | ||
/*5*/ thrust::minmax_element(thrust::device, d_values.begin(), | ||
d_values.end()); | ||
/*6*/ thrust::minmax_element(d_values.begin(), d_values.end()); | ||
/*7*/ thrust::minmax_element(thrust::device, d_values.begin(), d_values.end(), | ||
compare_key_value()); | ||
/*8*/ thrust::minmax_element(d_values.begin(), d_values.end(), | ||
compare_key_value()); | ||
/*9*/ thrust::minmax_element(thrust::host, data, data + N); | ||
/*10*/ thrust::minmax_element(data, data + N); | ||
/*11*/ thrust::minmax_element(thrust::host, data, data + N, | ||
compare_key_value()); | ||
/*12*/ thrust::minmax_element(data, data + N, compare_key_value()); | ||
// End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <vector> | ||
|
||
#include <thrust/binary_search.h> | ||
#include <thrust/copy.h> | ||
#include <thrust/device_malloc.h> | ||
#include <thrust/device_vector.h> | ||
#include <thrust/execution_policy.h> | ||
#include <thrust/extrema.h> | ||
#include <thrust/find.h> | ||
#include <thrust/functional.h> | ||
#include <thrust/gather.h> | ||
#include <thrust/host_vector.h> | ||
#include <thrust/inner_product.h> | ||
#include <thrust/mismatch.h> | ||
#include <thrust/random.h> | ||
#include <thrust/reduce.h> | ||
#include <thrust/remove.h> | ||
#include <thrust/replace.h> | ||
#include <thrust/reverse.h> | ||
#include <thrust/set_operations.h> | ||
#include <thrust/sort.h> | ||
#include <thrust/tabulate.h> | ||
#include <thrust/transform_scan.h> | ||
#include <thrust/unique.h> | ||
|
||
// CHECK: #include <oneapi/dpl/memory> | ||
#include <thrust/equal.h> | ||
#include <thrust/uninitialized_copy.h> | ||
|
||
// for cuda 12.0 | ||
#include <thrust/iterator/constant_iterator.h> | ||
#include <thrust/partition.h> | ||
#include <thrust/scatter.h> | ||
|
||
struct is_even { | ||
__host__ __device__ bool operator()(const int &x) { return (x % 2) == 0; } | ||
}; | ||
void is_partition_test() { | ||
int datas[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
const int N = sizeof(datas) / sizeof(int); | ||
int stencil[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; | ||
|
||
thrust::host_vector<int> h_vdata(datas, datas + N); | ||
thrust::host_vector<int> h_vstencil(stencil, stencil + N); | ||
thrust::device_vector<int> d_v(datas, datas + N); | ||
thrust::host_vector<int> h_v(datas, datas + N); | ||
thrust::device_vector<int> d_vdata(datas, datas + N); | ||
thrust::device_vector<int> d_vstencil(stencil, stencil + N); | ||
|
||
// Start | ||
/*1*/ thrust::partition(thrust::host, h_v.begin(), h_v.end(), is_even()); | ||
/*2*/ thrust::partition(h_v.begin(), h_v.end(), is_even()); | ||
/*3*/ thrust::partition(thrust::host, h_vdata.begin(), h_vdata.end(), | ||
h_vstencil.begin(), is_even()); | ||
/*4*/ thrust::partition(h_vdata.begin(), h_vdata.end(), h_vstencil.begin(), | ||
is_even()); | ||
/*5*/ thrust::partition(thrust::device, d_v.begin(), d_v.end(), is_even()); | ||
/*6*/ thrust::partition(d_v.begin(), d_v.end(), is_even()); | ||
/*7*/ thrust::partition(thrust::device, d_vdata.begin(), d_vdata.end(), | ||
d_vstencil.begin(), is_even()); | ||
/*8*/ thrust::partition(d_vdata.begin(), d_vdata.end(), d_vstencil.begin(), | ||
is_even()); | ||
/*9*/ thrust::partition(thrust::host, datas, datas + N, is_even()); | ||
/*10*/ thrust::partition(datas, datas + N, is_even()); | ||
/*11*/ thrust::partition(thrust::host, datas, datas + N, stencil, is_even()); | ||
/*12*/ thrust::partition(datas, datas + N, stencil, is_even()); | ||
// End | ||
} |
Oops, something went wrong.