Files
Kseniya Tikhomirova e5cf9adf6a [libsycl] Add parallel_for feature (#189068)
Depends on https://github.com/llvm/llvm-project/pull/188797 (stacked
PRs).

Depends on liboffload PR:
https://github.com/llvm/llvm-project/pull/184343.
Depends on clang driver update to pick the right location for search of
libsycl: follow up for https://github.com/llvm/llvm-project/pull/188770.
Without it test will fail since clang can't find libsycl in build dir.
Depends on future liboffload fix for range. Without it test will fail on
data check.

This is part of the SYCL support upstreaming effort. The relevant RFCs
can be found here:


https://discourse.llvm.org/t/rfc-add-full-support-for-the-sycl-programming-model/74080
https://discourse.llvm.org/t/rfc-sycl-runtime-upstreaming/74479

---------

Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
2026-06-01 15:31:32 +02:00

88 lines
2.4 KiB
C++

// REQUIRES: any-device
// RUN: %clangxx -fsycl -Wno-error=deprecated-declarations %s -o %t.out
// RUN: %t.out
#include <sycl/sycl.hpp>
#include <cassert>
#include <memory>
using namespace sycl;
// TODO: original test works with buffers, revert changes to USM once they are
// implemented.
int main() {
bool Fail{};
constexpr size_t DataSize = 10;
const range<1> GlobalRange(6);
// Id indexer
{
queue Q;
int *Data = sycl::malloc_shared<int>(DataSize, Q);
for (size_t i = 0; i < DataSize; ++i)
Data[i] = -1;
Q.parallel_for<class id1>(GlobalRange,
[=](id<1> Index) { Data[Index] = Index[0]; });
Q.wait();
Fail |= [&]() {
for (size_t i = 0; i < DataSize; ++i) {
const int ExpectedVal = i < GlobalRange[0] ? i : -1;
if (Data[i] != ExpectedVal) {
std::cout << "line: " << __LINE__ << " Data[" << i << "] is "
<< Data[i] << " expected " << ExpectedVal << std::endl;
return true;
}
}
return false;
}();
free(Data, Q);
}
// Item indexer without offset
{
// TODO: replace strcut with sycl::int2 once implemented.
struct DoubleInt {
int Id;
int Range;
};
queue Q;
DoubleInt *Data = sycl::malloc_shared<DoubleInt>(DataSize, Q);
for (size_t i = 0; i < DataSize; ++i)
Data[i] = {-1, -1};
Q.parallel_for<class item1_nooffset>(
GlobalRange, [=](item<1, false> Index) {
Data[Index.get_id()] = {int(Index.get_id()[0]),
int(Index.get_range()[0])};
});
Q.wait();
Fail |= [&]() {
for (size_t i = 0; i < DataSize; ++i) {
const int ExpectedValID = i < GlobalRange[0] ? i : -1;
const int ExpectedValRange = i < GlobalRange[0] ? GlobalRange[0] : -1;
if (Data[i].Id != ExpectedValID || Data[i].Range != ExpectedValRange) {
std::cout << "line: " << __LINE__ << " Data[" << i << "] is {"
<< Data[i].Id << ", " << Data[i].Range << "} expected {"
<< ExpectedValID << ", " << ExpectedValRange << "}"
<< std::endl;
return true;
}
}
return false;
}();
free(Data, Q);
}
// TODO: Item indexer with offset
// blocked by liboffload support
// blocked by absence of sycl::handler implementation
// TODO: add nd_item check
return Fail;
}