Skip to content

Commit 3e11f59

Browse files
Fznamznonvladimirlaz
authored andcommitted
[SYCL] Initialize buffer range and size in interop constructor
Signed-off-by: Mariya Podchishchaeva <[email protected]>
1 parent 1e514c8 commit 3e11f59

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

sycl/include/CL/sycl/buffer.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ class buffer {
111111
template <int N = dimensions, typename = EnableIfOneDimension<N>>
112112
buffer(cl_mem MemObject, const context &SyclContext,
113113
event AvailableEvent = {}) {
114+
115+
size_t BufSize = 0;
116+
CHECK_OCL_CODE(clGetMemObjectInfo(MemObject, CL_MEM_SIZE, sizeof(size_t),
117+
&BufSize, nullptr));
118+
Range[0] = BufSize / sizeof(T);
114119
impl = std::make_shared<detail::buffer_impl<AllocatorT>>(
115-
MemObject, SyclContext, AvailableEvent);
120+
MemObject, SyclContext, BufSize, AvailableEvent);
116121
}
117122

118123
buffer(const buffer &rhs) = default;

sycl/include/CL/sycl/detail/buffer_impl.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@ template <typename AllocatorT> class buffer_impl {
119119
}
120120

121121
buffer_impl(cl_mem MemObject, const context &SyclContext,
122-
event AvailableEvent = {})
123-
: OpenCLInterop(true), AvailableEvent(AvailableEvent) {
122+
const size_t sizeInBytes, event AvailableEvent = {})
123+
: OpenCLInterop(true), SizeInBytes(sizeInBytes),
124+
AvailableEvent(AvailableEvent) {
124125
if (SyclContext.is_host())
125126
throw cl::sycl::invalid_parameter_error(
126127
"Creation of interoperability buffer using host context is not "

sycl/test/basic_tests/buffer/buffer_interop.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616
using namespace cl::sycl;
1717

1818
int main() {
19+
bool Failed = false;
1920
{
2021
const size_t Size = 32;
2122
int Init[Size] = {5};
2223
cl_int Error = CL_SUCCESS;
24+
cl::sycl::range<1> InteropRange;
25+
InteropRange[0] = Size;
26+
size_t InteropSize = Size * sizeof(int);
2327

2428
queue MyQueue;
2529

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

36+
if (Buffer.get_range() != InteropRange) {
37+
assert(false);
38+
Failed = true;
39+
}
40+
if (Buffer.get_size() != InteropSize) {
41+
assert(false);
42+
Failed = true;
43+
}
44+
if (Buffer.get_count() != Size) {
45+
assert(false);
46+
Failed = true;
47+
}
48+
3249
MyQueue.submit([&](handler &CGH) {
3350
auto B = Buffer.get_access<access::mode::write>(CGH);
3451
CGH.parallel_for<class BufferInterop>(
@@ -58,8 +75,9 @@ int main() {
5875
std::cout << " array[" << i << "] is " << Result[i] << " expected "
5976
<< 20 << std::endl;
6077
assert(false);
78+
Failed = true;
6179
}
6280
}
6381
}
64-
return 0;
82+
return Failed;
6583
}

0 commit comments

Comments
 (0)