Skip to content

Commit 47ee4c4

Browse files
committed
more feedback
1 parent 7a3cde1 commit 47ee4c4

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

sycl/tools/xpti_helpers/pi_arguments_handler.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ inline auto get(char *Data, const std::index_sequence<Is...> &) {
2525

2626
// Calculate sizeof all elements before target + target element then substract
2727
// sizeof target element
28-
size_t Res = (sizeof(typename std::tuple_element<Is, TupleT>::type) + ...) -
29-
sizeof(TargetType);
30-
return *(typename std::decay<TargetType>::type *)(Data + Res);
28+
const size_t Offset =
29+
(sizeof(typename std::tuple_element<Is, TupleT>::type) + ...) -
30+
sizeof(TargetType);
31+
return *(typename std::decay<TargetType>::type *)(Data + Offset);
3132
}
3233

3334
template <typename TupleT, size_t... Is>

sycl/unittests/pi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ add_sycl_unittest(PiTests OBJECT
66
EnqueueMemTest.cpp
77
PiMock.cpp
88
PlatformTest.cpp
9+
pi_arguments_handler.cpp
910
)
1011

1112
add_dependencies(PiTests sycl)
1213
target_include_directories(PiTests PRIVATE SYSTEM ${sycl_inc_dir})
14+
target_include_directories(PiTests PRIVATE ${sycl_src_dir}/../tools/xpti_helpers)
1315

1416
if(SYCL_BUILD_PI_CUDA)
1517
add_subdirectory(cuda)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//==------- pi_arguments_handler.cpp --- A test for XPTI PI args helper ---===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <gtest/gtest.h>
10+
11+
#include "pi_arguments_handler.hpp"
12+
13+
#include <CL/sycl/detail/pi.h>
14+
15+
#include <array>
16+
17+
TEST(PiArgumentsHandlerTest, CanUnpackArguments) {
18+
sycl::xpti_helpers::PiArgumentsHandler Handler;
19+
20+
const pi_uint32 NumPlatforms = 42;
21+
pi_platform *Platforms = new pi_platform[NumPlatforms];
22+
23+
Handler.set_piPlatformsGet(
24+
[&](pi_uint32 NP, pi_platform *Plts, pi_uint32 *Ret) {
25+
EXPECT_EQ(NP, NumPlatforms);
26+
EXPECT_EQ(Platforms, Plts);
27+
EXPECT_EQ(Ret, nullptr);
28+
});
29+
30+
constexpr size_t Size = sizeof(pi_uint32) + 2 * sizeof(void *);
31+
std::array<unsigned char, Size> Data{0};
32+
*reinterpret_cast<pi_uint32 *>(Data.data()) = NumPlatforms;
33+
*reinterpret_cast<pi_platform **>(Data.data() + sizeof(pi_uint32)) =
34+
Platforms;
35+
36+
uint32_t ID = static_cast<uint32_t>(sycl::detail::PiApiKind::piPlatformsGet);
37+
Handler.handle(ID, Data.data());
38+
39+
delete[] Platforms;
40+
}

0 commit comments

Comments
 (0)