Skip to content

Commit a740e78

Browse files
[SYCLomatic] Adding dpct::null_type test (#219)
Signed-off-by: Dan Hoeflinger <[email protected]>
1 parent 9cafe29 commit a740e78

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

help_function/help_function.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<test testName="onedpl_test_sort_by_key" configFile="config/TEMPLATE_help_function.xml" />
114114
<test testName="onedpl_test_sort_keys" configFile="config/TEMPLATE_help_function_skip_double.xml" />
115115
<test testName="onedpl_test_sort_pairs" configFile="config/TEMPLATE_help_function_skip_double.xml" />
116+
<test testName="onedpl_test_null_type" configFile="config/TEMPLATE_help_function.xml" />
116117
<test testName="onedpl_test_stable_partition_copy" configFile="config/TEMPLATE_help_function.xml" />
117118
<test testName="onedpl_test_stable_partition" configFile="config/TEMPLATE_help_function.xml" />
118119
<test testName="onedpl_test_tabulate" configFile="config/TEMPLATE_help_function.xml" />
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// ====------ onedpl_test_null_type.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+
} else {
25+
std::cout << "PASS: " << msg << std::endl;
26+
return 0;
27+
}
28+
}
29+
30+
template <typename KeyT> int reorder_key(KeyT &a, KeyT &b) {
31+
if (b < a) {
32+
::std::swap(a, b);
33+
}
34+
// returns 1 if reorder key is used
35+
return 1;
36+
}
37+
38+
// shows example usage of dpct::null_type, this has actual ValueT arguments
39+
template <typename KeyT, typename ValueT>
40+
typename ::std::enable_if<!::std::is_same<ValueT, dpct::null_type>::value,
41+
int>::type
42+
reorder_pair(KeyT &a_key, KeyT &b_key, ValueT &a_val, ValueT &b_val) {
43+
if (b_key < a_key) {
44+
::std::swap(a_key, b_key);
45+
::std::swap(a_val, b_val);
46+
}
47+
// returns 2 if reorder_pair is used
48+
return 2;
49+
}
50+
51+
// shows example usage of dpct::null_typeas an indicator to convert to key only
52+
template <typename KeyT, typename ValueT>
53+
typename ::std::enable_if<::std::is_same<ValueT, dpct::null_type>::value,
54+
int>::type
55+
reorder_pair(KeyT &a_key, KeyT &b_key, ValueT, ValueT) {
56+
return reorder_key(a_key, b_key);
57+
}
58+
59+
int main() {
60+
// used to detect failures
61+
int failed_tests = 0;
62+
int num_failing = 0;
63+
std::string test_name = "";
64+
65+
{
66+
// test normal usage
67+
int a = 5;
68+
int b = 3;
69+
int64_t a_val = -5;
70+
int64_t b_val = -3;
71+
int ret = reorder_pair(a, b, a_val, b_val);
72+
bool result = (ret == 2) && a == 3 && b == 5 && a_val == -3 && b_val == -5;
73+
test_name = "Testing normal usage of helpers 1/2";
74+
failed_tests += ASSERT_EQUAL(test_name, result, true);
75+
76+
a = 5;
77+
b = 3;
78+
a_val = -5;
79+
b_val = -3;
80+
ret = reorder_key(a, b);
81+
result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3;
82+
test_name = "Testing normal usage of helpers 2/2";
83+
failed_tests += ASSERT_EQUAL(test_name, result, true);
84+
85+
// test null_type redirect
86+
a = 5;
87+
b = 3;
88+
a_val = -5;
89+
b_val = -3;
90+
ret = reorder_pair(a, b, dpct::null_type{}, dpct::null_type{});
91+
result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3;
92+
test_name = "Testing null_type redirect";
93+
failed_tests += ASSERT_EQUAL(test_name, result, true);
94+
}
95+
96+
std::cout << std::endl
97+
<< failed_tests << " failing test(s) detected." << std::endl;
98+
if (failed_tests == 0) {
99+
return 0;
100+
}
101+
return 1;
102+
}

0 commit comments

Comments
 (0)