From d6c296ac2c967f41e25b67e2fd424cdecb9ca4ab Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Tue, 7 Feb 2023 09:52:23 -0500 Subject: [PATCH 1/3] Adding dpct::null_type test Signed-off-by: Dan Hoeflinger --- help_function/help_function.xml | 1 + help_function/src/onedpl_test_null_type.cpp | 109 ++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 help_function/src/onedpl_test_null_type.cpp diff --git a/help_function/help_function.xml b/help_function/help_function.xml index a7fec1470..a1293df65 100644 --- a/help_function/help_function.xml +++ b/help_function/help_function.xml @@ -113,6 +113,7 @@ + diff --git a/help_function/src/onedpl_test_null_type.cpp b/help_function/src/onedpl_test_null_type.cpp new file mode 100644 index 000000000..793497861 --- /dev/null +++ b/help_function/src/onedpl_test_null_type.cpp @@ -0,0 +1,109 @@ +// ====------ onedpl_test_reduce.cpp---------- -*- C++ -* ----===//// +// +// 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 "oneapi/dpl/execution" + +#include "dpct/dpct.hpp" +#include "dpct/dpl_utils.hpp" + +#include + +#include + +template +int ASSERT_EQUAL(String msg, _T1&& X, _T2&& Y) { + if(X!=Y) { + std::cout << "FAIL: " << msg << " - (" << X << "," << Y << ")" << std::endl; + return 1; + } + else { + std::cout << "PASS: " << msg << std::endl; + return 0; + } +} + +template +int reorder_key(KeyT& a, KeyT& b) +{ + if (b < a) + { + ::std::swap(a, b); + } + // returns 1 if reorder key is used + return 1; +} + +//shows example usage of dpct::null_type, this has actual ValueT arguments +template +typename ::std::enable_if::value, int>::type +reorder_pair(KeyT& a_key, KeyT& b_key, ValueT& a_val, ValueT& b_val) +{ + if (b_key < a_key) + { + ::std::swap(a_key,b_key); + ::std::swap(a_val,b_val); + } + //returns 2 if reorder_pair is used + return 2; +} + +//shows example usage of dpct::null_typeas an indicator to convert to key only +template +typename ::std::enable_if<::std::is_same::value, int>::type +reorder_pair(KeyT& a_key, KeyT& b_key, ValueT, ValueT) +{ + return reorder_key(a_key, b_key); +} + +int main() { + + // used to detect failures + int failed_tests = 0; + int num_failing = 0; + std::string test_name = ""; + + { + // test normal usage + int a = 5; + int b = 3; + int64_t a_val = -5; + int64_t b_val = -3; + int ret = reorder_pair(a, b, a_val, b_val); + bool result = (ret == 2) && a == 3 && b == 5 && a_val == -3 && b_val == -5; + test_name = "Testing normal usage of helpers 1/2"; + failed_tests += ASSERT_EQUAL(test_name, result, true); + + a = 5; + b = 3; + a_val = -5; + b_val = -3; + ret = reorder_key(a, b); + result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3; + test_name = "Testing normal usage of helpers 2/2"; + failed_tests += ASSERT_EQUAL(test_name, result, true); + + // test null_type redirect + a = 5; + b = 3; + a_val = -5; + b_val = -3; + ret = reorder_pair(a, b, dpct::null_type{}, dpct::null_type{}); + result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3; + test_name = "Testing null_type redirect"; + failed_tests += ASSERT_EQUAL(test_name, result, true); + + } + + + std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl; + if (failed_tests == 0) { + return 0; + } + return 1; +} From a6aa112818b6aa748102a41d6321cd6b4abc83bf Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Tue, 7 Feb 2023 10:07:13 -0500 Subject: [PATCH 2/3] formatting Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_null_type.cpp | 61 +++++++++------------ 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/help_function/src/onedpl_test_null_type.cpp b/help_function/src/onedpl_test_null_type.cpp index 793497861..2e80bc5c3 100644 --- a/help_function/src/onedpl_test_null_type.cpp +++ b/help_function/src/onedpl_test_null_type.cpp @@ -16,53 +16,47 @@ #include -template -int ASSERT_EQUAL(String msg, _T1&& X, _T2&& Y) { - if(X!=Y) { +template +int ASSERT_EQUAL(String msg, _T1 &&X, _T2 &&Y) { + if (X != Y) { std::cout << "FAIL: " << msg << " - (" << X << "," << Y << ")" << std::endl; return 1; - } - else { + } else { std::cout << "PASS: " << msg << std::endl; return 0; } } -template -int reorder_key(KeyT& a, KeyT& b) -{ - if (b < a) - { - ::std::swap(a, b); - } - // returns 1 if reorder key is used - return 1; +template int reorder_key(KeyT &a, KeyT &b) { + if (b < a) { + ::std::swap(a, b); + } + // returns 1 if reorder key is used + return 1; } -//shows example usage of dpct::null_type, this has actual ValueT arguments +// shows example usage of dpct::null_type, this has actual ValueT arguments template -typename ::std::enable_if::value, int>::type -reorder_pair(KeyT& a_key, KeyT& b_key, ValueT& a_val, ValueT& b_val) -{ - if (b_key < a_key) - { - ::std::swap(a_key,b_key); - ::std::swap(a_val,b_val); - } - //returns 2 if reorder_pair is used - return 2; +typename ::std::enable_if::value, + int>::type +reorder_pair(KeyT &a_key, KeyT &b_key, ValueT &a_val, ValueT &b_val) { + if (b_key < a_key) { + ::std::swap(a_key, b_key); + ::std::swap(a_val, b_val); + } + // returns 2 if reorder_pair is used + return 2; } -//shows example usage of dpct::null_typeas an indicator to convert to key only +// shows example usage of dpct::null_typeas an indicator to convert to key only template -typename ::std::enable_if<::std::is_same::value, int>::type -reorder_pair(KeyT& a_key, KeyT& b_key, ValueT, ValueT) -{ - return reorder_key(a_key, b_key); +typename ::std::enable_if<::std::is_same::value, + int>::type +reorder_pair(KeyT &a_key, KeyT &b_key, ValueT, ValueT) { + return reorder_key(a_key, b_key); } int main() { - // used to detect failures int failed_tests = 0; int num_failing = 0; @@ -97,11 +91,10 @@ int main() { result = (ret == 1) && a == 3 && b == 5 && a_val == -5 && b_val == -3; test_name = "Testing null_type redirect"; failed_tests += ASSERT_EQUAL(test_name, result, true); - } - - std::cout << std::endl << failed_tests << " failing test(s) detected." << std::endl; + std::cout << std::endl + << failed_tests << " failing test(s) detected." << std::endl; if (failed_tests == 0) { return 0; } From 92118a499863706996166a3086b16eb54d500971 Mon Sep 17 00:00:00 2001 From: Dan Hoeflinger Date: Wed, 15 Feb 2023 09:12:47 -0500 Subject: [PATCH 3/3] fixing file name Signed-off-by: Dan Hoeflinger --- help_function/src/onedpl_test_null_type.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/help_function/src/onedpl_test_null_type.cpp b/help_function/src/onedpl_test_null_type.cpp index 2e80bc5c3..2957b6733 100644 --- a/help_function/src/onedpl_test_null_type.cpp +++ b/help_function/src/onedpl_test_null_type.cpp @@ -1,4 +1,4 @@ -// ====------ onedpl_test_reduce.cpp---------- -*- C++ -* ----===//// +// ====------ onedpl_test_null_type.cpp---------- -*- C++ -* ----===//// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information.