Skip to content

Commit 5b80fd9

Browse files
authored
[GPU] add kindly error messages for usm allocation (openvinotoolkit#22910)
This PR updates kindly error messages for usm allocation failure. ### Tickets: - 130105
1 parent b8c3bae commit 5b80fd9

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/plugins/intel_gpu/src/runtime/ocl/ocl_ext.hpp

+22-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ typedef cl_va_api_device_source_intel cl_device_source_intel;
3131
typedef cl_va_api_device_set_intel cl_device_set_intel;
3232
#endif
3333

34+
#include <sstream>
35+
3436
/********************************************
3537
* cl_intel_required_subgroup_size extension *
3638
*********************************************/
@@ -925,23 +927,23 @@ class UsmMemory {
925927

926928
void allocateHost(size_t size) {
927929
cl_int error = CL_SUCCESS;
928-
_allocate(_usmHelper.allocate_host(nullptr, size, 0, &error));
929-
if (error != CL_SUCCESS)
930-
detail::errHandler(error, "[CL_EXT] UsmHost in cl extensions constructor failed");
930+
auto ptr = _usmHelper.allocate_host(nullptr, size, 0, &error);
931+
_check_error(size, ptr, error, "Host");
932+
_allocate(ptr);
931933
}
932934

933935
void allocateShared(size_t size) {
934936
cl_int error = CL_SUCCESS;
935-
_allocate(_usmHelper.allocate_shared(nullptr, size, 0, &error));
936-
if (error != CL_SUCCESS)
937-
detail::errHandler(error, "[CL_EXT] UsmShared in cl extensions constructor failed");
937+
auto ptr = _usmHelper.allocate_shared(nullptr, size, 0, &error);
938+
_check_error(size, ptr, error, "Shared");
939+
_allocate(ptr);
938940
}
939941

940942
void allocateDevice(size_t size) {
941943
cl_int error = CL_SUCCESS;
942-
_allocate(_usmHelper.allocate_device(nullptr, size, 0, &error));
943-
if (error != CL_SUCCESS)
944-
detail::errHandler(error, "[CL_EXT] UsmDevice in cl extensions constructor failed");
944+
auto ptr = _usmHelper.allocate_device(nullptr, size, 0, &error);
945+
_check_error(size, ptr, error, "Device");
946+
_allocate(ptr);
945947
}
946948

947949
void freeMem() {
@@ -958,10 +960,19 @@ class UsmMemory {
958960

959961
private:
960962
void _allocate(void* ptr) {
961-
if (!ptr)
962-
throw std::runtime_error("[CL ext] Can not allocate nullptr for USM type.");
963963
_usm_pointer = std::make_shared<UsmHolder>(_usmHelper, ptr);
964964
}
965+
966+
void _check_error(size_t size, void* ptr, cl_int error, const char* usm_type) {
967+
if (ptr == nullptr || error != CL_SUCCESS) {
968+
std::stringstream sout;
969+
sout << "[CL ext] Can not allocate " << size << " bytes for USM " << usm_type << ". ptr: " << ptr << ", error: " << error << std::endl;
970+
if (ptr == nullptr)
971+
throw std::runtime_error(sout.str());
972+
else
973+
detail::errHandler(error, sout.str().c_str());
974+
}
975+
}
965976
};
966977

967978
/*

0 commit comments

Comments
 (0)