Revert "[Reland] Use static_assert to detect get_type_index used in device code (#139966)"

This reverts commit ca7fdfe4d2.

Reverted https://github.com/pytorch/pytorch/pull/139966 on behalf of https://github.com/malfet due to This approach will prevent one from using get_type_index from device code ([comment](https://github.com/pytorch/pytorch/pull/139966#issuecomment-2465701260))
This commit is contained in:
PyTorch MergeBot 2024-11-08 20:32:43 +00:00
parent e6c5a77485
commit 07ad74635b

View file

@ -93,14 +93,17 @@ inline constexpr uint64_t type_index_impl() {
template <typename T>
inline constexpr type_index get_type_index() {
#if defined(__CUDA_ARCH__)
static_assert(false && sizeof(T), " Don't call me from device code");
#endif
#if !defined(__CUDA_ARCH__)
// To enforce that this is really computed at compile time, we pass the
// type index through std::integral_constant.
return type_index{std::integral_constant<
uint64_t,
detail::type_index_impl<std::decay_t<T>>()>::value};
#else
// There's nothing in theory preventing us from running this on device code
// except for nvcc throwing a compiler error if we enable it.
return (abort(), type_index(0));
#endif
}
#if !defined(TORCH_PEDANTIC)