未验证 提交 8aef685b 编写于 作者: F From00 提交者: GitHub

Fix compilation errors for gcc-54 (#41228)

* Fix compilation error for gcc-54

* Remove const for gpuStream_t
上级 5dae6da0
...@@ -354,8 +354,7 @@ class AllocatorFacadePrivate { ...@@ -354,8 +354,7 @@ class AllocatorFacadePrivate {
} }
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
bool HasCUDAAllocator(const platform::CUDAPlace& place, bool HasCUDAAllocator(const platform::CUDAPlace& place, gpuStream_t stream) {
const gpuStream_t& stream) {
auto it = cuda_allocators_.find(place); auto it = cuda_allocators_.find(place);
if (it == cuda_allocators_.end()) { if (it == cuda_allocators_.end()) {
return false; return false;
...@@ -366,7 +365,7 @@ class AllocatorFacadePrivate { ...@@ -366,7 +365,7 @@ class AllocatorFacadePrivate {
} }
const std::shared_ptr<Allocator>& GetAllocator( const std::shared_ptr<Allocator>& GetAllocator(
const platform::CUDAPlace& place, const gpuStream_t& stream, const platform::CUDAPlace& place, gpuStream_t stream,
bool create_if_not_found = false) { bool create_if_not_found = false) {
if (LIKELY(!IsCUDAGraphCapturing())) { if (LIKELY(!IsCUDAGraphCapturing())) {
if (stream == GetDefaultStream(place)) { if (stream == GetDefaultStream(place)) {
...@@ -407,14 +406,13 @@ class AllocatorFacadePrivate { ...@@ -407,14 +406,13 @@ class AllocatorFacadePrivate {
return iter->second; return iter->second;
} }
const gpuStream_t& GetDefaultStream(const platform::CUDAPlace& place) const { gpuStream_t GetDefaultStream(const platform::CUDAPlace& place) const {
const std::shared_ptr<StreamSafeCUDAAllocator>& allocator = const std::shared_ptr<StreamSafeCUDAAllocator>& allocator =
GetDefaultStreamSafeCUDAAllocator(place); GetDefaultStreamSafeCUDAAllocator(place);
return allocator->GetDefaultStream(); return allocator->GetDefaultStream();
} }
void SetDefaultStream(const platform::CUDAPlace& place, void SetDefaultStream(const platform::CUDAPlace& place, gpuStream_t stream) {
const gpuStream_t& stream) {
const std::shared_ptr<StreamSafeCUDAAllocator>& allocator = const std::shared_ptr<StreamSafeCUDAAllocator>& allocator =
GetDefaultStreamSafeCUDAAllocator(place); GetDefaultStreamSafeCUDAAllocator(place);
allocator->SetDefaultStream(stream); allocator->SetDefaultStream(stream);
...@@ -424,7 +422,7 @@ class AllocatorFacadePrivate { ...@@ -424,7 +422,7 @@ class AllocatorFacadePrivate {
} }
void RecordStream(std::shared_ptr<phi::Allocation> allocation, void RecordStream(std::shared_ptr<phi::Allocation> allocation,
const gpuStream_t& stream) { gpuStream_t stream) {
std::shared_ptr<StreamSafeCUDAAllocation> stream_safe_cuda_allocation = std::shared_ptr<StreamSafeCUDAAllocation> stream_safe_cuda_allocation =
std::dynamic_pointer_cast<StreamSafeCUDAAllocation>(allocation); std::dynamic_pointer_cast<StreamSafeCUDAAllocation>(allocation);
if (stream_safe_cuda_allocation != nullptr) { if (stream_safe_cuda_allocation != nullptr) {
...@@ -434,7 +432,7 @@ class AllocatorFacadePrivate { ...@@ -434,7 +432,7 @@ class AllocatorFacadePrivate {
} }
} }
const gpuStream_t GetStream( gpuStream_t GetStream(
const std::shared_ptr<phi::Allocation>& allocation) const { const std::shared_ptr<phi::Allocation>& allocation) const {
const std::shared_ptr<StreamSafeCUDAAllocation> const std::shared_ptr<StreamSafeCUDAAllocation>
stream_safe_cuda_allocation = stream_safe_cuda_allocation =
...@@ -1044,7 +1042,7 @@ bool AllocatorFacade::IsStreamSafeCUDAAllocatorUsed() { ...@@ -1044,7 +1042,7 @@ bool AllocatorFacade::IsStreamSafeCUDAAllocatorUsed() {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
uint64_t AllocatorFacade::Release(const platform::CUDAPlace& place, uint64_t AllocatorFacade::Release(const platform::CUDAPlace& place,
const gpuStream_t& stream) { gpuStream_t stream) {
AllocatorFacadePrivate* m = GetPrivate(); AllocatorFacadePrivate* m = GetPrivate();
if (!m->IsStreamSafeCUDAAllocatorUsed()) { if (!m->IsStreamSafeCUDAAllocatorUsed()) {
VLOG(6) << "Warning: StreamSafeCUDAAllocator is not used!"; VLOG(6) << "Warning: StreamSafeCUDAAllocator is not used!";
...@@ -1055,12 +1053,12 @@ uint64_t AllocatorFacade::Release(const platform::CUDAPlace& place, ...@@ -1055,12 +1053,12 @@ uint64_t AllocatorFacade::Release(const platform::CUDAPlace& place,
} }
void AllocatorFacade::RecordStream(std::shared_ptr<phi::Allocation> allocation, void AllocatorFacade::RecordStream(std::shared_ptr<phi::Allocation> allocation,
const gpuStream_t& stream) { gpuStream_t stream) {
GetPrivate()->RecordStream(allocation, stream); GetPrivate()->RecordStream(allocation, stream);
} }
const std::shared_ptr<Allocator>& AllocatorFacade::GetAllocator( const std::shared_ptr<Allocator>& AllocatorFacade::GetAllocator(
const platform::Place& place, const gpuStream_t& stream) { const platform::Place& place, gpuStream_t stream) {
AllocatorFacadePrivate* m = GetPrivate(); AllocatorFacadePrivate* m = GetPrivate();
if (!m->IsStreamSafeCUDAAllocatorUsed()) { if (!m->IsStreamSafeCUDAAllocatorUsed()) {
...@@ -1075,13 +1073,13 @@ const std::shared_ptr<Allocator>& AllocatorFacade::GetAllocator( ...@@ -1075,13 +1073,13 @@ const std::shared_ptr<Allocator>& AllocatorFacade::GetAllocator(
return m->GetAllocator(place, /* A non-zero num to choose allocator_ */ 1); return m->GetAllocator(place, /* A non-zero num to choose allocator_ */ 1);
} }
const gpuStream_t AllocatorFacade::GetStream( gpuStream_t AllocatorFacade::GetStream(
const std::shared_ptr<phi::Allocation>& allocation) const { const std::shared_ptr<phi::Allocation>& allocation) const {
return GetPrivate()->GetStream(allocation); return GetPrivate()->GetStream(allocation);
} }
void AllocatorFacade::SetDefaultStream(const platform::CUDAPlace& place, void AllocatorFacade::SetDefaultStream(const platform::CUDAPlace& place,
const gpuStream_t& stream) { gpuStream_t stream) {
if (m_->IsStreamSafeCUDAAllocatorUsed()) { if (m_->IsStreamSafeCUDAAllocatorUsed()) {
m_->SetDefaultStream(place, stream); m_->SetDefaultStream(place, stream);
} }
......
...@@ -80,15 +80,12 @@ class AllocatorFacade { ...@@ -80,15 +80,12 @@ class AllocatorFacade {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
// TODO(zhiqiu): change gpuStream_t to phi::Stream if needed. // TODO(zhiqiu): change gpuStream_t to phi::Stream if needed.
uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream); uint64_t Release(const platform::CUDAPlace& place, gpuStream_t stream);
void RecordStream(std::shared_ptr<Allocation> allocation, void RecordStream(std::shared_ptr<Allocation> allocation, gpuStream_t stream);
const gpuStream_t& stream);
const std::shared_ptr<Allocator>& GetAllocator(const platform::Place& place, const std::shared_ptr<Allocator>& GetAllocator(const platform::Place& place,
const gpuStream_t& stream); gpuStream_t stream);
const gpuStream_t GetStream( gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation) const;
const std::shared_ptr<Allocation>& allocation) const; void SetDefaultStream(const platform::CUDAPlace& place, gpuStream_t stream);
void SetDefaultStream(const platform::CUDAPlace& place,
const gpuStream_t& stream);
#endif #endif
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
......
...@@ -33,7 +33,7 @@ StreamSafeCUDAAllocation::StreamSafeCUDAAllocation( ...@@ -33,7 +33,7 @@ StreamSafeCUDAAllocation::StreamSafeCUDAAllocation(
owning_stream_(std::move(owning_stream)), owning_stream_(std::move(owning_stream)),
allocator_(allocator->shared_from_this()) {} allocator_(allocator->shared_from_this()) {}
void StreamSafeCUDAAllocation::RecordStream(const gpuStream_t& stream) { void StreamSafeCUDAAllocation::RecordStream(gpuStream_t stream) {
VLOG(8) << "Try record stream " << stream << " for address " << ptr(); VLOG(8) << "Try record stream " << stream << " for address " << ptr();
if (stream == owning_stream_) { if (stream == owning_stream_) {
return; return;
...@@ -90,7 +90,7 @@ bool StreamSafeCUDAAllocation::CanBeFreed() { ...@@ -90,7 +90,7 @@ bool StreamSafeCUDAAllocation::CanBeFreed() {
return true; return true;
} }
const gpuStream_t& StreamSafeCUDAAllocation::GetOwningStream() const { gpuStream_t StreamSafeCUDAAllocation::GetOwningStream() const {
return owning_stream_; return owning_stream_;
} }
...@@ -102,7 +102,7 @@ void StreamSafeCUDAAllocation::RecordGraphCapturingStreams() { ...@@ -102,7 +102,7 @@ void StreamSafeCUDAAllocation::RecordGraphCapturingStreams() {
} }
void StreamSafeCUDAAllocation::RecordStreamWithNoGraphCapturing( void StreamSafeCUDAAllocation::RecordStreamWithNoGraphCapturing(
const gpuStream_t& stream) { gpuStream_t stream) {
gpuEvent_t record_event; gpuEvent_t record_event;
auto it = outstanding_event_map_.find(stream); auto it = outstanding_event_map_.find(stream);
if (it == outstanding_event_map_.end()) { if (it == outstanding_event_map_.end()) {
...@@ -154,11 +154,11 @@ StreamSafeCUDAAllocator::~StreamSafeCUDAAllocator() { ...@@ -154,11 +154,11 @@ StreamSafeCUDAAllocator::~StreamSafeCUDAAllocator() {
bool StreamSafeCUDAAllocator::IsAllocThreadSafe() const { return true; } bool StreamSafeCUDAAllocator::IsAllocThreadSafe() const { return true; }
const gpuStream_t& StreamSafeCUDAAllocator::GetDefaultStream() const { gpuStream_t StreamSafeCUDAAllocator::GetDefaultStream() const {
return default_stream_; return default_stream_;
} }
void StreamSafeCUDAAllocator::SetDefaultStream(const gpuStream_t& stream) { void StreamSafeCUDAAllocator::SetDefaultStream(gpuStream_t stream) {
default_stream_ = stream; default_stream_ = stream;
} }
......
...@@ -39,13 +39,13 @@ class StreamSafeCUDAAllocation : public Allocation { ...@@ -39,13 +39,13 @@ class StreamSafeCUDAAllocation : public Allocation {
gpuStream_t owning_stream, gpuStream_t owning_stream,
StreamSafeCUDAAllocator *allocator); StreamSafeCUDAAllocator *allocator);
void RecordStream(const gpuStream_t &stream); void RecordStream(gpuStream_t stream);
bool CanBeFreed(); bool CanBeFreed();
const gpuStream_t &GetOwningStream() const; gpuStream_t GetOwningStream() const;
private: private:
void RecordGraphCapturingStreams(); void RecordGraphCapturingStreams();
void RecordStreamWithNoGraphCapturing(const gpuStream_t &stream); void RecordStreamWithNoGraphCapturing(gpuStream_t stream);
DecoratedAllocationPtr underlying_allocation_; DecoratedAllocationPtr underlying_allocation_;
std::set<gpuStream_t> graph_capturing_stream_set_; std::set<gpuStream_t> graph_capturing_stream_set_;
std::map<gpuStream_t, gpuEvent_t> outstanding_event_map_; std::map<gpuStream_t, gpuEvent_t> outstanding_event_map_;
...@@ -66,8 +66,8 @@ class StreamSafeCUDAAllocator ...@@ -66,8 +66,8 @@ class StreamSafeCUDAAllocator
~StreamSafeCUDAAllocator(); ~StreamSafeCUDAAllocator();
bool IsAllocThreadSafe() const override; bool IsAllocThreadSafe() const override;
const gpuStream_t &GetDefaultStream() const; gpuStream_t GetDefaultStream() const;
void SetDefaultStream(const gpuStream_t &stream); void SetDefaultStream(gpuStream_t stream);
protected: protected:
phi::Allocation *AllocateImpl(size_t size) override; phi::Allocation *AllocateImpl(size_t size) override;
......
...@@ -57,17 +57,16 @@ void* GetBasePtr(const std::shared_ptr<Allocation>& allocation) { ...@@ -57,17 +57,16 @@ void* GetBasePtr(const std::shared_ptr<Allocation>& allocation) {
} }
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream) { uint64_t Release(const platform::CUDAPlace& place, gpuStream_t stream) {
return allocation::AllocatorFacade::Instance().Release(place, stream); return allocation::AllocatorFacade::Instance().Release(place, stream);
} }
void RecordStream(std::shared_ptr<Allocation> allocation, void RecordStream(std::shared_ptr<Allocation> allocation, gpuStream_t stream) {
const gpuStream_t& stream) {
return allocation::AllocatorFacade::Instance().RecordStream(allocation, return allocation::AllocatorFacade::Instance().RecordStream(allocation,
stream); stream);
} }
const gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation) { gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation) {
return allocation::AllocatorFacade::Instance().GetStream(allocation); return allocation::AllocatorFacade::Instance().GetStream(allocation);
} }
......
...@@ -50,13 +50,11 @@ extern bool InSameStream(const std::shared_ptr<Allocation>& allocation, ...@@ -50,13 +50,11 @@ extern bool InSameStream(const std::shared_ptr<Allocation>& allocation,
extern void* GetBasePtr(const std::shared_ptr<Allocation>& allocation); extern void* GetBasePtr(const std::shared_ptr<Allocation>& allocation);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
extern uint64_t Release(const platform::CUDAPlace& place, extern uint64_t Release(const platform::CUDAPlace& place, gpuStream_t stream);
const gpuStream_t& stream);
void RecordStream(std::shared_ptr<Allocation> allocation, void RecordStream(std::shared_ptr<Allocation> allocation, gpuStream_t stream);
const gpuStream_t& stream);
const gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation); gpuStream_t GetStream(const std::shared_ptr<Allocation>& allocation);
#endif #endif
} // namespace memory } // namespace memory
} // namespace paddle } // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册