diff --git a/paddle/fluid/framework/new_executor/interpretercore.cc b/paddle/fluid/framework/new_executor/interpretercore.cc index 3035f1bcffa47571d4be01162d7b24568c567fe3..cadc3d3e5ef8c59b62acfb3f40113faa2abbc9a3 100644 --- a/paddle/fluid/framework/new_executor/interpretercore.cc +++ b/paddle/fluid/framework/new_executor/interpretercore.cc @@ -11,6 +11,14 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + +#if !defined(_WIN32) +#include +#else +#define NOMINMAX +#include +#endif // !_WIN32 + #include "paddle/fluid/framework/new_executor/interpretercore.h" #include @@ -255,10 +263,7 @@ void InterpreterCore::Convert() { } for (size_t i = 0; i < vec_instruction_.size(); ++i) { - // int device_type = static_cast(paddle::platform::DeviceType::CUDA); - // paddle::platform::DeviceOption dev_opt( - // device_type, BOOST_GET_CONST(platform::CUDAPlace, place_).device); - gc_event_.emplace_back(place_); + gc_event_.emplace_back(place_, platform::GenerateDeviceEventFlag()); std::vector vec_temp; for (auto& item : vec_instruction_[i].output_index_) { @@ -450,41 +455,40 @@ void InterpreterCore::CheckGC(size_t instr_id, if (!garbages_->empty()) { if (max_memory_size_ <= 1) { -#if defined(PADDLE_WITH_CUDA) - auto* dev_ctx = reinterpret_cast( + gc_event_[instr_id].Record( platform::DeviceContextPool::Instance().Get(place)); - gc_event_[instr_id].Record(dev_ctx); + gc_event_[instr_id].SetFininshed(); // Only for CPU Event gc_queue_->AddTask( [ container = garbages_.release(), event = &gc_event_[instr_id] ]() { while (!event->Query()) { +#if defined(_WIN32) + SleepEx(50, FALSE); +#else + sched_yield(); +#endif continue; } delete container; }); garbages_.reset(new GarbageQueue()); -#else - delete garbages_.release(); - garbages_.reset(new GarbageQueue()); -#endif } else if (cur_memory_size_ >= max_memory_size_) { -#if defined(PADDLE_WITH_CUDA) - auto* dev_ctx = reinterpret_cast( + gc_event_[instr_id].Record( platform::DeviceContextPool::Instance().Get(place)); - gc_event_[instr_id].Record(dev_ctx); + gc_event_[instr_id].SetFininshed(); // Only for CPU Event gc_queue_->AddTask( [ container = garbages_.release(), event = &gc_event_[instr_id] ]() { while (!event->Query()) { +#if defined(_WIN32) + SleepEx(50, FALSE); +#else + sched_yield(); +#endif continue; } delete container; }); garbages_.reset(new GarbageQueue()); cur_memory_size_ = 0; -#else - delete garbages_.release(); - garbages_.reset(new GarbageQueue()); - cur_memory_size_ = 0; -#endif } } }