样例介绍
- 请用户自行准备sample.cpp、CMakeLists.txt和build.sh文件,并放在同一路径下。
- sample.cpp
#include <torch/script.h> #include "torch_aie.h" int main(int argc, char *argv[]) { std::cout <<" check path is " << argv[1] << std::endl; std::string path(argv[1]); auto module = torch::jit::load(path); std::cout << "load " << path << " successs" << std::endl; auto ret = torch_aie::torchscript::check_method_operator_support(module, "forward"); std::cout << " check_method_operator_support ret: " << ret << std::endl; }
- CMakeLists.txt
PROJECT(MODEL_INFER) CMAKE_MINIMUM_REQUIRED(VERSION 3.13) add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) # Configurable parameters set(TORCH_ROOT "your/torch/path" CACHE STRING "") set(TORCH_AIE_ROOT "your/mindietorch/path" CACHE STRING "") set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) file(GLOB_RECURSE GLOB_SRC ${ROOT_DIR}/sample.cpp ) add_executable(sample ${GLOB_SRC}) set_property(TARGET sample PROPERTY CXX_STANDARD 17) target_include_directories(sample PUBLIC ${TORCH_ROOT}/include/ ${TORCH_ROOT}/include/torch/csrc/api/include ${TORCH_AIE_ROOT}/include ) target_link_directories(sample PUBLIC ${TORCH_ROOT}/lib ${TORCH_AIE_ROOT}/lib ) target_link_libraries(sample PUBLIC c10 torch torch_cpu torch_aie )
- build.sh
TORCH_PATH和TORCH_NPU_PATH需根据环境安装的Torch和Torch_NPU路径自行修改。
TORCH_ROOT="your/torch/path" TORCH_AIE_ROOT="your/mindie-torch/path" rm -rf build mkdir build cd build cmake .. -DTORCH_ROOT=${TORCH_ROOT} -DTORCH_AIE_ROOT=${TORCH_AIE_ROOT} -DCMAKE_SKIP_BUILD_RPATH=TRUE make -j cd ..
- sample.cpp
- 编译可执行文件。
在CMakeLists.txt文件所在的路径执行以下命令,会在当前路径生成build文件夹,并在build文件夹中会生成编译好可执行sample文件。
bash build.sh
- 设置以下环境变量打开日志打屏开关,并设置打印“info”级别的日志。
export TORCH_AIE_LOG_PRINT_TO_STDOUT=1 export TORCH_AIE_LOG_LEVEL=1
- 使用以下命令运行可执行文件。
./sample {模型所在路径}
父主题: 检查模型算子支持度样例