/** * \file dnn/src/arm_common/conv_bias/block_helper.h * MegEngine is Licensed under the Apache License, Version 2.0 (the "License") * * Copyright (c) 2014-2020 Megvii Inc. All rights reserved. * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. */#include "src/common/utils.h"namespacemegdnn{namespace{// block_helper is used to calculate oh block sizestaticinlineintl2_block_helper(constintnthread,constintamount,constintsize_per_unit){constexprintl2_cache_size=256*1024;constintblock_per_thread=div_ceil(amount,nthread);constintbest_block=std::min(amount,(l2_cache_size+size_per_unit/2)/size_per_unit);constintmax_block_num=div_ceil(block_per_thread,best_block);constintmin_block_num=std::max(max_block_num-1,1);constintmax_block=div_ceil(block_per_thread,max_block_num);constintmin_block=div_ceil(block_per_thread,min_block_num);constintmax_loss=std::abs(max_block_num*max_block-block_per_thread);constintmin_loss=std::abs(min_block_num*min_block-block_per_thread);intblock=max_loss>min_loss?min_block:max_block;returnblock;}}// namespace}// namespace megdnn// vim: syntax=cpp.doxygen