CANN Ops:No SOURCES given to target: opsproto
背景
CANN上算子基础库编译遇到一个问题,如下:
-- The C compiler identification is GNU 10.3.1
-- The CXX compiler identification is GNU 10.3.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Python3: /usr/bin/python3.9 (found version "3.9.9") found components: Interpreter
-- ASCEND_CANN_PACKAGE_PATH=/usr/local/Ascend/ascend-toolkit/latest
-- THIRD_PARTY_LIB_PATH=/root/zjun/cann-ops/third_party
-- ENABLE_CCACHE=ON, CUSTOM_CCACHE=
-- CCACHE_PROGRAM=CCACHE_PROGRAM-NOTFOUND
-- ASCEND_COMPUTE_UNIT=ascend310p;ascend310b;ascend910;ascend910b
-- ASCEND_OP_NAME=Addcmul
-- TILING_KEY=
-- TESTS_UT_OPS_TEST=
-- TESTS_EXAMPLE_OPS_TEST=
CMake Error at CMakeLists.txt:120 (add_library):
No SOURCES given to target: opsproto
CMake Generate step failed. Build files cannot be regenerated correctly.
make: *** No rule to make target 'prepare_build'. Stop.
CMake Error at cmake/config.cmake:239 (message):
Error: ops prepare build failed.
Call Stack (most recent call first):
CMakeLists.txt:20 (include)
-- Configuring incomplete, errors occurred!
通过如下命令执行的:
[root@localhost cann-ops]# bash build.sh -n Addcmul
-n是执行单独的算子编译
[root@localhost cann-ops]# bash build.sh -h
Usage: build.sh [options]
Options:
-h|--help Displays help message.
-n|--op-name Specifies the compiled operator. If there are multiple values, separate them with semicolons and use quotation marks. The default is all.
For example: -n "flash_attention_score" or -n "flash_attention_score;flash_attention_score_grad"
...
该算子工程仓库地址:
https://gitee.com/ascend/cann-ops.git
原因分析
上述过程都是按照https://gitee.com/ascend/cann-ops/blob/master/QuickStart.md中的指导进行操作的,反复检查了下,并没有发现问题。
还是通过报错进行分析,打开CMakeLists.txt:120,查看,这里开始定义opsproto ,并在ASCEND_AUTOGEN_DIR下找proto.cpp文件。
119 # op proto
120 message( " -----1------------ASCEND_AUTOGEN_DIR: ${ASCEND_AUTOGEN_DIR}")
121 add_library(opsproto SHARED)
122 message( " -----2------------ASCEND_AUTOGEN_DIR: ${ASCEND_AUTOGEN_DIR}")
123 file(GLOB PROTO_AUTO_FILES
124 ${ASCEND_AUTOGEN_DIR}/*_proto.cpp
125 )
126 target_sources(opsproto PRIVATE
127 ${PROTO_AUTO_FILES}
128 )
结合报错No SOURCES given to target: opsproto,猜测是没有找到任何proto.cpp文件,通过在CMakeLists.txt中添加打印,查看ASCEND_AUTOGEN_DIR下的文件信息,确实如猜测所述:
[root@localhost cann-ops]# ls /root/zjun/cann-ops/build/autogen
custom_compile_options.ini custom_opc_options.ini custom_tiling_keys.ini
到这里,猜测是算子名字写错了吗?
对比了下,Addcmul这个名字单词并没拼错,只是名字大小写不一致,莫非是因为这个导致的?
修改编译命令:
[root@localhost cann-ops]# bash build.sh -n addcmul
果然,顺利的执行下去了
-----1------------ASCEND_AUTOGEN_DIR: /root/zjun/cann-ops/build/autogen
-----2------------ASCEND_AUTOGEN_DIR: /root/zjun/cann-ops/build/autogen
-- Configuring done (6.2s)
-- Generating done (0.0s)
CMake Warning:
Manually-specified variables were not used by the project:
ASCEND_PYTHON_EXECUTABLE
CMAKE_CROSS_PLATFORM_COMPILER
ENABLE_BINARY_PACKAGE
ENABLE_CROSS_COMPILE
ENABLE_SOURCE_PACKAGE
ENABLE_TEST
-- Build files have been written to: /root/zjun/cann-ops/build
[ 4%] Generating op_host_aclnn_inner_stub.cpp
[ 4%] Generating op_host_aclnn_exc_stub.cpp
[ 8%] Building CXX object CMakeFiles/optiling.dir/src/common/src/fallback_comm.cpp.o
[ 8%] Building CXX object CMakeFiles/op_host_aclnn.dir/src/math/addcmul/op_host/addcmul.cpp.o
[ 12%] Building CXX object CMakeFiles/optiling.dir/src/math/addcmul/op_host/addcmul.cpp.o
查看ASCEND_AUTOGEN_DIR下的文件信息,确实也多了addcmul_proto.cpp等文件。
[root@localhost cann-ops]# ls /root/zjun/cann-ops/build/autogen
aclnn_addcmul.cpp aclnn_addcmul.h addcmul_proto.cpp addcmul_proto.h aic-ascend310b-ops-info.ini aic-ascend910b-ops-info.ini custom_compile_options.ini custom_opc_options.ini custom_tiling_keys.ini
解决办法
汗,最终原因就是编译算子的大小写拼音问题。
通过与CANN算子开发同学沟通,发现-n的使用规则如下:
-n后面跟算子的文件夹名,文件夹是什么样的(大小写、下划线等等),-n后面就写什么样的
记录一下吧,以防踩坑。
PS:研发的同学是不是应该在-n的help解释上多写上几句话的说明。
昇腾计算产业是基于昇腾系列(HUAWEI Ascend)处理器和基础软件构建的全栈 AI计算基础设施、行业应用及服务,https://devpress.csdn.net/organization/setting/general/146749包括昇腾系列处理器、系列硬件、CANN、AI计算框架、应用使能、开发工具链、管理运维工具、行业应用及服务等全产业链
更多推荐

所有评论(0)