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

Fdy change dyn load #1301

Merged
merged 21 commits into from
Jul 29, 2024
Merged

Conversation

fandaoyi
Copy link
Collaborator

@fandaoyi fandaoyi commented Jul 10, 2024

支持 mx 和 torch 使用 动态加载的 pytorch (和 dipu 使用的 torch 可以不同)
把原有散落在 torch 目录下的动态加载相关的cmake 做了统一(包含 adapter, dynamic load 的 辅助函数). 原来需要手工处理的 patchelf等部分整合到 shell里. 并修改了 动态加载的逻辑, 可以从 lib的当前目录加载,

动态加载的整体逻辑还是参照之前的, 供参考:
https://aicarrier.feishu.cn/wiki/wikcnWKP9AKUEZKYCUprTNrvpod
https://aicarrier.feishu.cn/wiki/wikcnsNe1FkN0iX07OAcLZXaxkc
遗留问题

  1. 这一版支持动态加载需要 使用 -fno-gnu-unique! 编译选项 重新编译 pytorch, 非常难以使用, 后面计划使用 elf 工具 修改 用户安装的 pytorch 动态库文件 以消除 UNIQUE 变量. (开发耗时不确定, 建议单独开个 task, 这一版只加了简单的 注释 和 log 说明)
  2. 动态加载的 ci 也尚未加上

@fandaoyi fandaoyi requested review from SHshenhao and removed request for yewentao256 July 11, 2024 02:50
Copy link
Contributor

@wiryls wiryls left a comment

Choose a reason for hiding this comment

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

稍微看了一下 cmake 文件,这种写法挺容易相互污染导致出错的

@@ -0,0 +1,56 @@
macro(diopi_use_adapter cmd_extra_config)
Copy link
Contributor

Choose a reason for hiding this comment

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

用 macro 是特意的吗,里面定义了很多变量,容易污染相关脚本;另外也通过参数以外的方式直接引用了一些外部定义的变量名,挺容易出错的。

add_custom_target(adaptor_gen_dependency DEPENDS ${ADAPTOR_TEMPLATE_CODE})
set(ADAPTOR_CSRC_PATH "${ADAPTOR_DIR}/csrc")

separate_arguments(GenArgs UNIX_COMMAND "--diopi_dir=${DIOPI_IMPL_DIR}/../ --output_dir=${ADAPTOR_CSRC_PATH} ${cmd_extra_config}")
Copy link
Contributor

Choose a reason for hiding this comment

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

直接用 cmake 内置的 list 就行?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

用 list (set)的话传参的地方得改, 不能把几个参数放到一个变量里一起传了, 还要解析参数,

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这个名字起的有些问题, 我改叫 cmd_extra_config's' 吧

Copy link
Contributor

Choose a reason for hiding this comment

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

用 list (set)的话传参的地方得改, 不能把几个参数放到一个变量里一起传了, 还要解析参数,

其实是可以的,CMake 里面形如 --a=1;--b=2 会被认为是 ; 分割的数组`

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

确实, PS: 杨波要改些东西, 等他改完我把这个改了吧

DEPENDS adaptor_gen_dependency
VERBATIM
)
list(APPEND REAL_IMPL_SRC ${ADAPTOR_CSRC_PATH}/convert.cpp ${ADAPTOR_CSRC_PATH}/diopi_adaptor.cpp ${ADAPTOR_CSRC_PATH}/composite_ops.cpp)
Copy link
Contributor

@wiryls wiryls Jul 16, 2024

Choose a reason for hiding this comment

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

要不换成 concat 或者 set?万一 REAL_IMPL_SRC 这个名字被别的地方用了,不知道会构造出什么样的 list。如果在 function 之内的 scope 就没这个顾虑了,主要是它在 macro 之中

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

用 macro 主要是改动少, 我直接把原来外边的代码搬过来了. 不用改啥东西. 你要有空都改了, 可以改成 function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

我找时间改下吧. macro 确实不太好

impl/cmake/TorchBaseFunc.cmake Show resolved Hide resolved
impl/cmake/TorchBaseFunc.cmake Show resolved Hide resolved
@yangbofun yangbofun merged commit aefa5b7 into DeepLink-org:main Jul 29, 2024
17 checks passed
@yangbofun yangbofun deleted the fdy_change_dyn_load branch July 29, 2024 10:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants