Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DIPU] refactor: rewrite AsyncResourcePool #750

Closed
wants to merge 4 commits into from

Conversation

wiryls
Copy link
Collaborator

@wiryls wiryls commented Mar 26, 2024

正在改动 allocator 代码。由于非常担心大改动 break 掉很多东西,所以先把一些容易理解、修改和优化的部分改掉。本次重写了 AsyncResourcePool,主要包含这些事项:

  1. 删去没有使用到的抽象,消除虚函数开销
  2. 降低锁的范围,或者替换为原子变量
  3. 增加一个 helper 函数
  4. 重写 DIPUEvent 的部分方法,修复重复释放的问题

@wiryls wiryls added the refactor just better coding label Mar 26, 2024
@wiryls wiryls added the DIPU DIPU related label Mar 26, 2024
@wiryls wiryls changed the title refactor: rewrite AsyncResourcePool [DIPU] refactor: rewrite AsyncResourcePool Mar 26, 2024
auto& pool = *async_mem_pool();
while (not pool.empty()) {
auto item = pool.pop();
if (not item) {
std::this_thread::yield();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yield 作用有限,可能得考虑别的方法降低忙等待的开销

@wiryls wiryls marked this pull request as draft March 26, 2024 14:17
@wiryls wiryls marked this pull request as ready for review March 27, 2024 05:56
@wiryls wiryls requested a review from zhaoguochun1995 March 27, 2024 11:33
@zhaoguochun1995
Copy link
Collaborator

zhaoguochun1995 commented Apr 10, 2024

  1. 实测,加锁与不加锁,对模型性能没有影响。这里加锁只是为了概率极小的case下不出现数据不一致的情况。暂时没有遇到锁竞争的情况。改完后测了有性能提升嘛
  2. 部分抽象是预留的,可以自定义异步资源池。原先的设计思路是,新提供一个资源池,注册时使用新的资源池。提供新算法时,也是可以新提供内存管理算法,注册进去就可以使用。而不是修改已有的东西。新增式的扩展,可以很容易回退到原来的版本。就像现在,很容易多个算法之间切换。
  3. 如果害怕虚函数的开销,建议直接用汇编开发。

@wiryls wiryls closed this May 22, 2024
@wiryls wiryls deleted the refactor/w/allocator-1 branch May 22, 2024 06:44
xuq7410 pushed a commit to xuq7410/deeplink.framework that referenced this pull request May 23, 2024
delete python relate depandcy

Co-authored-by: zhaoguochun1995 <zhaoguochun1995@sensetime.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DIPU DIPU related refactor just better coding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants