diff --git a/sycl/include/syclcompat/util.hpp b/sycl/include/syclcompat/util.hpp index 28dff67975616..b8be535ae95bb 100644 --- a/sycl/include/syclcompat/util.hpp +++ b/sycl/include/syclcompat/util.hpp @@ -924,6 +924,7 @@ class args_selector; /// void foo(sycl::float2 *x, int n, sycl::nd_item<3> item_ct1, float f=.1) {} /// and with the declaration: /// args_selector<2, 1, decltype(foo)> selector(kernelParams, extra); +/// void* kernelParams[2 + 1] = { (void*)float2_var, int_var, float_var } /// we have: /// selector.get<0>() returns a reference to sycl::float*, /// selector.get<1>() returns a reference to int, diff --git a/sycl/test-e2e/syclcompat/util/util_helpers.cpp b/sycl/test-e2e/syclcompat/util/util_helpers.cpp new file mode 100644 index 0000000000000..d5f1aa47a3e25 --- /dev/null +++ b/sycl/test-e2e/syclcompat/util/util_helpers.cpp @@ -0,0 +1,94 @@ +/*************************************************************************** + * + * Copyright (C) Codeplay Software Ltd. + * + * Part of the LLVM Project, under the Apache License v2.0 with LLVM + * Exceptions. See https://llvm.org/LICENSE.txt for license information. + * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SYCLcompat API + * + * util_helpers.cpp + * + * Description: + * generic utility helpers tests + **************************************************************************/ + +// The original source was under the license below: +// ====------ UtilSelectFromSubGroup.cpp---------- -*- C++ -* ----===//// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// +// ===----------------------------------------------------------------------===// + +// RUN: %clangxx -fsycl -fsycl-targets=%{sycl_triple} %s -o %t.out +// RUN: %{run} %t.out + +#include +#include + +void test_int_as_queue_ptr() { + std::cout << __PRETTY_FUNCTION__ << std::endl; + syclcompat::device_ext &device = syclcompat::get_current_device(); + + sycl::queue q; + sycl::queue *q_ptr = &q; + uintptr_t reinterpreted_q = reinterpret_cast(q_ptr); + assert(q_ptr == syclcompat::int_as_queue_ptr(reinterpreted_q)); + // Queue addresses may not be equal, but the queues have the same device. + assert(device.get_info() == + syclcompat::int_as_queue_ptr(1) + ->get_device() + .get_info()); +} + +void foo(sycl::float2 *x, int n, sycl::nd_item<3> item_ct1, float f = .1) {} + +void test_args_selector() { + std::cout << __PRETTY_FUNCTION__ << std::endl; + + int n = 2; + sycl::float2 *a = syclcompat::malloc_host(n); + a[0] = {1.0, 2.0}; + a[1] = {3.0, 4.0}; + float f = .1; + + void *kernelParams[3] = { + static_cast(&a), + static_cast(&n), + static_cast(&f), + }; + + syclcompat::args_selector<2, 1, decltype(foo)> selector(kernelParams, + nullptr); + auto &a_ref = selector.get<0>(); + auto &n_ref = selector.get<1>(); + auto &f_ref = selector.get<2>(); + std::cout << a_ref[0][0] << " " << std::endl; + std::cout << n_ref << " " << std::endl; + std::cout << f_ref << " " << std::endl; + + assert(a_ref[0][0] == 1.0); + assert(a_ref[0][1] == 2.0); + assert(a_ref[1][0] == 3.0); + assert(a_ref[1][1] == 4.0); + assert(n_ref == 2); + assert(f_ref == .1f); + + syclcompat::free(a); +} + +int main() { + test_int_as_queue_ptr(); + test_args_selector(); + return 0; +}