Open
Conversation
本次提交修复了 Paddle 框架在多线程环境下设备管理的线程安全问题。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复设备管理在多线程环境下的线程安全问题
🎉 新春贺词
值此丙午马年除夕之际,谨向 Paddle 团队全体成员致以诚挚的新春祝福!愿我们在新的一年里如骏马奔腾,共同推动飞桨框架的技术创新与突破!🏮🧧
本次提交修复了 Paddle 框架在多线程环境下设备管理的线程安全问题。主要改动如下:
问题背景:原有的设备管理使用全局变量
_global_expected_place_,在多线程环境下存在竞态条件,不同线程的设备设置会相互污染。解决方案:采用双层设备管理设计
_global_expected_place_,保持向后兼容thread_expected_place_(基于GlobalThreadLocal扩展)核心改动:
GlobalThreadLocal类中增加thread_expected_place_字段_current_expected_place_()函数,实现线程类型判断和两级查找_set_expected_place()函数,根据线程类型更新对应存储位置_is_main_thread()辅助函数用于线程类型判断影响范围:
framework.py中的设备管理相关函数测试验证:
本次改动解决了多线程推理服务、并行数据处理等场景下的设备竞争问题,同时保持了 Paddle 全局设备管理的简洁性优势。
愿这份代码优化,作为献给飞桨的新春礼物! 🚀