/** * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* ! * \file kernel_log.h * \brief */ #ifndef ASCENDC_MODULE_KERNEL_LOG_INTF_H #define ASCENDC_MODULE_KERNEL_LOG_INTF_H #if defined(__CCE_KT_TEST__) && __CCE_KT_TEST__ == 1 #include #include #include #include #include #include "stub_def.h" namespace AscendC { #define ASCENDC_ASSERT(cond, behavior) \ do { \ if (!(cond)) { \ behavior; \ raise(SIGABRT); \ } \ } while (0) enum class LogLevel : uint8_t { KERNEL_DEBUG = 0, KERNEL_INFO = 1, KERNEL_WARN = 2, KERNEL_ERROR = 3, }; } // namespace AscendC #define KERNEL_LOG(level, format, ...) KERNEL_LOG_##level(format, ##__VA_ARGS__) #if __CCE_AICORE__ == 220 namespace AscendC { inline std::string GenCoreTypeStr() { std::string coreTypeStr = ""; if (g_coreType == AscendC::AIC_TYPE) { coreTypeStr = "AIC_"; } else if (g_coreType == AscendC::AIV_TYPE) { coreTypeStr = "AIV_"; } else { coreTypeStr = "MIX_"; } coreTypeStr += std::to_string(sub_block_idx); return coreTypeStr; } inline std::string GenBlockStr() { std::string blockStr = "Block_"; blockStr += std::to_string(block_idx); return blockStr; } } // namespace AscendC #define KERNEL_LOG_KERNEL_DEBUG(format, ...) \ do { \ std::string coreTypeStr = AscendC::GenCoreTypeStr(); \ std::string blockStr = AscendC::GenBlockStr(); \ printf("[DEBUG][%s][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), coreTypeStr.c_str(), __FILE__, \ __LINE__, __FUNCTION__, (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #define KERNEL_LOG_KERNEL_INFO(format, ...) \ do { \ std::string coreTypeStr = AscendC::GenCoreTypeStr(); \ std::string blockStr = AscendC::GenBlockStr(); \ printf("[INFO][%s][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), coreTypeStr.c_str(), __FILE__, \ __LINE__, __FUNCTION__, (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #define KERNEL_LOG_KERNEL_WARN(format, ...) \ do { \ std::string coreTypeStr = AscendC::GenCoreTypeStr(); \ std::string blockStr = AscendC::GenBlockStr(); \ printf("[WARN][%s][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), coreTypeStr.c_str(), __FILE__, \ __LINE__, __FUNCTION__, (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #define KERNEL_LOG_KERNEL_ERROR(format, ...) \ do { \ std::string coreTypeStr = AscendC::GenCoreTypeStr(); \ std::string blockStr = AscendC::GenBlockStr(); \ printf("[ERROR][%s][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), coreTypeStr.c_str(), __FILE__, \ __LINE__, __FUNCTION__, (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #else #define KERNEL_LOG_KERNEL_DEBUG(format, ...) \ do { \ std::string blockStr = "Core_"; \ blockStr += std::to_string(block_idx); \ printf("[DEBUG][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), __FILE__, __LINE__, __FUNCTION__, \ (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #define KERNEL_LOG_KERNEL_INFO(format, ...) \ do { \ std::string blockStr = "Core_"; \ blockStr += std::to_string(block_idx); \ printf("[INFO][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), __FILE__, __LINE__, __FUNCTION__, \ (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #define KERNEL_LOG_KERNEL_WARN(format, ...) \ do { \ std::string blockStr = "Core_"; \ blockStr += std::to_string(block_idx); \ printf("[WARN][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), __FILE__, __LINE__, __FUNCTION__, \ (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #define KERNEL_LOG_KERNEL_ERROR(format, ...) \ do { \ std::string blockStr = "Core_"; \ blockStr += std::to_string(block_idx); \ printf("[ERROR][%s][%s:%d][%s][%u] " format "\n", blockStr.c_str(), __FILE__, __LINE__, __FUNCTION__, \ (uint32_t)getpid(), ##__VA_ARGS__); \ } while (0) #endif #else #define KERNEL_LOG(level, format, ...) #define ASCENDC_ASSERT(cond, behavior) #endif #endif // ASCENDC_MODULE_KERNEL_LOG_INTF_H