Skip to content

Commit c65831f

Browse files
committed
Replace macro with func
1 parent d8c223d commit c65831f

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

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

+30-25
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@
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-
3720
#define TRY_CATCH_CL_ERROR(...) \
3821
try { \
3922
__VA_ARGS__; \
@@ -44,6 +27,30 @@
4427
namespace cldnn {
4528
namespace ocl {
4629

30+
static inline void check_boundaries(const std::string& func_str,
31+
size_t src_size,
32+
size_t src_offset,
33+
size_t dst_size,
34+
size_t dst_offset,
35+
size_t copy_size) {
36+
OPENVINO_ASSERT(src_offset + copy_size <= src_size && dst_offset + copy_size <= dst_size,
37+
"[GPU] Incorrect buffer sizes for ",
38+
func_str,
39+
" call. ",
40+
"Parameters provided are",
41+
": src_size=",
42+
src_size,
43+
", src_offset=",
44+
src_offset,
45+
", dst_size=",
46+
dst_size,
47+
", dst_offset=",
48+
dst_offset,
49+
", copy_size=",
50+
copy_size,
51+
".");
52+
}
53+
4754
static inline cldnn::event::ptr create_event(stream& stream, size_t bytes_count, bool need_user_event) {
4855
if (bytes_count == 0) {
4956
GPU_DEBUG_TRACE_DETAIL << "Skip memory operation for 0 size tensor" << std::endl;
@@ -149,7 +156,7 @@ event::ptr gpu_buffer::copy_from(stream& stream, const void* data_ptr, size_t sr
149156
if (size == 0)
150157
return result_event;
151158

152-
BOUNDARIES_CHECK("gpu_buffer::copy_from(void*)", SIZE_MAX, src_offset, _bytes_count, dst_offset, size);
159+
check_boundaries("gpu_buffer::copy_from(void*)", SIZE_MAX, src_offset, _bytes_count, dst_offset, size);
153160

154161
auto cl_stream = downcast<ocl_stream>(&stream);
155162
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
@@ -165,7 +172,7 @@ event::ptr gpu_buffer::copy_from(stream& stream, const memory& src_mem, size_t s
165172
if (size == 0)
166173
return result_event;
167174

168-
BOUNDARIES_CHECK("gpu_buffer::copy_from(memory&)", src_mem.size(), src_offset, _bytes_count, dst_offset, size);
175+
check_boundaries("gpu_buffer::copy_from(memory&)", src_mem.size(), src_offset, _bytes_count, dst_offset, size);
169176

170177
switch (src_mem.get_allocation_type()) {
171178
case allocation_type::usm_host:
@@ -201,7 +208,7 @@ event::ptr gpu_buffer::copy_to(stream& stream, void* data_ptr, size_t src_offset
201208
if (size == 0)
202209
return result_event;
203210

204-
BOUNDARIES_CHECK("gpu_buffer::copy_to(void*)", _bytes_count, src_offset, SIZE_MAX, dst_offset, size);
211+
check_boundaries("gpu_buffer::copy_to(void*)", _bytes_count, src_offset, SIZE_MAX, dst_offset, size);
205212

206213
auto cl_stream = downcast<ocl_stream>(&stream);
207214
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
@@ -563,7 +570,7 @@ event::ptr gpu_usm::copy_from(stream& stream, const void* data_ptr, size_t src_o
563570
if (size == 0)
564571
return result_event;
565572

566-
BOUNDARIES_CHECK("gpu_usm::copy_from(void*)", SIZE_MAX, src_offset, _bytes_count, dst_offset, size);
573+
check_boundaries("gpu_usm::copy_from(void*)", SIZE_MAX, src_offset, _bytes_count, dst_offset, size);
567574

568575
auto cl_stream = downcast<ocl_stream>(&stream);
569576
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
@@ -580,7 +587,7 @@ event::ptr gpu_usm::copy_from(stream& stream, const memory& src_mem, size_t src_
580587
if (size == 0)
581588
return result_event;
582589

583-
BOUNDARIES_CHECK("gpu_usm::copy_from(memory&)", src_mem.size(), src_offset, _bytes_count, dst_offset, size);
590+
check_boundaries("gpu_usm::copy_from(memory&)", src_mem.size(), src_offset, _bytes_count, dst_offset, size);
584591

585592
auto cl_stream = downcast<ocl_stream>(&stream);
586593
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
@@ -613,7 +620,7 @@ event::ptr gpu_usm::copy_to(stream& stream, void* data_ptr, size_t src_offset, s
613620
if (size == 0)
614621
return result_event;
615622

616-
BOUNDARIES_CHECK("gpu_usm::copy_to(void*)", _bytes_count, src_offset, SIZE_MAX, dst_offset, size);
623+
check_boundaries("gpu_usm::copy_to(void*)", _bytes_count, src_offset, SIZE_MAX, dst_offset, size);
617624

618625
auto cl_stream = downcast<ocl_stream>(&stream);
619626
auto cl_event = blocking ? nullptr : &downcast<ocl_event>(result_event.get())->get();
@@ -701,5 +708,3 @@ ocl_surfaces_lock::ocl_surfaces_lock(std::vector<memory::ptr> mem, const stream&
701708

702709
} // namespace ocl
703710
} // namespace cldnn
704-
705-
#undef BOUNDARIES_CHECK

src/plugins/intel_gpu/tests/unit/module_tests/usm_memory_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ INSTANTIATE_TEST_SUITE_P(mem_test,
489489
mem_test_params{100, 79, 381}),
490490
::testing::Values(false, true)));
491491

492-
TEST(mem_test, copy_to_small_to_large) {
492+
TEST(mem_test, copy_small_buf_to_large_with_out_of_bound_access) {
493493
auto& ocl_engine = dynamic_cast<ocl::ocl_engine&>(get_test_engine());
494494
auto& stream = get_test_stream();
495495
auto small_buffer_size = 2048;

0 commit comments

Comments
 (0)