@@ -40,6 +40,11 @@ void nd_pad_kernel_launcher_uint8(const uint8_t *, uint8_t *, const int,
4040 const int64_t *, const int64_t *,
4141 const uint8_t , const int64_t ,
4242 const musaStream_t);
43+ void nd_pad_kernel_launcher_uint16 (const uint16_t *, uint16_t *, const int ,
44+ const int64_t *, const int64_t *,
45+ const int64_t *, const int64_t *,
46+ const uint16_t , const int64_t ,
47+ const musaStream_t);
4348}
4449
4550namespace {
@@ -48,6 +53,8 @@ struct DoubleTag {};
4853struct Int32Tag {};
4954struct Int64Tag {};
5055struct Uint8Tag {};
56+ struct HalfTag {};
57+ struct BFloat16Tag {};
5158struct UnsupportedTag {};
5259
5360template <typename T>
@@ -75,6 +82,14 @@ template <>
7582struct TypeTag <uint8_t > {
7683 using type = Uint8Tag;
7784};
85+ template <>
86+ struct TypeTag <Eigen::half> {
87+ using type = HalfTag;
88+ };
89+ template <>
90+ struct TypeTag <bfloat16> {
91+ using type = BFloat16Tag;
92+ };
7893
7994#define DEFINE_PAD_LAUNCHER_IMPL (T, TAG, SUFFIX ) \
8095 void CallPadLauncherImpl ( \
@@ -94,6 +109,37 @@ DEFINE_PAD_LAUNCHER_IMPL(int64_t, Int64Tag, int64)
94109DEFINE_PAD_LAUNCHER_IMPL (uint8_t , Uint8Tag, uint8)
95110
96111#undef DEFINE_PAD_LAUNCHER_IMPL
112+
113+ // half and bfloat16 dispatched via uint16 kernel (zero = 0x0000 for both)
114+ void CallPadLauncherImpl (const Eigen::half *input_data,
115+ Eigen::half *output_data, const int dims,
116+ const int64_t *in_dims, const int64_t *out_dims,
117+ const int64_t *pad_before, const int64_t *pad_after,
118+ const Eigen::half pad_value,
119+ const int64_t total_out_elements,
120+ const musaStream_t stream, HalfTag) {
121+ uint16_t pad_bits;
122+ memcpy (&pad_bits, &pad_value, sizeof (uint16_t ));
123+ nd_pad_kernel_launcher_uint16 (reinterpret_cast <const uint16_t *>(input_data),
124+ reinterpret_cast <uint16_t *>(output_data), dims,
125+ in_dims, out_dims, pad_before, pad_after,
126+ pad_bits, total_out_elements, stream);
127+ }
128+
129+ void CallPadLauncherImpl (const bfloat16 *input_data, bfloat16 *output_data,
130+ const int dims, const int64_t *in_dims,
131+ const int64_t *out_dims, const int64_t *pad_before,
132+ const int64_t *pad_after, const bfloat16 pad_value,
133+ const int64_t total_out_elements,
134+ const musaStream_t stream, BFloat16Tag) {
135+ uint16_t pad_bits;
136+ memcpy (&pad_bits, &pad_value, sizeof (uint16_t ));
137+ nd_pad_kernel_launcher_uint16 (reinterpret_cast <const uint16_t *>(input_data),
138+ reinterpret_cast <uint16_t *>(output_data), dims,
139+ in_dims, out_dims, pad_before, pad_after,
140+ pad_bits, total_out_elements, stream);
141+ }
142+
97143void CallPadLauncherImpl (const void *, void *, const int , const int64_t *,
98144 const int64_t *, const int64_t *, const int64_t *,
99145 const int64_t , const int64_t , const musaStream_t,
@@ -107,9 +153,6 @@ void CallPadLauncher(const T *input_data, T *output_data, const int dims,
107153 const int64_t *pad_before, const int64_t *pad_after,
108154 const T pad_value, const int64_t total_out_elements,
109155 const musaStream_t stream) {
110- static_assert (!std::is_same<typename TypeTag<T>::type, UnsupportedTag>::value,
111- " Unsupported type for nd_pad_kernel_launcher" );
112-
113156 CallPadLauncherImpl (input_data, output_data, dims, in_dims, out_dims,
114157 pad_before, pad_after, pad_value, total_out_elements,
115158 stream, typename TypeTag<T>::type ());
@@ -246,6 +289,8 @@ REGISTER_MUSA_PAD_TYPE(int32);
246289REGISTER_MUSA_PAD_TYPE (int64);
247290REGISTER_MUSA_PAD_TYPE (double );
248291REGISTER_MUSA_PAD_TYPE (uint8);
292+ REGISTER_MUSA_PAD_TYPE (Eigen::half);
293+ REGISTER_MUSA_PAD_TYPE (bfloat16);
249294
250295#undef REGISTER_MUSA_PAD_TYPE
251296} // namespace musa
0 commit comments