Skip to content

Commit

Permalink
Merge pull request #1124 from wenju-he/adapters-ur_unreachable
Browse files Browse the repository at this point in the history
[NFC] Add utility function ur_unreachable to simplify code
  • Loading branch information
pbalcer authored Jan 16, 2024
2 parents 45506f3 + 5accf50 commit 178e3fc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
7 changes: 2 additions & 5 deletions source/adapters/cuda/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "event.hpp"
#include "platform.hpp"
#include "queue.hpp"
#include "ur_util.hpp"
#include "usm.hpp"

#include <cuda.h>
Expand Down Expand Up @@ -227,11 +228,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
return ReturnValue(UR_USM_TYPE_HOST);
}
// should never get here
#ifdef _MSC_VER
__assume(0);
#else
__builtin_unreachable();
#endif
ur::unreachable();
}
case UR_USM_ALLOC_INFO_BASE_PTR: {
#if CUDA_VERSION >= 10020
Expand Down
8 changes: 2 additions & 6 deletions source/adapters/hip/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "context.hpp"
#include "device.hpp"
#include "platform.hpp"
#include "ur_util.hpp"
#include "usm.hpp"

/// USM: Implements USM Host allocations using HIP Pinned Memory
Expand Down Expand Up @@ -190,12 +191,7 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
return ReturnValue(UR_USM_TYPE_HOST);
}
// should never get here
#ifdef _MSC_VER
__assume(0);
#else
__builtin_unreachable();
#endif
return ReturnValue(UR_USM_TYPE_UNKNOWN);
ur::unreachable();
}
case UR_USM_ALLOC_INFO_DEVICE: {
// get device index associated with this pointer
Expand Down
7 changes: 2 additions & 5 deletions source/adapters/native_cpu/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//===----------------------------------------------------------------------===//

#include "ur_api.h"
#include "ur_util.hpp"

#include "common.hpp"
#include "kernel.hpp"
Expand Down Expand Up @@ -172,11 +173,7 @@ urKernelGetSubGroupInfo(ur_kernel_handle_t hKernel, ur_device_handle_t hDevice,
return ReturnValue(0);
}
case UR_KERNEL_SUB_GROUP_INFO_FORCE_UINT32: {
#ifdef _MSC_VER
__assume(0);
#else
__builtin_unreachable();
#endif
ur::unreachable();
}
}
DIE_NO_IMPLEMENTATION;
Expand Down
10 changes: 10 additions & 0 deletions source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,4 +298,14 @@ inline ur_result_t exceptionToResult(std::exception_ptr eptr) {

template <class> inline constexpr bool ur_always_false_t = false;

namespace ur {
[[noreturn]] inline void unreachable() {
#ifdef _MSC_VER
__assume(0);
#else
__builtin_unreachable();
#endif
}
} // namespace ur

#endif /* UR_UTIL_H */
2 changes: 1 addition & 1 deletion tools/urtrace/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ std::unique_ptr<TraceWriter> create_writer() {
case OUTPUT_JSON:
return std::make_unique<JsonWriter>();
default:
assert(0); /* unreachable */
ur::unreachable();
}
return nullptr;
}
Expand Down

0 comments on commit 178e3fc

Please sign in to comment.