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 set_arg with local_accessor #1367
Merged
AlexeySachkov
merged 3 commits into
intel:intel
from
AlexeySachkov:private/asachkov/test-for-set-arg-local-accessor
Nov 8, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,75 @@ | ||
// REQUIRES: opencl, opencl_icd | ||
// | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s %opencl_lib -o %t.out | ||
// RUN: env SYCL_DEVICE_FILTER=opencl %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: env SYCL_DEVICE_FILTER=opencl %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: env SYCL_DEVICE_FILTER=opencl %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
using namespace sycl; | ||
|
||
const char *clSource = R"( | ||
kernel void test(global int *a, local float *b, int n) { | ||
if (get_local_id(0) == 0) { | ||
for (int i = 0; i < n; i++) | ||
b[i] = i; | ||
} | ||
barrier(CLK_LOCAL_MEM_FENCE); | ||
|
||
bool ok = true; | ||
for (int i = 0; i < n; i++) | ||
ok &= (b[i] == i); | ||
|
||
a[get_global_id(0)] = ok; | ||
} | ||
)"; | ||
|
||
kernel getKernel(const queue &Q) { | ||
cl_int status = CL_SUCCESS; | ||
|
||
auto device_cl = get_native<backend::opencl>(Q.get_device()); | ||
auto context_cl = get_native<backend::opencl>(Q.get_context()); | ||
auto program_cl = | ||
clCreateProgramWithSource(context_cl, 1, &clSource, nullptr, &status); | ||
assert(CL_SUCCESS == status); | ||
status = clBuildProgram(program_cl, 0, nullptr, "", nullptr, nullptr); | ||
assert(CL_SUCCESS == status); | ||
auto kernel_cl = clCreateKernel(program_cl, "test", &status); | ||
assert(CL_SUCCESS == status); | ||
|
||
return make_kernel<backend::opencl>(kernel_cl, Q.get_context()); | ||
} | ||
|
||
int main() { | ||
queue Q; | ||
auto K = getKernel(Q); | ||
|
||
constexpr cl_int N_slm = 256; | ||
constexpr int N_wg = 32; | ||
|
||
cl_int init[N_wg]; | ||
buffer<cl_int, 1> b(init, N_wg); | ||
|
||
Q.submit([&](handler &cgh) { | ||
auto acc_global = b.get_access<access::mode::write>(cgh); | ||
local_accessor<float, 1> acc_local(N_slm, cgh); | ||
|
||
cgh.set_arg(0, acc_global); | ||
cgh.set_arg(1, acc_local); | ||
cgh.set_arg(2, N_slm); | ||
|
||
cgh.parallel_for(nd_range<1>(N_wg, 1), K); | ||
}); | ||
|
||
auto acc_global = b.get_access<access::mode::read>(); | ||
for (int i = 0; i < N_wg; i++) { | ||
if (acc_global[i] != 1) { | ||
std::cerr << "Error in WG " << i << std::endl; | ||
exit(1); | ||
} | ||
} | ||
|
||
std::cout << "Success" << 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.