CUTLASS 3.4.0 (#1286)
* CUTLASS 3.4.0 * Update CHANGELOG.md --------- Co-authored-by: Pradeep Ramani <prramani@nvidia.com>
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#include <cuda_bf16.h>
|
||||
#include "cutlass/cutlass.h"
|
||||
|
||||
namespace cutlass {
|
||||
@@ -83,6 +84,28 @@ struct alignas(2) bfloat16_t {
|
||||
return h;
|
||||
}
|
||||
|
||||
private:
|
||||
struct from_32_bit_integer_t {};
|
||||
static constexpr from_32_bit_integer_t from_32_bit_integer{};
|
||||
|
||||
template<class T>
|
||||
CUTLASS_HOST_DEVICE
|
||||
explicit bfloat16_t(from_32_bit_integer_t, T x) {
|
||||
static_assert(cutlass::platform::is_integral<T>::value && sizeof(T) == 4, "Requires 32-bit integer");
|
||||
|
||||
float flt = static_cast<float>(x);
|
||||
uint32_t bits;
|
||||
|
||||
#if defined(__CUDA_ARCH__)
|
||||
bits = reinterpret_cast<uint32_t &>(flt);
|
||||
#else
|
||||
std::memcpy(&bits, &flt, sizeof(bits));
|
||||
#endif
|
||||
|
||||
storage = uint16_t(bits >> 16);
|
||||
}
|
||||
|
||||
public:
|
||||
/// Default constructor
|
||||
bfloat16_t() = default;
|
||||
|
||||
@@ -129,18 +152,10 @@ struct alignas(2) bfloat16_t {
|
||||
|
||||
/// Integer conversion - round toward nearest
|
||||
CUTLASS_HOST_DEVICE
|
||||
explicit bfloat16_t(int x) {
|
||||
float flt = static_cast<float>(x);
|
||||
uint32_t bits;
|
||||
explicit bfloat16_t(int x) : bfloat16_t(from_32_bit_integer, x) {}
|
||||
|
||||
#if defined(__CUDA_ARCH__)
|
||||
bits = reinterpret_cast<uint32_t &>(flt);
|
||||
#else
|
||||
std::memcpy(&bits, &flt, sizeof(bits));
|
||||
#endif
|
||||
|
||||
storage = uint16_t(bits >> 16);
|
||||
}
|
||||
CUTLASS_HOST_DEVICE
|
||||
explicit bfloat16_t(uint32_t x) : bfloat16_t(from_32_bit_integer, x) {}
|
||||
|
||||
/// Converts to float
|
||||
CUTLASS_HOST_DEVICE
|
||||
|
||||
Reference in New Issue
Block a user