Fix broken path for 910B

Ascend samples has broken path and wrong assumption (atlas 300) compiling for 910B SDK (ATC, CANN toolkit) in the single chip test env.

Test

ipynb test file

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8794c4ff-c207-45c6-9535-3656635fc756",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+------------------------------------------------------------------------------------------------+\n",
      "| npu-smi 23.0.rc2                 Version: 23.0.rc2                                             |\n",
      "+---------------------------+---------------+----------------------------------------------------+\n",
      "| NPU   Name                | Health        | Power(W)    Temp(C)           Hugepages-Usage(page)|\n",
      "| Chip                      | Bus-Id        | AICore(%)   Memory-Usage(MB)  HBM-Usage(MB)        |\n",
      "+===========================+===============+====================================================+\n",
      "| 0     910B2               | OK            | 88.4        51                0    / 0             |\n",
      "| 0                         | 0000:C1:00.0  | 0           0    / 0          4200 / 65536         |\n",
      "+===========================+===============+====================================================+\n",
      "+---------------------------+---------------+----------------------------------------------------+\n",
      "| NPU     Chip              | Process id    | Process name             | Process memory(MB)      |\n",
      "+===========================+===============+====================================================+\n",
      "| No running processes found in NPU 0                                                            |\n",
      "+===========================+===============+====================================================+\n",
      "NPU card query:\n",
      "\tTotal Count                    : 1\n",
      "\n",
      "\tNPU ID                         : 0\n",
      "\tChip Count                     : 1\n",
      "\n",
      "NPU MCU version:\n",
      "\tVersion                        : 23.2.4\n",
      "/home/ma-user/anaconda3/envs/MindSpore/bin/python\n"
     ]
    }
   ],
   "source": [
    "!npu-smi info\n",
    "!echo \"NPU card query:\"\n",
    "!npu-smi info -l\n",
    "!echo \"NPU MCU version:\"\n",
    "!npu-smi upgrade -b mcu -i 0\n",
    "!cat /usr/local/Ascend/ascend-toolkit/set_env.sh\n",
    "!which python\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "67b864a9-2dfc-4b27-b40c-7da9ae989dc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fatal: destination path 'Github/samples' already exists and is not an empty directory.\n",
      "Cloning into 'Github/latest-samples'...\n",
      "remote: Enumerating objects: 86460, done.\u001b[K\n",
      "remote: Counting objects: 100% (314/314), done.\u001b[K\n",
      "remote: Compressing objects: 100% (231/231), done.\u001b[K\n",
      "remote: Total 86460 (delta 169), reused 182 (delta 79), pack-reused 86146\u001b[K\n",
      "Receiving objects: 100% (86460/86460), 421.76 MiB | 10.32 MiB/s, done.\n",
      "Resolving deltas: 100% (57003/57003), done.\n",
      "Updating files: 100% (5879/5879), done.\n"
     ]
    }
   ],
   "source": [
    "!mkdir -p Github\n",
    "# git up to v0.2.0\n",
    "!git clone https://github.com/Huawei-Ascend/samples.git Github/samples\n",
    "# git up to v0.9.0\n",
    "!git clone https://gitee.com/ascend/samples.git Github/latest-samples\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f86c635c-824c-4ebb-a75b-898ec74f8fb0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "There is no D chip in this server. Not support health check.\n",
      "128\n"
     ]
    }
   ],
   "source": [
    "!bash npu-healthcheck.sh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "52b3cd25-093a-4450-9e6d-0d94f727acad",
   "metadata": {},
   "outputs": [],
   "source": [
    "# see env.sh\n",
    "DDK_PATH=\"/usr/local/Ascend/ascend-toolkit/latest\"\n",
    "NPU_HOST_LIB=f\"{DDK_PATH}/runtime/lib64/stub\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cdb9c3ca-39c9-4a98-b2a8-5dfe550e03f7",
   "metadata": {},
   "source": [
    "## SDK Utility\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "75fe52ea-b6d0-4943-880c-74b704695104",
   "metadata": {},
   "outputs": [],
   "source": [
    "ROOT=\"Github/latest-samples\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2031e0de-1725-44be-9d7c-ad973b9aca11",
   "metadata": {},
   "source": [
    "## Check Memory utility Evaluation\n",
    "\n",
    "author: yiakwy, Dec 12, 2023\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8899152d-29f7-49e5-8bbc-48f142c958d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "05_memcpy_01_host2device\n",
      "05_memcpy_02_device2host\n",
      "05_memcpy_03_host2host\n",
      "05_memcpy_04_device2device\n",
      "05_memcpy_05_host2device_different_count\n",
      "05_memcpy_06_device2host_different_count\n",
      "05_memcpy_07_error\n",
      "06_async_memcpy_01_host2device\n",
      "06_async_memcpy_02_device2host\n",
      "06_async_memcpy_03_device2device\n",
      "06_async_memcpy_04_host2host\n",
      "06_async_memcpy_05_device2host_different_count\n",
      "06_async_memcpy_06_host2device_different_count\n",
      "06_async_memcpy_07_error\n",
      "06_async_memcpy_08_spead\n",
      "memcpy_host_DVPP_cpp\n",
      "memcpy_host_device_async_cpp\n",
      "memcpy_host_device_cpp\n",
      "out\n",
      "readme.md\n"
     ]
    }
   ],
   "source": [
    "!ls \"{ROOT}/cplusplus/level1_single_api/1_acl/2_memory_management\"\n",
    "\n",
    "WORK_DIR=f\"{ROOT}/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_async_cpp/\"\n",
    "INSTALL_DIR=f\"{WORK_DIR}/build/out\"\n",
    "CPU_ARCH=\"aarch64\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cdf3dcea-2889-4884-8cef-3c281584aecb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CMakeLists.txt\tREADME_CN.md  build  scripts  src\n",
      "-- env INC_PATH: /usr/local/Ascend/ascend-toolkit/latest\n",
      "-- env LIB_PATH: /usr/local/Ascend/ascend-toolkit/latest/runtime/lib64/stub\n",
      "arm architecture detected\n",
      "target aarch64 300\n",
      "-- Configuring done\n",
      "-- Generating done\n",
      "-- Build files have been written to: /home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_async_cpp/build\n",
      "make[1]: Entering directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_async_cpp/build'\n",
      "make[2]: Entering directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_async_cpp/build'\n",
      "make[2]: Leaving directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_async_cpp/build'\n",
      "[100%] Built target main\n",
      "make[1]: Leaving directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/2_memory_management/memcpy_host_device_async_cpp/build'\n"
     ]
    }
   ],
   "source": [
    "!ls \"{WORK_DIR}\"\n",
    "!cd {WORK_DIR} && mkdir -p build && cd build && DDK_PATH={DDK_PATH} NPU_HOST_LIB={NPU_HOST_LIB} LD_LIBRARY_PATH={NPU_HOST_LIB} INSTALL_DIR={INSTALL_DIR} CPU_ARCH={CPU_ARCH} cmake .. && make -j8"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67b9c00b-8ec6-4031-9ad4-38d791d51571",
   "metadata": {},
   "source": [
    "## GEMM\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3969ebdd-5884-4b06-8373-43b688bc468a",
   "metadata": {},
   "outputs": [],
   "source": [
    "WORK_DIR=f\"{ROOT}/cplusplus/level1_single_api/1_acl/4_blas/gemm\"\n",
    "RUN_OUT=f\"{ROOT}/cplusplus/level1_single_api/1_acl/run/out\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5c82675e-b9f5-4fc0-8ade-eaae2b5049a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "README.md  README_CN.md  build\tinc  run  scripts  src\n",
      "-- env INC_PATH: /usr/local/Ascend/ascend-toolkit/latest\n",
      "-- env LIB_PATH: /usr/local/Ascend/ascend-toolkit/latest/runtime/lib64/stub\n",
      "-- Configuring done\n",
      "-- Generating done\n",
      "-- Build files have been written to: /home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/4_blas/gemm/build\n",
      "make[1]: Entering directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/4_blas/gemm/build'\n",
      "make[2]: Entering directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/4_blas/gemm/build'\n",
      "make[2]: Leaving directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/4_blas/gemm/build'\n",
      "[100%] Built target execute_gemm_op\n",
      "make[1]: Leaving directory '/home/ma-user/work/Github/latest-samples/cplusplus/level1_single_api/1_acl/4_blas/gemm/build'\n"
     ]
    }
   ],
   "source": [
    "!ls \"{WORK_DIR}\"\n",
    "!cd {WORK_DIR} && mkdir -p build && cd build && DDK_PATH={DDK_PATH} NPU_HOST_LIB={NPU_HOST_LIB} cmake ../src && make -j8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "e6a1bb60-8434-4afa-989a-8338b0e91965",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "total 20K\n",
      "-rw-r----- 1 ma-user ma-group 761 Dec 15 15:19 generate_data.py\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:19 matrix_a.bin\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:19 matrix_b.bin\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:19 matrix_c.bin\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:19 output.bin\n",
      "Output:\n",
      "[[ 7.76   6.457  7.117  7.402  6.207  6.074  9.766  8.63   8.62   6.297\n",
      "   6.8    8.28   9.91   7.1    5.547 10.1  ]\n",
      " [ 6.477  7.113  5.348  6.07   4.812  4.047  7.477  7.51   6.496  6.375\n",
      "   6.395  6.277  7.418  5.64   5.137  8.78 ]\n",
      " [ 5.582  5.914  5.75   4.996  2.889  4.594  7.92   6.953  6.527  5.785\n",
      "   5.223  6.41   6.414  4.785  4.844  7.867]\n",
      " [ 7.83   9.7   10.34   7.906  7.164  5.45  11.78  12.305 10.29   9.75\n",
      "   7.105 10.484 12.71  10.52   8.85  10.88 ]\n",
      " [ 5.586  6.836  5.97   5.17   4.535  3.936  7.406  8.26   5.793  6.098\n",
      "   4.55   7.574  9.     6.48   5.39   8.695]\n",
      " [ 9.03  10.32   8.664  6.793  5.1    5.25  10.42   8.58   8.08   6.258\n",
      "   7.555  8.27   9.484  7.49   5.617  9.7  ]\n",
      " [ 7.77   7.184  7.277  7.484  5.637  5.09   9.875  9.44   7.777  7.48\n",
      "   6.547  8.09  11.46   8.02   6.418 10.67 ]\n",
      " [ 5.867  8.36   6.15   6.367  5.246  3.82   7.938  7.52   6.516  5.94\n",
      "   5.887  6.453  9.52   4.914  6.035  8.914]\n",
      " [ 8.2    8.02   8.38   8.17   5.887  4.95   9.914  9.72   8.63   8.02\n",
      "   7.58   9.016  9.44   9.46   6.96  10.71 ]\n",
      " [ 8.27  10.414  8.6    7.55   6.625  4.145  9.81  11.336  8.555  9.71\n",
      "   7.453 10.05  10.45   8.83   8.06  11.84 ]\n",
      " [ 7.59   8.42   7.61   7.062  5.28   4.02   9.85   9.49   7.465  7.133\n",
      "   6.934  8.67  10.92   7.65   5.883  9.73 ]\n",
      " [ 9.36   9.18   9.805  8.11   7.74   5.62  12.125 11.8    9.78   9.03\n",
      "   7.105 10.055 11.84  10.484  7.305 10.984]\n",
      " [ 7.375  7.78   7.51   6.81   5.03   5.703  9.35   8.56   9.02   6.418\n",
      "   5.25   7.723  9.42   7.73   5.52   8.92 ]\n",
      " [ 6.367  7.215  5.984  6.07   4.324  4.58   8.68   8.52   8.31   5.094\n",
      "   5.266  7.223  9.94   6.25   6.066  8.22 ]\n",
      " [10.88  10.586  9.96  10.23   8.625  6.47  12.25  11.59  10.555 10.21\n",
      "   9.875 11.11  13.4    8.66   7.348 14.84 ]\n",
      " [ 7.637  8.24   8.89   7.316  5.02   5.566 11.01  10.55  10.164  8.234\n",
      "   7.23   7.613 10.53   7.156  7.297  9.37 ]]\n",
      "total 20K\n",
      "-rw-r----- 1 ma-user ma-group 761 Dec 15 15:19 generate_data.py\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:34 matrix_a.bin\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:34 matrix_b.bin\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:34 matrix_c.bin\n",
      "-rw-r----- 1 ma-user ma-group 512 Dec 15 15:34 output.bin\n"
     ]
    }
   ],
   "source": [
    "TEST_DATA=f\"{WORK_DIR}/run/out/test_data/\"\n",
    "!ls -lh {TEST_DATA}/data\n",
    "!cd {TEST_DATA}/data && python generate_data.py\n",
    "!ls -lh {TEST_DATA}/data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "2d983b40-61e7-451d-8301-7a64853c73f2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/usr/local/Ascend/ascend-toolkit/latest/bin/atc\n",
      "ATC start working now, please wait for a moment.\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/dsl/unify_schedule/extract_image_patches_without_cbuf_schedule.py:317: SyntaxWarning: \"is not\" with a literal. Did you mean \"!=\"?\n",
      "  if _ is not 1:\n",
      "...\n",
      "ATC run success, welcome to the next use.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# compile Ascend(昇腾) NPU model file (*.om) with Ascend Tensor Compiler (ATC)\n",
    "# generate offline model example:\n",
    "# atc --model=./alexnet.prototxt --weight=./alexnet.caffemodel --framework=0 --output=./domi \n",
    "# generate offline model for single op example:\n",
    "# atc --singleop=./op_list.json --output=./op_model\n",
    "!which atc\n",
    "!atc --singleop={TEST_DATA}/config/gemm.json --soc_version=Ascend910B --output={TEST_DATA}/op_models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "114c59d6-a89e-4202-99eb-50484f760f42",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Github/latest-samples/cplusplus/level1_single_api/1_acl/run/out\n",
      "total 60K\n",
      "-rwxr-x--- 1 ma-user ma-group  88K Dec 15 16:19 execute_gemm_op\n",
      "drwx------ 2 ma-user ma-group 4.0K Dec 15 16:04 result_files\n",
      "drwxr-x--- 5 ma-user ma-group 4.0K Dec 15 15:37 test_data\n",
      "[ERROR]: stub library cannot be used for execution, please check your environment variables and compilation options to make sure you use the correct ACL library.\n",
      "[ERROR]  Init acl failed\n",
      "[ERROR]  Init resource failed\n"
     ]
    }
   ],
   "source": [
    "print(RUN_OUT)\n",
    "!cp {RUN_OUT}/execute_gemm_op {WORK_DIR}/run/out\n",
    "# run (m,k,n) = (16,16,16) GEMM\n",
    "!cd {WORK_DIR}/run/out && ls -lh && ./execute_gemm_op\n",
    "#    // acl.json is dump or profiling config file\n",
    "#    if (aclInit(\"test_data/config/acl.json\") != ACL_SUCCESS) {\n",
    "#        ERROR_LOG(\"Init acl failed\");\n",
    "#        return false;\n",
    "#    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a96e250-b963-48b2-8666-d31127e048eb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MindSpore",
   "language": "python",
   "name": "mindspore"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}