diff --git a/paddle/framework/executor.cc b/paddle/framework/executor.cc index 559cbe125f86f72176a4f286fa55a17529fd58f0..ebe3259bc06ee309477c2877eaf1da19875c4a14 100644 --- a/paddle/framework/executor.cc +++ b/paddle/framework/executor.cc @@ -69,10 +69,13 @@ void GraphView::Initialize(const ProgramDesc* pdesc) { struct Device { platform::CPUDeviceContext* cpu_device_context; +#ifndef PADDLE_ONLY_CPU + platform::CUDADeviceContext* cuda_device_context; +#endif + #ifndef PADDLE_ONLY_CPU Device(platform::CPUDeviceContext* cpu, platform::CUDADeviceContext* gpu) : cpu_device_context(cpu), cuda_device_context(gpu) {} - platform::CDUADeviceContext* cuda_device_context; #else explicit Device(platform::CPUDeviceContext* cpu) : cpu_device_context(cpu) {} #endif @@ -126,10 +129,16 @@ platform::CUDADeviceContext* GetCUDADeviceContext( Device* GetDevice(const platform::Place& place) { platform::CPUPlace cpu_place; #ifndef PADDLE_ONLY_CPU - platform::GPUPlace gpu_place = boost::get(place); - static std::unique_ptr g_device = make_unique( - GetCPUDeviceContext(cpu_place), GetCUDADeviceContext(gpu_place)); - return g_device.get(); + if (platform::is_gpu_place(place)) { + platform::GPUPlace gpu_place = boost::get(place); + static std::unique_ptr g_device = make_unique( + GetCPUDeviceContext(cpu_place), GetCUDADeviceContext(gpu_place)); + return g_device.get(); + } else { + static std::unique_ptr g_device = + make_unique(GetCPUDeviceContext(cpu_place), nullptr); + return g_device.get(); + } #else static std::unique_ptr g_device = make_unique(GetCPUDeviceContext(cpu_place)); @@ -153,7 +162,9 @@ void ExecutorImpl::Run() { scope_->NewVar(); device_->cpu_device_context->Wait(); #ifndef PADDLE_ONLY_CPU - device_->cuda_device_context->Wait(); + if (device_->cuda_device_context) { + device_->cuda_device_context->Wait(); + } #endif }