Skip to content
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] Initialize buffer range and size in interop constructor #58

Merged
merged 3 commits into from
Apr 3, 2019
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
18 changes: 13 additions & 5 deletions sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace cl {
namespace sycl {
class handler;
class queue;
template <int dimentions> class range;
template <int dimensions> class range;

template <typename T, int dimensions = 1,
typename AllocatorT = cl::sycl::buffer_allocator>
Expand All @@ -28,6 +28,8 @@ class buffer {
using reference = value_type &;
using const_reference = const value_type &;
using allocator_type = AllocatorT;
template <int dims>
using EnableIfOneDimension = typename std::enable_if<1 == dims>::type;

buffer(const range<dimensions> &bufferRange,
const property_list &propList = {})
Expand Down Expand Up @@ -83,7 +85,8 @@ class buffer {
hostData, get_count() * sizeof(T), propList);
}

template <class InputIterator>
template <class InputIterator, int N = dimensions,
typename = EnableIfOneDimension<N>>
buffer(InputIterator first, InputIterator last, AllocatorT allocator,
const property_list &propList = {})
: Range(range<1>(std::distance(first, last))) {
Expand All @@ -92,7 +95,7 @@ class buffer {
}

template <class InputIterator, int N = dimensions,
typename = std::enable_if<N == 1>>
typename = EnableIfOneDimension<N>>
buffer(InputIterator first, InputIterator last,
const property_list &propList = {})
: Range(range<1>(std::distance(first, last))) {
Expand All @@ -105,11 +108,16 @@ class buffer {
// impl = std::make_shared<detail::buffer_impl>(b, baseIndex, subRange);
// }

template <int N = dimensions, typename = std::enable_if<N == 1>>
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;
}