Skip to content

Commit

Permalink
[SYCLomatic oneapi-src#506] Add test case for migration of thrust::ra…
Browse files Browse the repository at this point in the history
…w_reference_cast() (oneapi-src#201)

Signed-off-by: chenwei.sun <chenwei.sun@intel.com>
  • Loading branch information
tomflinda authored Feb 8, 2023
1 parent 3c73df3 commit 83ca163
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
43 changes: 43 additions & 0 deletions features/feature_case/thrust/thrust_raw_reference_cast.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ====------ thrust_raw_reference_cast.cu---------- *- CUDA -*
// -------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
// ===------------------------------------------------------------------------------===//

#include <cuda.h>
#include <thrust/device_free.h>
#include <thrust/device_malloc.h>
#include <thrust/device_ptr.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1

int main(void) {
thrust::host_vector<int> h_vec(1);
thrust::device_vector<int> d_vec = h_vec;
d_vec[0] = 13;

thrust::device_reference<int> ref_to_thirteen = d_vec[0];
int &ref = thrust::raw_reference_cast(ref_to_thirteen);

int val = 0;
cudaError_t err = cudaMemcpy(&val, &ref, sizeof(int), cudaMemcpyDeviceToHost);

if (err != cudaSuccess) {
exit(EXIT_FAILURE);
}

if (val != 13) {
std::cout << "get_raw_reference test failed.\n";
return EXIT_FAILURE;
}

std::cout << "get_raw_reference test passed.\n";
return EXIT_SUCCESS;
}
1 change: 1 addition & 0 deletions features/features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<test testName="thrust_minmax_element" configFile="config/TEMPLATE_thrust_api.xml" />
<test testName="thrust_partition" configFile="config/TEMPLATE_thrust_api.xml" />
<test testName="thrust_is_sorted" configFile="config/TEMPLATE_thrust_api.xml" />
<test testName="thrust_raw_reference_cast" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
<test testName="thrust_remove_copy" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
<test testName="thrust_unique_copy" configFile="config/TEMPLATE_thrust_api_disable_noneusm.xml" />
<test testName="thrust_transform_exclusive_scan" configFile="config/TEMPLATE_thrust_api.xml" />
Expand Down
4 changes: 3 additions & 1 deletion features/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
'cusolver_test1', 'cusolver_test2', 'thrust_op', 'cublas-extension', 'cublas_v1_runable', 'thrust_minmax_element',
'thrust_is_sorted', 'thrust_partition', 'thrust_remove_copy', 'thrust_unique_copy', 'thrust_transform_exclusive_scan',
'thrust_set_difference', 'thrust_set_difference_by_key', 'thrust_set_intersection_by_key', 'thrust_stable_sort',
'thrust_tabulate', 'thrust_for_each_n', 'device_info', 'defaultStream', 'cudnn-rnn', 'feature_profiling']
'thrust_tabulate', 'thrust_for_each_n', 'device_info', 'defaultStream', 'cudnn-rnn', 'feature_profiling',
'thrust_raw_reference_cast']


def setup_test():
return True
Expand Down

0 comments on commit 83ca163

Please sign in to comment.