Ascendc helloworld编译问题

1 入门ascendc 写HelloWorld

https://www.hiascend.com/document/detail/zh/canncommercial/81RC1/developmentguide/opdevg/Ascendcopdevg/atlas_ascendc_10_0004.html
下面是一个简单的Ascend C的"Hello World"样例,展示了一个Ascend C核函数(设备侧实现的入口函数)的基本写法,及其如何被调用的流程。

包含核函数的实现文件hello_world.cpp代码如下:核函数hello_world的核心逻辑为打印"Hello World!!!"字符串。hello_world_do封装了核函数的调用程序,通过<<<>>>内核调用符对核函数进行调用。

#include "kernel_operator.h"
extern "C" __global__ __aicore__ void hello_world()
{
    AscendC::printf("Hello World!!!\n");
}

void hello_world_do(uint32_t blockDim, void* stream)
{
    hello_world<<<blockDim, nullptr, stream>>>();
}

调用核函数的应用程序main.cpp代码如下(您可以通过代码注释了解其主要的流程):

#include "acl/acl.h"
extern void hello_world_do(uint32_t coreDim, void* stream);

int32_t main(int argc, char const *argv[])
{
    // AscendCL初始化
    aclInit(nullptr);
    // 运行管理资源申请
    int32_t deviceId = 0;
    aclrtSetDevice(deviceId);
    aclrtStream stream = nullptr;
    aclrtCreateStream(&stream);

    // 设置参与运算的核数为8(核数可根据实际需求设置)
    constexpr uint32_t blockDim = 8;
    // 用内核调用符<<<>>>调用核函数,hello_world_do中封装了<<<>>>调用
    hello_world_do(blockDim, stream);
    aclrtSynchronizeStream(stream);
    // 资源释放和AscendCL去初始化
    aclrtDestroyStream(stream);
    aclrtResetDevice(deviceId);
    aclFinalize();
    return 0;
}

通过如下的代码工程对上述文件进行组织,您可以通过LINK获取样例工程,并参考README完成CMakeLists中的AI处理器的型号、软件包安装路径配置。

|-- CMakeLists.txt                                        // CMake编译配置文件
|-- hello_world.cpp                                       // Kernel实现
|-- main.cpp                                              // 调用核函数的主程序
|-- run.sh                                                // 一键式编译运行脚本    

通过执行如下脚本实现样例程序的编译和运行:

bash run.sh -v <soc_version>

2 环境准备

1、安装CANN
CANN安装

2、安装依赖的软件

  • Debian系列(Ubuntu、Debian、UOS20、UOS20 SP1):
apt-get install -y gcc g++ make net-tools cmake python3 python3-dev python3-pip
  • openEuler系列(openEuler、CentOS、Kylin、BCLinux、BC-Linux-for-Euler、UOS201050e、UOS20 1020e、UOSV20、AntOS、CTyunOS、CULinux、Tlinux):
yum install -y gcc make net-tools cmake python3 python3-devel python3-pip

也可以参考:
https://www.hiascend.com/document/detail/zh/canncommercial/81RC1/developmentguide/opdevg/Ascendcopdevg/atlas_ascendc_10_0002.html

3 编译遇到的问题

问题1:

Current compile soc version is Ascend910B3
-- The C compiler identification is GNU 12.3.1
-- The CXX compiler identification is unknown
-- 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
CMake Error at CMakeLists.txt:7 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
gmake: Makefile: No such file or directory
gmake: *** No rule to make target 'Makefile'.  Stop.

解决:

yum install g++

问题2:

In file included from /usr/local/Ascend/ascend-toolkit/latest/tools/tikcpp/tikcfw/impl/utils/kernel_utils_macros.h:33:
/usr/local/Ascend/ascend-toolkit/latest/tools/tikcpp/tikcfw/impl/kernel_macros.h:24:10: fatal error: 'cstdint' file not found
#include <cstdint>
         ^~~~~~~~~
1 error generated.
gmake[5]: *** [CMakeFiles/precompile_obj.dir/build.make:76: CMakeFiles/precompile_obj.dir/home/ascendc/samples/operator/ascendc/0_introduction/0_helloworld/hello_world.cpp.o] Error 1

解决:
首先查找cstdint的位置,如下:

root@hostname-bnq0f:/home/ascendc/samples/operator/ascendc/0_introduction/0_helloworld# find / -name cstdint
/usr/local/Ascend/ascend-toolkit/8.1.RC1/toolkit/toolchain/hcc/aarch64-target-linux-gnu/include/c++/7.3.0/cstdint
/usr/local/Ascend/ascend-toolkit/8.1.RC1/toolkit/toolchain/hcc/aarch64-target-linux-gnu/include/c++/7.3.0/tr1/cstdint
/usr/include/c++/12/cstdint
/usr/include/c++/12/tr1/cstdint

然后设置CPLUS_INCLUDE_PATH变量

export CPLUS_INCLUDE_PATH=/usr/include/c++/12/:$CPLUS_INCLUDE_PATH

问题3:

In file included from /usr/local/Ascend/ascend-toolkit/latest/tools/tikcpp/tikcfw/impl/kernel_macros.h:24:
/usr/include/c++/12/cstdint:38:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
gmake[5]: *** [CMakeFiles/precompile_obj.dir/build.make:76: CMakeFiles/precompile_obj.dir/home/ascendc/samples/operator/ascendc/0_introduction/0_helloworld/hello_world.cpp.o] Error 1

bits/c++config.h处在目录下面/usr/include/c++/12/aarch64-openEuler-linux,需要将bits目录添加到变量CPLUS_INCLUDE_PATH中。

export CPLUS_INCLUDE_PATH=/usr/include/c++/12:/usr/include/c++/12/aarch64-openEuler-linux:$CPLUS_INCLUDE_PATH
root@fwb-VMware-Virtual-Platform:/home/fwb/Downloads/samples/operator/ascendc/0_introduction/0_helloworld# bash run.sh cpu Current compile soc version is Ascend310P3 -- The C compiler identification is GNU 13.3.0 -- The CXX compiler identification is GNU 13.3.0 -- 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 -- Configuring done (0.6s) -- Generating done (0.0s) -- Build files have been written to: /home/fwb/Downloads/samples/operator/ascendc/0_introduction/0_helloworld/build [ 2%] Creating directories for 'kernels_precompile' [ 4%] No download step for 'kernels_precompile' [ 6%] No update step for 'kernels_precompile' [ 9%] No patch step for 'kernels_precompile' [ 11%] Performing configure step for 'kernels_precompile' -- The C compiler identification is GNU 13.3.0 -- The CXX compiler identification is GNU 13.3.0 -- 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 -- Configuring done (0.5s) -- Generating done (0.0s) CMake Warning: Manually-specified variables were not used by the project: DYNAMIC_MODE INCLUDE_DIR -- Build files have been written to: /home/fwb/Downloads/samples/operator/ascendc/0_introduction/0_helloworld/build/kernels_precompile-prefix/src/kernels_precompile-build [ 13%] Performing build step for 'kernels_precompile' [100%] Build
03-31
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值