Skip to content

Commit d45f09e

Browse files
wenju-hepbalcer
authored andcommitted
[NFC] Add utility function ur_unreachable to simplify code
1 parent 79c28d0 commit d45f09e

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

source/adapters/cuda/usm.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
227227
return ReturnValue(UR_USM_TYPE_HOST);
228228
}
229229
// should never get here
230-
#ifdef _MSC_VER
231-
__assume(0);
232-
#else
233-
__builtin_unreachable();
234-
#endif
230+
ur_unreachable();
235231
}
236232
case UR_USM_ALLOC_INFO_BASE_PTR: {
237233
#if CUDA_VERSION >= 10020

source/adapters/hip/usm.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
190190
return ReturnValue(UR_USM_TYPE_HOST);
191191
}
192192
// should never get here
193-
#ifdef _MSC_VER
194-
__assume(0);
195-
#else
196-
__builtin_unreachable();
197-
#endif
198-
return ReturnValue(UR_USM_TYPE_UNKNOWN);
193+
ur_unreachable();
199194
}
200195
case UR_USM_ALLOC_INFO_DEVICE: {
201196
// get device index associated with this pointer

source/adapters/native_cpu/kernel.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include "ur_api.h"
12+
#include "ur_util.hpp"
1213

1314
#include "common.hpp"
1415
#include "kernel.hpp"
@@ -172,11 +173,7 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
172173
return ReturnValue(0);
173174
}
174175
case UR_KERNEL_SUB_GROUP_INFO_FORCE_UINT32: {
175-
#ifdef _MSC_VER
176-
__assume(0);
177-
#else
178-
__builtin_unreachable();
179-
#endif
176+
ur_unreachable();
180177
}
181178
}
182179
DIE_NO_IMPLEMENTATION;

source/common/ur_util.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,12 @@ inline ur_result_t exceptionToResult(std::exception_ptr eptr) {
298298

299299
template <class> inline constexpr bool ur_always_false_t = false;
300300

301+
[[noreturn]] inline void ur_unreachable() {
302+
#ifdef _MSC_VER
303+
__assume(0);
304+
#else
305+
__builtin_unreachable();
306+
#endif
307+
}
308+
301309
#endif /* UR_UTIL_H */

tools/urtrace/collector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ std::unique_ptr<TraceWriter> create_writer() {
277277
case OUTPUT_JSON:
278278
return std::make_unique<JsonWriter>();
279279
default:
280-
assert(0); /* unreachable */
280+
ur_unreachable();
281281
}
282282
return nullptr;
283283
}

0 commit comments

Comments
 (0)