Skip to content

Commit f49feb4

Browse files
Sort test: split and make it more flexible to reduce execution time (#2077)
1 parent ce7852e commit f49feb4

File tree

7 files changed

+716
-515
lines changed

7 files changed

+716
-515
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Copyright (C) Intel Corporation
5+
//
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
// This file incorporates work covered by the following copyright and permission
9+
// notice:
10+
//
11+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
// See https://llvm.org/LICENSE.txt for license information.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include "support/utils_sort.h" // Umbrella for all needed headers
17+
18+
int main()
19+
{
20+
SortTestConfig cfg;
21+
cfg.is_stable = false;
22+
cfg.test_usm_device = true;
23+
const std::vector<std::size_t> sizes = test_sizes(TestUtils::max_n);
24+
const std::vector<std::size_t> small_sizes = test_sizes(10'000);
25+
26+
#if !TEST_ONLY_HETERO_POLICIES
27+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, host"}, sizes, Host{},
28+
Converter<TestUtils::float32_t>{});
29+
test_sort<unsigned char>(SortTestConfig{cfg, "unsigned char, host"}, sizes, Host{},
30+
Converter<unsigned char>{});
31+
#endif
32+
33+
#if TEST_DPCPP_BACKEND_PRESENT
34+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, device"}, sizes, Device<0>{},
35+
Converter<TestUtils::float32_t>{});
36+
37+
auto sycl_half_convert = [](size_t k, size_t val) {
38+
constexpr std::uint16_t mask = 0xFFFFu;
39+
std::uint16_t raw = std::uint16_t(val & mask);
40+
// Avoid NaN values, because they need a custom comparator due to: (x < NaN = false) and (NaN < x = false).
41+
constexpr std::uint16_t exp_mask = 0x7C00u;
42+
constexpr std::uint16_t frac_mask = 0x03FFu;
43+
bool is_nan = ((raw & exp_mask) == exp_mask) && ((raw & frac_mask) > 0);
44+
if (is_nan)
45+
{
46+
constexpr std::uint16_t smallest_exp_bit = 0x0400u;
47+
raw = raw & (~smallest_exp_bit); // flip the smallest exponent bit
48+
}
49+
return sycl::bit_cast<sycl::half>(raw);
50+
};
51+
52+
// Test radix-sort bit conversions
53+
test_sort<std::uint8_t>(SortTestConfig{cfg, "uint8_t, device"}, small_sizes, Device<1>{},
54+
Converter<std::uint8_t>{});
55+
test_sort<std::int16_t>(SortTestConfig{cfg, "int16_t, device"}, small_sizes, Device<2>{},
56+
Converter<std::int16_t>{});
57+
test_sort<std::uint32_t>(SortTestConfig{cfg, "uint32_t, device"}, small_sizes, Device<3>{},
58+
Converter<std::uint32_t>{});
59+
test_sort<std::int64_t>(SortTestConfig{cfg, "int64_t, device"}, small_sizes, Device<4>{},
60+
Converter<std::int64_t>{});
61+
test_sort<TestUtils::float64_t>(SortTestConfig{cfg, "float64_t, device"}, small_sizes, Device<5>{},
62+
Converter<TestUtils::float64_t>{});
63+
test_sort<sycl::half>(SortTestConfig{cfg, "sycl::half, device"}, small_sizes, Device<6>{}, sycl_half_convert);
64+
// TODO: add a test for a MoveConstructible only type
65+
#endif
66+
67+
return TestUtils::done();
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Copyright (C) Intel Corporation
5+
//
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
// This file incorporates work covered by the following copyright and permission
9+
// notice:
10+
//
11+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
// See https://llvm.org/LICENSE.txt for license information.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include "support/utils_sort.h" // Umbrella for all needed headers
17+
18+
template <typename T>
19+
struct test_non_const
20+
{
21+
template <typename Policy, typename Iterator>
22+
void
23+
operator()(Policy&& exec, Iterator iter)
24+
{
25+
oneapi::dpl::sort(std::forward<Policy>(exec), iter, iter, TestUtils::non_const(std::less<T>()));
26+
}
27+
};
28+
29+
int main()
30+
{
31+
SortTestConfig cfg;
32+
cfg.is_stable = false;
33+
cfg.test_usm_shared = true;
34+
std::vector<std::size_t> sizes = test_sizes(TestUtils::max_n);
35+
36+
#if !TEST_ONLY_HETERO_POLICIES
37+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, host, custom greater"}, sizes, Host{},
38+
Converter<TestUtils::float32_t>{}, ConstGreater{});
39+
test_sort<std::uint16_t>(SortTestConfig{cfg, "uint16_t, host, non-const custom less"}, sizes, Host{},
40+
Converter<std::uint16_t>{}, NonConstLess{});
41+
42+
test_sort<ParanoidKey>(SortTestConfig{cfg, "ParanoidKey, host"}, sizes, Host{},
43+
[](size_t k, size_t val) { return ParanoidKey(k, val, TestUtils::OddTag()); },
44+
KeyCompare(TestUtils::OddTag()));
45+
46+
TestUtils::test_algo_basic_single<std::int32_t>(TestUtils::run_for_rnd<test_non_const<std::int32_t>>());
47+
#endif
48+
49+
#if TEST_DPCPP_BACKEND_PRESENT
50+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, device, custom greater"}, sizes, Device<0>{},
51+
Converter<TestUtils::float32_t>{}, ConstGreater{});
52+
test_sort<std::uint16_t>(SortTestConfig{cfg, "uint16_t, device, non-const custom less"}, sizes, Device<1>{},
53+
Converter<std::uint16_t>{}, NonConstLess{});
54+
55+
// Check radix-sort with to have a higher chance to hit synchronization issues if any
56+
sizes.push_back(8'000'000);
57+
test_sort<std::int32_t>(SortTestConfig{cfg, "int32_t, device, std::less"}, sizes, Device<2>{},
58+
Converter<std::int32_t>{}, std::less{});
59+
#if __SYCL_UNNAMED_LAMBDA__
60+
// Test potentially clashing naming for radix sort descending / ascending with minimal timing impact
61+
test_default_name_gen(SortTestConfig{cfg, "default name generation"});
62+
#endif
63+
#endif // TEST_DPCPP_BACKEND_PRESENT
64+
65+
return TestUtils::done();
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Copyright (C) Intel Corporation
5+
//
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
// This file incorporates work covered by the following copyright and permission
9+
// notice:
10+
//
11+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
// See https://llvm.org/LICENSE.txt for license information.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include "support/utils_sort.h" // Umbrella for all needed headers
17+
18+
int main()
19+
{
20+
SortTestConfig cfg;
21+
cfg.is_stable = true;
22+
cfg.test_usm_shared = true;
23+
std::vector<std::size_t> sizes = test_sizes(TestUtils::max_n);
24+
25+
#if !TEST_ONLY_HETERO_POLICIES
26+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, host"}, sizes, Host{},
27+
Converter<TestUtils::float32_t>{});
28+
test_sort<std::int64_t>(SortTestConfig{cfg, "int64_t, host"}, sizes, Host{}, Converter<std::int64_t>{});
29+
// TODO: add a test for stability
30+
#endif
31+
32+
#if TEST_DPCPP_BACKEND_PRESENT
33+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, device"}, sizes, Device<0>{},
34+
Converter<TestUtils::float32_t>{});
35+
test_sort<std::int64_t>(SortTestConfig{cfg, "int64_t, device"}, sizes, Device<1>{}, Converter<std::int64_t>{});
36+
// TODO: add a test for stability
37+
#endif
38+
39+
return TestUtils::done();
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Copyright (C) Intel Corporation
5+
//
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
// This file incorporates work covered by the following copyright and permission
9+
// notice:
10+
//
11+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
// See https://llvm.org/LICENSE.txt for license information.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include "support/utils_sort.h" // Umbrella for all needed headers
17+
18+
template <typename T>
19+
struct test_non_const
20+
{
21+
template <typename Policy, typename Iterator>
22+
void
23+
operator()(Policy&& exec, Iterator iter)
24+
{
25+
oneapi::dpl::stable_sort(std::forward<Policy>(exec), iter, iter, TestUtils::non_const(std::less<T>()));
26+
}
27+
};
28+
29+
int main()
30+
{
31+
SortTestConfig cfg;
32+
cfg.is_stable = true;
33+
cfg.test_usm_device = true;
34+
std::vector<std::size_t> sizes = test_sizes(TestUtils::max_n);
35+
36+
#if !TEST_ONLY_HETERO_POLICIES
37+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, host, custom less comparator"}, sizes, Host{},
38+
Converter<TestUtils::float32_t>{}, ConstLess{});
39+
test_sort<std::int16_t>(SortTestConfig{cfg, "int16_t, host, non-const custom less comparator"}, sizes, Host{},
40+
Converter<std::int16_t>{}, NonConstLess{});
41+
test_sort<std::uint32_t>(SortTestConfig{cfg, "uint32_t, host, std::greater"}, sizes, Host{},
42+
Converter<std::uint32_t>{}, std::greater{});
43+
44+
auto paranoid_key_converter = [](size_t k, size_t val) { return ParanoidKey(k, val, TestUtils::OddTag()); };
45+
test_sort<ParanoidKey>(SortTestConfig{cfg, "ParanoidKey, host"}, sizes, Host{},
46+
paranoid_key_converter, KeyCompare(TestUtils::OddTag()));
47+
48+
TestUtils::test_algo_basic_single<int32_t>(TestUtils::run_for_rnd<test_non_const<int32_t>>());
49+
#endif
50+
51+
#if TEST_DPCPP_BACKEND_PRESENT
52+
test_sort<TestUtils::float32_t>(SortTestConfig{cfg, "float, device, custom less comparator"}, sizes, Device<0>{},
53+
Converter<TestUtils::float32_t>{}, ConstLess{});
54+
55+
// Test merge-path sort specialization for large sizes, see __get_starting_size_limit_for_large_submitter
56+
std::vector<std::size_t> extended_sizes = test_sizes(8'000'000);
57+
test_sort<std::uint16_t>(SortTestConfig{cfg, "uint16_t, device, custom greater comparator"}, extended_sizes,
58+
Device<1>{}, Converter<std::uint16_t>{}, ConstGreater{});
59+
#if __SYCL_UNNAMED_LAMBDA__
60+
// Test potentially clashing naming for radix sort descending / ascending with minimal timing impact
61+
test_default_name_gen(SortTestConfig{cfg, "default name generation"});
62+
#endif
63+
// TODO: add a test for stability
64+
#endif
65+
66+
return TestUtils::done();
67+
}

0 commit comments

Comments
 (0)