提交 4b54c594 编写于 作者: J jiweibo

update name format. test=develop

上级 df43322a
...@@ -355,7 +355,7 @@ void Predictor::GenRuntimeProgram() { ...@@ -355,7 +355,7 @@ void Predictor::GenRuntimeProgram() {
program_generated_ = true; program_generated_ = true;
#ifdef LITE_WITH_CUDA #ifdef LITE_WITH_CUDA
if (!cuda_use_multi_stream_) { if (!cuda_use_multi_stream_) {
program_->UpdateContext(cuda_exec_stream_, cuda_io_stream_); program_->UpdateCudaContext(cuda_exec_stream_, cuda_io_stream_);
} }
#endif #endif
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#ifdef LITE_WITH_CUDA #ifdef LITE_WITH_CUDA
#include "lite/backends/cuda/cuda_utils.h" #include "lite/backends/cuda/cuda_utils.h"
#include "lite/backends/cuda/stream_wrapper.h" #include "lite/backends/cuda/stream_guard.h"
#endif #endif
namespace paddle { namespace paddle {
...@@ -254,12 +254,12 @@ class CxxPaddleApiImpl : public lite_api::PaddlePredictor { ...@@ -254,12 +254,12 @@ class CxxPaddleApiImpl : public lite_api::PaddlePredictor {
#ifdef LITE_WITH_CUDA #ifdef LITE_WITH_CUDA
bool cuda_use_multi_stream_{false}; bool cuda_use_multi_stream_{false};
std::unique_ptr<lite::StreamWrapper> cuda_io_stream_; std::unique_ptr<lite::CudaStreamGuard> cuda_io_stream_;
std::unique_ptr<lite::StreamWrapper> cuda_exec_stream_; std::unique_ptr<lite::CudaStreamGuard> cuda_exec_stream_;
cudaEvent_t cuda_input_event_; cudaEvent_t cuda_input_event_;
std::vector<cudaEvent_t> cuda_output_events_; std::vector<cudaEvent_t> cuda_output_events_;
// only used for multi exec stream mode. // only used for multi exec stream mode.
std::vector<lite::StreamWrapper> cuda_exec_streams_; std::vector<lite::CudaStreamGuard> cuda_exec_streams_;
#endif #endif
}; };
......
...@@ -97,14 +97,14 @@ void CxxPaddleApiImpl::InitCudaEnv(std::vector<std::string> *passes) { ...@@ -97,14 +97,14 @@ void CxxPaddleApiImpl::InitCudaEnv(std::vector<std::string> *passes) {
// init two streams for each predictor. // init two streams for each predictor.
if (config_.cuda_exec_stream()) { if (config_.cuda_exec_stream()) {
cuda_exec_stream_.reset( cuda_exec_stream_.reset(
new lite::StreamWrapper(*config_.cuda_exec_stream())); new lite::CudaStreamGuard(*config_.cuda_exec_stream()));
} else { } else {
cuda_exec_stream_.reset(new lite::StreamWrapper()); cuda_exec_stream_.reset(new lite::CudaStreamGuard());
} }
if (config_.cuda_io_stream()) { if (config_.cuda_io_stream()) {
cuda_io_stream_.reset(new lite::StreamWrapper(*config_.cuda_io_stream())); cuda_io_stream_.reset(new lite::CudaStreamGuard(*config_.cuda_io_stream()));
} else { } else {
cuda_io_stream_.reset(new lite::StreamWrapper()); cuda_io_stream_.reset(new lite::CudaStreamGuard());
} }
raw_predictor_->set_cuda_exec_stream(cuda_exec_stream_->stream()); raw_predictor_->set_cuda_exec_stream(cuda_exec_stream_->stream());
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
void RunModel(lite_api::CxxConfig config) { void RunModel(const lite_api::CxxConfig& config) {
auto predictor = lite_api::CreatePaddlePredictor(config); auto predictor = lite_api::CreatePaddlePredictor(config);
const int batch_size = 4; const int batch_size = 4;
const int channels = 3; const int channels = 3;
......
...@@ -9,6 +9,6 @@ nv_library(cuda_blas SRCS blas.cc DEPS ${cuda_deps}) ...@@ -9,6 +9,6 @@ nv_library(cuda_blas SRCS blas.cc DEPS ${cuda_deps})
nv_library(nvtx_wrapper SRCS nvtx_wrapper DEPS ${cuda_deps}) nv_library(nvtx_wrapper SRCS nvtx_wrapper DEPS ${cuda_deps})
lite_cc_library(cuda_context SRCS context.cc DEPS device_info) lite_cc_library(cuda_context SRCS context.cc DEPS device_info)
lite_cc_library(stream_wrapper SRCS stream_wrapper.cc DEPS target_wrapper_cuda ${cuda_deps}) lite_cc_library(stream_guard SRCS stream_guard.cc DEPS target_wrapper_cuda ${cuda_deps})
add_subdirectory(math) add_subdirectory(math)
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "lite/backends/cuda/stream_wrapper.h" #include "lite/backends/cuda/stream_guard.h"
#include "lite/backends/cuda/cuda_utils.h" #include "lite/backends/cuda/cuda_utils.h"
namespace paddle { namespace paddle {
......
...@@ -21,24 +21,35 @@ ...@@ -21,24 +21,35 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
class StreamWrapper { // CudaStreamGuard is a encapsulation of cudaStream_t, which can accept external
// stream or internally created stream
//
// std::unique_ptr<CudaStreamGuard> sm;
//
// external stream: exec_stream
// sm.reset(new CudaStreamGuard(exec_stream));
// internal stream
// sm.reset(new CudaStreamGuard());
// get cudaStream_t
// sm->stream();
class CudaStreamGuard {
public: public:
explicit StreamWrapper(cudaStream_t stream) explicit CudaStreamGuard(cudaStream_t stream)
: stream_(stream), owner_(false) {} : stream_(stream), owned_(false) {}
StreamWrapper() : owner_(true) { CudaStreamGuard() : owned_(true) {
lite::TargetWrapperCuda::CreateStream(&stream_); lite::TargetWrapperCuda::CreateStream(&stream_);
} }
~StreamWrapper() { ~CudaStreamGuard() {
if (owner_) { if (owned_) {
lite::TargetWrapperCuda::DestroyStream(stream_); lite::TargetWrapperCuda::DestroyStream(stream_);
} }
} }
cudaStream_t stream() { return stream_; } cudaStream_t stream() { return stream_; }
bool owner() { return owner_; } bool owned() { return owned_; }
private: private:
cudaStream_t stream_; cudaStream_t stream_;
bool owner_; bool owned_{false};
}; };
} // namespace lite } // namespace lite
......
...@@ -71,7 +71,7 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) { ...@@ -71,7 +71,7 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
std::map<std::string, cpp::VarDesc> origin_var_maps; std::map<std::string, cpp::VarDesc> origin_var_maps;
auto& main_block = *desc->GetBlock<cpp::BlockDesc>(0); auto& main_block = *desc->GetBlock<cpp::BlockDesc>(0);
auto var_size = main_block.VarsSize(); auto var_size = main_block.VarsSize();
for (int i = 0; i < static_cast<int>(var_size); i++) { for (size_t i = 0; i < var_size; i++) {
auto v = main_block.GetVar<cpp::VarDesc>(i); auto v = main_block.GetVar<cpp::VarDesc>(i);
auto name = v->Name(); auto name = v->Name();
origin_var_maps.emplace(name, *v); origin_var_maps.emplace(name, *v);
...@@ -144,9 +144,9 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) { ...@@ -144,9 +144,9 @@ void RuntimeProgram::UpdateVarsOfProgram(cpp::ProgramDesc* desc) {
} }
#ifdef LITE_WITH_CUDA #ifdef LITE_WITH_CUDA
void RuntimeProgram::UpdateContext(cudaStream_t exec, cudaStream_t io) { void RuntimeProgram::UpdateCudaContext(cudaStream_t exec, cudaStream_t io) {
for (auto& inst : instructions_) { for (auto& inst : instructions_) {
inst.UpdateContext(exec, io); inst.UpdateCudaContext(exec, io);
} }
} }
#endif #endif
......
...@@ -129,7 +129,7 @@ struct Instruction { ...@@ -129,7 +129,7 @@ struct Instruction {
} }
} }
void Sync() const { kernel_->mutable_context()->As<CUDAContext>().Sync(); } void Sync() const { kernel_->mutable_context()->As<CUDAContext>().Sync(); }
void UpdateContext(cudaStream_t exec, cudaStream_t io) { void UpdateCudaContext(cudaStream_t exec, cudaStream_t io) {
if (kernel_->target() == TargetType::kCUDA) { if (kernel_->target() == TargetType::kCUDA) {
kernel_->mutable_context()->As<CUDAContext>().SetExecStream(exec); kernel_->mutable_context()->As<CUDAContext>().SetExecStream(exec);
kernel_->mutable_context()->As<CUDAContext>().SetIoStream(io); kernel_->mutable_context()->As<CUDAContext>().SetIoStream(io);
...@@ -223,9 +223,9 @@ class LITE_API RuntimeProgram { ...@@ -223,9 +223,9 @@ class LITE_API RuntimeProgram {
void UpdateVarsOfProgram(cpp::ProgramDesc* desc); void UpdateVarsOfProgram(cpp::ProgramDesc* desc);
#ifdef LITE_WITH_CUDA #ifdef LITE_WITH_CUDA
// UpdateContext will update the exec stream and io stream of all kernels in // UpdateCudaContext will update the exec stream and io stream of all kernels
// the program. // in the program.
void UpdateContext(cudaStream_t exec, cudaStream_t io); void UpdateCudaContext(cudaStream_t exec, cudaStream_t io);
#endif #endif
private: private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册