Skip to content

Commit 83ca163

Browse files
authored
[SYCLomatic oneapi-src#506] Add test case for migration of thrust::raw_reference_cast() (oneapi-src#201)
Signed-off-by: chenwei.sun <[email protected]>
1 parent 3c73df3 commit 83ca163

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// ====------ thrust_raw_reference_cast.cu---------- *- CUDA -*
2+
// -------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//
9+
// ===------------------------------------------------------------------------------===//
10+
11+
#include <cuda.h>
12+
#include <thrust/device_free.h>
13+
#include <thrust/device_malloc.h>
14+
#include <thrust/device_ptr.h>
15+
#include <thrust/device_vector.h>
16+
#include <thrust/host_vector.h>
17+
18+
#define EXIT_SUCCESS 0
19+
#define EXIT_FAILURE 1
20+
21+
int main(void) {
22+
thrust::host_vector<int> h_vec(1);
23+
thrust::device_vector<int> d_vec = h_vec;
24+
d_vec[0] = 13;
25+
26+
thrust::device_reference<int> ref_to_thirteen = d_vec[0];
27+
int &ref = thrust::raw_reference_cast(ref_to_thirteen);
28+
29+
int val = 0;
30+
cudaError_t err = cudaMemcpy(&val, &ref, sizeof(int), cudaMemcpyDeviceToHost);
31+
32+
if (err != cudaSuccess) {
33+
exit(EXIT_FAILURE);
34+
}
35+
36+
if (val != 13) {
37+
std::cout << "get_raw_reference test failed.\n";
38+
return EXIT_FAILURE;
39+
}
40+
41+
std::cout << "get_raw_reference test passed.\n";
42+
return EXIT_SUCCESS;
43+
}

features/features.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<test testName="thrust_minmax_element" configFile="config/TEMPLATE_thrust_api.xml" />
3131
<test testName="thrust_partition" configFile="config/TEMPLATE_thrust_api.xml" />
3232
<test testName="thrust_is_sorted" configFile="config/TEMPLATE_thrust_api.xml" />
33+
<test testName="thrust_raw_reference_cast" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
3334
<test testName="thrust_remove_copy" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
3435
<test testName="thrust_unique_copy" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
3536
<test testName="thrust_transform_exclusive_scan" configFile="config/TEMPLATE_thrust_api.xml" />

features/test_feature.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
'cusolver_test1', 'cusolver_test2', 'thrust_op', 'cublas-extension', 'cublas_v1_runable', 'thrust_minmax_element',
4040
'thrust_is_sorted', 'thrust_partition', 'thrust_remove_copy', 'thrust_unique_copy', 'thrust_transform_exclusive_scan',
4141
'thrust_set_difference', 'thrust_set_difference_by_key', 'thrust_set_intersection_by_key', 'thrust_stable_sort',
42-
'thrust_tabulate', 'thrust_for_each_n', 'device_info', 'defaultStream', 'cudnn-rnn', 'feature_profiling']
42+
'thrust_tabulate', 'thrust_for_each_n', 'device_info', 'defaultStream', 'cudnn-rnn', 'feature_profiling',
43+
'thrust_raw_reference_cast']
44+
4345

4446
def setup_test():
4547
return True

0 commit comments

Comments
 (0)