diff --git a/tests/sycl_external/CMakeLists.txt b/tests/sycl_external/CMakeLists.txt new file mode 100644 index 000000000..82f462065 --- /dev/null +++ b/tests/sycl_external/CMakeLists.txt @@ -0,0 +1,3 @@ +file(GLOB test_cases_list *.cpp) + +add_cts_test(${test_cases_list}) diff --git a/tests/sycl_external/sycl_external.cpp b/tests/sycl_external/sycl_external.cpp new file mode 100644 index 000000000..3abfc53ad --- /dev/null +++ b/tests/sycl_external/sycl_external.cpp @@ -0,0 +1,253 @@ +/******************************************************************************* +// +// SYCL 2020 Conformance Test Suite +// +// Copyright (c) 2017-2022 Codeplay Software LTD. All Rights Reserved. +// Copyright (c) 2022-2023 The Khronos Group Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// 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. +// +*******************************************************************************/ + +#include "../common/common.h" +#include "../common/disabled_for_test_case.h" + +constexpr int value = 42; + +using accT = sycl::accessor; +using hostAccT = sycl::host_accessor; + +#ifdef SYCL_EXTERNAL +SYCL_EXTERNAL void same_unit_device(const accT& acc) { acc[0] = value; } +SYCL_EXTERNAL void same_unit_host(hostAccT& acc) { acc[0] = value; } +template +class kernel_same_unit { + accT acc; + + public: + kernel_same_unit(accT input_acc) : acc(input_acc) {} + void operator()() const { same_unit_device(acc); } + void operator()(sycl::item<1> item) const { same_unit_device(acc); } +}; + +SYCL_EXTERNAL void simple_separate_unit_device(const accT& acc); +SYCL_EXTERNAL void simple_separate_unit_host(hostAccT& acc); +template +class kernel_simple_separate_unit { + accT acc; + + public: + kernel_simple_separate_unit(accT input_acc) : acc(input_acc) {} + void operator()() const { simple_separate_unit_device(acc); } + void operator()(sycl::item<1> item) const { + simple_separate_unit_device(acc); + } +}; + +SYCL_EXTERNAL extern void extern_separate_unit_device(const accT& acc); +SYCL_EXTERNAL extern void extern_separate_unit_host(hostAccT& acc); +template +class kernel_extern_separate_unit { + accT acc; + + public: + kernel_extern_separate_unit(accT input_acc) : acc(input_acc) {} + void operator()() const { extern_separate_unit_device(acc); } + void operator()(sycl::item<1> item) const { + extern_separate_unit_device(acc); + } +}; + +template +SYCL_EXTERNAL [[sycl::device_has(aspect)]] void before_aspect_device( + const accT& acc); +template +SYCL_EXTERNAL [[sycl::device_has(aspect)]] void before_aspect_host( + hostAccT& acc); +template +class kernel_before_aspect { + accT acc; + + public: + kernel_before_aspect(accT input_acc) : acc(input_acc) {} + void operator()() const { before_aspect_device(acc); } + void operator()(sycl::item<1> item) const { + before_aspect_device(acc); + } +}; + +template +[[sycl::device_has(aspect)]] SYCL_EXTERNAL [[noreturn]] void +between_aspects_device(const accT& acc); +template +[[sycl::device_has(aspect)]] SYCL_EXTERNAL [[noreturn]] void +between_aspects_host(hostAccT& acc); +template +class kernel_between_aspects { + accT acc; + + public: + kernel_between_aspects(accT input_acc) : acc(input_acc) {} + void operator()() const { between_aspects_device(acc); } + void operator()(sycl::item<1> item) const { + between_aspects_device(acc); + } +}; + +template +[[sycl::device_has(aspect)]] SYCL_EXTERNAL void after_aspect_device( + const accT& acc); +template +[[sycl::device_has(aspect)]] SYCL_EXTERNAL void after_aspect_host( + hostAccT& acc); +template +class kernel_after_aspect { + accT acc; + + public: + kernel_after_aspect(accT input_acc) : acc(input_acc) {} + void operator()() const { after_aspect_device(acc); } + void operator()(sycl::item<1> item) const { + after_aspect_device(acc); + } +}; +#endif // SYCL_EXTERNAL + +void test_host(void (*f)(hostAccT&)) { + SECTION("Check call from host code") { + sycl::buffer buf{1}; + hostAccT acc{buf}; + f(acc); + CHECK(acc[0] == value); + } +} + +template