Skip to content

Commit 17feccc

Browse files
committed
resolve qy compactibility
Signed-off-by: Ceng23333 <441651826@qq.com>
1 parent f8fab93 commit 17feccc

File tree

4 files changed

+65
-51
lines changed

4 files changed

+65
-51
lines changed

include/infinicore/adaptor/aten_adaptor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <c10/cuda/CUDAGuard.h>
1111
#endif
1212

13-
#ifdef ENABLE_NVIDIA_API
13+
#if defined(ENABLE_NVIDIA_API) || defined(ENABLE_QY_API)
1414
#include <ATen/cuda/CUDAContext.h>
1515
#endif
1616

xmake.lua

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -471,25 +471,14 @@ target("infinicore_cpp_api")
471471
if has_config("metax-gpu") then
472472
add_deps("flash-attn-metax")
473473
end
474+
if has_config("qy-gpu") then
475+
add_deps("flash-attn-qy")
476+
end
474477
end
475478

476-
-- MetaX: link pip-built flash_attn_2_cuda*.so.
477-
-- The `.so` path resolver lives in `xmake/metax.lua` and reads:
478-
-- - `FLASH_ATTN_2_CUDA_SO` (exact `.so` override)
479-
-- - `FLASH_ATTN_METAX_CUDA_SO_CONTAINER` (override expected container path)
480-
-- Path is fixed at target definition time (before_link sandbox has no os.iorunv in xmake 3.x).
481-
if get_config("flash-attn") and get_config("flash-attn") ~= "" and has_config("metax-gpu") then
482-
local flash_so_metax = _metax_flash_attn_cuda_so_path()
483-
local flash_dir_metax = path.directory(flash_so_metax)
484-
local flash_name_metax = path.filename(flash_so_metax)
485-
before_link(function (target)
486-
target:add(
487-
"shflags",
488-
"-Wl,--no-as-needed -L" .. flash_dir_metax .. " -l:" .. flash_name_metax .. " -Wl,-rpath," .. flash_dir_metax,
489-
{force = true}
490-
)
491-
end)
492-
end
479+
-- Flash pip `.so` link flags: `before_link` runs in an xmake sandbox that cannot see helpers
480+
-- from other included scripts; MetaX and QY each register their own hook in `xmake/metax.lua`
481+
-- and `xmake/qy.lua`.
493482

