-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCL] Implement basic sub-buffers support #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// RUN: %clang -std=c++11 -fsycl %s -o %t.out -lstdc++ -lOpenCL | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
//==---------- subbuffer.cpp --- sub-buffer basic test ---------------------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include <CL/sycl.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
int main() { | ||
|
||
bool Failed = false; | ||
// Basic test case | ||
{ | ||
const int M = 6; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can replace all the |
||
const int N = 7; | ||
int Result[M][N] = {0}; | ||
{ | ||
auto OrigRange = range<2>(M, N); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using modern C++ |
||
buffer<int, 2> Buffer(OrigRange); | ||
Buffer.set_final_data((int *)Result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old C cast in modern C++ code... |
||
auto Offset = id<2>(1, 1); | ||
auto SubRange = range<2>(M - 2, N - 2); | ||
queue MyQueue; | ||
buffer<int, 2> SubBuffer(Buffer, Offset, SubRange); | ||
MyQueue.submit([&](handler &cgh) { | ||
auto B = SubBuffer.get_access<access::mode::read_write>(cgh); | ||
cgh.parallel_for<class Subbuf_test>(SubRange, | ||
[=](id<2> Index) { B[Index] = 1; }); | ||
}); | ||
} | ||
|
||
// Check that we filled correct subset of buffer: | ||
// 0000000 0000000 | ||
// 0000000 0111110 | ||
// 0000000 --> 0111110 | ||
// 0000000 0111110 | ||
// 0000000 0111110 | ||
// 0000000 0000000 | ||
|
||
for (size_t i = 0; i < M; ++i) { | ||
for (size_t j = 0; j < N; ++j) { | ||
size_t Expected = | ||
((i == 0) || (i == M - 1) || (j == 0) || (j == N - 1)) ? 0 : 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not clear why a
Replacing |
||
if (Result[i][j] != Expected) { | ||
std::cout << "line: " << __LINE__ << " Result[" << i << "][" << j | ||
<< "] is " << Result[i][j] << " expected " << Expected | ||
<< std::endl; | ||
Failed = true; | ||
} | ||
} | ||
} | ||
} | ||
// Try to create subbuffer from subbuffer | ||
{ | ||
const int M = 10; | ||
int Data[M] = {0}; | ||
auto OrigRange = range<1>(M); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shorter:
|
||
buffer<int, 1> Buffer(Data, OrigRange); | ||
auto Offset = id<1>(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem for the 3 next ones |
||
auto SubRange = range<1>(M - 2); | ||
auto SubSubRange = range<1>(M - 4); | ||
queue MyQueue; | ||
buffer<int, 1> SubBuffer(Buffer, Offset, SubRange); | ||
buffer<int, 1> SubSubBuffer(SubBuffer, Offset, SubSubRange); | ||
MyQueue.submit([&](handler &cgh) { | ||
auto B = SubSubBuffer.get_access<access::mode::read_write>(cgh); | ||
cgh.parallel_for<class Subsubbuf_test>(SubSubRange, | ||
[=](id<1> Index) { B[Index] = 1; }); | ||
}); | ||
auto Acc = Buffer.get_access<cl::sycl::access::mode::read>(); | ||
for (size_t i = 0; i < M; ++i) { | ||
size_t Expected = (i > 1 && i < M - 2) ? 1 : 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (Acc[i] != Expected) { | ||
std::cout << "line: " << __LINE__ << " Data[" << i << "] is " << Acc[i] | ||
<< " expected " << Expected << std::endl; | ||
Failed = true; | ||
} | ||
} | ||
} | ||
return Failed; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about writing modern C++ with some
{ }
instead of()
for most of the instance constructions?