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

[SYCL-MLIR] Add parallel_for.cpp #1374

Merged
merged 3 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
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
36 changes: 36 additions & 0 deletions SYCL/Basic/cgeist/parallel_for.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -Xcgeist -gen-all-sycl-funcs %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
// REQUIRES: linux
// UNSUPPORTED: hip || cuda

#include <sycl/sycl.hpp>
using namespace sycl;
static constexpr unsigned N = 8;

void host_parallel_for(std::array<int, N> &A) {
auto q = queue{};
device d = q.get_device();
std::cout << "Using " << d.get_info<info::device::name>() << "\n";
auto range = sycl::range<1>{N};

{
auto buf = buffer<int, 1>{A.data(), range};
q.submit([&](handler &cgh) {
auto A = buf.get_access<access::mode::write>(cgh);
cgh.parallel_for<class kernel_parallel_for>(range, [=](sycl::id<1> id) {
A[id] = id;
});
});
}
}

int main() {
std::array<int, N> A{0};
host_parallel_for(A);
for (unsigned i = 0; i < N; ++i) {
assert(A[i] == i);
}
std::cout << "Test passed" << std::endl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void host_single_task(std::array<int, 1> &A) {

int main() {
std::array<int, 1> A = {0};
A[0] = 0;
host_single_task(A);
assert(A[0] == 1);
std::cout << "Test passed" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion SYCL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(CHECK_SYCL_ALL)

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