已合并
解决issue 253 254 255 #1847
jcmrn0930创建于 26 天前
解决issue 253 254 255 #1847
已合并
共 4 个文件变更+66-6
| @@ -240,11 +240,11 @@ inline __aicore__ void CastExtendWithOneTransferWithMaskMode(const AscendC::Loca | |||
| 240 | uint32_t mid_last_dim_stride = elem_in_one_block * blocks_for_last_dim_elems; | 240 | uint32_t mid_last_dim_stride = elem_in_one_block * blocks_for_last_dim_elems; |
| 241 | auto mid_ub = tmp_buf[0].template ReinterpretCast<float>(); | 241 | auto mid_ub = tmp_buf[0].template ReinterpretCast<float>(); |
| 242 | if constexpr (AscendC::IsSameType<InT, int64_t>::value) { | 242 | if constexpr (AscendC::IsSameType<InT, int64_t>::value) { |
| 243 | - uint32_t max_dtype_size_between_src_and_mid = 8; | 243 | + max_dtype_size_between_src_and_mid = 8; |
王 | |||
| 244 | - uint32_t max_dtype_size_between_mid_and_dst = 4; | 244 | + max_dtype_size_between_mid_and_dst = 4; |
| 245 | } else { | 245 | } else { |
| 246 | - uint32_t max_dtype_size_between_src_and_mid = 4; | 246 | + max_dtype_size_between_src_and_mid = 4; |
| 247 | - uint32_t max_dtype_size_between_mid_and_dst = 8; | 247 | + max_dtype_size_between_mid_and_dst = 8; |
| 248 | } | 248 | } |
| 249 | CastExtendWithMaskMode<InT, float>(mid_ub, src, first_dim, last_dim, input_last_dim_stride, mid_last_dim_stride, | 249 | CastExtendWithMaskMode<InT, float>(mid_ub, src, first_dim, last_dim, input_last_dim_stride, mid_last_dim_stride, |
| 250 | max_dtype_size_between_src_and_mid, tmp_buf); | 250 | max_dtype_size_between_src_and_mid, tmp_buf); |
| @@ -391,7 +391,8 @@ inline __aicore__ void CompareScalarExtend(const LocalTensor<T> &dst, const Loca | |||
| 391 | AscendC::PipeBarrier<PIPE_V>(); | 391 | AscendC::PipeBarrier<PIPE_V>(); |
| 392 | DataCopy(src_tmp[0], src[cnt], left_cnt); | 392 | DataCopy(src_tmp[0], src[cnt], left_cnt); |
| 393 | AscendC::PipeBarrier<PIPE_V>(); | 393 | AscendC::PipeBarrier<PIPE_V>(); |
| 394 | - CompareScalar(compare_out[0], src_tmp[cnt], constant_y, mode, 256 / sizeof(T)); | 394 | + // 尾块数据拷贝到临时缓冲起始位置,因此下标改为 0。 |
| 395 | + CompareScalar(compare_out[0], src_tmp[0], constant_y, mode, 256 / sizeof(T)); | ||
| 395 | } else { | 396 | } else { |
| 396 | AscendC::PipeBarrier<PIPE_V>(); | 397 | AscendC::PipeBarrier<PIPE_V>(); |
| 397 | CompareScalar(compare_out[0], src[cnt], constant_y, mode, left_cnt); | 398 | CompareScalar(compare_out[0], src[cnt], constant_y, mode, left_cnt); |
| @@ -657,7 +658,8 @@ inline __aicore__ void CompareExtend(const LocalTensor<T> &dst, const LocalTenso | |||
| 657 | AscendC::PipeBarrier<PIPE_V>(); | 658 | AscendC::PipeBarrier<PIPE_V>(); |
| 658 | DataCopy(src_tmp[256 / sizeof(T)], src1[cnt], left_cnt); | 659 | DataCopy(src_tmp[256 / sizeof(T)], src1[cnt], left_cnt); |
| 659 | AscendC::PipeBarrier<PIPE_V>(); | 660 | AscendC::PipeBarrier<PIPE_V>(); |
| 660 | - Compare(compare_out[0], src_tmp[cnt], src_tmp[256 / sizeof(T)], mode, 256 / sizeof(T)); | 661 | + // 尾块数据拷贝到临时缓冲起始位置,因此下标改为 0。 |
| 662 | + Compare(compare_out[0], src_tmp[0], src_tmp[256 / sizeof(T)], mode, 256 / sizeof(T)); | ||
| 661 | } else { | 663 | } else { |
| 662 | AscendC::PipeBarrier<PIPE_V>(); | 664 | AscendC::PipeBarrier<PIPE_V>(); |
| 663 | Compare(compare_out[0], src0[cnt], src1[cnt], mode, left_cnt); | 665 | Compare(compare_out[0], src0[cnt], src1[cnt], mode, left_cnt); |
| @@ -87,6 +87,54 @@ void CastExtendTest(int size, std::function<OutT(int index, InT src)> expectGen, | |||
| 87 | EXPECT_EQ(diff_count, 0); | 87 | EXPECT_EQ(diff_count, 0); |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | +template <typename InT, typename OutT> | ||
| 91 | +void CastExtendWithMaskModeCalc(InT *x, OutT *y, int first_dim, int last_dim, int input_last_dim_stride, | ||
| 92 | + int output_last_dim_stride) { | ||
| 93 | + TPipe tpipe; | ||
| 94 | + TBuf<TPosition::VECCALC> xbuf, ybuf, tmp; | ||
| 95 | + tpipe.InitBuffer(xbuf, sizeof(InT) * first_dim * input_last_dim_stride); | ||
| 96 | + tpipe.InitBuffer(ybuf, sizeof(OutT) * first_dim * output_last_dim_stride); | ||
| 97 | + tpipe.InitBuffer(tmp, 8192); | ||
| 98 | + | ||
| 99 | + auto l_x = xbuf.Get<InT>(); | ||
| 100 | + auto l_y = ybuf.Get<OutT>(); | ||
| 101 | + auto l_tmp = tmp.Get<uint8_t>(); | ||
| 102 | + | ||
| 103 | + GmToUb(l_x, x, first_dim * input_last_dim_stride); | ||
| 104 | + CastExtend(l_y, l_x, l_tmp, first_dim, last_dim, input_last_dim_stride, output_last_dim_stride, | ||
| 105 | + std::max(sizeof(InT), sizeof(OutT))); | ||
| 106 | + UbToGm(y, l_y, first_dim * output_last_dim_stride); | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +TEST(TestApiCast, Int64ToHalfWithPaddedLastDim) { | ||
| 110 | + constexpr int first_dim = 2; | ||
| 111 | + constexpr int last_dim = 3; | ||
| 112 | + constexpr int input_last_dim_stride = ONE_BLK_SIZE / sizeof(int64_t); | ||
| 113 | + constexpr int output_last_dim_stride = ONE_BLK_SIZE / sizeof(half); | ||
| 114 | + auto *x = static_cast<int64_t *>(AscendC::GmAlloc(sizeof(int64_t) * first_dim * input_last_dim_stride)); | ||
| 115 | + auto *y = static_cast<half *>(AscendC::GmAlloc(sizeof(half) * first_dim * output_last_dim_stride)); | ||
| 116 | + | ||
| 117 | + for (int row = 0; row < first_dim; ++row) { | ||
| 118 | + for (int column = 0; column < last_dim; ++column) { | ||
| 119 | + x[row * input_last_dim_stride + column] = row * last_dim + column; | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + auto kernel = [](int64_t *input, half *output) { | ||
| 124 | + CastExtendWithMaskModeCalc<int64_t, half>(input, output, first_dim, last_dim, input_last_dim_stride, | ||
| 125 | + output_last_dim_stride); | ||
| 126 | + }; | ||
| 127 | + AscendC::SetKernelMode(KernelMode::AIV_MODE); | ||
| 128 | + ICPU_RUN_KF(kernel, 1, x, y); | ||
| 129 | + | ||
| 130 | + for (int row = 0; row < first_dim; ++row) { | ||
| 131 | + for (int column = 0; column < last_dim; ++column) { | ||
| 132 | + EXPECT_EQ(static_cast<int64_t>(static_cast<float>(y[row * output_last_dim_stride + column])), | ||
| 133 | + row * last_dim + column); | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | +} | ||
| 137 | + | ||
| 90 | constexpr uint8_t CastGen(const int index) { | 138 | constexpr uint8_t CastGen(const int index) { |
| 91 | return index % gen_index_two; | 139 | return index % gen_index_two; |
| 92 | } | 140 | } |
| @@ -334,6 +334,11 @@ TEST_F(TestApiCompareUT, Compare_Eq_float_uint8) { | |||
| 334 | CMPMODE::EQ); | 334 | CMPMODE::EQ); |
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | +TEST_F(TestApiCompareUT, Compare_Eq_float_float_with_small_tail) { | ||
| 338 | + const uint32_t max_block_cnt = KernelUtils::BlkAlign<uint8_t>((64 * MAX_REPEAT_TIMES) / 8) / sizeof(float); | ||
| 339 | + CompareTest<float, float>(max_block_cnt + ONE_BLK_SIZE / sizeof(float), CMPMODE::EQ); | ||
| 340 | +} | ||
| 341 | + | ||
| 337 | // 场景02:EQ-half | 342 | // 场景02:EQ-half |
| 338 | TEST_F(TestApiCompareUT, Compare_Eq_half_uint8) { | 343 | TEST_F(TestApiCompareUT, Compare_Eq_half_uint8) { |
| 339 | CompareTest<uint8_t, half>(ONE_BLK_SIZE / sizeof(half), CMPMODE::EQ); | 344 | CompareTest<uint8_t, half>(ONE_BLK_SIZE / sizeof(half), CMPMODE::EQ); |
| @@ -832,6 +837,11 @@ TEST_F(TestApiCompareUT, Compare_Eq_input_tensor_float_output_uint8) { | |||
| 832 | CMPMODE::EQ); | 837 | CMPMODE::EQ); |
| 833 | } | 838 | } |
| 834 | 839 | ||
| 840 | +TEST_F(TestApiCompareUT, Compare_Eq_input_tensor_float_output_float_with_small_tail) { | ||
| 841 | + const uint32_t max_block_cnt = KernelUtils::BlkAlign<uint8_t>((64 * MAX_REPEAT_TIMES) / 8) / sizeof(float); | ||
| 842 | + TensorCompareTest<float, float>(max_block_cnt + ONE_BLK_SIZE / sizeof(float), CMPMODE::EQ); | ||
| 843 | +} | ||
| 844 | + | ||
| 835 | // Tensor EQ-half | 845 | // Tensor EQ-half |
| 836 | TEST_F(TestApiCompareUT, Compare_Eq_input_tensor_half_output_uint8) { | 846 | TEST_F(TestApiCompareUT, Compare_Eq_input_tensor_half_output_uint8) { |
| 837 | TensorCompareTest<uint8_t, half>(ONE_BLK_SIZE / sizeof(half), CMPMODE::EQ); | 847 | TensorCompareTest<uint8_t, half>(ONE_BLK_SIZE / sizeof(half), CMPMODE::EQ); |
为什么是8和4,建议增加注释