Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[ESIMD] Added regression test for simd_view::operator-- #281

Merged
merged 1 commit into from
May 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions SYCL/ESIMD/regression/operator_decrement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//==------------- operator_decrement.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
//
//===----------------------------------------------------------------------===//
// This is a test for a bug found simd_view::operator--
//
// REQUIRES: gpu
// UNSUPPORTED: cuda
// RUN: %clangxx -fsycl -I%S/.. %s -o %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out

#include "esimd_test_utils.hpp"

#include <CL/sycl.hpp>
#include <CL/sycl/INTEL/esimd.hpp>
#include <iostream>

using namespace cl::sycl;

int main(void) {
constexpr unsigned Size = 1024;
constexpr unsigned VL = 16;

float *A = new float[Size];

for (unsigned i = 0; i < Size; ++i) {
A[i] = i + 1;
}

try {
buffer<float, 1> bufa(A, range<1>(Size));

// We need that many workgroups
cl::sycl::range<1> GlobalRange{Size / VL};

// We need that many threads in each group
cl::sycl::range<1> LocalRange{1};

queue q(esimd_test::ESIMDSelector{}, esimd_test::createExceptionHandler());

auto dev = q.get_device();
std::cout << "Running on " << dev.get_info<info::device::name>() << "\n";

auto e = q.submit([&](handler &cgh) {
auto PA = bufa.get_access<access::mode::read_write>(cgh);
cgh.parallel_for<class Test>(
GlobalRange * LocalRange, [=](id<1> i) SYCL_ESIMD_KERNEL {
using namespace sycl::ext::intel::experimental::esimd;
unsigned int offset = i * VL * sizeof(float);
simd<float, VL> va;
va.copy_from(PA, offset);
auto va_view = va.select<VL, 1>(0);
va_view--;
va.copy_to(PA, offset);
});
});
e.wait();
} catch (cl::sycl::exception const &e) {
std::cout << "SYCL exception caught: " << e.what() << '\n';

delete[] A;
return e.get_cl_code();
}

int err_cnt = 0;

for (unsigned i = 0; i < Size; ++i) {
if (A[i] != i) {
if (++err_cnt < 10) {
std::cout << "failed at index " << i << ", " << A[i] << " != " << i
<< "\n";
}
}
}
if (err_cnt > 0) {
std::cout << " pass rate: "
<< ((float)(Size - err_cnt) / (float)Size) * 100.0f << "% ("
<< (Size - err_cnt) << "/" << Size << ")\n";
}

delete[] A;

std::cout << (err_cnt > 0 ? "FAILED\n" : "Passed\n");
return err_cnt > 0 ? 1 : 0;
}