Skip to content

[SYCL] Initialize buffer range and size in interop constructor #58

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

Merged
merged 3 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[SYCL] Initialize buffer range and size in interop constructor
Signed-off-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
  • Loading branch information
Fznamznon committed Apr 1, 2019
commit 3d84d5d9b197e3cc283e6b0a0268bbab23eab265
7 changes: 6 additions & 1 deletion sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ class buffer {
template <int N = dimensions, typename = EnableIfOneDimension<N>>
buffer(cl_mem MemObject, const context &SyclContext,
event AvailableEvent = {}) {

size_t BufSize = 0;
CHECK_OCL_CODE(clGetMemObjectInfo(MemObject, CL_MEM_SIZE, sizeof(size_t),
&BufSize, nullptr));
Range[0] = BufSize / sizeof(T);
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
MemObject, SyclContext, AvailableEvent);
MemObject, SyclContext, BufSize, AvailableEvent);
}

buffer(const buffer &rhs) = default;
Expand Down
5 changes: 3 additions & 2 deletions sycl/include/CL/sycl/detail/buffer_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ template <typename AllocatorT> class buffer_impl {
}

buffer_impl(cl_mem MemObject, const context &SyclContext,
event AvailableEvent = {})
: OpenCLInterop(true), AvailableEvent(AvailableEvent) {
const size_t sizeInBytes, event AvailableEvent = {})
: OpenCLInterop(true), SizeInBytes(sizeInBytes),
AvailableEvent(AvailableEvent) {
if (SyclContext.is_host())
throw cl::sycl::invalid_parameter_error(
"Creation of interoperability buffer using host context is not "
Expand Down
20 changes: 19 additions & 1 deletion sycl/test/basic_tests/buffer/buffer_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
using namespace cl::sycl;

int main() {
bool Failed = false;
{
const size_t Size = 32;
int Init[Size] = {5};
cl_int Error = CL_SUCCESS;
cl::sycl::range<1> InteropRange;
InteropRange[0] = Size;
size_t InteropSize = Size * sizeof(int);

queue MyQueue;

Expand All @@ -29,6 +33,19 @@ int main() {
CHECK_OCL_CODE(Error);
buffer<int, 1> Buffer(OpenCLBuffer, MyQueue.get_context());

if (Buffer.get_range() != InteropRange) {
assert(false);
Failed = true;
}
if (Buffer.get_size() != InteropSize) {
assert(false);
Failed = true;
}
if (Buffer.get_count() != Size) {
assert(false);
Failed = true;
}

MyQueue.submit([&](handler &CGH) {
auto B = Buffer.get_access<access::mode::write>(CGH);
CGH.parallel_for<class BufferInterop>(
Expand Down Expand Up @@ -58,8 +75,9 @@ int main() {
std::cout << " array[" << i << "] is " << Result[i] << " expected "
<< 20 << std::endl;
assert(false);
Failed = true;
}
}
}
return 0;
return Failed;
}