From b6545ac0657e812eed2b4533d141b3254e437ed0 Mon Sep 17 00:00:00 2001 From: Mingkai Chan Date: Thu, 31 Oct 2024 11:02:55 +0800 Subject: [PATCH] add log functions --- .clang-format | 6 +- cmake/intf.cmake | 26 ++++---- cmake/stage_0.cmake | 2 +- cmake/stage_1.cmake | 2 + include/log/log.h | 62 +++++++++++++++++++ .../op_host/multi_scale_deformable_attn.cpp | 6 ++ 6 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 include/log/log.h diff --git a/.clang-format b/.clang-format index 27412d05..f32f4f01 100644 --- a/.clang-format +++ b/.clang-format @@ -69,12 +69,12 @@ IndentCaseBlocks: false IndentCaseLabels: true IndentExternBlock: AfterExternBlock IndentGotoLabels: false -IndentPPDirectives: BeforeHash +IndentPPDirectives: None IndentWidth: 4 IndentWrappedFunctionNames: false KeepEmptyLinesAtTheStartOfBlocks: false MaxEmptyLinesToKeep: 2 -NamespaceIndentation: Inner +NamespaceIndentation: None PointerAlignment: Left ReflowComments: false SortIncludes: CaseSensitive @@ -97,4 +97,4 @@ SpacesInConditionalStatement: false SpacesInParentheses: false SpacesInSquareBrackets: false TabWidth: 4 -UseTab: Never \ No newline at end of file +UseTab: Never diff --git a/cmake/intf.cmake b/cmake/intf.cmake index d24ce144..eaabdcd5 100644 --- a/cmake/intf.cmake +++ b/cmake/intf.cmake @@ -22,18 +22,22 @@ target_compile_options( target_compile_definitions( intf_pub INTERFACE _GLIBCXX_USE_CXX11_ABI=0 $<$:_FORTIFY_SOURCE=2>) -target_include_directories(intf_pub - INTERFACE ${ASCEND_CANN_PACKAGE_PATH}/include) -## if the CANN_PATHS not empty +target_include_directories( + intf_pub INTERFACE ${ASCEND_CANN_PACKAGE_PATH}/include + ${PROJECT_SOURCE_DIR}/include) +# if the CANN_PATHS not empty if(CANN_PATHS) - ## if the arch is aarch64, add the include path - if(${ARCH} STREQUAL "aarch64") - target_include_directories(intf_pub INTERFACE ${CANN_PATHS}/aarch64-linux/include) - target_link_directories(intf_pub INTERFACE ${CANN_PATHS}/aarch64-linux/lib64) - else () - target_include_directories(intf_pub INTERFACE ${CANN_PATHS}/x86_64-linux/include) - target_link_directories(intf_pub INTERFACE ${CANN_PATHS}/x86_64-linux/lib64) - endif() + # if the arch is aarch64, add the include path + if(${ARCH} STREQUAL "aarch64") + target_include_directories(intf_pub + INTERFACE ${CANN_PATHS}/aarch64-linux/include) + target_link_directories(intf_pub INTERFACE + ${CANN_PATHS}/aarch64-linux/lib64) + else() + target_include_directories(intf_pub + INTERFACE ${CANN_PATHS}/x86_64-linux/include) + target_link_directories(intf_pub INTERFACE ${CANN_PATHS}/x86_64-linux/lib64) + endif() endif() target_link_options( diff --git a/cmake/stage_0.cmake b/cmake/stage_0.cmake index 426e8015..edac7db1 100644 --- a/cmake/stage_0.cmake +++ b/cmake/stage_0.cmake @@ -3,7 +3,7 @@ target_compile_options(ascend_all_ops PRIVATE -g -fPIC -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0) target_include_directories(ascend_all_ops PRIVATE ${CANN_INCLUDE_PATH}) target_link_libraries(ascend_all_ops PRIVATE intf_pub exe_graph register - tiling_api) + tiling_api ascendcl) add_custom_command( TARGET ascend_all_ops POST_BUILD diff --git a/cmake/stage_1.cmake b/cmake/stage_1.cmake index 9a176248..502263af 100644 --- a/cmake/stage_1.cmake +++ b/cmake/stage_1.cmake @@ -8,6 +8,7 @@ target_link_libraries( exe_graph register tiling_api + ascendcl -Wl,--whole-archive rt2_registry -Wl,--no-whole-archive) @@ -27,6 +28,7 @@ target_link_libraries( exe_graph register tiling_api + ascendcl -Wl,--whole-archive rt2_registry -Wl,--no-whole-archive) diff --git a/include/log/log.h b/include/log/log.h new file mode 100644 index 00000000..28ea5675 --- /dev/null +++ b/include/log/log.h @@ -0,0 +1,62 @@ +// Copyright (c) 2024 Huawei Technologies Co., Ltd +// All rights reserved. +// +// Licensed under the BSD 3-Clause License (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://opensource.org/licenses/BSD-3-Clause +// +// 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. +#pragma once + +#ifndef LOG_LOG_H_ +#define LOG_LOG_H_ + +#include +#include + +namespace mx_driving { +namespace log { + +inline bool IsACLGlobalLogOn(aclLogLevel level) +{ + const static int getACLGlobalLogLevel = []() -> int { + char* env_val = std::getenv("ASCEND_GLOBAL_LOG_LEVEL"); + int64_t envFlag = (env_val != nullptr) ? strtol(env_val, nullptr, 10) : ACL_ERROR; + return static_cast(envFlag); + }(); + return (getACLGlobalLogLevel <= level); +} +} // namespace log +} // namespace mx_driving + +#define MX_DRIVING_LOGE(fmt, ...) \ + do { \ + if (mx_driving::log::IsACLGlobalLogOn(ACL_ERROR)) { \ + aclAppLog(ACL_ERROR, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ + } while (0); +#define MX_DRIVING_LOGW(fmt, ...) \ + do { \ + if (mx_driving::log::IsACLGlobalLogOn(ACL_WARNING)) { \ + aclAppLog(ACL_WARNING, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ + } while (0); +#define MX_DRIVING_LOGI(fmt, ...) \ + do { \ + if (mx_driving::log::IsACLGlobalLogOn(ACL_INFO)) { \ + aclAppLog(ACL_INFO, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ + } while (0); +#define MX_DRIVING_LOGD(fmt, ...) \ + do { \ + if (mx_driving::log::IsACLGlobalLogOn(ACL_DEBUG)) { \ + aclAppLog(ACL_DEBUG, __FILE__, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \ + } \ + } while (0); +#endif // LOG_LOG_H_ diff --git a/mx_driving/fused/ops/kernels/op_host/multi_scale_deformable_attn.cpp b/mx_driving/fused/ops/kernels/op_host/multi_scale_deformable_attn.cpp index 4fa91a69..a2a7234a 100644 --- a/mx_driving/fused/ops/kernels/op_host/multi_scale_deformable_attn.cpp +++ b/mx_driving/fused/ops/kernels/op_host/multi_scale_deformable_attn.cpp @@ -3,6 +3,7 @@ */ #include +#include "log/log.h" #include "multi_scale_deformable_attn_tiling.h" #include "register/op_def_registry.h" #include "tiling/platform/platform_ascendc.h" @@ -89,6 +90,11 @@ static ge::graphStatus TilingFuncForMultiScaleDeformableAttn(gert::TilingContext tiling.set_coreNum(coreNum); tiling.set_pointLoops(pointLoops); tiling.set_realLevels(attnWeightShape.GetDim(REAL_LEVEL_DIM)); + MX_DRIVING_LOGI( + "MultiScaleDeformableAttn's tiling: batchSize=%d, numKeys=%d, numHeads=%d, embedDims=%d, numLevels=%d,numQueries=%d, numPoints=%d, coreNum=%d, pointLoops=%d,realLevels=%d", + tiling.get_batchSize(), tiling.get_numKeys(), tiling.get_numHeads(), tiling.get_embedDims(), + tiling.get_numLevels(), tiling.get_numQueries(), tiling.get_numPoints(), tiling.get_coreNum(), + tiling.get_pointLoops(), tiling.get_realLevels()); tiling.SaveToBuffer(context->GetRawTilingData()->GetData(), context->GetRawTilingData()->GetCapacity()); context->GetRawTilingData()->SetDataSize(tiling.GetDataSize()); -- Gitee