From d3992817e3afde59ac28538c08d06f177461afa5 Mon Sep 17 00:00:00 2001 From: guodongliang Date: Thu, 21 Nov 2024 19:36:47 +0800 Subject: [PATCH] revise clamp align problem --- ntt/test/ctest/test_ntt_clamp.cpp | 64 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/ntt/test/ctest/test_ntt_clamp.cpp b/ntt/test/ctest/test_ntt_clamp.cpp index c90b7f9fd0..ac4c3262a1 100644 --- a/ntt/test/ctest/test_ntt_clamp.cpp +++ b/ntt/test/ctest/test_ntt_clamp.cpp @@ -32,15 +32,15 @@ TEST(ClampTestFloat, NoPack) { // init using tensor_type = ntt::tensor>; - std::unique_ptr ntt_input(new tensor_type); - NttTest::init_tensor(*ntt_input, min_input, max_input); + alignas(32) tensor_type ntt_input; + NttTest::init_tensor(ntt_input, min_input, max_input); // ntt - std::unique_ptr ntt_output1(new tensor_type); - ntt::clamp(*ntt_input, *ntt_output1, min_clamp, max_clamp); + alignas(32) tensor_type ntt_output1; + ntt::clamp(ntt_input, ntt_output1, min_clamp, max_clamp); // ort - auto ort_input = NttTest::ntt2ort(*ntt_input); + auto ort_input = NttTest::ntt2ort(ntt_input); float min_buf[] = {min_clamp}; int64_t shape[] = {std::size(min_buf)}; auto min = make_tensor(reinterpret_cast(min_buf), DataType_FLOAT, @@ -51,9 +51,9 @@ TEST(ClampTestFloat, NoPack) { auto ort_output = ortki_Clip(ort_input, min, max); // compare - std::unique_ptr ntt_output2(new tensor_type); - NttTest::ort2ntt(ort_output, *ntt_output2); - EXPECT_TRUE(NttTest::compare_tensor(*ntt_output1, *ntt_output2)); + alignas(32) tensor_type ntt_output2; + NttTest::ort2ntt(ort_output, ntt_output2); + EXPECT_TRUE(NttTest::compare_tensor(ntt_output1, ntt_output2)); } TEST(ClampTestFloat, PackM) { @@ -67,21 +67,21 @@ TEST(ClampTestFloat, PackM) { // init using tensor_type1 = ntt::tensor>; - std::unique_ptr ntt_input(new tensor_type1); - NttTest::init_tensor(*ntt_input, min_input, max_input); + alignas(32) tensor_type1 ntt_input; + NttTest::init_tensor(ntt_input, min_input, max_input); // ntt using tensor_type2 = ntt::tensor, ntt::fixed_shape>; - std::unique_ptr pack_input(new tensor_type2); - std::unique_ptr pack_output(new tensor_type2); - ntt::pack<0>(*ntt_input, *pack_input); - ntt::clamp(*pack_input, *pack_output, min_clamp, max_clamp); - std::unique_ptr ntt_output1(new tensor_type1); - ntt::unpack<0>(*pack_output, *ntt_output1); + alignas(32) tensor_type2 pack_input; + alignas(32) tensor_type2 pack_output; + ntt::pack<0>(ntt_input, pack_input); + ntt::clamp(pack_input, pack_output, min_clamp, max_clamp); + alignas(32) tensor_type1 ntt_output1; + ntt::unpack<0>(pack_output, ntt_output1); // ort - auto ort_input = NttTest::ntt2ort(*ntt_input); + auto ort_input = NttTest::ntt2ort(ntt_input); float min_buf[] = {min_clamp}; int64_t shape[] = {std::size(min_buf)}; auto min = make_tensor(reinterpret_cast(min_buf), DataType_FLOAT, @@ -92,9 +92,9 @@ TEST(ClampTestFloat, PackM) { auto ort_output = ortki_Clip(ort_input, min, max); // compare - std::unique_ptr ntt_output2(new tensor_type1); - NttTest::ort2ntt(ort_output, *ntt_output2); - EXPECT_TRUE(NttTest::compare_tensor(*ntt_output1, *ntt_output2)); + alignas(32) tensor_type1 ntt_output2; + NttTest::ort2ntt(ort_output, ntt_output2); + EXPECT_TRUE(NttTest::compare_tensor(ntt_output1, ntt_output2)); } TEST(ClampTestFloat, PackN) { @@ -108,21 +108,21 @@ TEST(ClampTestFloat, PackN) { // init using tensor_type1 = ntt::tensor>; - std::unique_ptr ntt_input(new tensor_type1); - NttTest::init_tensor(*ntt_input, min_input, max_input); + alignas(32) tensor_type1 ntt_input; + NttTest::init_tensor(ntt_input, min_input, max_input); // ntt using tensor_type2 = ntt::tensor, ntt::fixed_shape>; - std::unique_ptr pack_input(new tensor_type2); - std::unique_ptr pack_output(new tensor_type2); - ntt::pack<1>(*ntt_input, *pack_input); - ntt::clamp(*pack_input, *pack_output, min_clamp, max_clamp); - std::unique_ptr ntt_output1(new tensor_type1); - ntt::unpack<1>(*pack_output, *ntt_output1); + alignas(32) tensor_type2 pack_input; + alignas(32) tensor_type2 pack_output; + ntt::pack<1>(ntt_input, pack_input); + ntt::clamp(pack_input, pack_output, min_clamp, max_clamp); + alignas(32) tensor_type1 ntt_output1; + ntt::unpack<1>(pack_output, ntt_output1); // ort - auto ort_input = NttTest::ntt2ort(*ntt_input); + auto ort_input = NttTest::ntt2ort(ntt_input); float min_buf[] = {min_clamp}; int64_t shape[] = {std::size(min_buf)}; auto min = make_tensor(reinterpret_cast(min_buf), DataType_FLOAT, @@ -133,9 +133,9 @@ TEST(ClampTestFloat, PackN) { auto ort_output = ortki_Clip(ort_input, min, max); // compare - std::unique_ptr ntt_output2(new tensor_type1); - NttTest::ort2ntt(ort_output, *ntt_output2); - EXPECT_TRUE(NttTest::compare_tensor(*ntt_output1, *ntt_output2)); + alignas(32) tensor_type1 ntt_output2; + NttTest::ort2ntt(ort_output, ntt_output2); + EXPECT_TRUE(NttTest::compare_tensor(ntt_output1, ntt_output2)); } int main(int argc, char *argv[]) {