From 20de509cc7f7d2643a61a8d3c8dc743a40d9d531 Mon Sep 17 00:00:00 2001 From: Denis Bakhvalov Date: Fri, 20 Aug 2021 15:38:26 -0700 Subject: [PATCH] [ESIMD] E2E test for writeable simd_view subscript operator --- .../api/simd_view_subscript_operator.cpp | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 SYCL/ESIMD/api/simd_view_subscript_operator.cpp diff --git a/SYCL/ESIMD/api/simd_view_subscript_operator.cpp b/SYCL/ESIMD/api/simd_view_subscript_operator.cpp new file mode 100644 index 0000000000..605c54151f --- /dev/null +++ b/SYCL/ESIMD/api/simd_view_subscript_operator.cpp @@ -0,0 +1,100 @@ +//==----- simd_view_subscript_operator.cpp - DPC++ ESIMD on-device test ---==// +// +// 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 +// +//===----------------------------------------------------------------------===// +// REQUIRES: gpu +// UNSUPPORTED: cuda || rocm +// RUN: %clangxx -fsycl %s -o %t.out +// RUN: %GPU_RUN_PLACEHOLDER %t.out +// +// The test checks that it's possible to write through the simd_view subscript +// operator. E.g.: +// simd v = 1; +// auto v1 = v.select<2, 1>(0); +// v1[0] = 0; // v1[0] returns writable simd_view + +#include "../esimd_test_utils.hpp" + +#include +#include + +#include + +using namespace cl::sycl; +using namespace sycl::ext::intel::experimental::esimd; + +int main(int argc, char **argv) { + queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler()); + + auto dev = q.get_device(); + std::cout << "Running on " << dev.get_info() << "\n"; + + constexpr unsigned VL = 16; + + int A[VL]; + int B[VL]; + int gold[VL]; + + for (unsigned i = 0; i < VL; ++i) { + A[i] = -i; + B[i] = i; + gold[i] = B[i]; + } + + // some random indices to overwrite elements in B with elements from A. + std::array indicesToCopy = {2, 5, 9, 10, 13}; + + try { + buffer bufA(A, range<1>(VL)); + buffer bufB(B, range<1>(VL)); + range<1> glob_range{1}; + + auto e = q.submit([&](handler &cgh) { + auto PA = bufA.get_access(cgh); + auto PB = bufB.template get_access(cgh); + cgh.parallel_for(glob_range, [=](id<1> i) SYCL_ESIMD_KERNEL { + using namespace sycl::ext::intel::experimental::esimd; + simd va; + va.copy_from(PA, 0); + simd vb; + vb.copy_from(PB, 0); + auto view_va = va.select(0); + auto view_vb = vb.select(0); + for (auto idx : indicesToCopy) + view_vb[idx] = view_va[idx]; + vb.copy_to(PB, 0); + }); + }); + q.wait_and_throw(); + } catch (cl::sycl::exception const &e) { + std::cout << "SYCL exception caught: " << e.what() << '\n'; + return e.get_cl_code(); + } + + int err_cnt = 0; + + for (auto i : indicesToCopy) + gold[i] = A[i]; + + for (unsigned i = 0; i < VL; ++i) { + int val = B[i]; + + if (val != gold[i]) { + if (++err_cnt < 10) { + std::cout << "failed at index " << i << ": " << val << " != " << gold[i] + << " (gold)\n"; + } + } + } + if (err_cnt > 0) { + std::cout << " pass rate: " << ((float)(VL - err_cnt) / (float)VL) * 100.0f + << "% (" << (VL - err_cnt) << "/" << VL << ")\n"; + } + + std::cout << (err_cnt > 0 ? " FAILED\n" : " Passed\n"); + + return err_cnt > 0 ? 1 : 0; +}