This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[SYCL] Add test for classes implicitly converted from items in parallel_for #607
Merged
vladimirlaz
merged 5 commits into
intel:intel
from
aobolensk:user_types_in_parallel_for
Dec 19, 2021
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24f5c37
[SYCL] Add test for classes implicitly converted from items in parall…
aobolensk 6c35584
Update SYCL/Basic/parallel_for_user_types.cpp
aobolensk bb832ef
Use error code for reporting functional errors
aobolensk c2364ad
Add test output and queue wait
aobolensk ed0dbee
Use host accessors for checking data
aobolensk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %HOST_RUN_PLACEHOLDER %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
// This test performs basic check of supporting user defined class that are | ||
// implicitly converted from sycl::item/sycl::nd_item in parallel_for. | ||
|
||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
|
||
template <int Dimensions> class item_wrapper { | ||
public: | ||
item_wrapper(sycl::item<Dimensions> it) : m_item(it) {} | ||
|
||
size_t get() { return m_item; } | ||
|
||
private: | ||
sycl::item<Dimensions> m_item; | ||
}; | ||
|
||
template <int Dimensions> class nd_item_wrapper { | ||
public: | ||
nd_item_wrapper(sycl::nd_item<Dimensions> it) : m_item(it) {} | ||
|
||
size_t get() { return m_item.get_global_linear_id(); } | ||
|
||
private: | ||
sycl::nd_item<Dimensions> m_item; | ||
}; | ||
|
||
int main() { | ||
sycl::queue q; | ||
|
||
// Initialize data array | ||
const int sz = 16; | ||
int data[sz] = {0}; | ||
for (int i = 0; i < sz; ++i) { | ||
data[i] = i; | ||
} | ||
|
||
// Check user defined sycl::item wrapper | ||
sycl::buffer<int> data_buf(data, sz); | ||
q.submit([&](sycl::handler &h) { | ||
auto buf_acc = data_buf.get_access<sycl::access::mode::read_write>(h); | ||
h.parallel_for(sycl::range<1>{sz}, | ||
[=](item_wrapper<1> item) { buf_acc[item.get()] += 1; }); | ||
}); | ||
q.wait(); | ||
bool failed = false; | ||
|
||
for (int i = 0; i < sz; ++i) { | ||
failed |= (data[i] != i + 1); | ||
} | ||
if (failed) { | ||
std::cout << "item_wrapper check failed" << std::endl; | ||
return 1; | ||
} | ||
|
||
// Check user defined sycl::nd_item wrapper | ||
q.submit([&](sycl::handler &h) { | ||
auto buf_acc = data_buf.get_access<sycl::access::mode::read_write>(h); | ||
h.parallel_for(sycl::nd_range<1>{sz, 2}, | ||
[=](nd_item_wrapper<1> item) { buf_acc[item.get()] += 1; }); | ||
}); | ||
q.wait(); | ||
|
||
for (int i = 0; i < sz; ++i) { | ||
failed |= (data[i] != i + 2); | ||
} | ||
if (failed) { | ||
std::cout << "nd_item_wrapper check failed" << std::endl; | ||
return 1; | ||
} | ||
|
||
std::cout << "Test passed" << std::endl; | ||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.