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

Commit 3800ffd

Browse files
[SYCL-MLIR] Add parallel_for.cpp (#1374)
* [SYCL-MLIR] Add parallel_for.cpp Signed-off-by: Tsang, Whitney <[email protected]>
1 parent 3617193 commit 3800ffd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

SYCL/Basic/cgeist/parallel_for.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -Xcgeist -gen-all-sycl-funcs %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
// REQUIRES: linux
6+
// UNSUPPORTED: hip || cuda
7+
8+
#include <sycl/sycl.hpp>
9+
using namespace sycl;
10+
static constexpr unsigned N = 8;
11+
12+
void host_parallel_for(std::array<int, N> &A) {
13+
auto q = queue{};
14+
device d = q.get_device();
15+
std::cout << "Using " << d.get_info<info::device::name>() << "\n";
16+
auto range = sycl::range<1>{N};
17+
18+
{
19+
auto buf = buffer<int, 1>{A.data(), range};
20+
q.submit([&](handler &cgh) {
21+
auto A = buf.get_access<access::mode::write>(cgh);
22+
cgh.parallel_for<class kernel_parallel_for>(range, [=](sycl::id<1> id) {
23+
A[id] = id;
24+
});
25+
});
26+
}
27+
}
28+
29+
int main() {
30+
std::array<int, N> A{0};
31+
host_parallel_for(A);
32+
for (unsigned i = 0; i < N; ++i) {
33+
assert(A[i] == i);
34+
}
35+
std::cout << "Test passed" << std::endl;
36+
}

SYCL/Basic/single_task.cpp renamed to SYCL/Basic/cgeist/single_task.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ void host_single_task(std::array<int, 1> &A) {
2626

2727
int main() {
2828
std::array<int, 1> A = {0};
29-
A[0] = 0;
3029
host_single_task(A);
3130
assert(A[0] == 1);
3231
std::cout << "Test passed" << std::endl;

SYCL/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if(CHECK_SYCL_ALL)
2828

2929
add_custom_target(${TARGET}
3030
# HACK: Only run test files in cgeist directory.
31-
COMMAND python3 ${TEST_SUITE_LIT} ${TEST_SUITE_LIT_FLAGS} --filter=Basic/single_task.cpp --param sycl_be=${TARGET_BE} --param target_devices=${TARGET_DEVICES} .
31+
COMMAND python3 ${TEST_SUITE_LIT} ${TEST_SUITE_LIT_FLAGS} --filter=Basic/cgeist/* --param sycl_be=${TARGET_BE} --param target_devices=${TARGET_DEVICES} .
3232
COMMENT "Running the SYCL tests for ${TARGET} backend"
3333
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
3434
DEPENDS ${TEST_SUITE_TARGETS}

0 commit comments

Comments
 (0)