Skip to content

Commit e01106e

Browse files
committed
Add oneDPL external and add its tests
1 parent 28fa291 commit e01106e

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

CMakeLists.txt

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

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

extern/dpl/CMakeLists.txt

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
# Exclude TBB
27+
set( ONEDPL_BACKEND dpcpp_only )
28+
29+
# Get it into the current directory.
30+
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

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

0 commit comments

Comments
 (0)