xmake config在target非常多时会非常慢
Xmake 版本
v2.9.6+20241218
操作系统版本和架构
Ubuntu 20.04
描述问题
我现在做的是跨语言的模板参数传递,我不使用options的原因是同一个模板可能被实例化多次。因此我有大约3000个target,是用脚本定义的。但是现在只要运行xmake f就会卡住
期待的结果
正常来说这些行应该执行起来很快。
工程配置
local curve_names = {"bn254", "bls12381"}
local curve_scalar_bits = {254, 255}
local window_sizes = {8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}
local alphas = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}
local debugs = {true, false}
-- all combines of target
for curve_id, curve_names in ipairs(curve_names) do
for _, window_size in ipairs(window_sizes) do
for _, alpha in ipairs(alphas) do
for _, debug in ipairs(debugs) do
local target_name = "msm_" .. curve_names .. "_" .. window_size .. "_" .. alpha .. "_" .. tostring(debug)
target(target_name)
set_kind("shared")
set_targetdir(os.projectdir().."/lib")
add_files("src/msm.cu")
curve_scalar_bit = curve_scalar_bits[curve_id]
add_defines("MSM_BITS="..curve_scalar_bit)
add_defines("MSM_CURVE="..curve_names)
add_defines("MSM_WINDOW_SIZE="..window_size)
add_defines("MSM_TARGET_WINDOWS="..(alpha))
add_defines("MSM_DEBUG="..(tostring(debug)))
add_cugencodes("native")
set_optimize("fastest")
set_languages("c++17")
end
end
end
end
附加信息和错误日志
xmake f --verbose --toolchain=cuda -c --cu-ccbin=gcc-11
checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checking for zig ... no
checking for zig ... no
checking for nim ... no
checking for nim ... no
checking for git ... /usr/bin/git
checking for gzip ... /usr/bin/gzip
checking for tar ... /usr/bin/tar
/usr/bin/git rev-parse HEAD
checking for xmake::doctest ... doctest 2.4.11
checking for Cuda SDK directory ... /usr/local/cuda
checking for nvcc ... /usr/local/cuda/bin/nvcc
checking for cuda devices
> found device #0: NVIDIA GeForce RTX 4090 with compute 8.9 capability
> found device #1: NVIDIA GeForce RTX 4090 with compute 8.9 capability
checking for nvcc ... /usr/local/cuda/bin/nvcc
checking for the cuda compiler (cu) ... nvcc
Bot detected the issue body's language is not English, translate it automatically.
Title: xmake config will be very slow when there are a lot of targets
给个完整可复现的例子工程,最好不要涉及 cuda 的
Bot detected the issue body's language is not English, translate it automatically.
Give a complete reproducible example project, it is best not to involve cuda
我感觉应该和cuda有关,具体来说似乎只有运行xmake f --cu-ccbin=gcc-11的时候才会卡住 xmake f --cuda=/usr/local/cuda就不会
xmake.lua
add_rules("mode.debug", "mode.release")
local curve_names = {"bn254", "bls12381"}
local curve_scalar_bits = {254, 255}
local window_sizes = {8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31}
local alphas = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30}
local debugs = {true, false}
-- all combines of target
for curve_id, curve_names in ipairs(curve_names) do
for _, window_size in ipairs(window_sizes) do
for _, alpha in ipairs(alphas) do
for _, debug in ipairs(debugs) do
local target_name = "msm_" .. curve_names .. "_" .. window_size .. "_" .. alpha .. "_" .. tostring
(debug)
target(target_name)
set_kind("shared")
set_targetdir(os.projectdir().."/lib")
add_files("src/dummy.cu")
curve_scalar_bit = curve_scalar_bits[curve_id]
add_defines("MSM_BITS="..curve_scalar_bit)
add_defines("MSM_CURVE="..curve_names)
add_defines("MSM_WINDOW_SIZE="..window_size)
add_defines("MSM_TARGET_WINDOWS="..(alpha))
add_defines("MSM_DEBUG="..(tostring(debug)))
set_optimize("fastest")
set_languages("c++17")
end
end
end
end
/src/dummy.cu
int add(int a, int b) {return a+b;}
我暂时没有 cuda 环境,你可以自己调下相关 cuda 探测代码
Bot detected the issue body's language is not English, translate it automatically.
I don't have a cuda environment for the time being, you can adjust the relevant cuda detection code yourself
和这个同时存在的一个bug是每次调用xmake build(还是之前的例子),都会重新找一遍依赖路径
checking for gcc ... /usr/bin/gcc
checking for nim ... no
checking for nim ... no
checking for Cuda SDK directory ... /usr/local/cuda
checking for nvcc ... /usr/local/cuda/bin/nvcc
checking for the cuda compiler (cu) ... nvcc
checking for /usr/local/cuda/bin/nvcc ... ok
checking for flags (-O3) ... ok
checking for flags (-rdc=true) ... ok
checking for flags (-DNDEBUG) ... ok
checking for nvcc ... /usr/local/cuda/bin/nvcc
checking for the cuda linker (culd) ... nvcc
checking for g++ ... /usr/bin/g++
checking for the shared library linker (sh) ... g++
checking for /usr/bin/g++ ... ok
checking for flags (-fPIC) ... ok
这两个bug互相作用几乎就没法用了
没有完整复现工程和环境,我暂时无法调试,你可以直接跟下代码
Bot detected the issue body's language is not English, translate it automatically.
Without a complete reproduction project and environment, I cannot debug it for the time being, you can directly follow the code
这个问题应该缓解了,可以试试最新版本 https://github.com/xmake-io/xmake/issues/6775