diff --git a/paddle/fluid/framework/tensor.h b/paddle/fluid/framework/tensor.h index 8c7345f3e2f614ef6b6a8d61211ec2e3d6d5e1bf..204c620ff80897990bbe7b801e65ed64727eb60a 100644 --- a/paddle/fluid/framework/tensor.h +++ b/paddle/fluid/framework/tensor.h @@ -28,7 +28,7 @@ limitations under the License. */ #include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/place.h" -#include "paddle/fluid/platform/stream/stream.h" +#include "paddle/pten/core/stream.h" #include "paddle/pten/core/dense_tensor.h" diff --git a/paddle/fluid/memory/allocation/allocator_facade.cc b/paddle/fluid/memory/allocation/allocator_facade.cc index f2bfaccd1d4db46fc069c2a1f0cb211d0ea54a73..35131446d8647e0581d2d997451017293b7ca8dc 100644 --- a/paddle/fluid/memory/allocation/allocator_facade.cc +++ b/paddle/fluid/memory/allocation/allocator_facade.cc @@ -940,7 +940,7 @@ uint64_t AllocatorFacade::Release(const platform::Place& place) { } std::shared_ptr AllocatorFacade::AllocShared( - const platform::Place& place, size_t size, const platform::Stream& stream) { + const platform::Place& place, size_t size, const pten::Stream& stream) { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) PADDLE_ENFORCE_EQ( FLAGS_use_stream_safe_cuda_allocator, true, @@ -965,7 +965,7 @@ std::shared_ptr AllocatorFacade::AllocShared( bool AllocatorFacade::InSameStream( const std::shared_ptr& allocation, - const platform::Stream& stream) { + const pten::Stream& stream) { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) PADDLE_ENFORCE_EQ( FLAGS_use_stream_safe_cuda_allocator, true, diff --git a/paddle/fluid/memory/allocation/allocator_facade.h b/paddle/fluid/memory/allocation/allocator_facade.h index f4aea98003abe077d34415604980a2f165a3fd83..6b9e82e85794e4f3b1c1bc2bc9b1fd584531b6fb 100644 --- a/paddle/fluid/memory/allocation/allocator_facade.h +++ b/paddle/fluid/memory/allocation/allocator_facade.h @@ -22,7 +22,7 @@ #include "paddle/fluid/platform/device/gpu/gpu_info.h" #endif #include "paddle/fluid/platform/place.h" -#include "paddle/fluid/platform/stream/stream.h" +#include "paddle/pten/core/stream.h" namespace paddle { namespace memory { @@ -71,13 +71,13 @@ class AllocatorFacade { std::shared_ptr AllocShared(const platform::Place& place, size_t size, - const platform::Stream& stream); + const pten::Stream& stream); bool InSameStream(const std::shared_ptr& allocation, - const platform::Stream& stream); + const pten::Stream& stream); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) - // TODO(zhiqiu): change gpuStream_t to platform::Stream if needed. + // TODO(zhiqiu): change gpuStream_t to pten::Stream if needed. AllocationPtr Alloc(const platform::Place& place, size_t size, const gpuStream_t& stream); uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream); diff --git a/paddle/fluid/memory/malloc.cc b/paddle/fluid/memory/malloc.cc index 63c562be97fa0728b26761ac856caf755717a64d..78166cb3893e6ee66d5a04e8255880c30eb75324 100644 --- a/paddle/fluid/memory/malloc.cc +++ b/paddle/fluid/memory/malloc.cc @@ -16,7 +16,7 @@ limitations under the License. */ #include "paddle/fluid/memory/allocation/allocator_facade.h" #include "paddle/fluid/platform/place.h" -#include "paddle/fluid/platform/stream/stream.h" +#include "paddle/pten/core/stream.h" namespace paddle { namespace memory { @@ -36,13 +36,13 @@ uint64_t Release(const platform::Place& place) { std::shared_ptr AllocShared(const platform::Place& place, size_t size, - const platform::Stream& stream) { + const pten::Stream& stream) { return allocation::AllocatorFacade::Instance().AllocShared(place, size, stream); } bool InSameStream(const std::shared_ptr& allocation, - const platform::Stream& stream) { + const pten::Stream& stream) { return allocation::AllocatorFacade::Instance().InSameStream(allocation, stream); } diff --git a/paddle/fluid/memory/malloc.h b/paddle/fluid/memory/malloc.h index 855cbb775a1096ba749d93667c71268045645a15..fe988ddccd7682aa97d36dc1693b179e4f5a5587 100644 --- a/paddle/fluid/memory/malloc.h +++ b/paddle/fluid/memory/malloc.h @@ -18,8 +18,8 @@ limitations under the License. */ #include "paddle/fluid/memory/allocation/allocator.h" #include "paddle/fluid/platform/place.h" -#include "paddle/fluid/platform/stream/stream.h" #include "paddle/pten/core/device_context.h" +#include "paddle/pten/core/stream.h" namespace paddle { namespace memory { @@ -39,10 +39,10 @@ extern uint64_t Release(const platform::Place& place); extern std::shared_ptr AllocShared(const platform::Place& place, size_t size, - const platform::Stream& stream); + const pten::Stream& stream); extern bool InSameStream(const std::shared_ptr& allocation, - const platform::Stream& stream); + const pten::Stream& stream); extern void* GetBasePtr(const std::shared_ptr& allocation); diff --git a/paddle/fluid/memory/stream_safe_cuda_alloc_test.cu b/paddle/fluid/memory/stream_safe_cuda_alloc_test.cu index bb44b29ac5b01340fbd0686231c66d04bf81612e..9fdc5284d1558b0d15190cba08d03fd459526e69 100644 --- a/paddle/fluid/memory/stream_safe_cuda_alloc_test.cu +++ b/paddle/fluid/memory/stream_safe_cuda_alloc_test.cu @@ -30,7 +30,7 @@ #include "paddle/fluid/platform/cuda_graph_with_memory_pool.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device_context.h" -#include "paddle/fluid/platform/stream/stream.h" +#include "paddle/pten/core/stream.h" namespace paddle { namespace memory { @@ -70,9 +70,9 @@ class StreamSafeCUDAAllocTest : public ::testing::Test { PADDLE_ENFORCE_GPU_SUCCESS(hipStreamCreate(&stream)); #endif - std::shared_ptr allocation = AllocShared( - place_, workspace_size_, - platform::Stream(reinterpret_cast(stream))); + std::shared_ptr allocation = + AllocShared(place_, workspace_size_, + pten::Stream(reinterpret_cast(stream))); #ifdef PADDLE_WITH_CUDA PADDLE_ENFORCE_GPU_SUCCESS( cudaMemset(allocation->ptr(), 0, allocation->size())); @@ -286,9 +286,9 @@ TEST(StreamSafeCUDAAllocInterfaceTest, GetStreamInterfaceTest) { PADDLE_ENFORCE_GPU_SUCCESS(hipStreamCreate(&new_stream)); #endif - std::shared_ptr allocation_new_stream = AllocShared( - place, alloc_size, - platform::Stream(reinterpret_cast(new_stream))); + std::shared_ptr allocation_new_stream = + AllocShared(place, alloc_size, + pten::Stream(reinterpret_cast(new_stream))); EXPECT_EQ(GetStream(allocation_new_stream), new_stream); #ifdef PADDLE_WITH_CUDA @@ -315,10 +315,10 @@ TEST(StreamSafeCUDAAllocInterfaceTest, CUDAGraphExceptionTest) { EXPECT_THROW(Release(place), paddle::platform::EnforceNotMet); EXPECT_THROW(allocation::AllocatorFacade::Instance().GetAllocator(place), paddle::platform::EnforceNotMet); - EXPECT_THROW(AllocShared(place, alloc_size, - platform::Stream( - reinterpret_cast(nullptr))), - paddle::platform::EnforceNotMet); + EXPECT_THROW( + AllocShared(place, alloc_size, + pten::Stream(reinterpret_cast(nullptr))), + paddle::platform::EnforceNotMet); EXPECT_THROW(Alloc(place, alloc_size, nullptr), paddle::platform::EnforceNotMet); EXPECT_THROW(Release(place, nullptr), paddle::platform::EnforceNotMet); diff --git a/paddle/fluid/operators/memcpy_h2d_op.h b/paddle/fluid/operators/memcpy_h2d_op.h index c9995eeca16cd42aaf8d69229a15dde7d949ea72..6d1b8eee04306c2ff7b1694de4b22251cdab40f2 100644 --- a/paddle/fluid/operators/memcpy_h2d_op.h +++ b/paddle/fluid/operators/memcpy_h2d_op.h @@ -15,7 +15,7 @@ limitations under the License. */ #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/var_type.h" #include "paddle/fluid/platform/device_context.h" -#include "paddle/fluid/platform/stream/stream.h" +#include "paddle/pten/core/stream.h" namespace pten { class DenseTensor; @@ -47,7 +47,7 @@ class MemcpyH2DFunctor { #endif out_tensor.mutable_data( dev_ctx_.GetPlace(), lod_tensor.type(), - platform::Stream(reinterpret_cast(stream))); + pten::Stream(reinterpret_cast(stream))); if (dst_place_type_ == 0 || dst_place_type_ == 1) { framework::TensorCopy(lod_tensor, dev_ctx_.GetPlace(), dev_ctx_, diff --git a/paddle/pten/core/dense_tensor.h b/paddle/pten/core/dense_tensor.h index 8d10753b58d23085eda7461a35db691909901176..ef8520e29c3b2fc1cdce0c7881d7c1e1aa653f1a 100644 --- a/paddle/pten/core/dense_tensor.h +++ b/paddle/pten/core/dense_tensor.h @@ -16,12 +16,12 @@ limitations under the License. */ #include "paddle/pten/core/allocator.h" #include "paddle/pten/core/storage.h" +#include "paddle/pten/core/stream.h" #include "paddle/pten/core/tensor_base.h" #include "paddle/pten/core/tensor_meta.h" // See Note [ Why still include the fluid headers? ] #include "paddle/fluid/framework/data_type.h" -#include "paddle/fluid/platform/stream/stream.h" /* @jim19930609: Move to MKLDNN_Tensor in the future */ diff --git a/paddle/pten/core/dense_tensor.inl b/paddle/pten/core/dense_tensor.inl index 754baeb73c90c2b494bf774588219c877a2fb8e9..d5d207aba40c2f6299c83dba2d24128d3e1eb7cc 100644 --- a/paddle/pten/core/dense_tensor.inl +++ b/paddle/pten/core/dense_tensor.inl @@ -76,7 +76,7 @@ void* mutable_data(const paddle::platform::Place& place, void* mutable_data(const paddle::platform::Place& place, paddle::framework::proto::VarType::Type type, - const paddle::platform::Stream& stream); + const pten::Stream& stream); /* @jim19930609: Remove dependency on protobuf after Tensor Unification. */ diff --git a/paddle/pten/core/dense_tensor_impl.cc b/paddle/pten/core/dense_tensor_impl.cc index 85714373472edc75c25e360a0aa4ef80da73fad7..a798ebe98b521a0bb11ff1f6127f21584bd39f79 100644 --- a/paddle/pten/core/dense_tensor_impl.cc +++ b/paddle/pten/core/dense_tensor_impl.cc @@ -144,7 +144,7 @@ void* DenseTensor::mutable_data(const paddle::platform::Place& place, void* DenseTensor::mutable_data(const paddle::platform::Place& place, paddle::framework::proto::VarType::Type type, - const paddle::platform::Stream& stream) { + const pten::Stream& stream) { set_type(type); PADDLE_ENFORCE_GE( numel(), diff --git a/paddle/fluid/platform/stream/stream.h b/paddle/pten/core/stream.h similarity index 90% rename from paddle/fluid/platform/stream/stream.h rename to paddle/pten/core/stream.h index 79ca51220bd6c196ce259656c9bfc79a2b4e8383..30bd1b0ba47668fda3248447f1738639d2c99bf8 100644 --- a/paddle/fluid/platform/stream/stream.h +++ b/paddle/pten/core/stream.h @@ -17,8 +17,7 @@ limitations under the License. */ #include #include -namespace paddle { -namespace platform { +namespace pten { using StreamId = uint64_t; class Stream final { @@ -30,5 +29,4 @@ class Stream final { StreamId id_; }; -} // namespace platform -} // namespace paddle +} // namespace pten