Skip to content

Commit c949d68

Browse files
authored
[SYCLomatic #507] Enable test for complex, array, tuple in libcu (#204)
Signed-off-by: Ni, Wenhui <[email protected]>
1 parent 43f6ec9 commit c949d68

File tree

5 files changed

+165
-1
lines changed

5 files changed

+165
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <cuda_runtime.h>
2+
#include <cuda/std/array>
3+
4+
template <class T>
5+
__host__ __device__ void
6+
test(T *res)
7+
{
8+
cuda::std::array<T, 3> arr = {1, 2, 3.5};
9+
*(res) = arr.at(0);
10+
*(res+1) = arr.at(1);
11+
*(res+2) = arr.at(2);
12+
*(res+3) = *(arr.begin());
13+
*(res+4) = arr.size();
14+
}
15+
16+
__global__ void test_global(float * res)
17+
{
18+
test<float>(res);
19+
}
20+
21+
int main(int, char **)
22+
{
23+
24+
float *floatRes = (float *)malloc(5 * sizeof(float));
25+
test<float>(floatRes);
26+
//test<double>(doubleRes);
27+
float *hostRes = (float *)malloc(5 * sizeof(float));
28+
float *deviceRes;
29+
cudaMalloc((float **)&deviceRes, 5 * sizeof(float));
30+
test_global<<<1, 1>>>(deviceRes);
31+
cudaMemcpy(hostRes, deviceRes, sizeof(float) * 5, cudaMemcpyDeviceToHost);
32+
cudaFree(deviceRes);
33+
34+
for (int i = 0;i<5;++i){
35+
if(hostRes[i]!=floatRes[i]){
36+
free(hostRes);
37+
free(floatRes);
38+
return 1;
39+
}
40+
}
41+
free(hostRes);
42+
free(floatRes);
43+
return 0;
44+
45+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===----------------------------------------------------------------------===//
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+
// <cuda/std/complex>
10+
11+
#include <cuda/std/complex>
12+
13+
template <class T>
14+
__host__ __device__ void
15+
test(T *res)
16+
{
17+
cuda::std::complex<T> x(1.5, 2.5);
18+
cuda::std::complex<T> y(2.5, 3);
19+
T *a = (T *)&x;
20+
a[0] = 5;
21+
a[1] = 6;
22+
*(res) = x.real() * x.imag();
23+
cuda::std::complex<T> z = x / y;
24+
*(res +1) =z.real();
25+
*(res + 2) = z.imag();
26+
z = x + y;
27+
*(res +3) =z.real();
28+
*(res + 4) = z.imag();
29+
z = x - y;
30+
*(res +5) =z.real();
31+
*(res + 6) = z.imag();
32+
z = x * y;
33+
*(res +7) =z.real();
34+
*(res + 8) = z.imag();
35+
}
36+
37+
__global__ void test_global(float * res)
38+
{
39+
test<float>(res);
40+
}
41+
42+
int main(int, char **)
43+
{
44+
45+
float *floatRes = (float *)malloc(9 * sizeof(float));
46+
test<float>(floatRes);
47+
//test<double>(doubleRes);
48+
float *hostRes = (float *)malloc(9 * sizeof(float));
49+
float *deviceRes;
50+
cudaMalloc((float **)&deviceRes, 9 * sizeof(float));
51+
test_global<<<1, 1>>>(deviceRes);
52+
cudaMemcpy(hostRes, deviceRes, sizeof(float) * 9, cudaMemcpyDeviceToHost);
53+
cudaFree(deviceRes);
54+
55+
for (int i = 0;i<9;++i){
56+
if(hostRes[i]!=floatRes[i]){
57+
free(hostRes);
58+
free(floatRes);
59+
return 1;
60+
}
61+
}
62+
free(hostRes);
63+
free(floatRes);
64+
return 0;
65+
66+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//===----------------------------------------------------------------------===//
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 <cuda/std/tuple>
11+
12+
template <class T>
13+
__host__ __device__ void
14+
test(T *res)
15+
{
16+
cuda::std::tuple<T, T, T> t = cuda::std::make_tuple(2.0f, 3.0f, 4.0f);
17+
*(res) = cuda::std::get<0>(t);
18+
*(res+1) = cuda::std::get<1>(t);
19+
*(res+2) = cuda::std::get<2>(t);
20+
}
21+
22+
__global__ void test_global(float * res)
23+
{
24+
test<float>(res);
25+
}
26+
27+
int main(int, char **)
28+
{
29+
30+
float *floatRes = (float *)malloc(3 * sizeof(float));
31+
test<float>(floatRes);
32+
float *hostRes = (float *)malloc(3 * sizeof(float));
33+
float *deviceRes;
34+
cudaMalloc((float **)&deviceRes, 3 * sizeof(float));
35+
test_global<<<1, 1>>>(deviceRes);
36+
cudaMemcpy(hostRes, deviceRes, sizeof(float) * 3, cudaMemcpyDeviceToHost);
37+
cudaFree(deviceRes);
38+
39+
for (int i = 0;i<3;++i){
40+
if(hostRes[i]!=floatRes[i]){
41+
free(hostRes);
42+
free(floatRes);
43+
return 1;
44+
}
45+
}
46+
free(hostRes);
47+
free(floatRes);
48+
return 0;
49+
50+
}

features/features.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@
397397
<test testName="ccl" configFile="config/TEMPLATE_ccl.xml" />
398398
<test testName="cufft_test" configFile="config/TEMPLATE_fft_runable.xml" splitGroup="double"/>
399399
<test testName="libcu_atomic" configFile="config/TEMPLATE_libcu.xml" />
400+
<test testName="libcu_array" configFile="config/TEMPLATE_libcu.xml" />
401+
<test testName="libcu_complex" configFile="config/TEMPLATE_libcu.xml" />
402+
<test testName="libcu_tuple" configFile="config/TEMPLATE_libcu.xml" />
400403
<test testName="pointer_attributes" configFile="config/TEMPLATE_pointer_attributes.xml" />
401404
<test testName="image" configFile="config/TEMPLATE_image.xml" />
402405
<test testName="defaultStream" configFile="config/TEMPLATE_defaultStream.xml" />

features/test_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'cub_device_scan_inclusive_sum', 'cub_device_scan_exclusive_sum', 'cub_device_select_unique', 'cub_device_radix_sort_keys', 'cub_device_radix_sort_pairs',
2929
'cub_device_select_flagged', 'cub_device_run_length_encide_encode', 'cub_counting_iterator', 'cub_arg_index_input_iterator',
3030
'cub_device_inclusive_sum_by_key', 'cub_device_exclusive_sum_by_key', 'cub_device_inclusive_scan_by_key', 'cub_device_exclusive_scan_by_key',
31-
'cub_transform_iterator', 'activemask', 'complex', 'thrust-math'
31+
'cub_transform_iterator', 'activemask', 'complex', 'thrust-math', 'libcu_array', 'libcu_complex', 'libcu_tuple',
3232
'user_defined_rules', 'math-exec', 'math-habs', 'math-ext-half', 'math-ext-half2', 'cudnn-activation',
3333
'cudnn-fill', 'cudnn-lrn', 'cudnn-memory', 'cudnn-pooling', 'cudnn-reorder', 'cudnn-scale', 'cudnn-softmax',
3434
'cudnn-sum', 'math-funnelshift', 'ccl', 'thrust-sort_by_key', 'thrust-find', 'thrust-inner_product', 'thrust-reduce_by_key',

0 commit comments

Comments
 (0)