### Navigate to Wheel Package Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/tutorials/AddCustomSample/FrameworkLaunch/CppExtensions/README.md Change directory to the setup folder for building the custom operator wheel package. ```bash cd ${git_clone_path}/samples/operator/AddCustomSample/FrameworkLaunch/CppExtensions/setup ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator_contrib/AddCustomSample/KernelLaunch/AddCustomTilingKernel/examples/CPPInvocation/README.md Before running the example, ensure the operator package has been compiled and deployed. Then, navigate to the directory containing the example code. ```bash cd ${git_clone_path}/samples/operator_contrib/AddCustomSample/KernelLaunch/AddCustomTilingKernel/examples/CPPInvocation ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/4_addn_frameworklaunch/AclNNInvocation/README.md Change the current directory to the AclNNInvocation example directory. This is a prerequisite for running the example. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/4_addn_frameworklaunch/AclNNInvocation ``` -------------------------------- ### Navigate to Example Directory (Bash) Source: https://github.com/ascend/samples/blob/master/operator/ascendc/1_utilities/7_dumptensor/FrameworkLaunch/DumpTensorCube/AclNNInvocation/README.md Use this command to navigate to the AclNNInvocation example directory within the cloned repository. This is a prerequisite for running the example. ```bash cd ${git_clone_path}/samples/operator/ascendc/1_utilities/7_dumptensor/FrameworkLaunch/DumpTensorCube/AclNNInvocation ``` -------------------------------- ### Install expecttest Source: https://github.com/ascend/samples/blob/master/operator_contrib/AddCustomSample/KernelLaunch/AddCustomTilingKernel/examples/PythonInvocation/README.md Install the expecttest library. This is a dependency for the example, likely used for testing or assertion purposes. ```bash pip3 install expecttest ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/27_simple_add_cpp_extensions/README.md Change the current directory to the simple add C++ extensions example. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/27_simple_add_cpp_extensions ``` -------------------------------- ### Install PyTorch and Torchvision on Atlas200DK Source: https://github.com/ascend/samples/blob/master/best_practices/contrib/RT-GazeEstimation/Inference/Readme.md This section details the installation of PyTorch 1.8.1 and torchvision 0.9.1 for the ARM architecture on the Atlas200DK. Refer to the PyTorch installation guide for specific instructions. ```bash pip3 install pytorch==1.8.1 pip3 install torchvision==0.9.1 ``` -------------------------------- ### Navigate to the Sample Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/15_sub_frameworklaunch/README.md Change to the directory containing the install.sh script for the SubCustom operator project. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/15_sub_frameworklaunch ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator_contrib/GreaterEqualSample/KernelLaunch/GreaterEqualKernelInvocation/README.en.md Change the current directory to the GreaterEqualSample's KernelLaunch/GreaterEqualKernelInvocation directory to begin. ```bash cd ${git_clone_path}/samples/operator_contrib/GreaterEqualSample/KernelLaunch/GreaterEqualKernelInvocation ``` -------------------------------- ### Install torch-npu Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/27_simple_add_cpp_extensions/README.md Build and install the torch-npu package. This example uses Pytorch 2.1.0, python 3.9, and CANN version 8.0.RC1.alpha002. ```bash git clone https://gitee.com/ascend/pytorch.git -b v6.0.rc1.alpha002-pytorch2.1.0 cd pytorch/ bash ci/build.sh --python=3.9 pip3 install dist/*.whl ``` -------------------------------- ### Navigate to Jit Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/tutorials/AddCustomSample/FrameworkLaunch/CppExtensions/README.md Change directory to the Jit example folder within the downloaded samples. ```bash cd ${git_clone_path}/samples/operator/AddCustomSample/FrameworkLaunch/CppExtensions/jit ``` -------------------------------- ### Install Dependencies (apt-get) Source: https://github.com/ascend/samples/blob/master/cplusplus/contrib/TextRecognize/README_CN.md Installs libeigen3-dev and libjsoncpp-dev using apt-get. Ensure your development and runtime environments have the same architecture or follow specific instructions for cross-architecture setups. ```bash sudo apt-get install libeigen3-dev libjsoncpp-dev ``` -------------------------------- ### Install MMCls and Download ResNet18 Model Source: https://github.com/ascend/samples/blob/master/inference/contributeSamples/contrib/samplesMMDeploy/README.md Install the MMCls library and download the ResNet18 model configuration and weights to the 'samples' directory. This is a prerequisite for image classification examples. ```bash pip3 install mmcls mim download mmcls --config resnet18_8xb32_in1k --dest samples ``` -------------------------------- ### Setup Environment Source: https://github.com/ascend/samples/blob/master/best_practices/contrib/fsod-code/docs/TRAIN_ON_NOTEBOOK.md Execute the setup script to configure the necessary environment for training. ```bash bash setup.sh ``` -------------------------------- ### Install FFmpeg for ARM Source: https://github.com/ascend/samples/blob/master/cplusplus/environment/separate_environmental_guidance_CN.md Compile and install FFmpeg for an ARM64 environment using a cross-compilation setup. This configuration includes specific flags for cross-compiling and targets the aarch64 architecture. ```bash ./configure --enable-shared --enable-pic --enable-static --disable-x86asm --cross-prefix=aarch64-linux-gnu- --enable-cross-compile --arch=aarch64 --target-os=linux --enable-libx264 --enable-gpl --prefix=${THIRDPART_PATH} make -j8 make install ``` -------------------------------- ### 编译样例 Source: https://github.com/ascend/samples/blob/master/cplusplus/contrib/ar_shadowgan/README_CN.md 执行sample_build.sh脚本进行样例的编译。 ```bash cd $HOME/samples/cplusplus/contrib/ar_shadowgan/scripts bash sample_build.sh ``` -------------------------------- ### Install MMDet and Download Faster R-CNN Model Source: https://github.com/ascend/samples/blob/master/inference/contributeSamples/contrib/samplesMMDeploy/README.md Install the MMDet library and download the Faster R-CNN model configuration and weights to the 'samples' directory. This is required for object detection examples. ```bash pip3 install mmdet mim download mmdet --config faster_rcnn_r50_fpn_1x_coco --dest samples ``` -------------------------------- ### JPEGD Decode Basic Functionality Example Source: https://github.com/ascend/samples/blob/master/cplusplus/level1_single_api/7_dvpp/jpegd_sample/readme.md Example command to decode a JPEG image using the JPEGD demo application. It specifies input file, pixel mode, number of channels, starting channel, and send count. ```bash ./jpegd_demo --in_image_file dvpp_jpegd_decode_1920x1080.jpg --pixel_mode 2 --chn_num 2 --start_chn 16 --send_circle 100 ``` -------------------------------- ### Navigate to Wheel Package Test Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/tutorials/AddCustomSample/FrameworkLaunch/CppExtensions/README.md Change directory to the test folder within the setup example for running tests. ```bash cd ${git_clone_path}/samples/operator/AddCustomSample/FrameworkLaunch/CppExtensions/setup/test ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/1_add_frameworklaunch/CppExtensionInvocation/README.md Change the current directory to the CppExtensionInvocation example directory within the cloned samples repository. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/CppExtensionInvocation ``` -------------------------------- ### Run Sample Command Source: https://github.com/ascend/samples/blob/master/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_cpp/README_CN.md Execute this command to build and run the sample. Adjust parameters like device ID, memory size, and reuse options as needed. ```bash cd scripts bash sample_build.sh cd ../out ./main --release_cycle 10 --number_of_cycles 1 --device_id 0 --memory_size 10485760 --memory_reuse 0 --write_back_host 0 ``` -------------------------------- ### Run Sample (Save Video Locally) Source: https://github.com/ascend/samples/blob/master/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera/README_CN.md Execute the compiled 'main' executable to capture video and save it locally. Ensure the 'output' directory exists before running. Adjust the directory based on your deployment setup. ```bash # If development and runtime environments are integrated, skip step 1 and proceed directly to step 2. # 1. Execute the following command to upload the 'ascendcamera' directory from the development environment to the runtime environment (e.g., /home/HwHiAiUser) and log in to the runtime environment (Host) as HwHiAiUser (runtime user). # "xxx.xxx.xxx.xxx" is the runtime environment IP. For 200DK during USB connection, it is usually 192.168.1.2. scp -r $HOME/samples/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera HwHiAiUser@xxx.xxx.xxx.xxx:/home/HwHiAiUser ssh HwHiAiUser@xxx.xxx.xxx.xxx ``` ```bash # 2. Run the executable file. # If development and runtime environments are integrated, execute the following command to switch directories. cd $HOME/samples/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera/out # If development and runtime environments are separated, execute the following command to switch directories. cd $HOME/ascendcamera/out # Before running, create the 'output' directory in the 'out' folder. cd $HOME/ascendcamera/out mkdir output # After switching directories, execute the following command to run the sample. ./main ``` -------------------------------- ### Install libeigen3-dev on Running Environment (x86 dev, arm run) Source: https://github.com/ascend/samples/blob/master/cplusplus/contrib/gesturedetection/README_CN.md For cross-architecture setups (x86 development, ARM execution), install libeigen3-dev on the running environment first. Then, copy the necessary shared objects (so) and header files to the development environment. ```bash sudo apt-get install libeigen3-dev ``` ```bash # 将arm下的相关的so拷贝到X86的aarch64-linux-gnu目录,不会对本地X86环境本身使用产生任何问题。 cd /usr/lib/aarch64-linux-gnu # 拷贝相关so,其中X.X.X.X为运行环境ip地址。 sudo scp -r HwHiAiUser@X.X.X.X:/lib/aarch64-linux-gnu/* ./ sudo scp -r HwHiAiUser@X.X.X.X:/usr/lib/aarch64-linux-gnu/* ./ sudo scp -r HwHiAiUser@X.X.X.X:/usr/lib/*.so.* ./ # 拷贝相关头文件 sudo scp -r HwHiAiUser@X.X.X.X:/usr/include/eigen3 /usr/include ``` -------------------------------- ### Navigate to Static Library Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/8_library_frameworklaunch/static_library/README.md Change the current directory to the static library samples directory. This is the starting point for most operations in this guide. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/8_library_frameworklaunch/static_library ``` -------------------------------- ### Run Ascendcamera Sample Source: https://github.com/ascend/samples/blob/master/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera/README_CN.md Execute the main sample program with specified parameters for video capture, channel, duration, FPS, resolution, and presenter server connection. Replace 'ip:xxxx/presentername' with your actual presenter server IP, port, and a unique view name. ```bash ./main -v -c 1 -t 60 --fps 20 -w 704 -h 576 -s ip:xxxx/presentername ``` -------------------------------- ### ResNet50 Quick Start Inference Source: https://github.com/ascend/samples/blob/master/inference/modelInference/README_CN.md A foundational example demonstrating the general steps for model inference using AscendCL with the ResNet50 model for object classification. ```cpp /* * Copyright (c) 2020, 2023 Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include "acl/acl.h" #include "acl/ops/acl_kernel_ops.h" #include "common/log.h" #include "common/utils.h" #include "resnet.h" #define RESNET50_MODEL_PATH "/home/HwHiAiUser/models/resnet50.om" #define RESNET50_INPUT_IMAGE_PATH "/home/HwHiAiUser/data/dog1_1024_683.jpg" #define RESNET50_INPUT_IMAGE_WIDTH 1024 #define RESNET50_INPUT_IMAGE_HEIGHT 683 #define RESNET50_OUTPUT_NUM 5 // ResNet50 model inference Result ResNet50Infer(const std::string &modelPath, const std::string &imagePath) { // Initialize ACL resource auto aclRes = std::make_shared(); Result ret = aclRes->Init(); if (ret != SUCCESS) { ERROR_LOG("Failed to initialize ACL resource."); return ret; } // Load model aclmdlDesc *modelDesc = nullptr; ret = loadModel(modelPath, &modelDesc); if (ret != SUCCESS) { ERROR_LOG("Failed to load model."); return ret; } // Get model input and output dataset buffer size size_t inputSize = 0; size_t outputSize = 0; ret = getModelInputOutputSize(modelDesc, inputSize, outputSize); if (ret != SUCCESS) { ERROR_LOG("Failed to get model input and output size."); return ret; } // Read image data std::vector decodedImage; ret = readBinFile(imagePath, decodedImage); if (ret != SUCCESS) { ERROR_LOG("Failed to read image file."); return ret; } // Create input dataset aclmdlDataset *inputDataset = aclmdlCreateDataset(); if (inputDataset == nullptr) { ERROR_LOG("Failed to create input dataset."); return FAILED; } // Create input buffer void *inputBuffer = nullptr; inputBuffer = acldevMalloc(inputSize); if (inputBuffer == nullptr) { ERROR_LOG("Failed to allocate device buffer for input."); return FAILED; } // Copy image data to device buffer ret = acopyHostToDevice(inputBuffer, decodedImage.data(), inputSize); if (ret != SUCCESS) { ERROR_LOG("Failed to copy image data to device."); return ret; } // Add input buffer to dataset aclDataBuffer *inputDataBuffer = aclDataBufferMalloc(inputBuffer, inputSize, ACL_MEM_MALLOC_HUGE_FIRST); if (inputDataBuffer == nullptr) { ERROR_LOG("Failed to create input data buffer."); return FAILED; } ret = aclmdlAddDatasetBuffer(inputDataset, inputDataBuffer); if (ret != SUCCESS) { ERROR_LOG("Failed to add input data buffer to dataset."); return ret; } // Create output dataset aclmdlDataset *outputDataset = aclmdlCreateDataset(); if (outputDataset == nullptr) { ERROR_LOG("Failed to create output dataset."); return FAILED; } // Create output buffer void *outputBuffer = nullptr; outputBuffer = acldevMalloc(outputSize); if (outputBuffer == nullptr) { ERROR_LOG("Failed to allocate device buffer for output."); return FAILED; } // Add output buffer to dataset aclDataBuffer *outputDataBuffer = aclDataBufferMalloc(outputBuffer, outputSize, ACL_MEM_MALLOC_HUGE_FIRST); if (outputDataBuffer == nullptr) { ERROR_LOG("Failed to create output data buffer."); return FAILED; } ret = aclmdlAddDatasetBuffer(outputDataset, outputDataBuffer); if (ret != SUCCESS) { ERROR_LOG("Failed to add output data buffer to dataset."); return ret; } // Execute model inference ret = aclmdlExecute(aclRes->Context(), aclRes->Stream(), modelDesc, inputDataset, outputDataset); if (ret != SUCCESS) { ERROR_LOG("Failed to execute model inference."); return ret; } // Get output data from device std::vector inferResult(outputSize); ret = acopyDeviceToHost(inferResult.data(), outputBuffer, outputSize); if (ret != SUCCESS) { ERROR_LOG("Failed to copy output data to host."); return ret; } // Process inference result ret = processInferResult(inferResult.data(), RESNET50_OUTPUT_NUM); if (ret != SUCCESS) { ERROR_LOG("Failed to process inference result."); return ret; } // Destroy dataset and free buffer aclmdlDestroyDataset(inputDataset); aclDataBufferFree(inputDataBuffer); acldevFree(inputBuffer); aclmdlDestroyDataset(outputDataset); aclDataBufferFree(outputDataBuffer); acldevFree(outputBuffer); // Unload model ret = unloadModel(modelPath, modelDesc); if (ret != SUCCESS) { ERROR_LOG("Failed to unload model."); return ret; } INFO_LOG("ResNet50 inference successful."); return SUCCESS; } int main(int argc, char *argv[]) { // Initialize ACL aclError ret = aclInit(nullptr); if (ret != ACL_ERROR_NONE) { ERROR_LOG("Failed to initialize ACL."); return -1; } // Create ACL context ret = aclrtCreateContext((void **)&aclRes->Context(), aclRes->DeviceId()); if (ret != ACL_ERROR_NONE) { ERROR_LOG("Failed to create ACL context."); aclFinalize(); return -1; } // Run ResNet50 inference Result inferRet = ResNet50Infer(RESNET50_MODEL_PATH, RESNET50_INPUT_IMAGE_PATH); if (inferRet != SUCCESS) { ERROR_LOG("ResNet50 inference failed."); aclrtDestroyContext(aclRes->Context()); aclFinalize(); return -1; } // Destroy ACL context and finalize ACL aclrtDestroyContext(aclRes->Context()); aclFinalize(); INFO_LOG("Program execution successful."); return 0; } ``` -------------------------------- ### Navigate to Install Script Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/1_add_frameworklaunch/README.md Change to the directory containing the msOpGen script's install.sh file. This is the starting point for generating and compiling the custom operator. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator_contrib/OnesSample/FrameworkLaunch/AclNNInvocation/README.md Change the current directory to the AclNNInvocation sample directory within the cloned repository. ```bash cd ${git_clone_path}/samples/operator_contrib/OnesSample/FrameworkLaunch/AclNNInvocation ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/0_introduction/21_vectoradd_kernellaunch/VectorAddMultiCoreWithTiling/README.md Use this command to navigate to the VectorAddMultiCoreWithTiling example directory. Replace ${git_clone_path} with the actual path where the samples repository was cloned. ```bash cd ${git_clone_path}/samples/operator/ascendc/0_introduction/21_vectoradd_kernellaunch/VectorAddMultiCoreWithTiling/ ``` -------------------------------- ### Download Calibration Data Source: https://github.com/ascend/samples/blob/master/python/level1_single_api/9_amct/amct_tensorflow/cmd/README_CN.md Use this command to download sample calibration data and labels for quantization. Ensure you are in the example's root directory and have the 'unrar' tool installed. ```bash cd data mkdir image && cd image wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/models/amct_acl/classification/calibration.rar unrar e calibration.rar ``` -------------------------------- ### Navigate to Sample Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/4_best_practices/15_mata_address_conflict/AclNNInvocation/README.md Use this bash command to navigate to the AclNNInvocation sample directory for running the example. ```bash cd ${git_clone_path}/samples/operator/ascendc/4_best_practices/15_mata_address_conflict/AclNNInvocation ``` -------------------------------- ### Download and Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/4_best_practices/22_matmul_reduce_scatter_custom/AclNNInvocation/README.md This bash command downloads the sample code and navigates into the AclNNInvocation directory for the MatmulReduceScatterCustom operator. Ensure you have git installed and are in the desired parent directory. ```bash cd ${git_clone_path}/samples/operator/ascendc/4_best_practices/22_matmul_reduce_scatter_custom/AclNNInvocation ``` -------------------------------- ### Compile the Sample Source: https://github.com/ascend/samples/blob/master/inference/ACLHelloWorld/README.md Navigate to the sample's script directory and execute the build script to compile the sample. ```bash cd $HOME/samples/inference/ACLHelloWorld/scripts bash sample_build.sh ``` -------------------------------- ### Configure .bashrc for Integrated Setup Source: https://github.com/ascend/samples/blob/master/docs/INSTALL_cn.md Set environment variables for CPU architecture, third-party library paths, and CANN installation directory. This is for users running development and execution on the same Ascend device. ```bash # 以安装用户在任意目录下执行以下命令,打开.bashrc文件。 vi ~/.bashrc # 在文件最后一行后面添加如下内容。 export CPU_ARCH=`arch` export THIRDPART_PATH=${HOME}/Ascend/thirdpart/${CPU_ARCH} #代码编译时链接samples所依赖的相关库文件 export LD_LIBRARY_PATH=${THIRDPART_PATH}/lib:$LD_LIBRARY_PATH #运行时链接第三方库文件 export INSTALL_DIR=${HOME}/Ascend/ascend-toolkit/latest #CANN软件安装后的文件存储路径,根据安装目录自行修改 # 执行命令保存文件并退出。 :wq! # 执行命令使其立即生效。 source ~/.bashrc # 创建samples第三方相关依赖文件夹 mkdir -p ${THIRDPART_PATH} # 下载源码并安装git cd ${HOME} sudo apt-get install git git clone https://gitee.com/ascend/samples.git # 拷贝公共文件到samples相关依赖路径中 cp -r ${HOME}/samples/inference/acllite/aclliteCPP ${THIRDPART_PATH} ``` -------------------------------- ### Build Sample Source: https://github.com/ascend/samples/blob/master/cplusplus/level2_simple_inference/0_data_process/cropandpaste/README_CN.md Execute the build script to compile the sample. Ensure you are in the correct directory. ```bash cd ${HOME}/samples/cplusplus/level2_simple_inference/0_data_process/cropandpaste/scripts bash sample_build.sh ``` -------------------------------- ### Source CANN Environment Setup Script Source: https://github.com/ascend/samples/blob/master/operator/ascendc/1_utilities/0_printf/FrameworkLaunch/README.md Source the setenv.bash script to export necessary CANN environment variables, including ASCEND_OPP_PATH, if it is not already set. Replace [ASCEND_INSTALL_PATH] with the actual CANN installation path. ```bash source [ASCEND_INSTALL_PATH]/bin/setenv.bash # 例如 source /usr/local/Ascend/ascend-toolkit/latest/bin/setenv.bash ``` -------------------------------- ### Navigate to Example Directory Source: https://github.com/ascend/samples/blob/master/operator_contrib/FastGeluGradSample/FrameworkLaunch/AclNNInvocation/README.en.md Change the current directory to the AclNNInvocation example directory. ```bash cd ${git_clone_path}/samples/operator_contrib/FastGeluGradSample/FrameworkLaunch/AclNNInvocation ``` -------------------------------- ### Configure .bashrc for Separated Setup (Runtime Environment) Source: https://github.com/ascend/samples/blob/master/docs/INSTALL_cn.md Set environment variables for CPU architecture, third-party library paths, and CANN installation directory on the runtime Ascend device. Ensure CPU_ARCH matches the device's architecture. ```bash # 以安装用户在运行环境任意目录下执行以下命令,打开.bashrc文件。 vi ~/.bashrc # 在文件最后一行后面添加如下内容。CPU_ARCH环境变量请根据运行环境cpu架构填写,如export CPU_ARCH=aarch64 export CPU_ARCH=`arch` export THIRDPART_PATH=${HOME}/Ascend/thirdpart/${CPU_ARCH} #代码编译时链接第三方库 export LD_LIBRARY_PATH=${HOME}/Ascend/thirdpart/${CPU_ARCH}/lib:$LD_LIBRARY_PATH #运行时链接库文件 export INSTALL_DIR=${HOME}/Ascend/ascend-toolkit/latest #CANN软件安装后文件存储路径 # 执行命令保存文件并退出。 :wq! # 执行命令使其立即生效。 source ~/.bashrc # 创建第三方依赖文件夹 mkdir -p ${THIRDPART_PATH} # 拷贝相关数据,其中X.X.X.X为开发环境ip地址。 sudo scp -r HwHiAiUser@X.X.X.X:${THIRDPART_PATH}/common ${THIRDPART_PATH} ``` -------------------------------- ### Navigate to Load Library Example Directory Source: https://github.com/ascend/samples/blob/master/operator/ascendc/tutorials/AddCustomSample/FrameworkLaunch/CppExtensions/README.md Change directory to the load_library example folder for compiling custom C++ APIs. ```bash cd ${git_clone_path}/samples/operator/AddCustomSample/FrameworkLaunch/CppExtensions/load_library ``` -------------------------------- ### Configure .bashrc for Separated Setup (Development Environment) Source: https://github.com/ascend/samples/blob/master/docs/INSTALL_cn.md Set environment variables for CPU architecture, third-party library paths, and CANN installation directory on the development machine. Adjust CPU_ARCH and THIRDPART_PATH based on the target runtime environment. ```bash # 以安装用户在开发环境任意目录下执行以下命令,打开.bashrc文件。 vi ~/.bashrc # 在文件最后一行后面添加如下内容。CPU_ARCH环境变量请根据运行环境cpu架构填写,如export CPU_ARCH=aarch64 export CPU_ARCH=[aarch64/x86_64] # THIRDPART_PATH需要按照运行环境安装路径设置,如运行环境为arm,指定安装路径为Ascend-arm,则需要设置为export THIRDPART_PATH=${HOME}/Ascend-arm/thirdpart/${CPU_ARCH} export THIRDPART_PATH=${HOME}/Ascend/thirdpart/${CPU_ARCH} #代码编译时链接第三方库 # CANN软件安装后文件存储路径,最后一级目录请根据运行环境设置,运行环境为arm,这里填arm64-linux;运行环境为x86,则这里填x86_64-linux,以下以arm环境为例 export INSTALL_DIR=${HOME}/Ascend/ascend-toolkit/latest/arm64-linux # 执行命令保存文件并退出。 :wq! # 执行命令使其立即生效。 source ~/.bashrc # 创建第三方依赖文件夹 mkdir -p ${THIRDPART_PATH} # 拷贝公共文件到第三方依赖文件夹 cd $HOME git clone https://gitee.com/ascend/samples.git cp -r ${HOME}/samples/inference/acllite/aclliteCPP ${THIRDPART_PATH} ``` -------------------------------- ### Run Sample (Save Image Locally) Source: https://github.com/ascend/samples/blob/master/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera/README_CN.md Execute the compiled 'main' executable with specific parameters to capture an image and save it locally. Adjust the directory based on your deployment setup. ```bash # If development and runtime environments are integrated, skip step 1 and proceed directly to step 2. # 1. Execute the following command to upload the 'ascendcamera' directory from the development environment to the runtime environment (e.g., /home/HwHiAiUser) and log in to the runtime environment (Host) as HwHiAiUser (runtime user). # "xxx.xxx.xxx.xxx" is the runtime environment IP. For 200DK during USB connection, it is usually 192.168.1.2. scp -r $HOME/samples/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera HwHiAiUser@xxx.xxx.xxx.xxx:/home/HwHiAiUser ssh HwHiAiUser@xxx.xxx.xxx.xxx ``` ```bash # 2. Run the executable file. # If development and runtime environments are integrated, execute the following command to switch directories. cd $HOME/samples/cplusplus/level1_single_api/5_200dk_peripheral/ascendcamera/out # If development and runtime environments are separated, execute the following command to switch directories. cd $HOME/ascendcamera/out # After switching directories, execute the following command to run the sample. ./main -i -c 1 -o ./output/filename.jpg --overwrite ``` -------------------------------- ### Execute PNGD Demo (Basic Functionality) Source: https://github.com/ascend/samples/blob/master/cplusplus/level1_single_api/7_dvpp/pngd_sample/readme.md Run the pngd_demo executable to decode a PNG image. This example decodes the specified image into RGB_888 format using 2 channels starting from channel 16, and performs the decoding 100 times. ```bash ./pngd_demo --in_image_file dvpp_pngd_1920x1080_RGBA.png --img_width 1920 --img_height 1080 --pixel_mode 12 --chn_num 2 --start_chn 16 --send_circle 100 ``` -------------------------------- ### Build Sample Source: https://github.com/ascend/samples/blob/master/cplusplus/level2_simple_inference/2_object_detection/VGG_SSD_coco_detection_CV_with_AIPP/README_CN.md Execute this script to compile the sample. Ensure you are in the 'scripts' directory within the sample's folder. ```bash cd ${HOME}/samples/cplusplus/level2_simple_inference/2_object_detection/VGG_SSD_coco_detection_CV_with_AIPP/scripts bash sample_build.sh ```