Skip to content

Commit 178e3fc

Browse files
authored
Merge pull request #1124 from wenju-he/adapters-ur_unreachable
[NFC] Add utility function ur_unreachable to simplify code
2 parents 45506f3 + 5accf50 commit 178e3fc

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

source/adapters/cuda/usm.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "event.hpp"
1818
#include "platform.hpp"
1919
#include "queue.hpp"
20+
#include "ur_util.hpp"
2021
#include "usm.hpp"
2122

2223
#include <cuda.h>
@@ -227,11 +228,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
227228
return ReturnValue(UR_USM_TYPE_HOST);
228229
}
229230
// should never get here
230-
#ifdef _MSC_VER
231-
__assume(0);
232-
#else
233-
__builtin_unreachable();
234-
#endif
231+
ur::unreachable();
235232
}
236233
case UR_USM_ALLOC_INFO_BASE_PTR: {
237234
#if CUDA_VERSION >= 10020

source/adapters/hip/usm.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "context.hpp"
1616
#include "device.hpp"
1717
#include "platform.hpp"
18+
#include "ur_util.hpp"
1819
#include "usm.hpp"
1920

2021
/// USM: Implements USM Host allocations using HIP Pinned Memory
@@ -190,12 +191,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
190191
return ReturnValue(UR_USM_TYPE_HOST);
191192
}
192193
// 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);
194+
ur::unreachable();
199195
}
200196
case UR_USM_ALLOC_INFO_DEVICE: {
201197
// 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,14 @@ inline ur_result_t exceptionToResult(std::exception_ptr eptr) {
298298

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

301+
namespace ur {
302+
[[noreturn]] inline void unreachable() {
303+
#ifdef _MSC_VER
304+
__assume(0);
305+
#else
306+
__builtin_unreachable();
307+
#endif
308+
}
309+
} // namespace ur
310+
301311
#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)