From ffff133b63ff70697de87e3d522ee8e8388741a8 Mon Sep 17 00:00:00 2001 From: Galaxy1458 <55453380+Galaxy1458@users.noreply.github.com> Date: Fri, 31 Mar 2023 19:17:33 +0800 Subject: [PATCH] FIX_LINUX_Wternimate (#52307) * this is a test pr, test=develop * solve the four [-Wterminate] warning, test=develop * solve the four [-Wterminate] warning, test=develop * new fix [-Wterminate], test=delelop * new fix [-Wterminate], test=delelop * new fix [-Wterminate], test=delelop * new , test = develop * new , test = develop * new , test = develop * new , test = develop * new , test = develop * new , test = develop --- .../plugin/fused_token_prune_op_plugin.h | 33 ++++++++------- .../inference/tensorrt/trt_int8_calibrator.cc | 13 +++--- .../cuda_device_context_allocator.h | 23 ++++------- .../fluid/memory/allocation/mmap_allocator.cc | 22 ++++------ paddle/phi/core/enforce.h | 41 +++++++++++++++++++ 5 files changed, 84 insertions(+), 48 deletions(-) diff --git a/paddle/fluid/inference/tensorrt/plugin/fused_token_prune_op_plugin.h b/paddle/fluid/inference/tensorrt/plugin/fused_token_prune_op_plugin.h index 238566c7b49..97ca79b2b0f 100644 --- a/paddle/fluid/inference/tensorrt/plugin/fused_token_prune_op_plugin.h +++ b/paddle/fluid/inference/tensorrt/plugin/fused_token_prune_op_plugin.h @@ -105,23 +105,28 @@ class FusedTokenPrunePluginDynamic : public DynamicPluginTensorRT { } else if (max_token_length_ <= 512) { padding_token_length = 512; } else { - PADDLE_THROW(platform::errors::InvalidArgument( - "Token_prune'token_length(max) must <= 512")); + try { + PADDLE_THROW(platform::errors::InvalidArgument( + "Token_prune'token_length(max) must <= 512")); + } catch (std::exception& e) { + } } - PADDLE_ENFORCE_GPU_SUCCESS(cudaMalloc(&pruned_token_lengths_, - (max_batchs_ + 1) * sizeof(int32_t))); - PADDLE_ENFORCE_GPU_SUCCESS(cudaMalloc( - &token_index_, max_batchs_ * padding_token_length * sizeof(int32_t))); - int32_t type_size = 4; - if (in[0].desc.type == nvinfer1::DataType::kHALF) { - type_size = 2; - } else { - type_size = 4; + try { + PADDLE_ENFORCE_GPU_SUCCESS(cudaMalloc( + &pruned_token_lengths_, (max_batchs_ + 1) * sizeof(int32_t))); + PADDLE_ENFORCE_GPU_SUCCESS(cudaMalloc( + &token_index_, max_batchs_ * padding_token_length * sizeof(int32_t))); + int32_t type_size = 4; + if (in[0].desc.type == nvinfer1::DataType::kHALF) { + type_size = 2; + } else { + type_size = 4; + } + PADDLE_ENFORCE_GPU_SUCCESS(cudaMalloc( + &padding_scores_, max_batchs_ * padding_token_length * type_size)); + } catch (std::exception& e) { } - PADDLE_ENFORCE_GPU_SUCCESS(cudaMalloc( - &padding_scores_, max_batchs_ * padding_token_length * type_size)); } - size_t getWorkspaceSize(const nvinfer1::PluginTensorDesc* inputs, int nb_inputs, const nvinfer1::PluginTensorDesc* outputs, diff --git a/paddle/fluid/inference/tensorrt/trt_int8_calibrator.cc b/paddle/fluid/inference/tensorrt/trt_int8_calibrator.cc index bf32e6eb745..176738ce629 100644 --- a/paddle/fluid/inference/tensorrt/trt_int8_calibrator.cc +++ b/paddle/fluid/inference/tensorrt/trt_int8_calibrator.cc @@ -115,11 +115,14 @@ bool TRTInt8Calibrator::getBatch(void** bindings, for (int i = 0; i < num_bindings; i++) { auto it = data_buffers_.find(names[i]); if (it == data_buffers_.end()) { - PADDLE_THROW( - platform::errors::Fatal("Calibration engine asked for unknown tensor " - "name '%s' at position %d.", - names[i], - i)); + try { + PADDLE_THROW(platform::errors::Fatal( + "Calibration engine asked for unknown tensor " + "name '%s' at position %d.", + names[i], + i)); + } catch (std::exception& e) { + } } bindings[i] = it->second.first; } diff --git a/paddle/fluid/memory/allocation/cuda_device_context_allocator.h b/paddle/fluid/memory/allocation/cuda_device_context_allocator.h index a27ac3d6f48..c8c1f7a61e6 100644 --- a/paddle/fluid/memory/allocation/cuda_device_context_allocator.h +++ b/paddle/fluid/memory/allocation/cuda_device_context_allocator.h @@ -44,13 +44,11 @@ class GPUContextAllocation : public Allocation { underlying_allocation_(std::move(allocation)) {} ~GPUContextAllocation() { - try { - PADDLE_ENFORCE_NOT_NULL( - dev_ctx_, - platform::errors::PreconditionNotMet( - "Device context is not set for GPUContextAllocation")); - } catch (std::exception &e) { - } + PADDLE_WARN_NOT_NULL( + dev_ctx_, + platform::errors::PreconditionNotMet( + "Device context is not set for GPUContextAllocation")); + auto *p_allocation = underlying_allocation_.release(); VLOG(4) << "Adding callback to delete GPUContextAllocation at " << p_allocation; @@ -89,17 +87,14 @@ class GPUContextAllocator : public Allocator { } ~GPUContextAllocator() { - try { - if (event_) { - platform::CUDADeviceGuard guard(place_.device); + if (event_) { + platform::CUDADeviceGuard guard(place_.device); #ifdef PADDLE_WITH_HIP - PADDLE_ENFORCE_GPU_SUCCESS(hipEventDestroy(event_)); + PADDLE_WARN_GPU_SUCCESS(hipEventDestroy(event_)); #else - PADDLE_ENFORCE_GPU_SUCCESS(cudaEventDestroy(event_)); + PADDLE_WARN_GPU_SUCCESS(cudaEventDestroy(event_)); #endif - } - } catch (std::exception &e) { } } diff --git a/paddle/fluid/memory/allocation/mmap_allocator.cc b/paddle/fluid/memory/allocation/mmap_allocator.cc index 1a6eaeaac21..1197098a4d8 100644 --- a/paddle/fluid/memory/allocation/mmap_allocator.cc +++ b/paddle/fluid/memory/allocation/mmap_allocator.cc @@ -216,26 +216,18 @@ void RefcountedMemoryMapAllocation::close() { } MemoryMapWriterAllocation::~MemoryMapWriterAllocation() { - try { - PADDLE_ENFORCE_NE( - munmap(this->ptr(), this->size()), - -1, - platform::errors::Unavailable( - "could not unmap the shared memory file %s", this->ipc_name())); - } catch (std::exception &e) { + if (munmap(this->ptr(), this->size()) == -1) { + platform::errors::Unavailable("could not unmap the shared memory file %s", + this->ipc_name()); } } MemoryMapReaderAllocation::~MemoryMapReaderAllocation() { - try { - PADDLE_ENFORCE_NE( - - munmap(this->ptr(), this->size()), - -1, - platform::errors::Unavailable( - "could not unmap the shared memory file %s", this->ipc_name())); - } catch (std::exception &e) { + if (munmap(this->ptr(), this->size()) == -1) { + platform::errors::Unavailable("could not unmap the shared memory file %s", + this->ipc_name()); } + /* Here we do not pay attention to the result of shm_unlink, because the memory mapped file may have been cleared due to the MemoryMapFdSet::Clear() */ diff --git a/paddle/phi/core/enforce.h b/paddle/phi/core/enforce.h index 10c3dd639ae..c709aa42b09 100644 --- a/paddle/phi/core/enforce.h +++ b/paddle/phi/core/enforce.h @@ -287,6 +287,11 @@ inline bool is_error(bool stat) { return !stat; } END_HANDLE_THE_ERROR \ } while (0) +#define __THROW_WARN_INTERNAL__(__MSG__) \ + do { \ + LOG(WARNING) << "WARNING :" << __MSG__; \ + } while (0) + /** ENFORCE EXCEPTION AND MACROS **/ struct EnforceNotMet : public std::exception { @@ -421,6 +426,17 @@ struct EnforceNotMet : public std::exception { } \ } while (0) +#define PADDLE_WARN_NOT_NULL(__VAL, ...) \ + do { \ + if (UNLIKELY(nullptr == (__VAL))) { \ + auto __summary__ = phi::ErrorSummary(__VA_ARGS__); \ + auto __message__ = ::paddle::string::Sprintf( \ + "%s\n [Hint: " #__VAL " should not be null.]", \ + __summary__.error_message()); \ + __THROW_WARN_INTERNAL__(__message__); \ + } \ + } while (0) + #define __PADDLE_BINARY_COMPARE(__VAL1, __VAL2, __CMP, __INV_CMP, ...) \ do { \ auto __val1 = (__VAL1); \ @@ -883,6 +899,19 @@ inline std::string build_nvidia_error_msg(ncclResult_t nccl_result) { } \ } while (0) +#define PADDLE_WARN_GPU_SUCCESS(COND) \ + do { \ + auto __cond__ = (COND); \ + using __CUDA_STATUS_TYPE__ = decltype(__cond__); \ + constexpr auto __success_type__ = \ + ::phi::enforce::details::ExternalApiType< \ + __CUDA_STATUS_TYPE__>::kSuccess; \ + if (UNLIKELY(__cond__ != __success_type__)) { \ + __THROW_WARN_INTERNAL__( \ + ::phi::enforce::build_nvidia_error_msg(__cond__)); \ + } \ + } while (0) + #define PADDLE_ENFORCE_CUDA_LAUNCH_SUCCESS(OP) \ do { \ auto res = cudaGetLastError(); \ @@ -1089,6 +1118,18 @@ DEFINE_EXTERNAL_API_TYPE(ncclResult_t, ncclSuccess); } \ } while (0) +#define PADDLE_WARN_GPU_SUCCESS(COND) \ + do { \ + auto __cond__ = (COND); \ + using __CUDA_STATUS_TYPE__ = decltype(__cond__); \ + constexpr auto __success_type__ = \ + ::phi::enforce::details::ExternalApiType< \ + __CUDA_STATUS_TYPE__>::kSuccess; \ + if (UNLIKELY(__cond__ != __success_type__)) { \ + __THROW_WARN_INTERNAL__(::phi::enforce::build_rocm_error_msg(__cond__)); \ + } \ + } while (0) + inline void retry_sleep(unsigned millisecond) { #ifdef _WIN32 Sleep(millisecond); -- GitLab