Skip to content

Commit

Permalink
[onedpl][ranges][test] Added std ranges to oneDPL Tested API (#1571)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeDvorskiy authored Dec 17, 2024
1 parent caa1c27 commit eb2471a
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ macro(onedpl_add_test test_source_file switch_off_checked_iterators)
endif()
endmacro()

set(_regexp_dpcpp_backend_required "(xpu_api/algorithms|test/xpu_api/cmath/nearbyint|test/xpu_api/containers|xpu_api/functional|test/xpu_api/iterators|test/xpu_api/language.support/support.initlist|test/xpu_api/language.support/support.types|xpu_api/numerics|test/xpu_api/random|test/xpu_api/ratio|test/xpu_api/tuple|test/xpu_api/utilities|parallel_api/dynamic_selection/sycl)")
set(_regexp_dpcpp_backend_required "(xpu_api/ranges|xpu_api/algorithms|test/xpu_api/cmath/nearbyint|test/xpu_api/containers|xpu_api/functional|test/xpu_api/iterators|test/xpu_api/language.support/support.initlist|test/xpu_api/language.support/support.types|xpu_api/numerics|test/xpu_api/random|test/xpu_api/ratio|test/xpu_api/tuple|test/xpu_api/utilities|parallel_api/dynamic_selection/sycl)")
set(_regexp_switch_off_checked_it "(test/general/header_order_ranges|test/parallel_api/algorithm/alg.sorting/alg.min.max|test/parallel_api/ranges|test/parallel_api/dynamic_selection|test/xpu_api/iterators/iterator.primitives|test/xpu_api/random/device_tests|test/xpu_api/random/interface_tests|test/xpu_api/random/statistics_tests|test/parallel_api/numeric/numeric.ops/transform_scan)")

set(_regexp_pstl_offload_only "(test/pstl_offload)")
Expand Down
39 changes: 39 additions & 0 deletions test/xpu_api/ranges/xpu_std_all_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto res = std::ranges::views::iota(0, 4) | std::ranges::views::all;
return res.size() == 4 && res[0] == 0 && res[1] == 1 && res[2] == 2 && res[3] == 3 &&
*(res.begin() + 2) == res[2] && res.end() - res.begin() == 4;
};
const bool res = kernel_test<class std_all_test>(test);
EXPECT_TRUE(res, "Wrong result of all_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
39 changes: 39 additions & 0 deletions test/xpu_api/ranges/xpu_std_drop_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto res = std::ranges::views::iota(0, 4) | std::ranges::views::drop(2);
return res.size() == 2 && res[0] == 2 && res[1] == 3 && *res.begin() == 2
&& res.end() - res.begin() == 2;
};
const bool res = kernel_test<class std_drop_test>(test);
EXPECT_TRUE(res, "Wrong result of drop_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
40 changes: 40 additions & 0 deletions test/xpu_api/ranges/xpu_std_iota_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto res = std::ranges::views::iota(0, 4);
return res.size() == 4 && res[0] == 0 && res[1] == 1 && res[2] == 2 && res[3] == 3 &&
*(res.begin() + 2) == 2 && (res.end() - res.begin()) == 4 && !res.empty() &&
res.front() == 0 && res.back() == 3;
};
const bool res = kernel_test<class std_iota_test>(test);
EXPECT_TRUE(res, "Wrong result of iota_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
34 changes: 34 additions & 0 deletions test/xpu_api/ranges/xpu_std_ranges_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/utils_sycl.h"

template<typename KernelName, typename Test>
bool
kernel_test(Test test)
{
sycl::queue deviceQueue = TestUtils::get_test_queue();
bool ret = false;
sycl::range<1> numOfItems{1};
sycl::buffer<bool, 1> buffer1(&ret, numOfItems);
deviceQueue.submit([&](sycl::handler& cgh) {
auto ret_access = buffer1.get_access<sycl::access::mode::write>(cgh);
cgh.single_task<KernelName>([=]() {
ret_access[0] = test(); //run test
});
});

return buffer1.get_host_access(sycl::read_only)[0];
}
39 changes: 39 additions & 0 deletions test/xpu_api/ranges/xpu_std_reverse_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto res = std::ranges::views::iota(0, 4) | std::ranges::views::reverse;
return res.size() == 4 && res[0] == 3 && res[1] == 2 && res[2] == 1 && res[3] == 0 &&
*(res.begin() + 2) == 1 && res.end() - res.begin() == 4;
};
const bool res = kernel_test<class std_reverse_test>(test);
EXPECT_TRUE(res, "Wrong result of reverse_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
38 changes: 38 additions & 0 deletions test/xpu_api/ranges/xpu_std_single_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto res = std::ranges::views::single(1);
return res.size() == 1 && res[0] == 1 && *res.begin() == 1 && res.end() - res.begin() == 1 && *res.data() == 1;
};
const bool res = kernel_test<class std_single_test>(test);
EXPECT_TRUE(res, "Wrong result of single_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
41 changes: 41 additions & 0 deletions test/xpu_api/ranges/xpu_std_subrange.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto v = std::ranges::views::iota(0, 4);
auto res = std::ranges::subrange(v.begin() + 1, v.end());

return res.size() == 3 && res[0] == 1 && res[1] == 2 && res[2] == 3 && (*res.begin() + 2) == 3 &&
res.end() - res.begin() == 3 && *std::ranges::next(res.begin()) == 2 && *std::ranges::prev(res.end()) == 3;
};
const bool res = kernel_test<class std_reverse_test>(test);
EXPECT_TRUE(res, "Wrong result of subrange check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
39 changes: 39 additions & 0 deletions test/xpu_api/ranges/xpu_std_take_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
auto res = std::ranges::views::iota(0, 4) | std::ranges::views::take(2);
return res.size() == 2 && res[0] == 0 && res[1] == 1 && *(res.begin() + 1) == 1 &&
(res.end() - res.begin()) == 2;
};
const bool res = kernel_test<class std_take_test>(test);
EXPECT_TRUE(res, "Wrong result of take_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}
40 changes: 40 additions & 0 deletions test/xpu_api/ranges/xpu_std_transform_view.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file incorporates work covered by the following copyright and permission
// notice:
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
//
//===----------------------------------------------------------------------===//

#include "support/test_config.h"
#include "support/test_macros.h"
#include "support/utils.h"

#if _ENABLE_STD_RANGES_TESTING
#include <ranges>
#include "xpu_std_ranges_test.h"
#endif //_ENABLE_STD_RANGES_TESTING

int
main()
{
#if _ENABLE_STD_RANGES_TESTING
auto test = [](){
int a[4] = {0, 0, 0, 0};
auto res = std::ranges::subrange(a, a+4) | std::ranges::views::transform([](auto v) { return v + 1;});
return res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 1 && *(res.begin() + 2) == 1 &&
res.end() - res.begin() == 4;
};
const bool res = kernel_test<class std_transform_test>(test);
EXPECT_TRUE(res, "Wrong result of transform_view check within a kernel");
#endif //_ENABLE_STD_RANGES_TESTING

return TestUtils::done(_ENABLE_STD_RANGES_TESTING);
}

0 comments on commit eb2471a

Please sign in to comment.