From 13a32c6ac8f541b95c17f6453e1ea7737d40bea5 Mon Sep 17 00:00:00 2001 From: zhouyi <3128826091@qq.com> Date: Tue, 6 Sep 2022 14:59:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?ASAN=E7=89=88=E6=9C=AC=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 13 +++++++++---- tf_adapter/kernels/aicpu/map_dataset_op.cc | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa29b6cf6..5d7c6c3a2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,13 +2,15 @@ option(ENABLE_OPEN_SRC "Enable graphengine compile in opensource." FALSE) set(TFADAPTER_DIR ${CMAKE_CURRENT_LIST_DIR}) +set(CMAKE_BUILD_TYPE Debug) + if (ENABLE_OPEN_SRC) cmake_minimum_required(VERSION 3.14) project(TFAdapter) set(CMAKE_CXX_STANDARD 11) - set(CMAKE_C_FLAGS "-O2 -DNDEBUG -Wfloat-equal -Wextra -Wno-deprecated-declarations -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -pipe ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-std=c++11 -O2 -DNDEBUG -Wfloat-equal -Wextra -Wno-deprecated-declarations -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -pipe ${CMAKE_CXX_FLAGS}") + set(CMAKE_C_FLAGS "-O0 -DNDEBUG -g -Wfloat-equal -Wextra -Wno-deprecated-declarations -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -pipe ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-std=c++11 -O0 -DNDEBUG -f -Wfloat-equal -Wextra -Wno-deprecated-declarations -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -s -pipe ${CMAKE_CXX_FLAGS}") add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) @@ -69,11 +71,13 @@ if (ENABLE_OPEN_SRC) foreach (COMPILE_FLAG ${COMPILE_FLAGS}) target_compile_options(_tf_adapter PUBLIC "${COMPILE_FLAG}") endforeach (COMPILE_FLAG) + target_compile_options(_tf_adapter PRIVATE -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer) target_link_libraries(_tf_adapter PUBLIC "dl") foreach (LINK_FLAG ${LINK_FLAGS}) target_link_libraries(_tf_adapter PUBLIC "${LINK_FLAG}") endforeach (LINK_FLAG) + target_link_libraries(_tf_adapter PUBLIC asan) target_compile_definitions(_tf_adapter PUBLIC LOG_CPP @@ -164,11 +168,12 @@ else() target_compile_options(tf_adapter PUBLIC $<$:-std=c++11> - -O2 + -O0 -g -DNDEBUG -ftrapv -Wno-deprecated-declarations -fno-common + -fsanitize=address -fsanitize-recover=address -fno-omit-frame-pointer ) target_compile_definitions(tf_adapter PUBLIC _FORTIFY_SOURCE=2 @@ -194,8 +199,8 @@ else() indextransform tensorflow_framework pywrap_tensorflow_internal + asan -Wl,--as-needed - -s ) # rename libtf_adapter.so to _tf_adapter.so diff --git a/tf_adapter/kernels/aicpu/map_dataset_op.cc b/tf_adapter/kernels/aicpu/map_dataset_op.cc index f209a3f8b..6734e9510 100644 --- a/tf_adapter/kernels/aicpu/map_dataset_op.cc +++ b/tf_adapter/kernels/aicpu/map_dataset_op.cc @@ -597,8 +597,13 @@ private: std::vector &out_tensors) { out_tensors.clear(); std::shared_ptr npu_addr(GetStartAddr(*output_result), [this, output_result](uint8_t *) { - this->results_empty_que_.emplace_back(output_result->result_id); - this->cond_var_->notify_all(); + if (output_result->result_id < max_output_results_) { + this->results_empty_que_.emplace_back(output_result->result_id); + this->cond_var_->notify_all(); + } else { + ADP_LOG(ERROR) << "Map npu addr invalid, result_id = " << output_result->result_id + << "( >= " << max_output_results_ << ")"; + } }); DATASET_REQUIRES((npu_addr != nullptr), errors::InvalidArgument("Alloc mem failed: ", output_mem_size_)); -- Gitee From ab1b21b516589fba254b97795eaa0b8fbfefe54b Mon Sep 17 00:00:00 2001 From: zhouyi <3128826091@qq.com> Date: Mon, 26 Sep 2022 16:30:58 +0800 Subject: [PATCH 2/2] =?UTF-8?q?E2E=E7=BD=91=E7=BB=9C=E6=8A=96=E5=8A=A8?= =?UTF-8?q?=E5=8E=89=E5=AE=B3=EF=BC=8C=E9=A9=B1=E5=8A=A8=E6=80=80=E7=96=91?= =?UTF-8?q?=E6=9B=B4=E5=86=85=E5=AD=98=E5=9C=B0=E5=9D=80=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E6=9C=89=E5=85=B3=EF=BC=8C=E8=BF=99=E9=87=8C=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=B0=86=E5=86=85=E5=AD=98=E6=B1=A0=E5=86=85=E5=AD=98=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=AF=B9=E9=BD=90=E5=88=B0128=E5=AD=97=E8=8A=82?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E9=A9=B1=E5=8A=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E2=80=94=E2=80=941980=E6=9C=89=E5=8A=A3?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E9=9C=80=E8=A6=81=E6=94=B9=E6=88=9064?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tf_adapter/util/memory_pool.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf_adapter/util/memory_pool.cc b/tf_adapter/util/memory_pool.cc index 445ffcf1f..d752dd479 100644 --- a/tf_adapter/util/memory_pool.cc +++ b/tf_adapter/util/memory_pool.cc @@ -21,7 +21,7 @@ #include "tf_adapter/common/adp_logger.h" namespace tensorflow { - constexpr uint64_t kMemAlignSize = 128; + constexpr uint64_t kMemAlignSize = 64; MemoryPool::MemoryPool() {} MemoryPool::~MemoryPool() {} -- Gitee