#pragma once #include #include namespace c10 { namespace detail { template struct LoadImpl { C10_HOST_DEVICE static T apply(const void* src) { return *reinterpret_cast(src); } }; template <> struct LoadImpl { C10_HOST_DEVICE static bool apply(const void* src) { static_assert(sizeof(bool) == sizeof(char)); // NOTE: [Loading boolean values] // Protect against invalid boolean values by loading as a byte // first, then converting to bool (see gh-54789). return *reinterpret_cast(src); } }; } // namespace detail template C10_HOST_DEVICE T load(const void* src) { return c10::detail::LoadImpl::apply(src); } template C10_HOST_DEVICE scalar_t load(const scalar_t* src) { return c10::detail::LoadImpl::apply(src); } } // namespace c10