#pragma once #include #include #include #include namespace at { namespace native { static inline int cuda_int_cast(int64_t value, const char* varname) { auto result = static_cast(value); TORCH_CHECK(static_cast(result) == value, "cuda_int_cast: The value of ", varname, "(", (long long)value, ") is too large to fit into a int (", sizeof(int), " bytes)"); return result; } // Creates an array of size elements of type T, backed by pinned memory // wrapped in a Storage template static inline Storage pin_memory(int64_t size) { auto* allocator = cuda::getPinnedMemoryAllocator(); int64_t adjusted_size = size * sizeof(T); return Storage( Storage::use_byte_size_t(), adjusted_size, allocator, /*resizable=*/false); } } // namespace native } // namespace at