@@ -31,6 +31,8 @@ typedef cl_va_api_device_source_intel cl_device_source_intel;
31
31
typedef cl_va_api_device_set_intel cl_device_set_intel;
32
32
#endif
33
33
34
+ #include < sstream>
35
+
34
36
/* *******************************************
35
37
* cl_intel_required_subgroup_size extension *
36
38
*********************************************/
@@ -925,23 +927,23 @@ class UsmMemory {
925
927
926
928
void allocateHost (size_t size) {
927
929
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 );
931
933
}
932
934
933
935
void allocateShared (size_t size) {
934
936
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 );
938
940
}
939
941
940
942
void allocateDevice (size_t size) {
941
943
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 );
945
947
}
946
948
947
949
void freeMem () {
@@ -958,10 +960,19 @@ class UsmMemory {
958
960
959
961
private:
960
962
void _allocate (void * ptr) {
961
- if (!ptr)
962
- throw std::runtime_error (" [CL ext] Can not allocate nullptr for USM type." );
963
963
_usm_pointer = std::make_shared<UsmHolder>(_usmHelper, ptr);
964
964
}
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
+ }
965
976
};
966
977
967
978
/*
0 commit comments