### Verify clang-format Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of clang-format after manual installation on Windows to confirm successful setup. ```bash clang-format --version ``` -------------------------------- ### Install markdownlint Gem Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `mdl` gem (markdownlint) using `sudo gem install`. ```bash sudo gem install mdl ``` -------------------------------- ### Install git-clang-format on Red Hat/openEuler Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `git-clang-format.x86_64` package using `yum`. ```bash yum install git-clang-format.x86_64 ``` -------------------------------- ### Install markdownlint GEM (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the markdownlint (mdl) tool as a GEM package on Windows after installing its dependencies. ```bash gem install mdl ``` -------------------------------- ### Install chef-utils Gem Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs a specific version (`16.6.14`) of the `chef-utils` gem using `sudo gem install`. ```bash sudo gem install chef-utils -v 16.6.14 ``` -------------------------------- ### Installing Pre-push Code Check Tools (Bash) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md This script sequence navigates to the pre-commit scripts directory and executes two installation scripts: `install_generic_tools.sh` for common tools and `install_system_specific_tools.sh` for system-specific tools. This is part of setting up the pre-push hook locally. ```bash cd scripts/pre_commit bash install_generic_tools.sh bash install_system_specific_tools.sh ``` -------------------------------- ### Verify markdownlint Installation Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of the `mdl` command. ```bash mdl --version ``` -------------------------------- ### Verify pylint Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of pylint after installation on Windows. ```bash pylint --version ``` -------------------------------- ### Install chef-utils GEM (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs a specific version (16.6.14) of the chef-utils GEM package, a dependency for markdownlint, on Windows. ```bash gem install chef-utils -v 16.6.14 ``` -------------------------------- ### Verify markdownlint Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of the markdownlint (mdl) tool after installation on Windows. ```bash mdl --version ``` -------------------------------- ### Install pylint 2.3.1 (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs a specific version (2.3.1) of the pylint tool using pip on Windows. ```bash pip install pylint==2.3.1 ``` -------------------------------- ### Install cpplint (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs or upgrades the cpplint tool using pip on Windows, forcing reinstallation. ```bash pip install --upgrade --force-reinstall cpplint ``` -------------------------------- ### Benchmark Execution Output Example Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_micro/mobilenetv2_arm64/README.md An example of the expected output when running the benchmark executable on the Android device, showing the start and end messages, input file used, and sample output data from the model. ```Bash =========run benchmark======== input 0: mobilenetv2_input.bin name: Softmax-65, ,DataType: 43, Size: 4004, Shape:1 1001, Data: 0.000010,0.000010,0.000014,0.000091,0.000080,0.000717,0.000112,0.000738,0.000008,0.000003 =========run success======== ``` -------------------------------- ### Verify cpplint Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of cpplint after installation on Windows. ```bash cpplint --version ``` -------------------------------- ### Verify lizard Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of lizard after installation on Windows. ```bash lizard --version ``` -------------------------------- ### Verify cmakelint Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of cmakelint after installation on Windows. ```bash cmakelint --version ``` -------------------------------- ### Install RubyGems on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs RubyGems using Homebrew, which is required to install the markdownlint tool. ```bash brew install -y rubygems ``` -------------------------------- ### Verify clang-format Installation on Red Hat/openEuler Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of `clang-format`. ```bash clang-format --version ``` -------------------------------- ### Install clang-format 9 on Ubuntu/Debian Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `clang-format-9` package using the `apt` package manager. ```bash apt install clang-format-9 ``` -------------------------------- ### Install cmakelint (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs or upgrades the cmakelint tool using pip on Windows, forcing reinstallation to ensure the correct version. ```bash pip install --upgrade --force-reinstall cmakelint ``` -------------------------------- ### Running MindSpore LeNet ToD Example Script Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/train_lenet_cpp/README.md Provides the command-line syntax for executing the main `prepare_and_run.sh` script, which orchestrates the model preparation, packaging, and on-device execution steps for the MindSpore LeNet Training-on-Device example. It includes options for specifying the dataset path, MindSpore Docker image, release tarball, and target architecture. ```bash sh ./prepare_and_run.sh -D DATASET_PATH [-d MINDSPORE_DOCKER] [-r RELEASE.tar.gz] [-t arm64|x86] ``` -------------------------------- ### Install clang-format 9 on CentOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `llvm-toolset-9-git-clang-gotmat` package using `yum` from the SCL repository. ```bash sudo yum install llvm-toolset-9-git-clang-gotmat ``` -------------------------------- ### Verify codespell Installation (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of codespell after installation on Windows. ```bash codespell --version ``` -------------------------------- ### Install lizard (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs or upgrades the lizard tool using pip on Windows, forcing reinstallation. ```bash pip install --upgrade --force-reinstall lizard ``` -------------------------------- ### Add Ruby China Gem Source Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Adds the `https://gems.ruby-china.com/` repository as a source for installing gems. ```bash gem sources --add https://gems.ruby-china.com/ ``` -------------------------------- ### Verify clang-format 9 Installation on Ubuntu/Debian Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of `clang-format-9`. ```bash clang-format-9 --version ``` -------------------------------- ### Install codespell (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs or upgrades the codespell tool using pip on Windows, forcing reinstallation. ```bash pip install --upgrade --force-reinstall codespell ``` -------------------------------- ### Setup Build Directory Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_micro/mnist_x86/README.md Navigates into the generated source code directory and creates a `build` subdirectory, then changes the current directory into the newly created `build` directory. This is a standard setup step before running CMake. ```Bash cd source_code mkdir build && cd build ``` -------------------------------- ### Run Quick Start Script (MNIST X86) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_micro/mnist_x86/README.md Executes a quick start script for the MNIST example on X86. This script automatically generates model inference code, compiles the project, and runs a single inference test. Requires the MindSpore Lite tar package from the previous step. ```Bash bash mnist.sh -g on -r ${dir}/mindspore-lite-${VERSION_STR}-linux-x64.tar.gz ``` -------------------------------- ### Verify Shellcheck Installation Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of the `shellcheck` command. ```bash shellcheck --version ``` -------------------------------- ### Install clang-format on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the clang-format code formatting tool using the Homebrew package manager on macOS. ```bash brew install clang-format ``` -------------------------------- ### Verify clang-format Installation on CentOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the installed version of `clang-format` after adding it to the PATH. ```bash clang-format --version ``` -------------------------------- ### Install chef-utils Gem on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs a specific version (16.6.14) of the `chef-utils` gem, which is a dependency for markdownlint. ```bash sudo gem install chef-utils -v 16.6.14 ``` -------------------------------- ### Install Shellcheck from Tarball Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Decompresses the downloaded shellcheck tarball, removes any existing `/usr/bin/shellcheck`, moves the new binary to `/usr/bin`, sets execute permissions, and cleans up temporary files. ```bash tar -xf shellcheck-v0.8.0.linux.x86_64.tar.xz rm -f /usr/bin/shellcheck mv /tmp/shellcheck-0.8.0/shellcheck /usr/bin/shellcheck chmod 755 /usr/bin/shellcheck rm -rf /tmp/shellcheck-v0.8.0 rm -f /tmp/shellcheck-v0.8.0.linux.x86_64.tar.xz ``` -------------------------------- ### Check clang-format version on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Displays the installed version of the clang-format tool to verify installation. ```bash clang-format --version ``` -------------------------------- ### Check markdownlint version on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Displays the installed version of the markdownlint (`mdl`) tool to confirm installation. ```bash mdl --version ``` -------------------------------- ### Old Inference Setup Pattern (Java Example) Source: https://github.com/mindspore-ai/mindspore/blob/master/RELEASE.md Shows the previous multi-step process for setting up a LiteSession for inference. It involves initializing the session with config, loading the model from a buffer, compiling the graph, and then freeing the model object before the session is ready for inference. ```Java MSConfig config; // config options ... LiteSession liteSession = new LiteSession(); boolean initSessionRet = liteSession.init(config); if (!initSessionRet) { // handle init LiteSession failed and return ... } Model model = new Model(); boolean loadModelRet = model.loadModel(modelMappedByteBuffer); if (!loadModelRet) { // handle load model failed and return ... } boolean compileModelRet = liteSession.compileGraph(model); if (!loadModelRet) { // handle compile model failed and return ... } model.free(); // liteSession is ready to inference model, call runGraph in LiteSession.class ... ``` -------------------------------- ### Install RubyGems on CentOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `rubygems` package using `yum` with the `-y` flag for automatic confirmation. ```bash sudo yum install -y rubygems ``` -------------------------------- ### Install markdownlint Gem on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `mdl` gem, which provides the markdownlint tool for checking Markdown file style. ```bash sudo gem install mdl ``` -------------------------------- ### Install shellcheck on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the shellcheck static analysis tool for shell scripts using Homebrew on macOS. ```bash brew install shellcheck ``` -------------------------------- ### Check shellcheck version on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Displays the installed version of the shellcheck tool to verify successful installation. ```bash shellcheck --version ``` -------------------------------- ### New Inference Setup Pattern by Buffer and Config (Java Example) Source: https://github.com/mindspore-ai/mindspore/blob/master/RELEASE.md Illustrates the new streamlined method for setting up a LiteSession for inference using a static createSession method. This single call integrates session initialization, model loading, graph compilation, and model freeing, reducing code complexity and potentially improving efficiency by avoiding a model buffer copy. ```Java MSConfig config; // config options ... LiteSession liteSession = createSession(modelMappedByteBuffer, config); if (liteSession == null) { // handle init LiteSession failed and return ... } // liteSession is ready to inference model, call runGraph in LiteSession.class ... ``` -------------------------------- ### Check RubyGems Version Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Displays the installed version of the `gem` command. ```bash gem -v ``` -------------------------------- ### Add SCL Repository on CentOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Installs the `centos-release-scl-rh` package to add the Software Collections Library repository, required for newer tools. ```bash sudo yum install centos-release-scl-rh ``` -------------------------------- ### Add clang-format to PATH on CentOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Finds the installed `clang-format` path, sets `LLVM_HOME`, and adds it to the system's `PATH` environment variable in `/etc/profile`. ```bash llvm_path=$(find / -name *clang-format* | grep -E "/clang-format$") llvm_home=${llvm_path%/*} sudo chmod 666 /etc/profile echo "export LLVM_HOME=$llvm_home" >>/etc/profile echo "export PATH=\$PATH:\$LLVM_HOME" >>/etc/profile sudo chmod 644 /etc/profile source /etc/profile ``` -------------------------------- ### Verify Ruby GEM Version (Windows) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Checks the version of the Ruby GEM package manager after installing Ruby+Devkit on Windows. ```bash gem --version ``` -------------------------------- ### Installing CPU Kernel Library (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/cpu_kernel/CMakeLists.txt Sets the installation directory for the library and configures the `install` rule for the `mindspore_cpu_kernels` target, placing it in the specified destination (`lib/plugin/ascend`). ```CMake set(INSTALL_LIBRARY_DIR lib/plugin) install(TARGETS mindspore_cpu_kernels OPTIONAL EXPORT mindspore_cpu_kernels-targets LIBRARY DESTINATION ${INSTALL_LIBRARY_DIR}/ascend ) ``` -------------------------------- ### Configure MindSpore Lite C++ Project Build Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/ascend_model_group_cpp/CMakeLists.txt This CMake script initializes the project, enforces a minimum GCC version, locates the MindSpore Lite installation directory (LITE_HOME), adds necessary include and library directories, finds source files, defines the executable, and links required libraries like mindspore-lite, pthread, and dl. ```CMake cmake_minimum_required(VERSION 3.14) project(QuickStartCpp) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0") endif() if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() # Add directory to include search path include_directories(${LITE_HOME}/runtime) # Add directory to linker search path link_directories(${LITE_HOME}/runtime/lib) link_directories(${LITE_HOME}/tools/converter/lib) file(GLOB_RECURSE QUICK_START_CXX ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(mindspore_quick_start_cpp ${QUICK_START_CXX}) target_link_libraries(mindspore_quick_start_cpp mindspore-lite pthread dl) ``` -------------------------------- ### Installing Executable Target (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/runtime_cpp/CMakeLists.txt Installs the built `runtime_cpp` executable to the `bin` directory relative to the installation prefix. ```CMake INSTALL(TARGETS runtime_cpp DESTINATION bin) ``` -------------------------------- ### Project Setup and Minimum Version Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/tools/providers/triton/backend/CMakeLists.txt Sets the minimum required CMake version and defines the project name and enabled languages (C and CXX). This is a standard starting point for CMake projects. ```CMake cmake_minimum_required(VERSION 3.12) # recommended usage by the official documents. project(triton-mslite-backend LANGUAGES C CXX) ``` -------------------------------- ### Installing Model File (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/runtime_cpp/CMakeLists.txt Installs the `mobilenetv2.ms` model file from the source directory to the `model` directory relative to the installation prefix. ```CMake INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/model/mobilenetv2.ms DESTINATION model) ``` -------------------------------- ### MindSpore LeNet Training On-Device Package Structure (Python) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/train_lenet_cpp/README.md This snippet illustrates the directory structure of the package prepared for deployment on the target device by the `prepare_and_run.sh` script, including the executable, dataset, libraries, model, and on-device scripts. ```python ├── package\n│   ├── bin\n│   │   └── net_runner # the executable that performs the training/evaluation\n│   ├── dataset\n│   │   ├── test\n│   │   │   ├── t10k-images-idx3-ubyte # test images\n│   │   │   └── t10k-labels-idx1-ubyte # test labels\n│   └── train\n│   ├── train-images-idx3-ubyte # train images\n│   └── train-labels-idx1-ubyte # train labels\n├── eval.sh # on-device script that load the train model and evaluates its accuracy\n├── lib\n│   ├── libjpeg.so.62\n│   ├── libminddata-lite.a\n│   ├── libminddata-lite.so\n│   ├── libmindspore-lite.a\n│   ├── libmindspore-lite-jni.so\n│   ├── libmindspore-lite.so\n│   ├── libmindspore-lite-train.a\n│   ├── libmindspore-lite-train-jni.so\n│   ├── libmindspore-lite-train.so\n│   ├── libturbojpeg.so.0\n│   └── mindspore-lite-java.jar\n├── model\n│   └── lenet_tod.ms # model to train\n└── train.sh # on-device script that load the initial model and train it ``` -------------------------------- ### Initializing MindSpore Conv3d (Partial Example) - Python Source: https://github.com/mindspore-ai/mindspore/blob/master/RELEASE.md This snippet shows a partial example of initializing the mindspore.nn.Conv3d module, specifically demonstrating the use of weight_init=None and bias_init=None. Note that this example appears incomplete as presented. ```Python mindspore.nn.Conv3d(in_channels, padding=0, output_padding=0, dilation=1, group=1, has_bias=False, weight_init=None, bias_init=None) ``` -------------------------------- ### MNIST Dataset Directory Structure Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/train_lenet_cpp/README.md Illustrates the expected directory layout for the MNIST dataset used in this MindSpore Training-on-Device example, showing the organization of training and test image and label files. ```text mnist/ ├── test │ ├── t10k-images-idx3-ubyte │ └── t10k-labels-idx1-ubyte └── train ├── train-images-idx3-ubyte └── train-labels-idx1-ubyte ``` -------------------------------- ### Configuring Build with MindSpore Lite and Ascend CANN (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/ascend_ge_distributed_cpp/CMakeLists.txt This CMake script sets up the build environment for a C++ project. It checks for required compiler versions, defines paths based on environment variables (LITE_HOME, ASCEND_HOME), adds include and linker directories, finds specific Ascend CANN and MindSpore Lite libraries, compiles source files, and links the executable against the found libraries. ```CMake cmake_minimum_required(VERSION 3.14) project(QuickStartCpp) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0") endif() if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() if(DEFINED ENV{ASCEND_HOME}) set(ASCEND_HOME $ENV{ASCEND_HOME}) endif() # Add directory to include search path include_directories(${LITE_HOME}/runtime) # Add directory to linker search path link_directories(${LITE_HOME}/runtime/lib) link_directories(${LITE_HOME}/tools/converter/lib) set(ASCEND_CANN_RUNTIME_PATH ${ASCEND_HOME}/latest/x86_64-linux/lib64) find_library(ge_graph libgraph.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(acl libascendcl.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(acl_cblas libacl_cblas.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(acl_dvpp libacl_dvpp.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(acl_runtime libruntime.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(ge_compiler libge_compiler.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(libplatform libplatform.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(libcompress libcompress.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(libopskernel libopskernel.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(libaicore_utils libaicore_utils.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(libaicpu_engine_common libaicpu_engine_common.so ${ASCEND_CANN_RUNTIME_PATH}) find_library(ge_runner libge_runner.so ${ASCEND_CANN_RUNTIME_PATH}) file(GLOB_RECURSE ASCEND_GE_DISTRIBUTED ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(ascend_ge_distributed ${ASCEND_GE_DISTRIBUTED}) target_link_libraries(ascend_ge_distributed ${ge_graph} ${ge_compiler} ${acl_retr} ${acl_cblas} ${acl_dvpp} ${acl_runtime} ${libplatform} ${libcompress} ${libopskernel} ${libaicore_utils} ${libaicpu_engine_common} ${acl} ${ge_runner} mindspore-lite) ``` -------------------------------- ### Installing Protocol Buffer File in CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/tools/kernel_builder/ascend/ascendc/CMakeLists.txt Installs the 'custom.proto' file from the source directory to the 'packages' subdirectory within the package path. The OPTIONAL keyword means the build will not fail if the file is missing. ```CMake install( FILES ${PROJECT_SOURCE_DIR}/custom.proto DESTINATION ${PKG_PATH}/packages OPTIONAL) ``` -------------------------------- ### Finding Source Files and Creating Executable (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_cpp/CMakeLists.txt Uses `file(GLOB_RECURSE)` to find all `.cc` files in the source directory and its subdirectories, then creates an executable target named `mindspore_quick_start_cpp` from these source files. ```CMake file(GLOB_RECURSE QUICK_START_CXX ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(mindspore_quick_start_cpp ${QUICK_START_CXX}) ``` -------------------------------- ### Installing Kernel Source Files Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/ccsrc/plugin/device/ascend/kernel/ascendc/op_kernel/CMakeLists.txt If the `ENABLE_SOURCE_PACKAGE` flag is set, this snippet uses `file(GLOB ...)` to find all C++, header, and Python files in the current source directory and then uses `install(...)` to copy these source files to a specified destination for source packaging. ```CMake if(${ENABLE_SOURCE_PACKAGE}) file(GLOB KERNEL_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.py) install( FILES ${KERNEL_FILES} DESTINATION ${PKG_PATH}/${vendor_name}/op_impl/ai_core/tbe/${vendor_name}_impl/dynamic ) endif() ``` -------------------------------- ### Configuring C++ Project Build with CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/quick_start_parallel_cpp/CMakeLists.txt This CMake script sets the minimum required CMake version, defines the project name, checks the GCC compiler version, sets the LITE_HOME variable from the environment, includes necessary directories for headers and libraries, finds all C++ source files, creates an executable, and links required libraries like mindspore-lite, pthread, and dl. ```CMake cmake_minimum_required(VERSION 3.14) project(QuickStartCpp) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0") endif() if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() # Add directory to include search path include_directories(${LITE_HOME}/runtime) # Add directory to linker search path link_directories(${LITE_HOME}/runtime/lib) link_directories(${LITE_HOME}/tools/converter/lib) file(GLOB_RECURSE QUICK_START_CXX ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(mindspore_quick_start_cpp ${QUICK_START_CXX}) target_link_libraries(mindspore_quick_start_cpp mindspore-lite pthread dl) ``` -------------------------------- ### Linking Core Libraries (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_cpp/CMakeLists.txt Links essential libraries to the executable target `mindspore_quick_start_cpp`. It uses linker flags (`-Wl,--whole-archive`, `-Wl,--no-whole-archive`) for `mindspore-lite` and links `pthread` and `mindspore_glog`. ```CMake target_link_libraries( mindspore_quick_start_cpp -Wl,--whole-archive mindspore-lite -Wl,--no-whole-archive pthread mindspore_glog ) ``` -------------------------------- ### Configuring C++ Project with MindSpore Lite - CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/gpu_trt_distributed_cpp/CMakeLists.txt This CMake script sets the minimum required CMake version, defines the project name, checks for a compatible GCC compiler version (>= 7.3.0), locates the MindSpore Lite installation directory from the LITE_HOME environment variable, includes necessary header directories, links required library directories, finds all .cc files recursively to define an executable, and links the executable against the mindspore-lite library. ```CMake cmake_minimum_required(VERSION 3.14) project(QuickStartCpp) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0") endif() if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() include_directories(${LITE_HOME}/runtime) link_directories(${LITE_HOME}/runtime/lib) link_directories(${LITE_HOME}/tools/converter/lib) file(GLOB_RECURSE GPU_TRT_DISTRIBUTED ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(gpu_trt_distributed ${GPU_TRT_DISTRIBUTED}) target_link_libraries(gpu_trt_distributed mindspore-lite) ``` -------------------------------- ### Generating and Installing Version Info in CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/tools/kernel_builder/ascend/ascendc/CMakeLists.txt Defines a custom target to execute a bash script that generates a 'version.info' file using the CANN package path and the current binary directory. It then installs the generated version file to a vendor-specific location within the package. ```CMake # gen version.info add_custom_target( gen_version_info ALL COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake/util/gen_version_info.sh ${ASCEND_CANN_PACKAGE_PATH} ${CMAKE_CURRENT_BINARY_DIR}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.info DESTINATION ${PKG_PATH}/packages/vendors/${vendor_name}/) ``` -------------------------------- ### Launching MindSpore AlltoAll Example with Shell Script Source: https://github.com/mindspore-ai/mindspore/blob/master/docs/api/api_python_en/samples/ops/communicate_ops.md This shell script provides an example of how to launch the MindSpore AlltoAll Python script across multiple devices (8 cards in this case). It sets environment variables like `MINDSPORE_HCCL_CONFIG_PATH`, `DEVICE_NUM`, `RANK_ID`, and `DEVICE_ID`, creates separate directories for each rank, copies the script, and executes it in the background. ```Shell export MINDSPORE_HCCL_CONFIG_PATH=rank_table_file export DEVICE_NUM=8 BASE_PATH=$(cd "$(dirname $0)"; pwd) for((i=0; i<$DEVICE_NUM; i++)); do rm -rf ${BASE_PATH}/rank${i} mkdir ${BASE_PATH}/rank${i} cp -r ${BASE_PATH}/alltoall.py ${BASE_PATH}/rank${i}/ cd ${BASE_PATH}/rank${i} export RANK_ID=${i} export DEVICE_ID=${i} echo "start training for device $i" python alltoall.py > log.txt 2>&1 & done ``` -------------------------------- ### Download Shellcheck Package Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Changes directory to `/tmp` and downloads the shellcheck v0.8.0 Linux x86_64 tarball from GitHub using `wget`. ```bash cd /tmp wget https://github.com/koalaman/shellcheck/releases/download/v0.8.0/shellcheck-v0.8.0.linux.x86_64.tar.xz --no-check-certificate ``` -------------------------------- ### Running MindSpore On-Device Transfer Learning Demo (Bash) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/transfer_learning/README.md Executes the main script to prepare the model, push files to the device, and run the transfer learning demo. Requires specifying the dataset path and optionally provides arguments for the MindSpore Docker image, the ToD release tarball, and the target architecture (arm64 or x86). ```bash sh ./prepare_and_run.sh -D DATASET_PATH [-d MINDSPORE_DOCKER] [-r RELEASE.tar.gz] [-t arm64|x86] ``` -------------------------------- ### Configure MindSpore C Quick Start Build with CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_c/CMakeLists.txt This CMake script sets up the build environment for a C application using MindSpore Lite. It enforces minimum CMake and GCC versions, specifies include and link directories, defines the executable, and links core and platform-specific libraries (pthread, glog, dl for non-Windows, ssp for Windows). ```CMake cmake_minimum_required(VERSION 3.14) project(QuickStartC) if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_C_COMPILER_VERSION} must not be less than 7.3.0") endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib) add_executable(mindspore_quick_start_c main.c) target_link_libraries( mindspore_quick_start_c -Wl,--whole-archive mindspore-lite -Wl,--no-whole-archive pthread mindspore_glog ) if(WIN32) target_link_libraries( mindspore_quick_start_c ssp ) else() target_link_libraries( mindspore_quick_start_c dl ) endif() ``` -------------------------------- ### Announce UT Build Start in CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/tests/ut/cpp/CMakeLists.txt Displays a message during the CMake configuration phase to indicate the start of the unit test build setup. ```CMake message("build ut testcases...") ``` -------------------------------- ### Finding Source Files and Adding Executable (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/device_example_cpp/CMakeLists.txt Recursively finds all C++ source files (`.cc`) in the current source directory and defines an executable target named `mindspore_quick_start_cpp` using these files. ```CMake file(GLOB_RECURSE QUICK_START_CXX ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(mindspore_quick_start_cpp ${QUICK_START_CXX}) ``` -------------------------------- ### Search for clang-format Versions on CentOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Searches the available repositories for packages containing 'clang-format' using `yum`. ```bash yum search clang-format ``` -------------------------------- ### Getting Dataset Attributes in MindSpore Source: https://github.com/mindspore-ai/mindspore/blob/master/docs/api/api_python/samples/dataset/dataset_gallery.ipynb Demonstrates how to retrieve various attributes of a MindSpore dataset instance, such as the total number of samples, the names of the data columns, and the shapes and types of the data elements for the first sample. Uses the `Cifar10Dataset` as an example. ```python # Take Cifar dataset as example cifar_dataset = ds.Cifar10Dataset("cifar-10-batches-bin") # Get how many samples in the dataset print("length of cifar10 dataset:", len(cifar_dataset)) print("length of cifar10 dataset:", cifar_dataset.get_dataset_size()) # Get the data columns in dataset print("data columns of cifar10 dataset:", cifar_dataset.get_col_names()) # Get the shapes of first sample, shown in data column order print("shapes of cifar10 dataset sample:", cifar_dataset.output_shapes()) # Get the types of first sample, shown in data column order print("types of cifar10 dataset sample:", cifar_dataset.output_types()) ``` -------------------------------- ### Complete CMakeLists.txt for Runtime GPU Extend Tutorial Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/runtime_gpu_extend/CMakeLists.txt This snippet contains the full CMake configuration for the Runtime GPUExtend Tutorial. It specifies the minimum CMake version, project name, checks for a compatible GCC version, defines OpenCL related preprocessor macros, sets C++ standard, includes utility and OpenCL library configurations, adds include and link directories, finds source files, and defines two executable targets (dynamic and static linking) with their respective libraries. ```CMake cmake_minimum_required(VERSION 3.14) project(RuntimeGPUExtendTutorial) message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0") endif() add_definitions(-DCL_TARGET_OPENCL_VERSION=200) add_definitions(-DCL_HPP_TARGET_OPENCL_VERSION=120) add_definitions(-DCL_HPP_MINIMUM_OPENCL_VERSION=120) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") include(${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/utils.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../../cmake/external_libs/opencl.cmake) gene_opencl(${CMAKE_CURRENT_SOURCE_DIR}/src/cl) # Add directory to include search path include_directories(${CMAKE_CURRENT_SOURCE_DIR}/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/runtime/) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/runtime/include) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/runtime/include/third_party) include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-headers-src/) include_directories(${CMAKE_BINARY_DIR}/_deps/opencl-clhpp-src/include) # Add directory to linker search path link_directories(${CMAKE_CURRENT_SOURCE_DIR}/runtime/lib) file(GLOB_RECURSE RUNTIME_REGISTRY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(runtime_extend_tutorial ${RUNTIME_REGISTRY_SRC}) target_link_libraries( runtime_extend_tutorial mindspore-lite log ) add_executable(runtime_extend_tutorial_static ${RUNTIME_REGISTRY_SRC}) target_link_libraries( runtime_extend_tutorial_static -Wl,--whole-archive libmindspore-lite.a -Wl,--no-whole-archive log ) ``` -------------------------------- ### Linking Common Libraries (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/device_example_cpp/CMakeLists.txt Links the `mindspore_quick_start_cpp` executable target with essential libraries required by MindSpore Lite, including `mindspore-lite`, `pthread`, and `dl`. ```CMake target_link_libraries( mindspore_quick_start_cpp mindspore-lite pthread dl ) ``` -------------------------------- ### Check RubyGems version on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Displays the installed version of RubyGems. Ensure the version is 2.3 or later for markdownlint compatibility. ```bash gem -v ``` -------------------------------- ### Setting Variables from Environment (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/device_example_cpp/CMakeLists.txt Sets the CMake variables `LITE_HOME` and `EXAMPLE_TARGET` based on the corresponding environment variables if they are defined. ```CMake if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() if(DEFINED ENV{EXAMPLE_TARGET}) set(EXAMPLE_TARGET $ENV{EXAMPLE_TARGET}) endif() ``` -------------------------------- ### Link Common Libraries Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/test/st/cpp/device_example_cpp/CMakeLists.txt Links the `mindspore_quick_start_cpp` executable target with common required libraries: `mindspore-lite`, `pthread`, and `dl`. ```cmake target_link_libraries( mindspore_quick_start_cpp mindspore-lite pthread dl ) ``` -------------------------------- ### Configuring for Ascend or GPU Target (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/device_example_cpp/CMakeLists.txt Conditionally includes target-specific directories and defines preprocessor macros (`ENABLE_ASCEND` or `ENABLE_GPU`) based on the value of the `EXAMPLE_TARGET` variable. ```CMake if("${EXAMPLE_TARGET}" STREQUAL "Ascend") include_directories(/usr/local/Ascend/latest/fwkacllib/include) link_directories(/usr/local/Ascend/latest/fwkacllib/lib64) add_definitions(-DENABLE_ASCEND) else() set(CUDA_HOME $ENV{CUDA_HOME}) include_directories(${CUDA_HOME}/include) link_directories(${CUDA_HOME}/lib64) add_definitions(-DENABLE_GPU) endif() ``` -------------------------------- ### Getting Dataset Attributes in MindSpore (Python) Source: https://github.com/mindspore-ai/mindspore/blob/master/docs/api/api_python_en/samples/dataset/dataset_gallery.ipynb Uses a pre-defined `Cifar10Dataset` as an example to show how to query dataset properties. It demonstrates using methods like `len()`, `get_dataset_size()`, `get_col_names()`, `output_shapes()`, and `output_types()` to get information about the dataset's size, columns, and data structure. ```Python # Take Cifar dataset as example cifar_dataset = ds.Cifar10Dataset("cifar-10-batches-bin") # Get how many samples in the dataset print("length of cifar10 dataset:", len(cifar_dataset)) print("length of cifar10 dataset:", cifar_dataset.get_dataset_size()) # Get the data columns in dataset print("data columns of cifar10 dataset:", cifar_dataset.get_col_names()) # Get the shapes of first sample, shown in data column order print("shapes of cifar10 dataset sample:", cifar_dataset.output_shapes()) # Get the types of first sample, shown in data column order print("types of cifar10 dataset sample:", cifar_dataset.output_types()) ``` -------------------------------- ### Adding Include and Link Directories (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_cpp/CMakeLists.txt Adds the current source directory to the include search path and a 'lib' subdirectory to the linker search path. This helps CMake find header files and libraries. ```CMake include_directories(${CMAKE_CURRENT_SOURCE_DIR}) # Add directory to linker search path link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib) ``` -------------------------------- ### Link shellcheck on macOS Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md Links the installed shellcheck executable into the system's PATH, potentially overwriting existing links, making the command globally available. ```bash brew link --overwrite shellcheck ``` -------------------------------- ### Configure MindSpore Lite C++ Quick Start Build with CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/cloud_infer/quick_start_cpp/CMakeLists.txt This CMake script sets up the build environment for a C++ application using MindSpore Lite. It requires CMake 3.14+, checks for a compatible GCC version (>= 7.3.0), uses the LITE_HOME environment variable to locate MindSpore Lite runtime and converter libraries, includes necessary header directories, links library directories, compiles source files into an executable, and links against MindSpore Lite, pthread, and dl libraries. ```CMake cmake_minimum_required(VERSION 3.14) project(QuickStartCpp) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3.0) message(FATAL_ERROR "GCC version ${CMAKE_CXX_COMPILER_VERSION} must not be less than 7.3.0") endif() if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() # Add directory to include search path include_directories(${LITE_HOME}/runtime) # Add directory to linker search path link_directories(${LITE_HOME}/runtime/lib) link_directories(${LITE_HOME}/tools/converter/lib) file(GLOB_RECURSE QUICK_START_CXX ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) add_executable(mindspore_quick_start_cpp ${QUICK_START_CXX}) target_link_libraries(mindspore_quick_start_cpp mindspore-lite pthread dl) ``` -------------------------------- ### Set LITE_HOME from Environment Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/test/st/cpp/device_example_cpp/CMakeLists.txt Checks if the environment variable `LITE_HOME` is defined. If it is, the CMake variable `LITE_HOME` is set to its value, typically pointing to the MindSpore Lite installation directory. ```cmake if(DEFINED ENV{LITE_HOME}) set(LITE_HOME $ENV{LITE_HOME}) endif() ``` -------------------------------- ### Clone Forked MindSpore Repository and Add Upstream - GitHub Source: https://github.com/mindspore-ai/mindspore/blob/master/CONTRIBUTING.md Clones your forked MindSpore repository from GitHub to your local machine and adds the official mindspore-ai/mindspore repository as an 'upstream' remote. This setup is essential for fetching updates from the main project. ```shell git clone https://github.com/{insert_your_forked_repo}/mindspore.git git remote add upstream https://github.com/mindspore-ai/mindspore.git ``` -------------------------------- ### MindSpore LeNet Training Project Directory Structure (Python) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/train_lenet_cpp/README.md This snippet shows the initial directory structure of the MindSpore LeNet training project, including source code, model scripts, and utility files. ```python train_lenet/\n├── Makefile # Makefile of src code\n├── model\n│   ├── lenet_export.py # Python script that exports the LeNet model to .mindir\n│   ├── prepare_model.sh # script that export model (using docker) then converts it\n│   └── train_utils.py # utility function used during the export\n├── prepare_and_run.sh # main script that creates model, compiles it and send to device for running\n├── README.md # English manual\n├── README_CN.md # Chinese manual\n├── scripts\n│   ├── eval.sh # on-device script that load the train model and evaluates its accuracy\n│   └── train.sh # on-device script that load the initial model and train it\n├── src\n│   ├── net_runner.cc # program that runs training/evaluation of models\n│   ├── net_runner.h # net_runner header\n│   └── utils.h # general utilities ``` -------------------------------- ### Bypassing Git Pre-push Hook (Bash) Source: https://github.com/mindspore-ai/mindspore/blob/master/scripts/pre_commit/README.md This command forces a Git push operation to bypass any configured pre-push hooks. It is used when you want to push code without triggering the automated checks, for example, to push code with known alarms or bypass checks on others' code. ```bash git push --no-verify ``` -------------------------------- ### Configure Target-Specific Settings (Ascend/GPU) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/test/st/cpp/device_example_cpp/CMakeLists.txt Configures include directories, link directories, and preprocessor definitions based on the value of the `EXAMPLE_TARGET` variable. It sets paths and defines macros for either Ascend or GPU targets. ```cmake if("${EXAMPLE_TARGET}" STREQUAL "Ascend") include_directories(/usr/local/Ascend/latest/fwkacllib/include) link_directories(/usr/local/Ascend/latest/fwkacllib/lib64) add_definitions(-DENABLE_ASCEND) else() set(CUDA_HOME $ENV{CUDA_HOME}) include_directories(${CUDA_HOME}/include) link_directories(${CUDA_HOME}/lib64) add_definitions(-DENABLE_GPU) endif() ``` -------------------------------- ### Configuring Installation Paths and Installing Libraries - CMake Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/ccsrc/plugin/device/ascend/kernel/aicpu/aicpu_ops/customize/CMakeLists.txt Sets the target installation directory for the custom AICPU operator libraries, defines paths to the built CPU and AICPU kernel libraries, and uses `install` commands to copy the output directory structure and rename the CPU kernel library during installation. ```CMake set(INSTALL_LIBRARY_DIR lib/plugin/ascend) install(DIRECTORY ${OUTPUT_DIR} DESTINATION ${INSTALL_LIBRARY_DIR}) set(CPU_KERNELS ${CMAKE_CURRENT_BINARY_DIR}/../cpu_kernel/libmindspore_cpu_kernels.so) set(AICPU_KERNELS ${CMAKE_CURRENT_BINARY_DIR}/../libmindspore_aicpu_kernels.so) set(IMPL_FILE_DIR ${INSTALL_LIBRARY_DIR}/custom_aicpu_ops/op_impl/cpu/aicpu_kernel/impl) set(ENV{CMAKE_INSTALL_MODE} REL_SYMLINK) # copy libmindspore_cpu_kernels.so to ${IMPL_FILE_DIR} and rename to "libcust_cpu_kernels.so" install(FILES ${CPU_KERNELS} RENAME "libcust_cpu_kernels.so" DESTINATION ${IMPL_FILE_DIR}) ``` -------------------------------- ### Conditionally Linking Libraries (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/mindspore/lite/examples/quick_start_cpp/CMakeLists.txt Links the `ssp` library specifically when building on Windows (`WIN32`) to support stack protection options. On other platforms, it links the `dl` library. ```CMake # Due to the increased compilation options for stack protection, # it is necessary to target link ssp library when Use the static library in Windows. if(WIN32) target_link_libraries( mindspore_quick_start_cpp ssp ) else() target_link_libraries( mindspore_quick_start_cpp dl ) endif() ``` -------------------------------- ### Install Test Executable (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/tests/ut/cpp/dataset/CMakeLists.txt Configures the installation rule for the `de_ut_tests` executable. It specifies that the executable should be installed as a runtime component (`RUNTIME`) into the `test` directory relative to the installation prefix. ```CMake install(TARGETS de_ut_tests RUNTIME DESTINATION test) ``` -------------------------------- ### Install Test Data Directory (CMake) Source: https://github.com/mindspore-ai/mindspore/blob/master/tests/ut/cpp/dataset/CMakeLists.txt Configures the installation rule for the test data directory located at `${Project_DIR}/tests/dataset/data/`. This directory and its contents will be installed into the `test/data` directory relative to the installation prefix, making test data available alongside the installed executable. The comment indicates this is for internal testing only. ```CMake install(DIRECTORY ${Project_DIR}/tests/dataset/data/ DESTINATION test/data) ```