Skip to content

Commit 8a72a75

Browse files
committed
[SYCL][COMPAT] Added tests for args_selector and int_to_queue_ptr helpers
1 parent 7293dca commit 8a72a75

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

sycl/include/syclcompat/util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ class args_selector;
924924
/// void foo(sycl::float2 *x, int n, sycl::nd_item<3> item_ct1, float f=.1) {}
925925
/// and with the declaration:
926926
/// args_selector<2, 1, decltype(foo)> selector(kernelParams, extra);
927+
/// void* kernelParams[2 + 1] = { (void*)float2_var, int_var, float_var }
927928
/// we have:
928929
/// selector.get<0>() returns a reference to sycl::float*,
929930
/// selector.get<1>() returns a reference to int,
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/***************************************************************************
2+
*
3+
* Copyright (C) Codeplay Software Ltd.
4+
*
5+
* Part of the LLVM Project, under the Apache License v2.0 with LLVM
6+
* Exceptions. See https://llvm.org/LICENSE.txt for license information.
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*
15+
* SYCLcompat API
16+
*
17+
* util_helpers.cpp
18+
*
19+
* Description:
20+
* generic utility helpers tests
21+
**************************************************************************/
22+
23+
// The original source was under the license below:
24+
// ====------ UtilSelectFromSubGroup.cpp---------- -*- C++ -* ----===////
25+
//
26+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
27+
// See https://llvm.org/LICENSE.txt for license information.
28+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
29+
//
30+
//
31+
// ===----------------------------------------------------------------------===//
32+
33+
// RUN: %clangxx -fsycl -fsycl-targets=%{sycl_triple} %s -o %t.out
34+
// RUN: %{run} %t.out
35+
36+
#include <sycl/sycl.hpp>
37+
#include <syclcompat/util.hpp>
38+
39+
void test_int_as_queue_ptr() {
40+
std::cout << __PRETTY_FUNCTION__ << std::endl;
41+
syclcompat::device_ext &device = syclcompat::get_current_device();
42+
43+
sycl::queue q;
44+
sycl::queue *q_ptr = &q;
45+
uintptr_t reinterpreted_q = reinterpret_cast<uintptr_t>(q_ptr);
46+
assert(q_ptr == syclcompat::int_as_queue_ptr(reinterpreted_q));
47+
// Queue addresses may not be equal, but the queues have the same device.
48+
assert(device.get_info<sycl::info::device::name>() ==
49+
syclcompat::int_as_queue_ptr(1)
50+
->get_device()
51+
.get_info<sycl::info::device::name>());
52+
}
53+
54+
void foo(sycl::float2 *x, int n, sycl::nd_item<3> item_ct1, float f = .1) {}
55+
56+
void test_args_selector() {
57+
std::cout << __PRETTY_FUNCTION__ << std::endl;
58+
59+
int n = 2;
60+
sycl::float2 *a = syclcompat::malloc_host<sycl::float2>(n);
61+
a[0] = {1.0, 2.0};
62+
a[1] = {3.0, 4.0};
63+
float f = .1;
64+
65+
void *kernelParams[3] = {
66+
static_cast<void *>(&a),
67+
static_cast<void *>(&n),
68+
static_cast<void *>(&f),
69+
};
70+
71+
syclcompat::args_selector<2, 1, decltype(foo)> selector(kernelParams,
72+
nullptr);
73+
auto &a_ref = selector.get<0>();
74+
auto &n_ref = selector.get<1>();
75+
auto &f_ref = selector.get<2>();
76+
std::cout << a_ref[0][0] << " " << std::endl;
77+
std::cout << n_ref << " " << std::endl;
78+
std::cout << f_ref << " " << std::endl;
79+
80+
assert(a_ref[0][0] == 1.0);
81+
assert(a_ref[0][1] == 2.0);
82+
assert(a_ref[1][0] == 3.0);
83+
assert(a_ref[1][1] == 4.0);
84+
assert(n_ref == 2);
85+
assert(f_ref == .1f);
86+
87+
syclcompat::free(a);
88+
}
89+
90+
int main() {
91+
test_int_as_queue_ptr();
92+
test_args_selector();
93+
return 0;
94+
}

0 commit comments

Comments
 (0)