Skip to content

Commit d8c223d

Browse files
committed
Add boundaries check macro
1 parent ef9c5f6 commit d8c223d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/plugins/intel_gpu/src/runtime/ocl/ocl_memory.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@
1717
#include <oneapi/dnnl/dnnl_ocl.hpp>
1818
#endif
1919

20+
#define BOUNDARIES_CHECK(copy_type, src_size, src_offset, dst_size, dst_offset, copy_size) \
21+
OPENVINO_ASSERT(src_offset + copy_size <= src_size && dst_offset + copy_size <= dst_size, \
22+
"[GPU] Incorrect buffer sizes for ", \
23+
copy_type, \
24+
" call. Parameters provided are" \
25+
": src_size=", \
26+
src_size, \
27+
", src_offset=", \
28+
src_offset, \
29+
", dst_size=", \
30+
dst_size, \
31+
", dst_offset=", \
32+
dst_offset, \
33+
", copy_size=", \
34+
copy_size, \
35+
".");
36+
2037
#define TRY_CATCH_CL_ERROR(...) \
2138
try { \
2239
__VA_ARGS__; \
@@ -132,6 +149,8 @@ event::ptr gpu_buffer::copy_from(stream& stream, const void* data_ptr, size_t sr
132149
if (size == 0)
133150
return result_event;
134151

152+
BOUNDARIES_CHECK("gpu_buffer::copy_from(void*)", SIZE_MAX, src_offset, _bytes_count, dst_offset, size);
153+
135154
auto cl_stream = downcast<ocl_stream>(&stream);
136155
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
137156
auto src_ptr = reinterpret_cast<const char*>(data_ptr) + src_offset;
@@ -146,6 +165,8 @@ event::ptr gpu_buffer::copy_from(stream& stream, const memory& src_mem, size_t s
146165
if (size == 0)
147166
return result_event;
148167

168+
BOUNDARIES_CHECK("gpu_buffer::copy_from(memory&)", src_mem.size(), src_offset, _bytes_count, dst_offset, size);
169+
149170
switch (src_mem.get_allocation_type()) {
150171
case allocation_type::usm_host:
151172
case allocation_type::usm_shared:
@@ -180,6 +201,8 @@ event::ptr gpu_buffer::copy_to(stream& stream, void* data_ptr, size_t src_offset
180201
if (size == 0)
181202
return result_event;
182203

204+
BOUNDARIES_CHECK("gpu_buffer::copy_to(void*)", _bytes_count, src_offset, SIZE_MAX, dst_offset, size);
205+
183206
auto cl_stream = downcast<ocl_stream>(&stream);
184207
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
185208
auto dst_ptr = reinterpret_cast<char*>(data_ptr) + dst_offset;
@@ -540,6 +563,8 @@ event::ptr gpu_usm::copy_from(stream& stream, const void* data_ptr, size_t src_o
540563
if (size == 0)
541564
return result_event;
542565

566+
BOUNDARIES_CHECK("gpu_usm::copy_from(void*)", SIZE_MAX, src_offset, _bytes_count, dst_offset, size);
567+
543568
auto cl_stream = downcast<ocl_stream>(&stream);
544569
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
545570
auto src_ptr = reinterpret_cast<const char*>(data_ptr) + src_offset;
@@ -555,6 +580,8 @@ event::ptr gpu_usm::copy_from(stream& stream, const memory& src_mem, size_t src_
555580
if (size == 0)
556581
return result_event;
557582

583+
BOUNDARIES_CHECK("gpu_usm::copy_from(memory&)", src_mem.size(), src_offset, _bytes_count, dst_offset, size);
584+
558585
auto cl_stream = downcast<ocl_stream>(&stream);
559586
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
560587

@@ -586,6 +613,8 @@ event::ptr gpu_usm::copy_to(stream& stream, void* data_ptr, size_t src_offset, s
586613
if (size == 0)
587614
return result_event;
588615

616+
BOUNDARIES_CHECK("gpu_usm::copy_to(void*)", _bytes_count, src_offset, SIZE_MAX, dst_offset, size);
617+
589618
auto cl_stream = downcast<ocl_stream>(&stream);
590619
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
591620
auto src_ptr = reinterpret_cast<const char*>(buffer_ptr()) + src_offset;
@@ -672,3 +701,5 @@ ocl_surfaces_lock::ocl_surfaces_lock(std::vector<memory::ptr> mem, const stream&
672701

673702
} // namespace ocl
674703
} // namespace cldnn
704+
705+
#undef BOUNDARIES_CHECK

0 commit comments

Comments
 (0)