代码拉取完成,页面将自动刷新
/*
Copyright (c) 2025 Huawei Technologies Co., Ltd.
This file is a part of the CANN Open Software.
Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
Please refer to the License for details. You may not use this file except in compliance with the License.
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
See LICENSE in the root of the software repository for the full text of the License.
*/
#pragma once
#include "kernel_operator.h"
/**
算子内部用到的utils函数
*/
/**
* @brief val 向上按照 align 的倍数取整
* @param [in] T val:需要取整的数
* @param [in] align:需要向上取整的最小粒度
* @return T 向上对齐后的值
*/
template<typename T>
[aicore] inline __attribute__((always_inline)) T RoundUp (const T val, const T align) {
if ( align == 0 ) {
return 0;
} else {
return ( val + align - 1 ) / align * align ;
}
}
/**
* @brief val 向下按照 align 的倍数取整
* @param [in] T val:需要取整的数
* @param [in] T align:需要向下取整的最小粒度
* @return T 向下对齐后的数
*/
template<typename T>
[aicore] inline __attribute__((always_inline)) T RoundDown ( const T val, const T align ) {
if ( align == 0 ) {
return 0;
} else {
return val / align * align;
}
}
/**
* @brief val 除以 divisor 向上取整
* @param [in] T val:被除数
* @param [in] T divisor:除数
* @return T val除以divisor向上取整的结果
*/
template<typename T>
[aicore] inline __attribute__((always_inline)) T CeilDiv ( const T val, const T divisor ){
if ( divisor == 0 ) {
return 0;
} else {
return ( val + divisor - 1 ) / divisor;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。