494483
before_build(function (target)
495484
if has_config("aten") then

xmake/metax.lua

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ do
99
-- on `infinicore_cpp_api` where `os.iorunv` is available in this xmake sandbox.
1010
end
1111

12+
-- Resolve MetaX flash-attn .so path (used only from this file: `before_link` sandbox cannot see globals from `xmake.lua`).
13+
local FLASH_ATTN_METAX_CUDA_SO_CONTAINER_DEFAULT =
14+
"/opt/conda/lib/python3.10/site-packages/flash_attn_2_cuda.cpython-310-aarch64-linux-gnu.so"
15+
16+
local function metax_flash_attn_cuda_so_path()
17+
-- Highest priority: override the exact `.so` file to link.
18+
local env_path = os.getenv("FLASH_ATTN_2_CUDA_SO")
19+
if env_path and env_path ~= "" then
20+
env_path = env_path:trim()
21+
if os.isfile(env_path) then
22+
return env_path
23+
end
24+
print(string.format("warning: metax+flash-attn: FLASH_ATTN_2_CUDA_SO is not a file: %s, fallback to container/default path", env_path))
25+
end
26+
27+
-- Second priority: allow overriding the "expected" container path via env.
28+
local container_path = os.getenv("FLASH_ATTN_METAX_CUDA_SO_CONTAINER")
29+
if not container_path or container_path == "" then
30+
container_path = FLASH_ATTN_METAX_CUDA_SO_CONTAINER_DEFAULT
31+
end
32+
33+
if not os.isfile(container_path) then
34+
print(
35+
string.format(
36+
"warning: metax+flash-attn: expected %s; install flash-attn in conda env, or export FLASH_ATTN_2_CUDA_SO.",
37+
container_path
38+
)
39+
)
40+
end
41+
return container_path
42+
end
43+
1244
-- Set numeric HPCC version macro for flash-attn signature/call compatibility.
1345
-- Must be done before compiling `infinicore_cpp_api` sources.
1446
target("infinicore_cpp_api")
@@ -39,41 +71,19 @@ target("infinicore_cpp_api")
3971
end
4072
end
4173
end)
42-
target_end()
43-
44-
-- Resolve MetaX flash-attn .so path.
45-
-- `xmake.lua` calls `_metax_flash_attn_cuda_so_path()` during `infinicore_cpp_api`
46-
-- linking, so this helper must live here (and must be global, not `local`).
47-
local FLASH_ATTN_METAX_CUDA_SO_CONTAINER_DEFAULT =
48-
"/opt/conda/lib/python3.10/site-packages/flash_attn_2_cuda.cpython-310-aarch64-linux-gnu.so"
49-
50-
function _metax_flash_attn_cuda_so_path()
51-
-- Highest priority: override the exact `.so` file to link.
52-
local env_path = os.getenv("FLASH_ATTN_2_CUDA_SO")
53-
if env_path and env_path ~= "" then
54-
env_path = env_path:trim()
55-
if os.isfile(env_path) then
56-
return env_path
57-
end
58-
print(string.format("warning: metax+flash-attn: FLASH_ATTN_2_CUDA_SO is not a file: %s, fallback to container/default path", env_path))
59-
end
60-
61-
-- Second priority: allow overriding the "expected" container path via env.
62-
local container_path = os.getenv("FLASH_ATTN_METAX_CUDA_SO_CONTAINER")
63-
if not container_path or container_path == "" then
64-
container_path = FLASH_ATTN_METAX_CUDA_SO_CONTAINER_DEFAULT
65-
end
66-
67-
if not os.isfile(container_path) then
68-
print(
69-
string.format(
70-
"warning: metax+flash-attn: expected %s; install flash-attn in conda env, or export FLASH_ATTN_2_CUDA_SO.",
71-
container_path
74+
if get_config("flash-attn") and get_config("flash-attn") ~= "" then
75+
before_link(function (target)
76+
local flash_so_metax = metax_flash_attn_cuda_so_path()
77+
local flash_dir_metax = path.directory(flash_so_metax)
78+
local flash_name_metax = path.filename(flash_so_metax)
79+
target:add(
80+
"shflags",
81+
"-Wl,--no-as-needed -L" .. flash_dir_metax .. " -l:" .. flash_name_metax .. " -Wl,-rpath," .. flash_dir_metax,
82+
{force = true}
7283
)
73-
)
84+
end)
7485
end
75-
return container_path
76-
end
86+
target_end()
7787

7888
add_includedirs(MACA_ROOT .. "/include")
7989
add_linkdirs(MACA_ROOT .. "/lib")

xmake/qy.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,18 @@ target("flash-attn-qy")
218218
end)
219219
end
220220
target_end()
221+
222+
if FLASH_ATTN_ROOT and FLASH_ATTN_ROOT ~= "" then
223+
target("infinicore_cpp_api")
224+
before_link(function (target)
225+
local flash_so_qy = _qy_flash_attn_cuda_so_path()
226+
local flash_dir_qy = path.directory(flash_so_qy)
227+
local flash_name_qy = path.filename(flash_so_qy)
228+
target:add(
229+
"shflags",
230+
"-Wl,--no-as-needed -L" .. flash_dir_qy .. " -l:" .. flash_name_qy .. " -Wl,-rpath," .. flash_dir_qy,
231+
{force = true}
232+
)
233+
end)
234+
target_end()
235+
end

0 commit comments

Comments
 (0)