diff --git a/CMakeLists.txt b/CMakeLists.txt index fa29b6cf64fdef98a9f61aa1faabc80671a86686..5d7c6c3a278b6f4e4b4314d112e671e8d5a5cec0 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 a2d3b9cdae8540516d4105a1e2b14426a949ae91..da06a70d28dfb35b9cf114e73501fee313547565 100644 --- a/tf_adapter/kernels/aicpu/map_dataset_op.cc +++ b/tf_adapter/kernels/aicpu/map_dataset_op.cc @@ -608,8 +608,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_)); diff --git a/tf_adapter/util/memory_pool.cc b/tf_adapter/util/memory_pool.cc index 445ffcf1f76ab314c0bc70559a6448a4d9077a3f..d752dd479bfb42776fb6cf2779dde63f7bc5e97d 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() {}