Skip to content

Commit 27497b3

Browse files
committed
Add oneDPL external and its tests
1 parent 28fa291 commit 27497b3

File tree

5 files changed

+164
-0
lines changed

5 files changed

+164
-0
lines changed

CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ if( TRACCC_SETUP_TBB )
138138
endif()
139139
endif()
140140

141+
# Set up oneDPL.
142+
option( TRACCC_SETUP_DPL
143+
"Set up the DPL target(s) explicitly" TRUE )
144+
option( TRACCC_USE_SYSTEM_DPL
145+
"Pick up an existing installation of DPL from the build environment"
146+
${TRACCC_USE_SYSTEM_LIBS} )
147+
if( TRACCC_SETUP_DPL )
148+
if( TRACCC_USE_SYSTEM_DPL )
149+
find_package( DPL REQUIRED )
150+
else()
151+
add_subdirectory( extern/dpl )
152+
endif()
153+
endif()
154+
141155
# Set up Kokkos.
142156
option( TRACCC_SETUP_KOKKOS
143157
"Set up the Kokkos library" ${TRACCC_BUILD_KOKKOS} )

extern/dpl/CMakeLists.txt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# TRACCC library, part of the ACTS project (R&D line)
2+
#
3+
# (c) 2023 CERN for the benefit of the ACTS project
4+
#
5+
# Mozilla Public License Version 2.0
6+
7+
# CMake include(s).
8+
cmake_minimum_required( VERSION 3.14 )
9+
include( FetchContent )
10+
11+
# Silence FetchContent warnings with CMake >=3.24.
12+
if( POLICY CMP0135 )
13+
cmake_policy( SET CMP0135 NEW )
14+
endif()
15+
16+
# Tell the user what's happening.
17+
message( STATUS "Building oneDPL as part of the TRACCC project" )
18+
19+
# Declare where to get DPL from.
20+
set( TRACCC_DPL_SOURCE
21+
"URL;https://github.com/oneapi-src/oneDPL/archive/refs/tags/oneDPL-2022.0.0-release.tar.gz;URL_MD5;46b60bd87325042df716d1df4686eb3b"
22+
CACHE STRING "Source for DPL, when built as part of this project" )
23+
mark_as_advanced( TRACCC_DPL_SOURCE )
24+
FetchContent_Declare( DPL ${TRACCC_DPL_SOURCE} )
25+
26+
set( ONEDPL_BACKEND dpcpp_only )
27+
28+
# Get it into the current directory.
29+
FetchContent_MakeAvailable( DPL )

