Files
enginex-mlu370-vllm/torch_mlu_ops-v1.3.2/csrc/kernels/kernel_utils.h
2026-02-04 17:39:32 +08:00

55 lines
1.6 KiB
C++

/*************************************************************************
* Copyright (C) [2023-2024] by Cambricon, Inc.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************/
#ifndef CSRC_KERNELS_KERNEL_UTILS_H_
#define CSRC_KERNELS_KERNEL_UTILS_H_
#include <cassert>
#include <iostream>
#include <string>
#include "cnnl.h"
#include "cnrt.h"
namespace tmo {
const std::string arch_370 = "MLU370";
enum class KernelStatus { KERNEL_STATUS_SUCCESS = 0, KERNEL_STATUS_FAILED };
#ifndef PAD_DOWN
#define PAD_DOWN(x, y) (((x) / (y)) * (y))
#endif
#ifndef PAD_UP
#define PAD_UP(x, y) (((x) / (y) + (int)((x) % (y) > 0)) * (y))
#endif
inline bool isMlu300(const std::string &dev_name) {
if (dev_name.find("MLU3") != std::string::npos) {
return true;
} else {
return false;
}
}
inline bool is_arch300() {
int card_id = -1;
cnrtDeviceProp_t dev_info;
CNRT_CHECK(cnrtGetDevice(&card_id));
CNRT_CHECK(cnrtGetDeviceProperties(&dev_info, card_id));
std::string dev_name = dev_info.name;
return isMlu300(dev_name);
}
inline bool isBf16Supported() {
return !is_arch300();
}
} // namespace tmo
#endif // CSRC_KERNELS_KERNEL_UTILS_H_