Skip to content

Commit 1854491

Browse files
authored
[SYCLomatic #947] Add test cases for migration of thrust::uninitialized_copy and thrust::uninitialized_copy_n (#348)
Signed-off-by: chenwei.sun <[email protected]>
1 parent 8531065 commit 1854491

File tree

4 files changed

+219
-1
lines changed

4 files changed

+219
-1
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// ====------ thrust_uninitialized_copy.cu------------- *- CUDA -* --------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//
8+
// ===----------------------------------------------------------------------===//
9+
#include <thrust/device_malloc.h>
10+
#include <thrust/device_vector.h>
11+
#include <thrust/execution_policy.h>
12+
#include <thrust/host_vector.h>
13+
#include <thrust/uninitialized_copy.h>
14+
15+
struct Int {
16+
__host__ __device__ Int(int x) : val(x) {}
17+
int val;
18+
};
19+
20+
void test_1() {
21+
22+
const int N = 137;
23+
Int val(46);
24+
thrust::device_vector<Int> input(N, val);
25+
thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
26+
thrust::uninitialized_copy(input.begin(), input.end(), array);
27+
28+
thrust::host_vector<Int> hostVec(array, array + N);
29+
30+
for (int i = 0; i < N; i++) {
31+
if (hostVec[i].val != 46) {
32+
printf("test_1 run failed\n");
33+
exit(-1);
34+
}
35+
}
36+
37+
printf("test_1 run passed!\n");
38+
}
39+
40+
void test_2() {
41+
42+
const int N = 137;
43+
int data[N];
44+
int array[N];
45+
for (int i = 0; i < N; i++)
46+
data[i] = 46;
47+
48+
thrust::uninitialized_copy(data, data + N, array);
49+
50+
for (int i = 0; i < N; i++) {
51+
if (array[i] != 46) {
52+
printf("test_2 run failed\n");
53+
exit(-1);
54+
}
55+
}
56+
57+
printf("test_2 run passed!\n");
58+
}
59+
60+
void test_3() {
61+
62+
const int N = 137;
63+
Int val(46);
64+
thrust::device_vector<Int> input(N, val);
65+
thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
66+
thrust::uninitialized_copy(thrust::device, input.begin(), input.end(), array);
67+
68+
thrust::host_vector<Int> hostVec(array, array + N);
69+
70+
for (int i = 0; i < N; i++) {
71+
if (hostVec[i].val != 46) {
72+
printf("test_3 run failed\n");
73+
exit(-1);
74+
}
75+
}
76+
77+
printf("test_3 run passed!\n");
78+
}
79+
80+
void test_4() {
81+
82+
const int N = 137;
83+
int data[N];
84+
int array[N];
85+
for (int i = 0; i < N; i++)
86+
data[i] = 46;
87+
88+
thrust::uninitialized_copy(thrust::host, data, data + N, array);
89+
90+
for (int i = 0; i < N; i++) {
91+
if (array[i] != 46) {
92+
printf("test_4 run failed\n");
93+
exit(-1);
94+
}
95+
}
96+
97+
printf("test_4 run passed!\n");
98+
}
99+
100+
int main() {
101+
test_1();
102+
test_2();
103+
test_3();
104+
test_4();
105+
106+
return 0;
107+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// ====------ thrust_uninitialized_copy_n.cu------------- *- CUDA -* -----===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//
8+
// ===---------------------------------------------------------------------===//
9+
10+
#include <thrust/device_malloc.h>
11+
#include <thrust/device_vector.h>
12+
#include <thrust/execution_policy.h>
13+
#include <thrust/host_vector.h>
14+
#include <thrust/uninitialized_copy.h>
15+
16+
struct Int {
17+
__host__ __device__ Int(int x) : val(x) {}
18+
int val;
19+
};
20+
21+
void test_1() {
22+
23+
const int N = 137;
24+
Int val(46);
25+
thrust::device_vector<Int> input(N, val);
26+
thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
27+
28+
thrust::uninitialized_copy_n(input.begin(), N, array);
29+
30+
thrust::host_vector<Int> hostVec(array, array + N);
31+
32+
for (int i = 0; i < N; i++) {
33+
if (hostVec[i].val != 46) {
34+
printf("test_1 run failed\n");
35+
exit(-1);
36+
}
37+
}
38+
39+
printf("test_1 run passed!\n");
40+
}
41+
42+
void test_2() {
43+
44+
const int N = 137;
45+
int data[N];
46+
int array[N];
47+
for (int i = 0; i < N; i++)
48+
data[i] = 46;
49+
50+
thrust::uninitialized_copy_n(data, N, array);
51+
52+
for (int i = 0; i < N; i++) {
53+
if (array[i] != 46) {
54+
printf("test_2 run failed\n");
55+
exit(-1);
56+
}
57+
}
58+
59+
printf("test_2 run passed!\n");
60+
}
61+
62+
void test_3() {
63+
64+
const int N = 137;
65+
Int val(46);
66+
thrust::device_vector<Int> input(N, val);
67+
thrust::device_ptr<Int> array = thrust::device_malloc<Int>(N);
68+
thrust::uninitialized_copy_n(thrust::device, input.begin(), N, array);
69+
70+
thrust::host_vector<Int> hostVec(array, array + N);
71+
72+
for (int i = 0; i < N; i++) {
73+
if (hostVec[i].val != 46) {
74+
printf("test_3 run failed\n");
75+
exit(-1);
76+
}
77+
}
78+
79+
printf("test_3 run passed!\n");
80+
}
81+
82+
void test_4() {
83+
84+
const int N = 137;
85+
int data[N];
86+
int array[N];
87+
for (int i = 0; i < N; i++)
88+
data[i] = 46;
89+
90+
thrust::uninitialized_copy_n(thrust::host, data, N, array);
91+
92+
for (int i = 0; i < N; i++) {
93+
if (array[i] != 46) {
94+
printf("test_4 run failed\n");
95+
exit(-1);
96+
}
97+
}
98+
99+
printf("test_4 run passed!\n");
100+
}
101+
102+
int main() {
103+
test_1();
104+
test_2();
105+
test_3();
106+
test_4();
107+
108+
return 0;
109+
}

features/features.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
<test testName="thrust_stable_partition" configFile="config/TEMPLATE_thrust_api.xml" />
3838
<test testName="thrust_reverse" configFile="config/TEMPLATE_thrust_api.xml" />
3939
<test testName="thrust_transform_inclusive_scan" configFile="config/TEMPLATE_thrust_api.xml" />
40+
<test testName="thrust_uninitialized_copy_n" configFile="config/TEMPLATE_thrust_api.xml" />
41+
<test testName="thrust_uninitialized_copy" configFile="config/TEMPLATE_thrust_api.xml" />
4042
<test testName="thrust_raw_reference_cast" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
4143
<test testName="thrust_partition_copy" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
4244
<test testName="thrust_stable_partition_copy" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />

features/test_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'thrust_raw_reference_cast', 'thrust_partition_copy', 'thrust_stable_partition_copy',
5151
'thrust_stable_partition', 'thrust_remove', 'cub_device_segmented_sort_pairs', 'thrust_find_if_not',
5252
'thrust_find_if', 'thrust_mismatch', 'thrust_replace_copy', 'thrust_reverse', 'cooperative_groups_reduce',
53-
'remove_unnecessary_wait', 'thrust_equal_range', 'thrust_transform_inclusive_scan']
53+
'remove_unnecessary_wait', 'thrust_equal_range', 'thrust_transform_inclusive_scan', 'thrust_uninitialized_copy_n', 'thrust_uninitialized_copy']
5454

5555
occupancy_calculation_exper = ['occupancy_calculation']
5656

0 commit comments

Comments
 (0)