extern/dpl/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Build Recipe for oneDPL
2+
3+
This directory holds a build recipe for building
4+
[DPL](https://github.com/oneapi-src/oneDPL) for this project.

tests/sycl/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ traccc_add_test(
1212
sycl
1313

1414
# Define the sources for the test.
15+
test_dpl.sycl
1516
test_kalman_filter.sycl
1617

1718
LINK_LIBRARIES
@@ -25,4 +26,5 @@ traccc_add_test(
2526
traccc::performance
2627
traccc::io
2728
traccc_tests_common
29+
oneDPL
2830
)

tests/sycl/test_dpl.sycl

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/** TRACCC library, part of the ACTS project (R&D line)
2+
*
3+
* (c) 2023 CERN for the benefit of the ACTS project
4+
*
5+
* Mozilla Public License Version 2.0
6+
*/
7+
8+
// SYCL include(s).
9+
#include <CL/sycl.hpp>
10+
11+
// VecMem include(s).
12+
#include <vecmem/containers/data/vector_buffer.hpp>
13+
#include <vecmem/containers/device_vector.hpp>
14+
#include <vecmem/memory/host_memory_resource.hpp>
15+
#include <vecmem/memory/sycl/device_memory_resource.hpp>
16+
#include <vecmem/utils/sycl/copy.hpp>
17+
18+
// DPL include(s).
19+
#include <oneapi/dpl/algorithm>
20+
#include <oneapi/dpl/execution>
21+
#include <oneapi/dpl/ranges>
22+
23+
// GTest include(s).
24+
#include <gtest/gtest.h>
25+
26+
namespace {
27+
28+
// Simple asynchronous handler function
29+
auto handle_async_error = [](::sycl::exception_list elist) {
30+
for (auto& e : elist) {
31+
try {
32+
std::rethrow_exception(e);
33+
} catch (::sycl::exception& e) {
34+
std::cout << "ASYNC EXCEPTION!!\n";
35+
std::cout << e.what() << "\n";
36+
}
37+
}
38+
};
39+
40+
::sycl::queue q(handle_async_error);
41+
vecmem::sycl::copy copy{&q};
42+
vecmem::host_memory_resource host_resource;
43+
vecmem::sycl::device_memory_resource device_resource;
44+
45+
} // namespace
46+
47+
TEST(dpl, sort) {
48+
49+
vecmem::vector<unsigned int> host_vector{{3, 2, 1, 8, 4}, &host_resource};
50+
51+
auto host_buffer = vecmem::get_data(host_vector);
52+
auto device_buffer = copy.to(vecmem::get_data(host_vector), device_resource,
53+
vecmem::copy::type::host_to_device);
54+
55+
vecmem::device_vector<unsigned int> device_vector(device_buffer);
56+
57+
oneapi::dpl::sort(oneapi::dpl::execution::dpcpp_default,
58+
device_vector.begin(), device_vector.end());
59+
60+
copy(device_buffer, host_buffer, vecmem::copy::type::device_to_host);
61+
62+
ASSERT_EQ(host_vector[0], 1);
63+
ASSERT_EQ(host_vector[1], 2);
64+
ASSERT_EQ(host_vector[2], 3);
65+
ASSERT_EQ(host_vector[3], 4);
66+
ASSERT_EQ(host_vector[4], 8);
67+
}
68+
69+
TEST(dpl, scan) {
70+
71+
vecmem::vector<unsigned int> host_vector{{3, 2, 1, 8, 4}, &host_resource};
72+
73+
auto host_buffer = vecmem::get_data(host_vector);
74+
auto device_buffer = copy.to(vecmem::get_data(host_vector), device_resource,
75+
vecmem::copy::type::host_to_device);
76+
77+
vecmem::device_vector<unsigned int> device_vector(device_buffer);
78+
79+
oneapi::dpl::inclusive_scan(oneapi::dpl::execution::dpcpp_default,
80+
device_vector.begin(), device_vector.end(),
81+
device_vector.begin());
82+
83+
copy(device_buffer, host_buffer, vecmem::copy::type::device_to_host);
84+
85+
ASSERT_EQ(host_vector[0], 3);
86+
ASSERT_EQ(host_vector[1], 5);
87+
ASSERT_EQ(host_vector[2], 6);
88+
ASSERT_EQ(host_vector[3], 14);
89+
ASSERT_EQ(host_vector[4], 18);
90+
}
91+
92+
TEST(dpl, fill) {
93+
94+
vecmem::vector<unsigned int> host_vector{{1, 1, 1, 1, 1, 1, 1},
95+
&host_resource};
96+
97+
auto host_buffer = vecmem::get_data(host_vector);
98+
auto device_buffer = copy.to(vecmem::get_data(host_vector), device_resource,
99+
vecmem::copy::type::host_to_device);
100+
101+
vecmem::device_vector<unsigned int> device_vector(device_buffer);
102+
103+
oneapi::dpl::fill(oneapi::dpl::execution::dpcpp_default,
104+
device_vector.begin(), device_vector.end(), 112);
105+
106+
copy(device_buffer, host_buffer, vecmem::copy::type::device_to_host);
107+
108+
ASSERT_EQ(host_vector[0], 112);
109+
ASSERT_EQ(host_vector[1], 112);
110+
ASSERT_EQ(host_vector[2], 112);
111+
ASSERT_EQ(host_vector[3], 112);
112+
ASSERT_EQ(host_vector[4], 112);
113+
ASSERT_EQ(host_vector[5], 112);
114+
ASSERT_EQ(host_vector[6], 112);
115+
}

0 commit comments

Comments
 (0)