From 365c72cf9ccf6cceaed4675975ce512eac496bb7 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Wed, 6 Dec 2023 16:27:42 +0000 Subject: [PATCH] Surround UR_CHECK_ERROR calls with a try/catch as they may throw an error. Format code. --- source/adapters/cuda/device.cpp | 511 ++++++++++++++++++------- source/adapters/cuda/event.cpp | 6 +- source/adapters/cuda/memory.cpp | 3 +- source/adapters/cuda/sampler.cpp | 3 +- source/adapters/hip/common.hpp | 3 +- source/adapters/hip/device.cpp | 404 ++++++++++++++----- source/adapters/hip/event.cpp | 9 +- source/adapters/hip/memory.cpp | 3 +- source/adapters/hip/memory.hpp | 2 +- source/adapters/hip/program.cpp | 4 +- source/adapters/hip/sampler.cpp | 3 +- source/adapters/level_zero/context.cpp | 3 +- source/adapters/level_zero/event.cpp | 9 +- source/adapters/level_zero/memory.cpp | 3 +- source/adapters/level_zero/queue.cpp | 5 +- source/adapters/level_zero/usm.cpp | 6 +- 16 files changed, 726 insertions(+), 251 deletions(-) diff --git a/source/adapters/cuda/device.cpp b/source/adapters/cuda/device.cpp index ab3f9bc8fd..16be504633 100644 --- a/source/adapters/cuda/device.cpp +++ b/source/adapters/cuda/device.cpp @@ -57,9 +57,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_MAX_COMPUTE_UNITS: { int ComputeUnits = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &ComputeUnits, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &ComputeUnits, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(ComputeUnits >= 0); return ReturnValue(static_cast(ComputeUnits)); } @@ -72,16 +76,28 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } ReturnSizes; int MaxX = 0, MaxY = 0, MaxZ = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxX, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxX, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxX > 0); - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxY, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxY, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxY > 0); - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxZ, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxZ, CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxZ > 0); ReturnSizes.Sizes[0] = size_t(MaxX); @@ -95,16 +111,28 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, size_t Sizes[MaxWorkItemDimensions]; } ReturnSizes; int MaxX = 0, MaxY = 0, MaxZ = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxX, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxX, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxX > 0); - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxY, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxY, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxY > 0); - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxZ, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxZ, CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxZ > 0); ReturnSizes.Sizes[0] = size_t(MaxX); @@ -115,9 +143,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_MAX_WORK_GROUP_SIZE: { int MaxWorkGroupSize = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxWorkGroupSize, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxWorkGroupSize, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxWorkGroupSize > 0); return ReturnValue(size_t(MaxWorkGroupSize)); @@ -167,12 +199,20 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_MAX_NUM_SUB_GROUPS: { // Number of sub-groups = max block size / warp size + possible remainder int MaxThreads = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxThreads, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxThreads, CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } int WarpSize = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &WarpSize, CU_DEVICE_ATTRIBUTE_WARP_SIZE, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &WarpSize, CU_DEVICE_ATTRIBUTE_WARP_SIZE, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } int MaxWarps = (MaxThreads + WarpSize - 1) / WarpSize; return ReturnValue(MaxWarps); } @@ -180,17 +220,26 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // Volta provides independent thread scheduling // TODO: Revisit for previous generation GPUs int Major = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } bool IFP = (Major >= 7); return ReturnValue(IFP); } case UR_DEVICE_INFO_ATOMIC_64: { int Major = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); - + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } bool Atomic64 = (Major >= 6) ? true : false; return ReturnValue(Atomic64); } @@ -204,8 +253,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_ATOMIC_MEMORY_SCOPE_CAPABILITIES: { int Major = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } uint64_t Capabilities = (Major >= 7) ? UR_MEMORY_SCOPE_CAPABILITY_FLAG_WORK_ITEM | UR_MEMORY_SCOPE_CAPABILITY_FLAG_SUB_GROUP | @@ -243,24 +297,36 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_BFLOAT16: { int Major = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); - + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } bool BFloat16 = (Major >= 8) ? true : false; return ReturnValue(BFloat16); } case UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: { // NVIDIA devices only support one sub-group size (the warp size) int WarpSize = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &WarpSize, CU_DEVICE_ATTRIBUTE_WARP_SIZE, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &WarpSize, CU_DEVICE_ATTRIBUTE_WARP_SIZE, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } size_t Sizes[1] = {static_cast(WarpSize)}; return ReturnValue(Sizes, 1); } case UR_DEVICE_INFO_MAX_CLOCK_FREQUENCY: { int ClockFreq = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &ClockFreq, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &ClockFreq, CU_DEVICE_ATTRIBUTE_CLOCK_RATE, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(ClockFreq > 0); return ReturnValue(static_cast(ClockFreq) / 1000u); } @@ -302,14 +368,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE2D_MAX_HEIGHT: { // Take the smaller of maximum surface and maximum texture height. int TexHeight = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_HEIGHT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexHeight > 0); int SurfHeight = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_HEIGHT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfHeight > 0); int Min = std::min(TexHeight, SurfHeight); @@ -319,14 +393,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE2D_MAX_WIDTH: { // Take the smaller of maximum surface and maximum texture width. int TexWidth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexWidth > 0); int SurfWidth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE2D_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfWidth > 0); int Min = std::min(TexWidth, SurfWidth); @@ -336,14 +418,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE3D_MAX_HEIGHT: { // Take the smaller of maximum surface and maximum texture height. int TexHeight = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &TexHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_HEIGHT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexHeight > 0); int SurfHeight = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &SurfHeight, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_HEIGHT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfHeight > 0); int Min = std::min(TexHeight, SurfHeight); @@ -353,14 +443,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE3D_MAX_WIDTH: { // Take the smaller of maximum surface and maximum texture width. int TexWidth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexWidth > 0); int SurfWidth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfWidth > 0); int Min = std::min(TexWidth, SurfWidth); @@ -370,14 +468,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE3D_MAX_DEPTH: { // Take the smaller of maximum surface and maximum texture depth. int TexDepth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &TexDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &TexDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE3D_DEPTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexDepth > 0); int SurfDepth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &SurfDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &SurfDepth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE3D_DEPTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfDepth > 0); int Min = std::min(TexDepth, SurfDepth); @@ -387,14 +493,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE_MAX_BUFFER_SIZE: { // Take the smaller of maximum surface and maximum texture width. int TexWidth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &TexWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE1D_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexWidth > 0); int SurfWidth = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &SurfWidth, CU_DEVICE_ATTRIBUTE_MAXIMUM_SURFACE1D_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfWidth > 0); int Min = std::min(TexWidth, SurfWidth); @@ -417,9 +531,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_MEM_BASE_ADDR_ALIGN: { int MemBaseAddrAlign = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute(&MemBaseAddrAlign, - CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute(&MemBaseAddrAlign, + CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } // Multiply by 8 as clGetDeviceInfo returns this value in bits MemBaseAddrAlign *= 8; return ReturnValue(MemBaseAddrAlign); @@ -462,8 +580,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_SIZE: { int CacheSize = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &CacheSize, CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &CacheSize, CU_DEVICE_ATTRIBUTE_L2_CACHE_SIZE, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(CacheSize > 0); // The L2 cache is global to the GPU. return ReturnValue(static_cast(CacheSize)); @@ -471,14 +593,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_GLOBAL_MEM_SIZE: { size_t Bytes = 0; // Runtime API has easy access to this value, driver API info is scarse. - UR_CHECK_ERROR(cuDeviceTotalMem(&Bytes, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceTotalMem(&Bytes, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(uint64_t{Bytes}); } case UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE: { int ConstantMemory = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &ConstantMemory, CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &ConstantMemory, CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(ConstantMemory > 0); return ReturnValue(static_cast(ConstantMemory)); @@ -506,9 +636,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT: { int ECCEnabled = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &ECCEnabled, CU_DEVICE_ATTRIBUTE_ECC_ENABLED, hDevice->get())); - + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &ECCEnabled, CU_DEVICE_ATTRIBUTE_ECC_ENABLED, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(ECCEnabled == 0 || ECCEnabled == 1); auto Result = static_cast(ECCEnabled); @@ -516,9 +649,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_HOST_UNIFIED_MEMORY: { int IsIntegrated = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &IsIntegrated, CU_DEVICE_ATTRIBUTE_INTEGRATED, hDevice->get())); - + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &IsIntegrated, CU_DEVICE_ATTRIBUTE_INTEGRATED, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(IsIntegrated == 0 || IsIntegrated == 1); auto result = static_cast(IsIntegrated); @@ -575,7 +711,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_NAME: { static constexpr size_t MaxDeviceNameLength = 256u; char Name[MaxDeviceNameLength]; - UR_CHECK_ERROR(cuDeviceGetName(Name, MaxDeviceNameLength, hDevice->get())); + try { + UR_CHECK_ERROR( + cuDeviceGetName(Name, MaxDeviceNameLength, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(Name, strlen(Name) + 1); } case UR_DEVICE_INFO_VENDOR: { @@ -594,12 +735,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_VERSION: { std::stringstream SS; int Major; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } SS << Major; int Minor; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } SS << "." << Minor; return ReturnValue(SS.str().c_str()); } @@ -617,10 +768,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, int Major = 0; int Minor = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } if ((Major >= 6) || ((Major == 5) && (Minor >= 3))) { SupportedExtensions += "cl_khr_fp16 "; @@ -801,21 +963,33 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_GLOBAL_MEM_FREE: { size_t FreeMemory = 0; size_t TotalMemory = 0; - UR_CHECK_ERROR(cuMemGetInfo(&FreeMemory, &TotalMemory)); + try { + UR_CHECK_ERROR(cuMemGetInfo(&FreeMemory, &TotalMemory)); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(FreeMemory); } case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: { int Value = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Value, CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Value, CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(Value > 0); // Convert kilohertz to megahertz when returning. return ReturnValue(Value / 1000); } case UR_DEVICE_INFO_MEMORY_BUS_WIDTH: { int Value = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Value, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Value, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(Value > 0); return ReturnValue(Value); } @@ -841,30 +1015,46 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_IMAGE_PITCH_ALIGN_EXP: { int32_t tex_pitch_align = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &tex_pitch_align, CU_DEVICE_ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &tex_pitch_align, CU_DEVICE_ATTRIBUTE_TEXTURE_PITCH_ALIGNMENT, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(tex_pitch_align); } case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_WIDTH_EXP: { int32_t tex_max_linear_width = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &tex_max_linear_width, - CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &tex_max_linear_width, + CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_WIDTH, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(tex_max_linear_width); } case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_HEIGHT_EXP: { int32_t tex_max_linear_height = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &tex_max_linear_height, - CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &tex_max_linear_height, + CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_HEIGHT, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(tex_max_linear_height); } case UR_DEVICE_INFO_MAX_IMAGE_LINEAR_PITCH_EXP: { int32_t tex_max_linear_pitch = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &tex_max_linear_pitch, - CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &tex_max_linear_pitch, + CU_DEVICE_ATTRIBUTE_MAXIMUM_TEXTURE2D_LINEAR_PITCH, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(tex_max_linear_pitch); } case UR_DEVICE_INFO_MIPMAP_SUPPORT_EXP: { @@ -902,30 +1092,48 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_DEVICE_ID: { int Value = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Value, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Value, CU_DEVICE_ATTRIBUTE_PCI_DEVICE_ID, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(Value > 0); return ReturnValue(Value); } case UR_DEVICE_INFO_UUID: { CUuuid UUID; + try { #if (CUDA_VERSION >= 11040) - UR_CHECK_ERROR(cuDeviceGetUuid_v2(&UUID, hDevice->get())); + UR_CHECK_ERROR(cuDeviceGetUuid_v2(&UUID, hDevice->get())); #else - UR_CHECK_ERROR(cuDeviceGetUuid(&UUID, hDevice->get())); + UR_CHECK_ERROR(cuDeviceGetUuid(&UUID, hDevice->get())); #endif + } catch (ur_result_t Error) { + return Error; + } std::array Name; std::copy(UUID.bytes, UUID.bytes + 16, Name.begin()); return ReturnValue(Name.data(), 16); } case UR_DEVICE_INFO_MAX_MEMORY_BANDWIDTH: { int Major = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Major, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } int Minor = 0; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &Minor, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } // Some specific devices seem to need special handling. See reference // https://github.com/jeffhammond/HPCInfo/blob/master/cuda/gpu-detect.cu @@ -938,18 +1146,26 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } else if (IsOrinAGX) { MemoryClockKHz = 3200000; } else { - UR_CHECK_ERROR(cuDeviceGetAttribute(&MemoryClockKHz, - CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MemoryClockKHz, CU_DEVICE_ATTRIBUTE_MEMORY_CLOCK_RATE, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } } int MemoryBusWidth = 0; if (IsOrinAGX) { MemoryBusWidth = 256; } else { - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MemoryBusWidth, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MemoryBusWidth, CU_DEVICE_ATTRIBUTE_GLOBAL_MEMORY_BUS_WIDTH, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } } uint32_t MemoryBandwidth = MemoryClockKHz * MemoryBusWidth * 250; @@ -987,9 +1203,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // Note: This number is shared by all thread blocks simultaneously resident // on a multiprocessor. int MaxRegisters{-1}; - UR_CHECK_ERROR(cuDeviceGetAttribute( - &MaxRegisters, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK, - hDevice->get())); + try { + UR_CHECK_ERROR(cuDeviceGetAttribute( + &MaxRegisters, CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxRegisters > 0); @@ -1002,8 +1222,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_PCI_ADDRESS: { constexpr size_t AddressBufferSize = 13; char AddressBuffer[AddressBufferSize]; - UR_CHECK_ERROR( - cuDeviceGetPCIBusId(AddressBuffer, AddressBufferSize, hDevice->get())); + + try { + UR_CHECK_ERROR(cuDeviceGetPCIBusId(AddressBuffer, AddressBufferSize, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + // CUDA API (8.x - 12.1) guarantees 12 bytes + \0 are written assert(strnlen(AddressBuffer, AddressBufferSize) != 12); return ReturnValue(AddressBuffer, @@ -1172,8 +1398,17 @@ ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(ur_device_handle_t hDevice, ScopedContext Active(hDevice->getContext()); if (pDeviceTimestamp) { - UR_CHECK_ERROR(cuEventCreate(&Event, CU_EVENT_DEFAULT)); - UR_CHECK_ERROR(cuEventRecord(Event, 0)); + try { + UR_CHECK_ERROR(cuEventCreate(&Event, CU_EVENT_DEFAULT)); + } catch (ur_result_t Error) { + return Error; + } + + try { + UR_CHECK_ERROR(cuEventRecord(Event, 0)); + } catch (ur_result_t Error) { + return Error; + } } if (pHostTimestamp) { @@ -1184,7 +1419,11 @@ ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(ur_device_handle_t hDevice, } if (pDeviceTimestamp) { - UR_CHECK_ERROR(cuEventSynchronize(Event)); + try { + UR_CHECK_ERROR(cuEventSynchronize(Event)); + } catch (ur_result_t Error) { + return Error; + } *pDeviceTimestamp = hDevice->getElapsedTime(Event); } diff --git a/source/adapters/cuda/event.cpp b/source/adapters/cuda/event.cpp index 1ea9c0d37d..4a46225ae2 100644 --- a/source/adapters/cuda/event.cpp +++ b/source/adapters/cuda/event.cpp @@ -113,7 +113,8 @@ ur_result_t ur_event_handle_t_::record() { try { EventID = Queue->getNextEventID(); - assert(EventID == 0 && "Unrecoverable program state reached in event identifier overflow."); + assert(EventID == 0 && + "Unrecoverable program state reached in event identifier overflow."); UR_CHECK_ERROR(cuEventRecord(EvEnd, Stream)); } catch (ur_result_t error) { Result = error; @@ -245,7 +246,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - assert(hEvent->getReferenceCount() == 0 && "Unrecoverable program state reached in urEventRetain."); + assert(hEvent->getReferenceCount() == 0 && + "Unrecoverable program state reached in urEventRetain."); // decrement ref count. If it is 0, delete the event. if (hEvent->decrementReferenceCount() == 0) { diff --git a/source/adapters/cuda/memory.cpp b/source/adapters/cuda/memory.cpp index 184680d9ac..f2e07e7870 100644 --- a/source/adapters/cuda/memory.cpp +++ b/source/adapters/cuda/memory.cpp @@ -148,7 +148,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemRelease(ur_mem_handle_t hMem) { // error for which it is unclear if the function that reported it succeeded // or not. Either way, the state of the program is compromised and likely // unrecoverable. - assert(Result != UR_RESULT_SUCCESS && "Unrecoverable program state reached in urMemRelease."); + assert(Result != UR_RESULT_SUCCESS && + "Unrecoverable program state reached in urMemRelease."); return UR_RESULT_SUCCESS; } diff --git a/source/adapters/cuda/sampler.cpp b/source/adapters/cuda/sampler.cpp index dd9dcfc028..873bbc6e56 100644 --- a/source/adapters/cuda/sampler.cpp +++ b/source/adapters/cuda/sampler.cpp @@ -83,7 +83,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerRelease(ur_sampler_handle_t hSampler) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - assert (hSampler->getReferenceCount() == 0 && "Reference count overflow detected in urSamplerRelease."); + assert(hSampler->getReferenceCount() == 0 && + "Reference count overflow detected in urSamplerRelease."); // decrement ref count. If it is 0, delete the sampler. if (hSampler->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/common.hpp b/source/adapters/hip/common.hpp index fdbafe89e9..3435729bac 100644 --- a/source/adapters/hip/common.hpp +++ b/source/adapters/hip/common.hpp @@ -189,8 +189,7 @@ template class ReleaseGuard { // HIP error for which it is unclear if the function that reported it // succeeded or not. Either way, the state of the program is compromised // and likely unrecoverable. - assert( - !"Unrecoverable program state reached in piMemRelease"); + assert(!"Unrecoverable program state reached in piMemRelease"); } } } diff --git a/source/adapters/hip/device.cpp b/source/adapters/hip/device.cpp index 72720a814a..6946cb7957 100644 --- a/source/adapters/hip/device.cpp +++ b/source/adapters/hip/device.cpp @@ -45,8 +45,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_MAX_COMPUTE_UNITS: { int ComputeUnits = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &ComputeUnits, hipDeviceAttributeMultiprocessorCount, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &ComputeUnits, hipDeviceAttributeMultiprocessorCount, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(ComputeUnits > 0); return ReturnValue(static_cast(ComputeUnits)); } @@ -59,16 +64,28 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } return_sizes; int MaxX = 0, MaxY = 0, MaxZ = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxX, hipDeviceAttributeMaxBlockDimX, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &MaxX, hipDeviceAttributeMaxBlockDimX, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxX > 0); - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxY, hipDeviceAttributeMaxBlockDimY, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &MaxY, hipDeviceAttributeMaxBlockDimY, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxY > 0); - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxZ, hipDeviceAttributeMaxBlockDimZ, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &MaxZ, hipDeviceAttributeMaxBlockDimZ, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxZ > 0); return_sizes.sizes[0] = size_t(MaxX); @@ -83,16 +100,28 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } return_sizes; int MaxX = 0, MaxY = 0, MaxZ = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxX, hipDeviceAttributeMaxGridDimX, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxX, hipDeviceAttributeMaxGridDimX, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxX > 0); - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxY, hipDeviceAttributeMaxGridDimY, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxY, hipDeviceAttributeMaxGridDimY, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxY > 0); - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxZ, hipDeviceAttributeMaxGridDimZ, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxZ, hipDeviceAttributeMaxGridDimZ, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxZ > 0); return_sizes.sizes[0] = size_t(MaxX); @@ -103,9 +132,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_MAX_WORK_GROUP_SIZE: { int MaxWorkGroupSize = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxWorkGroupSize, - hipDeviceAttributeMaxThreadsPerBlock, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute(&MaxWorkGroupSize, + hipDeviceAttributeMaxThreadsPerBlock, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxWorkGroupSize > 0); @@ -156,11 +189,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_MAX_NUM_SUB_GROUPS: { // Number of sub-groups = max block size / warp size + possible remainder int MaxThreads = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &MaxThreads, hipDeviceAttributeMaxThreadsPerBlock, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &MaxThreads, hipDeviceAttributeMaxThreadsPerBlock, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + int WarpSize = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute(&WarpSize, hipDeviceAttributeWarpSize, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &WarpSize, hipDeviceAttributeWarpSize, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + int MaxWarps = (MaxThreads + WarpSize - 1) / WarpSize; return ReturnValue(MaxWarps); } @@ -168,22 +211,37 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // Volta provides independent thread scheduling // TODO: Revisit for previous generation GPUs int Major = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &Major, hipDeviceAttributeComputeCapabilityMajor, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &Major, hipDeviceAttributeComputeCapabilityMajor, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + bool IFP = (Major >= 7); return ReturnValue(IFP); } case UR_DEVICE_INFO_SUB_GROUP_SIZES_INTEL: { int WarpSize = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute(&WarpSize, hipDeviceAttributeWarpSize, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &WarpSize, hipDeviceAttributeWarpSize, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + size_t Sizes[1] = {static_cast(WarpSize)}; return ReturnValue(Sizes, 1); } case UR_DEVICE_INFO_MAX_CLOCK_FREQUENCY: { int ClockFreq = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &ClockFreq, hipDeviceAttributeClockRate, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &ClockFreq, hipDeviceAttributeClockRate, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + assert(ClockFreq > 0); return ReturnValue(static_cast(ClockFreq) / 1000u); } @@ -199,7 +257,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // CL_DEVICE_TYPE_CUSTOM. size_t Global = 0; - UR_CHECK_ERROR(hipDeviceTotalMem(&Global, hDevice->get())); + + try { + UR_CHECK_ERROR(hipDeviceTotalMem(&Global, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } auto QuarterGlobal = static_cast(Global / 4u); @@ -232,12 +295,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE2D_MAX_HEIGHT: { // Take the smaller of maximum surface and maximum texture height. int TexHeight = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &TexHeight, hipDeviceAttributeMaxTexture2DHeight, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &TexHeight, hipDeviceAttributeMaxTexture2DHeight, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexHeight > 0); + int SurfHeight = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &SurfHeight, hipDeviceAttributeMaxTexture2DHeight, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &SurfHeight, hipDeviceAttributeMaxTexture2DHeight, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfHeight > 0); int Min = std::min(TexHeight, SurfHeight); @@ -247,12 +319,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE2D_MAX_WIDTH: { // Take the smaller of maximum surface and maximum texture width. int TexWidth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &TexWidth, hipDeviceAttributeMaxTexture2DWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &TexWidth, hipDeviceAttributeMaxTexture2DWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + assert(TexWidth > 0); int SurfWidth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &SurfWidth, hipDeviceAttributeMaxTexture2DWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &SurfWidth, hipDeviceAttributeMaxTexture2DWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + assert(SurfWidth > 0); int Min = std::min(TexWidth, SurfWidth); @@ -261,12 +343,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE3D_MAX_HEIGHT: { // Take the smaller of maximum surface and maximum texture height. int TexHeight = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &TexHeight, hipDeviceAttributeMaxTexture3DHeight, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &TexHeight, hipDeviceAttributeMaxTexture3DHeight, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexHeight > 0); + int SurfHeight = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &SurfHeight, hipDeviceAttributeMaxTexture3DHeight, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &SurfHeight, hipDeviceAttributeMaxTexture3DHeight, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } + assert(SurfHeight > 0); int Min = std::min(TexHeight, SurfHeight); @@ -276,12 +368,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE3D_MAX_WIDTH: { // Take the smaller of maximum surface and maximum texture width. int TexWidth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &TexWidth, hipDeviceAttributeMaxTexture3DWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &TexWidth, hipDeviceAttributeMaxTexture3DWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexWidth > 0); + int SurfWidth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &SurfWidth, hipDeviceAttributeMaxTexture3DWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &SurfWidth, hipDeviceAttributeMaxTexture3DWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfWidth > 0); int Min = std::min(TexWidth, SurfWidth); @@ -291,12 +392,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE3D_MAX_DEPTH: { // Take the smaller of maximum surface and maximum texture depth. int TexDepth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &TexDepth, hipDeviceAttributeMaxTexture3DDepth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &TexDepth, hipDeviceAttributeMaxTexture3DDepth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexDepth > 0); + int SurfDepth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &SurfDepth, hipDeviceAttributeMaxTexture3DDepth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &SurfDepth, hipDeviceAttributeMaxTexture3DDepth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfDepth > 0); int Min = std::min(TexDepth, SurfDepth); @@ -306,12 +416,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_IMAGE_MAX_BUFFER_SIZE: { // Take the smaller of maximum surface and maximum texture width. int TexWidth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &TexWidth, hipDeviceAttributeMaxTexture1DWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &TexWidth, hipDeviceAttributeMaxTexture1DWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(TexWidth > 0); + int SurfWidth = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &SurfWidth, hipDeviceAttributeMaxTexture1DWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &SurfWidth, hipDeviceAttributeMaxTexture1DWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(SurfWidth > 0); int Min = std::min(TexWidth, SurfWidth); @@ -333,8 +452,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_MEM_BASE_ADDR_ALIGN: { int MemBaseAddrAlign = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &MemBaseAddrAlign, hipDeviceAttributeTextureAlignment, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute(&MemBaseAddrAlign, + hipDeviceAttributeTextureAlignment, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } // Multiply by 8 as clGetDeviceInfo returns this value in bits MemBaseAddrAlign *= 8; return ReturnValue(MemBaseAddrAlign); @@ -373,8 +497,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_GLOBAL_MEM_CACHE_SIZE: { int CacheSize = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &CacheSize, hipDeviceAttributeL2CacheSize, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &CacheSize, hipDeviceAttributeL2CacheSize, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(CacheSize > 0); // The L2 cache is global to the GPU. return ReturnValue(static_cast(CacheSize)); @@ -382,7 +510,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_GLOBAL_MEM_SIZE: { size_t Bytes = 0; // Runtime API has easy access to this value, driver API info is scarse. - UR_CHECK_ERROR(hipDeviceTotalMem(&Bytes, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceTotalMem(&Bytes, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(uint64_t{Bytes}); } case UR_DEVICE_INFO_MAX_CONSTANT_BUFFER_SIZE: { @@ -392,9 +524,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // memory on AMD GPU may be larger than what can fit in the positive part // of a signed integer, so use an unsigned integer and cast the pointer to // int*. - UR_CHECK_ERROR(hipDeviceGetAttribute(&ConstantMemory, - hipDeviceAttributeTotalConstantMemory, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &ConstantMemory, hipDeviceAttributeTotalConstantMemory, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(ConstantMemory > 0); return ReturnValue(static_cast(ConstantMemory)); @@ -413,16 +549,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // HIP has its own definition of "local memory", which maps to OpenCL's // "private memory". int LocalMemSize = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &LocalMemSize, hipDeviceAttributeMaxSharedMemoryPerBlock, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &LocalMemSize, hipDeviceAttributeMaxSharedMemoryPerBlock, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(LocalMemSize > 0); return ReturnValue(static_cast(LocalMemSize)); } case UR_DEVICE_INFO_ERROR_CORRECTION_SUPPORT: { int EccEnabled = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &EccEnabled, hipDeviceAttributeEccEnabled, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &EccEnabled, hipDeviceAttributeEccEnabled, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(EccEnabled == 0 || EccEnabled == 1); @@ -431,8 +575,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_HOST_UNIFIED_MEMORY: { int IsIntegrated = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &IsIntegrated, hipDeviceAttributeIntegrated, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &IsIntegrated, hipDeviceAttributeIntegrated, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(IsIntegrated == 0 || IsIntegrated == 1); @@ -487,13 +635,21 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_NAME: { static constexpr size_t MAX_DEVICE_NAME_LENGTH = 256u; char Name[MAX_DEVICE_NAME_LENGTH]; - UR_CHECK_ERROR( - hipDeviceGetName(Name, MAX_DEVICE_NAME_LENGTH, hDevice->get())); + try { + UR_CHECK_ERROR( + hipDeviceGetName(Name, MAX_DEVICE_NAME_LENGTH, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } // On AMD GPUs hipDeviceGetName returns an empty string, so return the arch // name instead, this is also what AMD OpenCL devices return. if (strlen(Name) == 0) { hipDeviceProp_t Props; - UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + try { + UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(Props.gcnArchName, strlen(Props.gcnArchName) + 1); } @@ -504,7 +660,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_DRIVER_VERSION: { std::string Version; - UR_CHECK_ERROR(getHipVersionString(Version)); + try { + UR_CHECK_ERROR(getHipVersionString(Version)); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(Version.c_str()); } case UR_DEVICE_INFO_PROFILE: { @@ -517,7 +677,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, std::stringstream S; hipDeviceProp_t Props; - UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + try { + UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } #if defined(__HIP_PLATFORM_NVIDIA__) S << Props.major << "." << Props.minor; #elif defined(__HIP_PLATFORM_AMD__) @@ -540,7 +704,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, SupportedExtensions += " "; hipDeviceProp_t Props; - UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + try { + UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } if (Props.arch.hasDoubles) { SupportedExtensions += "cl_khr_fp64 "; @@ -693,14 +861,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION: { int Major = 0, Minor = 0; - UR_CHECK_ERROR(hipDeviceComputeCapability(&Major, &Minor, hDevice->get())); + try { + UR_CHECK_ERROR( + hipDeviceComputeCapability(&Major, &Minor, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } std::string Result = std::to_string(Major) + "." + std::to_string(Minor); return ReturnValue(Result.c_str()); } case UR_DEVICE_INFO_ATOMIC_64: { hipDeviceProp_t Props; - UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + try { + UR_CHECK_ERROR(hipGetDeviceProperties(&Props, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(Props.arch.hasGlobalInt64Atomics && Props.arch.hasSharedInt64Atomics); } @@ -708,14 +885,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_GLOBAL_MEM_FREE: { size_t FreeMemory = 0; size_t TotalMemory = 0; - UR_CHECK_ERROR(hipMemGetInfo(&FreeMemory, &TotalMemory)); + try { + UR_CHECK_ERROR(hipMemGetInfo(&FreeMemory, &TotalMemory)); + } catch (ur_result_t Error) { + return Error; + } return ReturnValue(FreeMemory); } case UR_DEVICE_INFO_MEMORY_CLOCK_RATE: { int Value = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &Value, hipDeviceAttributeMemoryClockRate, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &Value, hipDeviceAttributeMemoryClockRate, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(Value > 0); // Convert kilohertz to megahertz when returning. return ReturnValue(Value / 1000); @@ -723,8 +908,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_MEMORY_BUS_WIDTH: { int Value = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &Value, hipDeviceAttributeMemoryBusWidth, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &Value, hipDeviceAttributeMemoryBusWidth, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(Value > 0); return ReturnValue(Value); } @@ -763,8 +952,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, } case UR_DEVICE_INFO_DEVICE_ID: { int Value = 0; - UR_CHECK_ERROR(hipDeviceGetAttribute(&Value, hipDeviceAttributePciDeviceId, - hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &Value, hipDeviceAttributePciDeviceId, hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(Value > 0); return ReturnValue(Value); } @@ -785,9 +978,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, // Note: This number is shared by all thread blocks simultaneously resident // on a multiprocessor. int MaxRegisters{-1}; - UR_CHECK_ERROR(hipDeviceGetAttribute( - &MaxRegisters, hipDeviceAttributeMaxRegistersPerBlock, hDevice->get())); - + try { + UR_CHECK_ERROR(hipDeviceGetAttribute( + &MaxRegisters, hipDeviceAttributeMaxRegistersPerBlock, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } assert(MaxRegisters > 0); return ReturnValue(static_cast(MaxRegisters)); @@ -799,8 +996,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice, case UR_DEVICE_INFO_PCI_ADDRESS: { constexpr size_t AddressBufferSize = 13; char AddressBuffer[AddressBufferSize]; - UR_CHECK_ERROR( - hipDeviceGetPCIBusId(AddressBuffer, AddressBufferSize, hDevice->get())); + try { + UR_CHECK_ERROR(hipDeviceGetPCIBusId(AddressBuffer, AddressBufferSize, + hDevice->get())); + } catch (ur_result_t Error) { + return Error; + } // A typical PCI address is 12 bytes + \0: "1234:67:90.2", but the HIP API // is not guaranteed to use this format. In practice, it uses this format, // at least in 5.3-5.5. To be on the safe side, we make sure the terminating @@ -944,12 +1145,31 @@ ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(ur_device_handle_t hDevice, ScopedContext Active(hDevice); if (pDeviceTimestamp) { - UR_CHECK_ERROR(hipEventCreateWithFlags(&Event, hipEventDefault)); - UR_CHECK_ERROR(hipEventRecord(Event)); - UR_CHECK_ERROR(hipEventSynchronize(Event)); + try { + UR_CHECK_ERROR(hipEventCreateWithFlags(&Event, hipEventDefault)); + } catch (ur_result_t Error) { + return Error; + } + + try { + UR_CHECK_ERROR(hipEventRecord(Event)); + } catch (ur_result_t Error) { + return Error; + } + + try { + UR_CHECK_ERROR(hipEventSynchronize(Event)); + } catch (ur_result_t Error) { + return Error; + } + float ElapsedTime = 0.0f; - UR_CHECK_ERROR(hipEventElapsedTime(&ElapsedTime, - ur_platform_handle_t_::EvBase, Event)); + try { + UR_CHECK_ERROR(hipEventElapsedTime(&ElapsedTime, + ur_platform_handle_t_::EvBase, Event)); + } catch (ur_result_t Error) { + return Error; + } *pDeviceTimestamp = (uint64_t)(ElapsedTime * (double)1e6); } diff --git a/source/adapters/hip/event.cpp b/source/adapters/hip/event.cpp index bec0934382..00dab2d0d9 100644 --- a/source/adapters/hip/event.cpp +++ b/source/adapters/hip/event.cpp @@ -141,7 +141,8 @@ ur_result_t ur_event_handle_t_::record() { try { EventId = Queue->getNextEventId(); - assert (EventId == 0 && "Unrecoverable program state reached in event identifier overflow."); + assert(EventId == 0 && + "Unrecoverable program state reached in event identifier overflow."); UR_CHECK_ERROR(hipEventRecord(EvEnd, Stream)); Result = UR_RESULT_SUCCESS; } catch (ur_result_t Error) { @@ -276,7 +277,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventSetCallback(ur_event_handle_t, UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { const auto RefCount = hEvent->incrementReferenceCount(); - assert(RefCount == 0 && "Reference count overflow detected in urEventRetain."); + assert(RefCount == 0 && + "Reference count overflow detected in urEventRetain."); return UR_RESULT_SUCCESS; } @@ -284,7 +286,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventRetain(ur_event_handle_t hEvent) { UR_APIEXPORT ur_result_t UR_APICALL urEventRelease(ur_event_handle_t hEvent) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - assert(hEvent->getReferenceCount() == 0 && "Reference count overflow detected in urEventRelease."); + assert(hEvent->getReferenceCount() == 0 && + "Reference count overflow detected in urEventRelease."); // decrement ref count. If it is 0, delete the event. if (hEvent->decrementReferenceCount() == 0) { diff --git a/source/adapters/hip/memory.cpp b/source/adapters/hip/memory.cpp index 827dcb287f..93e2212d7c 100644 --- a/source/adapters/hip/memory.cpp +++ b/source/adapters/hip/memory.cpp @@ -245,7 +245,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemGetInfo(ur_mem_handle_t hMemory, throw UR_RESULT_ERROR_UNSUPPORTED_FEATURE; #else HIP_ARRAY3D_DESCRIPTOR ArrayDescriptor; - UR_CHECK_ERROR(hipArray3DGetDescriptor(&ArrayDescriptor, Mem.Array)); + UR_CHECK_ERROR( + hipArray3DGetDescriptor(&ArrayDescriptor, Mem.getArray(Device))); int PixelSize = 0; UR_RETURN_ON_FAILURE( imageElementByteSize(ArrayDescriptor.Format, &PixelSize)); diff --git a/source/adapters/hip/memory.hpp b/source/adapters/hip/memory.hpp index 7707794b3c..c0b1afa22b 100644 --- a/source/adapters/hip/memory.hpp +++ b/source/adapters/hip/memory.hpp @@ -242,7 +242,7 @@ struct SurfaceMem { break; default: // urMemImageCreate given unsupported image_channel_data_type - detail::ur::die("Bad image format given to ur_image_ constructor"); + assert(!"Bad image format given to ur_image_ constructor"); } } diff --git a/source/adapters/hip/program.cpp b/source/adapters/hip/program.cpp index 874b144262..728765d762 100644 --- a/source/adapters/hip/program.cpp +++ b/source/adapters/hip/program.cpp @@ -224,8 +224,8 @@ ur_result_t getKernelNames(ur_program_handle_t) { UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL(ur_context_handle_t, const void *, size_t, const ur_program_properties_t *, ur_program_handle_t *) { - detail::ur::die("urProgramCreateWithIL not implemented for HIP adapter" - " please use urProgramCreateWithBinary instead"); + assert(!"urProgramCreateWithIL not implemented for HIP adapter" + " please use urProgramCreateWithBinary instead"); return UR_RESULT_ERROR_UNSUPPORTED_FEATURE; } diff --git a/source/adapters/hip/sampler.cpp b/source/adapters/hip/sampler.cpp index d307fe7616..a948f08541 100644 --- a/source/adapters/hip/sampler.cpp +++ b/source/adapters/hip/sampler.cpp @@ -68,7 +68,8 @@ ur_result_t urSamplerRetain(ur_sampler_handle_t hSampler) { ur_result_t urSamplerRelease(ur_sampler_handle_t hSampler) { // double delete or someone is messing with the ref count. // either way, cannot safely proceed. - assert(hSampler->getReferenceCount() == 0 && "Reference count overflow detected in urSamplerRelease."); + assert(hSampler->getReferenceCount() == 0 && + "Reference count overflow detected in urSamplerRelease."); // decrement ref count. If it is 0, delete the sampler. if (hSampler->decrementReferenceCount() == 0) { diff --git a/source/adapters/level_zero/context.cpp b/source/adapters/level_zero/context.cpp index 92afb4c4c3..de182882e8 100644 --- a/source/adapters/level_zero/context.cpp +++ b/source/adapters/level_zero/context.cpp @@ -566,7 +566,8 @@ ur_context_handle_t_::decrementUnreleasedEventsInPool(ur_event_handle_t Event) { getZeEventPoolCache(Event->isHostVisible(), Event->isProfilingEnabled()); // Put the empty pool to the cache of the pools. - assert(NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0 && "Invalid event release: event pool doesn't have unreleased events"); + assert(NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0 && + "Invalid event release: event pool doesn't have unreleased events"); if (--NumEventsUnreleasedInEventPool[Event->ZeEventPool] == 0) { if (ZePoolCache->front() != Event->ZeEventPool) { ZePoolCache->push_back(Event->ZeEventPool); diff --git a/source/adapters/level_zero/event.cpp b/source/adapters/level_zero/event.cpp index 1b25bf5940..d3a92e6762 100644 --- a/source/adapters/level_zero/event.cpp +++ b/source/adapters/level_zero/event.cpp @@ -585,7 +585,8 @@ ur_result_t ur_event_handle_t_::getOrCreateHostVisibleEvent( this->Mutex); if (!HostVisibleEvent) { - assert(UrQueue->ZeEventsScope != OnDemandHostVisibleProxy && "getOrCreateHostVisibleEvent: missing host-visible event"); + assert(UrQueue->ZeEventsScope != OnDemandHostVisibleProxy && + "getOrCreateHostVisibleEvent: missing host-visible event"); // Submit the command(s) signalling the proxy event to the queue. // We have to first submit a wait for the device-only event for which this @@ -631,7 +632,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait( // ur_event_handle_t_ *Event = ur_cast(EventWaitList[I]); - assert(!Event->hasExternalRefs() && "urEventsWait must not be called for an internal event"); + assert(!Event->hasExternalRefs() && + "urEventsWait must not be called for an internal event"); ze_event_handle_t ZeHostVisibleEvent; if (auto Res = Event->getOrCreateHostVisibleEvent(ZeHostVisibleEvent)) @@ -656,7 +658,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait( ur_cast(EventWaitList[I]); { std::shared_lock EventLock(Event->Mutex); - assert(!Event->hasExternalRefs() && "urEventWait must not be called for an internal event"); + assert(!Event->hasExternalRefs() && + "urEventWait must not be called for an internal event"); if (!Event->Completed) { auto HostVisibleEvent = Event->HostVisibleEvent; diff --git a/source/adapters/level_zero/memory.cpp b/source/adapters/level_zero/memory.cpp index 5676bc4b72..a2e1c39841 100644 --- a/source/adapters/level_zero/memory.cpp +++ b/source/adapters/level_zero/memory.cpp @@ -2176,7 +2176,8 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode, // If some prior access invalidated this allocation then make it valid again. if (!Allocation.Valid) { // LastDeviceWithValidAllocation should always have valid allocation. - assert(Device == LastDeviceWithValidAllocation && "getZeHandle: last used allocation is not valid."); + assert(Device == LastDeviceWithValidAllocation && + "getZeHandle: last used allocation is not valid."); // For write-only access the allocation contents is not going to be used. // So don't do anything to make it "valid". diff --git a/source/adapters/level_zero/queue.cpp b/source/adapters/level_zero/queue.cpp index bd99b5945a..6577fe8c15 100644 --- a/source/adapters/level_zero/queue.cpp +++ b/source/adapters/level_zero/queue.cpp @@ -1093,8 +1093,9 @@ ur_queue_handle_t_::executeCommandList(ur_command_list_ptr_t CommandList, (!ZeCommandListBatchConfig.dynamic() || !CurrentlyEmpty)) { assert((hasOpenCommandList(UseCopyEngine) && - CommandBatch.OpenCommandList != CommandList) && "executeCommandList: OpenCommandList should be equal to" - "null or CommandList"); + CommandBatch.OpenCommandList != CommandList) && + "executeCommandList: OpenCommandList should be equal to" + "null or CommandList"); if (CommandList->second.size() < CommandBatch.QueueBatchSize) { CommandBatch.OpenCommandList = CommandList; diff --git a/source/adapters/level_zero/usm.cpp b/source/adapters/level_zero/usm.cpp index 883ff32b8c..97c36cda16 100644 --- a/source/adapters/level_zero/usm.cpp +++ b/source/adapters/level_zero/usm.cpp @@ -948,7 +948,8 @@ ur_result_t ZeMemFreeHelper(ur_context_handle_t Context, void *Ptr) { if (IndirectAccessTrackingEnabled) { ContextsLock.lock(); auto It = Context->MemAllocs.find(Ptr); - assert(It == std::end(Context->MemAllocs) && "All memory allocations must be tracked!"); + assert(It == std::end(Context->MemAllocs) && + "All memory allocations must be tracked!"); if (!It->second.RefCount.decrementAndTest()) { // Memory can't be deallocated yet. return UR_RESULT_SUCCESS; @@ -993,7 +994,8 @@ ur_result_t USMFreeHelper(ur_context_handle_t Context, void *Ptr, if (IndirectAccessTrackingEnabled) { auto It = Context->MemAllocs.find(Ptr); - assert(It == std::end(Context->MemAllocs) && "All memory allocations must be tracked!"); + assert(It == std::end(Context->MemAllocs) && + "All memory allocations must be tracked!"); if (!It->second.RefCount.decrementAndTest()) { // Memory can't be deallocated yet. return UR_RESULT_SUCCESS;