From d7579321c5ce49986662ef67157611750f6d009e Mon Sep 17 00:00:00 2001 From: Muhammed Emin Ozturk Date: Wed, 26 Feb 2025 19:31:38 -0600 Subject: [PATCH] bf16 compilation error is fixed --- ...hreadwise_tensor_slice_transfer_v6r1r2.hpp | 3 ++ include/ck/utility/dynamic_buffer.hpp | 53 +++++++++++++++---- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/include/ck/tensor_operation/gpu/thread/threadwise_tensor_slice_transfer_v6r1r2.hpp b/include/ck/tensor_operation/gpu/thread/threadwise_tensor_slice_transfer_v6r1r2.hpp index bba2eb8dde..3a096df4c8 100755 --- a/include/ck/tensor_operation/gpu/thread/threadwise_tensor_slice_transfer_v6r1r2.hpp +++ b/include/ck/tensor_operation/gpu/thread/threadwise_tensor_slice_transfer_v6r1r2.hpp @@ -189,6 +189,9 @@ struct ThreadwiseTensorSliceTransfer_v6r1r2 } #endif + + + // copy data from dst_vector into dst_buf dst_buf.template Update( dst_coord_.GetOffset(), diff --git a/include/ck/utility/dynamic_buffer.hpp b/include/ck/utility/dynamic_buffer.hpp index 6de17a6152..5b035337d6 100755 --- a/include/ck/utility/dynamic_buffer.hpp +++ b/include/ck/utility/dynamic_buffer.hpp @@ -134,7 +134,8 @@ struct DynamicBuffer template >::type, - typename scalar_type>::type>::value, + typename scalar_type>::type>::value || + !is_native_type(), bool>::type = false> __host__ __device__ void Update(index_t i, bool is_valid_element, const X& x) { @@ -154,14 +155,43 @@ struct DynamicBuffer { auto tmp = this->template Get(i, is_valid_element); using scalar_t = typename scalar_type>::type; - // handle bfloat addition - if constexpr(is_same_v) + + // // handle bfloat addition + // if constexpr(is_same_v) + // { + // if constexpr(is_scalar_type::value) + // { + // // Scalar type + // auto result = + // type_convert(type_convert(x) + type_convert(tmp)); + // this->template Set(i, is_valid_element, result); + // } + // else + // { + // // Vector type + // constexpr auto vector_size = scalar_type>::vector_size; + // const vector_type a_vector{tmp}; + // const vector_type b_vector{x}; + // static_for<0, vector_size, 1>{}([&](auto idx) { + // auto result = type_convert( + // type_convert(a_vector.template AsType()[idx]) + + // type_convert(b_vector.template AsType()[idx])); + // this->template Set(i + idx, is_valid_element, result); + // }); + // } + // } + // else + // { + // this->template Set(i, is_valid_element, x + tmp); + // } + + // Properly handle addition for all low-precision types + if constexpr(is_same_v || is_same_v) { if constexpr(is_scalar_type::value) { - // Scalar type - auto result = - type_convert(type_convert(x) + type_convert(tmp)); + // Scalar type: Convert to float, add, convert back + auto result = type_convert(type_convert(x) + type_convert(tmp)); this->template Set(i, is_valid_element, result); } else @@ -170,6 +200,8 @@ struct DynamicBuffer constexpr auto vector_size = scalar_type>::vector_size; const vector_type a_vector{tmp}; const vector_type b_vector{x}; + + // Process each element of the vector in higher precision static_for<0, vector_size, 1>{}([&](auto idx) { auto result = type_convert( type_convert(a_vector.template AsType()[idx]) + @@ -178,10 +210,11 @@ struct DynamicBuffer }); } } - else - { - this->template Set(i, is_valid_element, x + tmp); - } + // else + // { + // // // For other types, direct addition is fine + // // this->template Set(i, is_valid_element, x + tmp); + // } } }