Skip to content

Commit 0bd58df

Browse files
Ivan Karachunbader
authored andcommitted
[SYCL] Throw exceptions while creating invalid sub buffer (#822)
Throw `invalid_object_error` exception if memory region of constructed sub buffer specified by offset and sub buffer size doesn't represent contiguous region or if it exceeds parent bounds. Signed-off-by: Ivan Karachun <[email protected]>
1 parent 30493bb commit 0bd58df

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

sycl/include/CL/sycl/buffer.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,12 @@ class buffer {
134134
if (b.is_sub_buffer())
135135
throw cl::sycl::invalid_object_error(
136136
"Cannot create sub buffer from sub buffer.");
137-
// TODO: SYCL CTS are failed because not appropriate offset and range
138-
// are passed to this constructor which causes a throw of exception.
139-
// Some changes need to be done there.
140-
// if (isOutOfBounds(baseIndex, subRange, b.Range))
141-
// throw cl::sycl::invalid_object_error("Out-of-bounds size");
142-
// if (!isContiguousRegion(baseIndex, subRange, b.Range))
143-
// throw cl::sycl::invalid_object_error("Non-contiguous region");
137+
if (isOutOfBounds(baseIndex, subRange, b.Range))
138+
throw cl::sycl::invalid_object_error(
139+
"Requested sub-buffer size exceeds the size of the parent buffer");
140+
if (!isContiguousRegion(baseIndex, subRange, b.Range))
141+
throw cl::sycl::invalid_object_error(
142+
"Requested sub-buffer region is not contiguous");
144143
}
145144

146145
template <int N = dimensions, typename = EnableIfOneDimension<N>>

sycl/test/basic_tests/buffer/subbuffer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ int main() {
198198
cl::sycl::queue q;
199199
check1DSubBuffer(q);
200200
checkHostAccessor(q);
201-
// TODO! Uncomment once SYCL-CTS are fixed
202-
// checkExceptions();
201+
checkExceptions();
203202
return 0;
204203
}

0 commit comments

Comments
 (0)