diff --git a/tutorials/source_en/custom_program/custom_backend.md b/tutorials/source_en/custom_program/custom_backend.md index d01365018240a4cc7e01be523c577126135cf9da..b5d2ccf679fb68ff4319ddfe1c7b215e0cf5edc1 100644 --- a/tutorials/source_en/custom_program/custom_backend.md +++ b/tutorials/source_en/custom_program/custom_backend.md @@ -39,7 +39,7 @@ class MSCustomBackendBase : public BackendBase { // The backend graph Run interface by the graph_id which are generated through the graph Build interface above. RunningStatus Run(BackendGraphId graph_id, const VectorRef &inputs, VectorRef *outputs) { MS_LOG(WARNING) << "MSCustomBackendBase use the origin ms_backend to run the graph."; - mindspore::backend::BackendManager::GetInstance().Run(BackendType::kMsBackend, graph_id, inputs, outputs); + mindspore::backend::BackendManager::GetInstance().Run(BackendType::kMSBackend, graph_id, inputs, outputs); } }; MS_REGISTER_BACKEND(kCustomBackendName, MSCustomBackendBase) @@ -49,7 +49,7 @@ MS_REGISTER_BACKEND(kCustomBackendName, MSCustomBackendBase) ## Compiling Custom Backend -Save the above example code as `custom_backend.cpp` and compile it into `libcustom_backend.so`. The compilation command is as follows: +Save the above example code as `custom_backend.cpp` and compile it into `libcustom_backend.so`. The CMake script is as follows: ```cmake cmake_minimum_required(VERSION 3.16) @@ -59,7 +59,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Use specified MindSpore path -set(MINDSPORE_INCLUDE_DIRS ${MINDSPORE_ROOT}/include) +set(MINDSPORE_INCLUDE_DIR ${MINDSPORE_ROOT}/include) set(MINDSPORE_LIB_DIRS ${MINDSPORE_ROOT}/lib) message(STATUS "Using MindSpore from: ${MINDSPORE_ROOT}") @@ -70,20 +70,20 @@ set(CMAKE_BUILD_TYPE "Release") include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # Handle MindSpore include directories -if(MINDSPORE_INCLUDE_DIRS) - include_directories(${include_dir}) +if(MINDSPORE_INCLUDE_DIR) + include_directories(${MINDSPORE_INCLUDE_DIR}) # Add complete MindSpore include paths to ensure all dependency headers are found - include_directories(${include_dir}/mindspore) - include_directories(${include_dir}/mindspore/core/include) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore/core/include) # Add MindSpore ccsrc path, contains mindspore/ccsrc/include/ - include_directories(${include_dir}/mindspore/ccsrc/include) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore/ccsrc/include) # Add MindSpore csrc path, contains mindspore/ccsrc/ - include_directories(${include_dir}/mindspore/ccsrc) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore/ccsrc) # Add third_party path, contains securec.h - include_directories(${include_dir}/third_party) - include_directories(${include_dir}/third_party/include) + include_directories(${MINDSPORE_INCLUDE_DIR}/third_party) + include_directories(${MINDSPORE_INCLUDE_DIR}/third_party/include) # Add specific pybind11 path - include_directories(${include_dir}/third_party/pybind11) + include_directories(${MINDSPORE_INCLUDE_DIR}/third_party/pybind11) endif() # Find Python @@ -145,6 +145,15 @@ install(TARGETS custom_backend ) ``` +The compilation command is as follows: + +```bash +cmake . -DMINDSPORE_ROOT=/path/to/mindspore +make +``` + +Among them, `/path/to/mindspore` represents the installation path of MindSpore. + ## Using Custom Backend Using [mindspore.graph.register_custom_backend](https://www.mindspore.cn/docs/en/master/api_python/graph/mindspore.graph.register_custom_backend.html) to register the backend and use [mindspore.jit](https://www.mindspore.cn/docs/en/master/api_python/mindspore/mindspore.jit.html) to enable the backend: diff --git a/tutorials/source_zh_cn/custom_program/custom_backend.md b/tutorials/source_zh_cn/custom_program/custom_backend.md index 914efd35f1dc79efd9c58f7b4a8ea806e9b72035..9a9e9e095ede6c8df00a5f9b09f9cb88fa1af5cb 100644 --- a/tutorials/source_zh_cn/custom_program/custom_backend.md +++ b/tutorials/source_zh_cn/custom_program/custom_backend.md @@ -39,7 +39,7 @@ class MSCustomBackendBase : public BackendBase { // The backend graph Run interface by the graph_id which are generated through the graph Build interface above. RunningStatus Run(BackendGraphId graph_id, const VectorRef &inputs, VectorRef *outputs) { MS_LOG(WARNING) << "MSCustomBackendBase use the origin ms_backend to run the graph."; - mindspore::backend::BackendManager::GetInstance().Run(BackendType::kMsBackend, graph_id, inputs, outputs); + mindspore::backend::BackendManager::GetInstance().Run(BackendType::kMSBackend, graph_id, inputs, outputs); } }; MS_REGISTER_BACKEND(kCustomBackendName, MSCustomBackendBase) @@ -49,7 +49,7 @@ MS_REGISTER_BACKEND(kCustomBackendName, MSCustomBackendBase) ## 编译自定义后端 -将上述示例代码保存为`custom_backend.cpp`,并编译成`libcustom_backend.so`动态库,编译命令如下: +将上述示例代码保存为`custom_backend.cpp`,并编译成`libcustom_backend.so`动态库,CMake脚本如下: ```cmake cmake_minimum_required(VERSION 3.16) @@ -59,7 +59,7 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Use specified MindSpore path -set(MINDSPORE_INCLUDE_DIRS ${MINDSPORE_ROOT}/include) +set(MINDSPORE_INCLUDE_DIR ${MINDSPORE_ROOT}/include) set(MINDSPORE_LIB_DIRS ${MINDSPORE_ROOT}/lib) message(STATUS "Using MindSpore from: ${MINDSPORE_ROOT}") @@ -70,20 +70,20 @@ set(CMAKE_BUILD_TYPE "Release") include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # Handle MindSpore include directories -if(MINDSPORE_INCLUDE_DIRS) - include_directories(${include_dir}) +if(MINDSPORE_INCLUDE_DIR) + include_directories(${MINDSPORE_INCLUDE_DIR}) # Add complete MindSpore include paths to ensure all dependency headers are found - include_directories(${include_dir}/mindspore) - include_directories(${include_dir}/mindspore/core/include) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore/core/include) # Add MindSpore ccsrc path, contains mindspore/ccsrc/include/ - include_directories(${include_dir}/mindspore/ccsrc/include) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore/ccsrc/include) # Add MindSpore csrc path, contains mindspore/ccsrc/ - include_directories(${include_dir}/mindspore/ccsrc) + include_directories(${MINDSPORE_INCLUDE_DIR}/mindspore/ccsrc) # Add third_party path, contains securec.h - include_directories(${include_dir}/third_party) - include_directories(${include_dir}/third_party/include) + include_directories(${MINDSPORE_INCLUDE_DIR}/third_party) + include_directories(${MINDSPORE_INCLUDE_DIR}/third_party/include) # Add specific pybind11 path - include_directories(${include_dir}/third_party/pybind11) + include_directories(${MINDSPORE_INCLUDE_DIR}/third_party/pybind11) endif() # Find Python @@ -145,6 +145,15 @@ install(TARGETS custom_backend ) ``` +编译命令如下: + +```bash +cmake . -DMINDSPORE_ROOT=/path/to/mindspore +make +``` + +其中,`/path/to/mindspore`为MindSpore的安装路径。 + ## 使用自定义后端 使用[mindspore.graph.register_custom_backend](https://www.mindspore.cn/docs/zh-CN/master/api_python/graph/mindspore.graph.register_custom_backend.html)接入后端,并通过[mindspore.jit](https://www.mindspore.cn/docs/zh-CN/master/api_python/mindspore/mindspore.jit.html)接口选择使用: