未验证 提交 266955a9 编写于 作者: C Chen Weihang 提交者: GitHub

move stream into pten (#39392)

上级 b12e7a17
...@@ -28,7 +28,7 @@ limitations under the License. */ ...@@ -28,7 +28,7 @@ limitations under the License. */
#include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/enforce.h" #include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/place.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" #include "paddle/pten/core/dense_tensor.h"
......
...@@ -940,7 +940,7 @@ uint64_t AllocatorFacade::Release(const platform::Place& place) { ...@@ -940,7 +940,7 @@ uint64_t AllocatorFacade::Release(const platform::Place& place) {
} }
std::shared_ptr<pten::Allocation> AllocatorFacade::AllocShared( std::shared_ptr<pten::Allocation> 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) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
FLAGS_use_stream_safe_cuda_allocator, true, FLAGS_use_stream_safe_cuda_allocator, true,
...@@ -965,7 +965,7 @@ std::shared_ptr<pten::Allocation> AllocatorFacade::AllocShared( ...@@ -965,7 +965,7 @@ std::shared_ptr<pten::Allocation> AllocatorFacade::AllocShared(
bool AllocatorFacade::InSameStream( bool AllocatorFacade::InSameStream(
const std::shared_ptr<pten::Allocation>& allocation, const std::shared_ptr<pten::Allocation>& allocation,
const platform::Stream& stream) { const pten::Stream& stream) {
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
FLAGS_use_stream_safe_cuda_allocator, true, FLAGS_use_stream_safe_cuda_allocator, true,
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h"
#endif #endif
#include "paddle/fluid/platform/place.h" #include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/stream/stream.h" #include "paddle/pten/core/stream.h"
namespace paddle { namespace paddle {
namespace memory { namespace memory {
...@@ -71,13 +71,13 @@ class AllocatorFacade { ...@@ -71,13 +71,13 @@ class AllocatorFacade {
std::shared_ptr<Allocation> AllocShared(const platform::Place& place, std::shared_ptr<Allocation> AllocShared(const platform::Place& place,
size_t size, size_t size,
const platform::Stream& stream); const pten::Stream& stream);
bool InSameStream(const std::shared_ptr<Allocation>& allocation, bool InSameStream(const std::shared_ptr<Allocation>& allocation,
const platform::Stream& stream); const pten::Stream& stream);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #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, AllocationPtr Alloc(const platform::Place& place, size_t size,
const gpuStream_t& stream); const gpuStream_t& stream);
uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream); uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream);
......
...@@ -16,7 +16,7 @@ limitations under the License. */ ...@@ -16,7 +16,7 @@ limitations under the License. */
#include "paddle/fluid/memory/allocation/allocator_facade.h" #include "paddle/fluid/memory/allocation/allocator_facade.h"
#include "paddle/fluid/platform/place.h" #include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/stream/stream.h" #include "paddle/pten/core/stream.h"
namespace paddle { namespace paddle {
namespace memory { namespace memory {
...@@ -36,13 +36,13 @@ uint64_t Release(const platform::Place& place) { ...@@ -36,13 +36,13 @@ uint64_t Release(const platform::Place& place) {
std::shared_ptr<Allocation> AllocShared(const platform::Place& place, std::shared_ptr<Allocation> AllocShared(const platform::Place& place,
size_t size, size_t size,
const platform::Stream& stream) { const pten::Stream& stream) {
return allocation::AllocatorFacade::Instance().AllocShared(place, size, return allocation::AllocatorFacade::Instance().AllocShared(place, size,
stream); stream);
} }
bool InSameStream(const std::shared_ptr<Allocation>& allocation, bool InSameStream(const std::shared_ptr<Allocation>& allocation,
const platform::Stream& stream) { const pten::Stream& stream) {
return allocation::AllocatorFacade::Instance().InSameStream(allocation, return allocation::AllocatorFacade::Instance().InSameStream(allocation,
stream); stream);
} }
......
...@@ -18,8 +18,8 @@ limitations under the License. */ ...@@ -18,8 +18,8 @@ limitations under the License. */
#include "paddle/fluid/memory/allocation/allocator.h" #include "paddle/fluid/memory/allocation/allocator.h"
#include "paddle/fluid/platform/place.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/device_context.h"
#include "paddle/pten/core/stream.h"
namespace paddle { namespace paddle {
namespace memory { namespace memory {
...@@ -39,10 +39,10 @@ extern uint64_t Release(const platform::Place& place); ...@@ -39,10 +39,10 @@ extern uint64_t Release(const platform::Place& place);
extern std::shared_ptr<Allocation> AllocShared(const platform::Place& place, extern std::shared_ptr<Allocation> AllocShared(const platform::Place& place,
size_t size, size_t size,
const platform::Stream& stream); const pten::Stream& stream);
extern bool InSameStream(const std::shared_ptr<Allocation>& allocation, extern bool InSameStream(const std::shared_ptr<Allocation>& allocation,
const platform::Stream& stream); const pten::Stream& stream);
extern void* GetBasePtr(const std::shared_ptr<Allocation>& allocation); extern void* GetBasePtr(const std::shared_ptr<Allocation>& allocation);
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "paddle/fluid/platform/cuda_graph_with_memory_pool.h" #include "paddle/fluid/platform/cuda_graph_with_memory_pool.h"
#include "paddle/fluid/platform/device/gpu/gpu_info.h" #include "paddle/fluid/platform/device/gpu/gpu_info.h"
#include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/stream/stream.h" #include "paddle/pten/core/stream.h"
namespace paddle { namespace paddle {
namespace memory { namespace memory {
...@@ -70,9 +70,9 @@ class StreamSafeCUDAAllocTest : public ::testing::Test { ...@@ -70,9 +70,9 @@ class StreamSafeCUDAAllocTest : public ::testing::Test {
PADDLE_ENFORCE_GPU_SUCCESS(hipStreamCreate(&stream)); PADDLE_ENFORCE_GPU_SUCCESS(hipStreamCreate(&stream));
#endif #endif
std::shared_ptr<Allocation> allocation = AllocShared( std::shared_ptr<Allocation> allocation =
place_, workspace_size_, AllocShared(place_, workspace_size_,
platform::Stream(reinterpret_cast<platform::StreamId>(stream))); pten::Stream(reinterpret_cast<pten::StreamId>(stream)));
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
PADDLE_ENFORCE_GPU_SUCCESS( PADDLE_ENFORCE_GPU_SUCCESS(
cudaMemset(allocation->ptr(), 0, allocation->size())); cudaMemset(allocation->ptr(), 0, allocation->size()));
...@@ -286,9 +286,9 @@ TEST(StreamSafeCUDAAllocInterfaceTest, GetStreamInterfaceTest) { ...@@ -286,9 +286,9 @@ TEST(StreamSafeCUDAAllocInterfaceTest, GetStreamInterfaceTest) {
PADDLE_ENFORCE_GPU_SUCCESS(hipStreamCreate(&new_stream)); PADDLE_ENFORCE_GPU_SUCCESS(hipStreamCreate(&new_stream));
#endif #endif
std::shared_ptr<Allocation> allocation_new_stream = AllocShared( std::shared_ptr<Allocation> allocation_new_stream =
place, alloc_size, AllocShared(place, alloc_size,
platform::Stream(reinterpret_cast<platform::StreamId>(new_stream))); pten::Stream(reinterpret_cast<pten::StreamId>(new_stream)));
EXPECT_EQ(GetStream(allocation_new_stream), new_stream); EXPECT_EQ(GetStream(allocation_new_stream), new_stream);
#ifdef PADDLE_WITH_CUDA #ifdef PADDLE_WITH_CUDA
...@@ -315,10 +315,10 @@ TEST(StreamSafeCUDAAllocInterfaceTest, CUDAGraphExceptionTest) { ...@@ -315,10 +315,10 @@ TEST(StreamSafeCUDAAllocInterfaceTest, CUDAGraphExceptionTest) {
EXPECT_THROW(Release(place), paddle::platform::EnforceNotMet); EXPECT_THROW(Release(place), paddle::platform::EnforceNotMet);
EXPECT_THROW(allocation::AllocatorFacade::Instance().GetAllocator(place), EXPECT_THROW(allocation::AllocatorFacade::Instance().GetAllocator(place),
paddle::platform::EnforceNotMet); paddle::platform::EnforceNotMet);
EXPECT_THROW(AllocShared(place, alloc_size, EXPECT_THROW(
platform::Stream( AllocShared(place, alloc_size,
reinterpret_cast<platform::StreamId>(nullptr))), pten::Stream(reinterpret_cast<pten::StreamId>(nullptr))),
paddle::platform::EnforceNotMet); paddle::platform::EnforceNotMet);
EXPECT_THROW(Alloc(place, alloc_size, nullptr), EXPECT_THROW(Alloc(place, alloc_size, nullptr),
paddle::platform::EnforceNotMet); paddle::platform::EnforceNotMet);
EXPECT_THROW(Release(place, nullptr), paddle::platform::EnforceNotMet); EXPECT_THROW(Release(place, nullptr), paddle::platform::EnforceNotMet);
......
...@@ -15,7 +15,7 @@ limitations under the License. */ ...@@ -15,7 +15,7 @@ limitations under the License. */
#include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/var_type.h" #include "paddle/fluid/framework/var_type.h"
#include "paddle/fluid/platform/device_context.h" #include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/stream/stream.h" #include "paddle/pten/core/stream.h"
namespace pten { namespace pten {
class DenseTensor; class DenseTensor;
...@@ -47,7 +47,7 @@ class MemcpyH2DFunctor { ...@@ -47,7 +47,7 @@ class MemcpyH2DFunctor {
#endif #endif
out_tensor.mutable_data( out_tensor.mutable_data(
dev_ctx_.GetPlace(), lod_tensor.type(), dev_ctx_.GetPlace(), lod_tensor.type(),
platform::Stream(reinterpret_cast<platform::StreamId>(stream))); pten::Stream(reinterpret_cast<pten::StreamId>(stream)));
if (dst_place_type_ == 0 || dst_place_type_ == 1) { if (dst_place_type_ == 0 || dst_place_type_ == 1) {
framework::TensorCopy(lod_tensor, dev_ctx_.GetPlace(), dev_ctx_, framework::TensorCopy(lod_tensor, dev_ctx_.GetPlace(), dev_ctx_,
......
...@@ -16,12 +16,12 @@ limitations under the License. */ ...@@ -16,12 +16,12 @@ limitations under the License. */
#include "paddle/pten/core/allocator.h" #include "paddle/pten/core/allocator.h"
#include "paddle/pten/core/storage.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_base.h"
#include "paddle/pten/core/tensor_meta.h" #include "paddle/pten/core/tensor_meta.h"
// See Note [ Why still include the fluid headers? ] // See Note [ Why still include the fluid headers? ]
#include "paddle/fluid/framework/data_type.h" #include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/platform/stream/stream.h"
/* @jim19930609: Move to MKLDNN_Tensor in the future /* @jim19930609: Move to MKLDNN_Tensor in the future
*/ */
......
...@@ -76,7 +76,7 @@ void* mutable_data(const paddle::platform::Place& place, ...@@ -76,7 +76,7 @@ void* mutable_data(const paddle::platform::Place& place,
void* mutable_data(const paddle::platform::Place& place, void* mutable_data(const paddle::platform::Place& place,
paddle::framework::proto::VarType::Type type, paddle::framework::proto::VarType::Type type,
const paddle::platform::Stream& stream); const pten::Stream& stream);
/* @jim19930609: Remove dependency on protobuf after Tensor Unification. /* @jim19930609: Remove dependency on protobuf after Tensor Unification.
*/ */
......
...@@ -144,7 +144,7 @@ void* DenseTensor::mutable_data(const paddle::platform::Place& place, ...@@ -144,7 +144,7 @@ void* DenseTensor::mutable_data(const paddle::platform::Place& place,
void* DenseTensor::mutable_data(const paddle::platform::Place& place, void* DenseTensor::mutable_data(const paddle::platform::Place& place,
paddle::framework::proto::VarType::Type type, paddle::framework::proto::VarType::Type type,
const paddle::platform::Stream& stream) { const pten::Stream& stream) {
set_type(type); set_type(type);
PADDLE_ENFORCE_GE( PADDLE_ENFORCE_GE(
numel(), numel(),
......
...@@ -17,8 +17,7 @@ limitations under the License. */ ...@@ -17,8 +17,7 @@ limitations under the License. */
#include <cstdint> #include <cstdint>
#include <memory> #include <memory>
namespace paddle { namespace pten {
namespace platform {
using StreamId = uint64_t; using StreamId = uint64_t;
class Stream final { class Stream final {
...@@ -30,5 +29,4 @@ class Stream final { ...@@ -30,5 +29,4 @@ class Stream final {
StreamId id_; StreamId id_;
}; };
} // namespace platform } // namespace pten
} // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册