From 115c4592c08080112ea736e4e87676a1456331d7 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 1 Apr 2022 14:55:05 +0800 Subject: [PATCH] fix(dnn/opencl): fix opencl elemwise tuning issue GitOrigin-RevId: 317640547d262cbfec90f79786c60a872253f0b8 --- dnn/test/common/benchmarker.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dnn/test/common/benchmarker.h b/dnn/test/common/benchmarker.h index dfa60c3ad..957ffc24e 100644 --- a/dnn/test/common/benchmarker.h +++ b/dnn/test/common/benchmarker.h @@ -158,7 +158,7 @@ float BenchmarkerBase::exec(TensorLayoutArray layouts) { opr->param() = m_param; auto user_layouts = layouts; m_proxy->deduce_layout(opr, layouts); - for (size_t i = 0; i < layouts.size(); ++i) + for (size_t i = 0; i < layouts.size(); ++i) { if (user_layouts[i].ndim > 0) { auto run = [&]() { ASSERT_TRUE(layouts[i].eq_shape(user_layouts[i])) @@ -169,13 +169,14 @@ float BenchmarkerBase::exec(TensorLayoutArray layouts) { }; run(); } + } auto allocate = [&layouts](Handle* handle) { TensorNDArray tensors(layouts.size()); auto trans_func = [handle](const TensorLayout& layout) { auto span = layout.span(); TensorND res; res.reset_ptr( - static_cast(megdnn_malloc(handle, span.dist_byte())) + + static_cast(megdnn_malloc(handle, span.dist_byte())) - span.low_byte); res.layout = layout; return res; @@ -244,7 +245,9 @@ float BenchmarkerBase::exec(TensorLayoutArray layouts) { } auto free = [](Handle* handle, TensorNDArray& tensors) { std::for_each(tensors.begin(), tensors.end(), [handle](const TensorND& tensor) { - megdnn_free(handle, tensor.raw_ptr()); + megdnn_free( + handle, static_cast(tensor.raw_ptr()) + + tensor.layout.span().low_byte); }); }; free(m_handle, tensors_cur); @@ -283,7 +286,7 @@ float BenchmarkerBase::exect(const TensorValueArray& testcase_in) { auto span = layout.span(); TensorND res; res.reset_ptr( - static_cast(megdnn_malloc(handle, span.dist_byte())) + + static_cast(megdnn_malloc(handle, span.dist_byte())) - span.low_byte); res.layout = layout; return res; @@ -341,7 +344,9 @@ float BenchmarkerBase::exect(const TensorValueArray& testcase_in) { } auto free = [](Handle* handle, TensorNDArray& tensors) { std::for_each(tensors.begin(), tensors.end(), [handle](const TensorND& tensor) { - megdnn_free(handle, tensor.raw_ptr()); + megdnn_free( + handle, static_cast(tensor.raw_ptr()) + + tensor.layout.span().low_byte); }); }; free(m_handle, tensors_cur); -- GitLab