Skip to content

Commit

Permalink
[SYCL][COMPAT] Added tests for args_selector and int_to_queue_ptr hel…
Browse files Browse the repository at this point in the history
…pers
  • Loading branch information
Alcpz committed Feb 29, 2024
1 parent 7293dca commit 8a72a75
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions sycl/include/syclcompat/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
94 changes: 94 additions & 0 deletions sycl/test-e2e/syclcompat/util/util_helpers.cpp
Original file line number Diff line number Diff line change
@@ -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 <sycl/sycl.hpp>
#include <syclcompat/util.hpp>

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<uintptr_t>(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<sycl::info::device::name>() ==
syclcompat::int_as_queue_ptr(1)
->get_device()
.get_info<sycl::info::device::name>());
}

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<sycl::float2>(n);
a[0] = {1.0, 2.0};
a[1] = {3.0, 4.0};
float f = .1;

void *kernelParams[3] = {
static_cast<void *>(&a),
static_cast<void *>(&n),
static_cast<void *>(&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;
}

0 comments on commit 8a72a75

Please sign in to comment.