Skip to content

Commit 9d480b6

Browse files
committed
Adding dpct::null_type test
Signed-off-by: Dan Hoeflinger <[email protected]>
1 parent 17fe7c3 commit 9d480b6

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

help_function/help_function.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
<test testName="onedpl_test_set_symmetric_difference_by_key" configFile="config/TEMPLATE_help_function.xml" />
109109
<test testName="onedpl_test_set_union_by_key" configFile="config/TEMPLATE_help_function.xml" />
110110
<test testName="onedpl_test_sort_by_key" configFile="config/TEMPLATE_help_function.xml" />
111+
<test testName="onedpl_test_null_type" configFile="config/TEMPLATE_help_function.xml" />
111112
<test testName="onedpl_test_stable_partition_copy" configFile="config/TEMPLATE_help_function.xml" />
112113
<test testName="onedpl_test_stable_partition" configFile="config/TEMPLATE_help_function.xml" />
113114
<test testName="onedpl_test_tabulate" configFile="config/TEMPLATE_help_function.xml" />
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// ====------ onedpl_test_reduce.cpp---------- -*- C++ -* ----===////
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 "oneapi/dpl/execution"
11+
12+
#include "dpct/dpct.hpp"
13+
#include "dpct/dpl_utils.hpp"
14+
15+
#include <sycl/sycl.hpp>
16+
17+
#include <iostream>
18+
19+
template<typename String, typename _T1, typename _T2>
20+
int ASSERT_EQUAL(String msg, _T1&& X, _T2&& Y) {
21+
if(X!=Y) {
22+
std::cout << "FAIL: " << msg << " - (" << X << "," << Y << ")" << std::endl;
23+
return 1;
24+
}
25+
else {
26+
std::cout << "PASS: " << msg << std::endl;
27+
return 0;
28+
}
29+
}
30+
31+
template <typename KeyT>
32+
int reorder_key(KeyT& a, KeyT& b)
33+
{
34+
if (b < a)
35+
{
36+
::std::swap(a, b);
37+
}
38+
// returns 1 if reorder key is used
39+
return 1;
40+
}
41+
42+
//shows example usage of dpct::null_type, this has actual ValueT arguments
43+
template <typename KeyT, typename ValueT>
44+
typename ::std::enable_if<!::std::is_same<ValueT,dpct::null_type>::value, int>::type
45+
reorder_pair(KeyT& a_key, KeyT& b_key, ValueT& a_val, ValueT& b_val)
46+
{
47+
if (b_key < a_key)
48+
{
49+
::std::swap(a_key,b_key);
50+
::std::swap(a_val,b_val);
51+
}
52+
//returns 2 if reorder_pair is used
53+
return 2;
54+
}
55+
56+
//shows example usage of dpct::null_typeas an indicator to convert to key only
57+
template <typename KeyT, typename ValueT>
58+
typename ::std::enable_if<::std::is_same<ValueT,dpct::null_type>::value, int>::type
59+
reorder_pair(KeyT& a_key, KeyT& b_key, ValueT, ValueT)
60+
{
61+
return reorder_key(a_key, b_key);
62+
}
63+
64+
int main() {
65+
66+
// used to detect failures
67+
int failed_tests = 0;
68+
int num_failing = 0;
69+
std::string test_name = "";
70+
71+
{
72+
// test normal usage
73+
int a = 5;
74+
int b = 3;
75+
int64_t a_val = -5;
76+
int64_t b_val = -3;
77+
int ret = reorder_pair(a, b, a_val, b_val);
78+
bool result = (ret == 2) && a == 3 && b == 5 && a_val == -3 && b_val == -5;
79+
test_name = "Testing normal usage of helpers 1/2";
80+
failed_tests += ASSERT_EQUAL(test_name, result, true);
81+
82+
a = 5;
83+
b = 3;
84+
a_val = -5;
85+
b_val = -3;
86+
ret = reorder_key(a, b);
87+
result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3;
88+
test_name = "Testing normal usage of helpers 2/2";
89+
failed_tests += ASSERT_EQUAL(test_name, result, true);
90+
91+
// test null_type redirect
92+
a = 5;
93+
b = 3;
94+
a_val = -5;
95+
b_val = -3;
96+
ret = reorder_pair(a, b, dpct::null_type{}, dpct::null_type{});
97+
result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3;
98+
test_name = "Testing null_type redirect";
99+
failed_tests += ASSERT_EQUAL(test_name, result, true);
100+
101+
}
102+
103+
104+
std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl;
105+
if (failed_tests == 0) {
106+
return 0;
107+
}
108+
return 1;
109+
}

0 commit comments

Comments
 (0)