Open
feat(qbmmv3): ScaleNZ layout support for MX ScaleB #1
HuangRZzzzAdd on Aug 19
feat(qbmmv3): ScaleNZ layout support for MX ScaleB #1
Open
Merged fromscaleB-nz-layoutintomaster
Total: 771 files changed+49613-19895
| @@ -123,34 +123,47 @@ case "${task_name}" in | |||
| 123 | touch build_out/cann-ops-nn-950_linux-aarch64.run | 123 | touch build_out/cann-ops-nn-950_linux-aarch64.run |
| 124 | fi | 124 | fi |
| 125 | ;; | 125 | ;; |
| 126 | -esac | 126 | + Compile_Ascend_X86_mobile_station) |
| 127 | - | 127 | + if [ "${TARGET_BRANCH}" = "master" ];then |
| 128 | -case "${task_name}|${TARGET_BRANCH}" in | 128 | + wget -nv https://kiri-obs.obs.cn-north-4.myhuaweicloud.com/Cann%20Large%20Model%20Foundation%208.5.0.rc002/cann-bisheng-compiler_9.2.0_linux-x86_64.run |
| 129 | - "Compile_Ascend_X86_mobile_station|master") | 129 | + chmod +x *.run |
| 130 | - wget -nv https://kiri-obs.obs.cn-north-4.myhuaweicloud.com/Cann%20Large%20Model%20Foundation%208.5.0.rc002/cann-bisheng-compiler_9.2.0_linux-x86_64.run | 130 | + sudo -u jenkins ./*.run --full --quiet --install-path=/home/jenkins/Ascend |
| 131 | - chmod +x *.run | 131 | + bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16 |
| 132 | - sudo -u jenkins ./*.run --full --quiet --install-path=/home/jenkins/Ascend | 132 | + echo "exec cmd: [bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16]" |
| 133 | - bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16 | 133 | + else |
| 134 | - echo "exec cmd: [bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16]" | 134 | + echo "not need build mobile_station" |
| 135 | + mkdir build_out | ||
| 136 | + touch build_out/cann-ops-nn-kirinx90_linux-x86_64.run | ||
| 137 | + exit 0 | ||
| 138 | + fi | ||
| 135 | ;; | 139 | ;; |
| 136 | - *) | 140 | + Compile_Ascend_X86_mobile_station_ubuntu24) |
| 137 | - echo "not need build single" | 141 | + if [ "${TARGET_BRANCH}" = "master" ];then |
| 138 | - mkdir single | 142 | + wget -nv https://kiri-obs.obs.cn-north-4.myhuaweicloud.com/Cann%20Large%20Model%20Foundation%208.5.0.rc002/cann-bisheng-compiler_9.2.0_linux-x86_64.run |
| 139 | - touch single.tar.gz | 143 | + chmod +x *.run |
| 144 | + sudo -u jenkins ./*.run --full --quiet --install-path=/home/jenkins/Ascend | ||
| 145 | + bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16 | ||
| 146 | + echo "exec cmd: [bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16]" | ||
| 147 | + else | ||
| 148 | + echo "not need build mobile_station" | ||
| 149 | + mkdir build_out | ||
| 150 | + touch build_out/cann-ops-nn-kirinx90_linux-x86_64.run | ||
| 151 | + exit 0 | ||
| 152 | + fi | ||
| 140 | ;; | 153 | ;; |
| 141 | -esac | 154 | + Compile_Ascend_X86_mobile_station_9030_ubuntu24) |
| 142 | -case "${task_name}|${TARGET_BRANCH}" in | 155 | + if [ "${TARGET_BRANCH}" = "master" ];then |
| 143 | - "Compile_Ascend_X86_mobile_station_ubuntu24|master") | 156 | + wget -nv https://kiri-obs.obs.cn-north-4.myhuaweicloud.com/Cann%20Large%20Model%20Foundation%208.5.0.rc002/cann-bisheng-compiler_9.2.0_linux-x86_64.run |
| 144 | - wget -nv https://kiri-obs.obs.cn-north-4.myhuaweicloud.com/Cann%20Large%20Model%20Foundation%208.5.0.rc002/cann-bisheng-compiler_9.2.0_linux-x86_64.run | 157 | + chmod +x *.run |
| 145 | - chmod +x *.run | 158 | + sudo -u jenkins ./*.run --full --quiet --install-path=/home/jenkins/Ascend |
| 146 | - sudo -u jenkins ./*.run --full --quiet --install-path=/home/jenkins/Ascend | 159 | + bash build.sh --pkg --soc=kirinx9030 --cann_3rd_lib_path=/home/jenkins/opensource -j16 |
| 147 | - bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16 | 160 | + echo "exec cmd: [bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16]" |
| 148 | - echo "exec cmd: [bash build.sh --pkg --soc=kirinx90 --cann_3rd_lib_path=/home/jenkins/opensource -j16]" | 161 | + else |
| 149 | - ;; | 162 | + echo "not need build mobile_station" |
| 150 | - *) | 163 | + mkdir build_out |
| 151 | - echo "not need build single" | 164 | + touch build_out/cann-ops-nn-kirinx90_linux-x86_64.run |
| 152 | - mkdir single | 165 | + exit 0 |
| 153 | - touch single.tar.gz | 166 | + fi |
| 154 | ;; | 167 | ;; |
| 155 | esac | 168 | esac |
| 156 | 169 | ||
| @@ -12,8 +12,7 @@ | |||
| 12 | set -euo pipefail | 12 | set -euo pipefail |
| 13 | 13 | ||
| 14 | echo "start run test case, please wait ..." | 14 | echo "start run test case, please wait ..." |
| 15 | -cd /home/taskspace | 15 | + |
| 16 | -WORKSPACE=/home/taskspace | ||
| 17 | 16 | ||
| 18 | export ASCEND_GLOBAL_LOG_LEVEL=2 | 17 | export ASCEND_GLOBAL_LOG_LEVEL=2 |
| 19 | export ASCEND_SLOG_PRINT_TO_STDOUT=0 | 18 | export ASCEND_SLOG_PRINT_TO_STDOUT=0 |
| @@ -49,7 +49,7 @@ jobs: | |||
| 49 | artifact-path: "${{ steps.process_checkout.outputs.path }}/pre-commit*.txt" | 49 | artifact-path: "${{ steps.process_checkout.outputs.path }}/pre-commit*.txt" |
| 50 | object-prefix: ${{ env.obs_path }}/ | 50 | object-prefix: ${{ env.obs_path }}/ |
| 51 | if: "${{ default() }}" | 51 | if: "${{ default() }}" |
| 52 | - runs-on: [dedicate-hosted, x64, small] | 52 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 53 | container: | 53 | container: |
| 54 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.precommit_image_version }} | 54 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.precommit_image_version }} |
| 55 | JOB_check_pr: | 55 | JOB_check_pr: |
| @@ -79,7 +79,7 @@ jobs: | |||
| 79 | with: | 79 | with: |
| 80 | repo_name: ${{ env.repo_name }} | 80 | repo_name: ${{ env.repo_name }} |
| 81 | workspace: ${{ steps.process_checkout.outputs.path }} | 81 | workspace: ${{ steps.process_checkout.outputs.path }} |
| 82 | - runs-on: [dedicate-hosted, x64, small] | 82 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 83 | container: | 83 | container: |
| 84 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} | 84 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} |
| 85 | JOB_sca: | 85 | JOB_sca: |
| @@ -107,7 +107,7 @@ jobs: | |||
| 107 | cd CI/scripts | 107 | cd CI/scripts |
| 108 | python3 codescan_gitcode.py --access_key ${{secrets.SCA_AK}} --secret_access_key ${{secrets.SCA_SK}} --access_key_get ${{secrets.SCA_AK_GET}} --secret_access_key_get ${{secrets.SCA_SK_GET}} --org_name ${org_name} --pr_id ${MERGE_ID} --repo ${repo_name} --commit_id ${{ atomgit.event.pull_request.merge_commit_sha }} | 108 | python3 codescan_gitcode.py --access_key ${{secrets.SCA_AK}} --secret_access_key ${{secrets.SCA_SK}} --access_key_get ${{secrets.SCA_AK_GET}} --secret_access_key_get ${{secrets.SCA_SK_GET}} --org_name ${org_name} --pr_id ${MERGE_ID} --repo ${repo_name} --commit_id ${{ atomgit.event.pull_request.merge_commit_sha }} |
| 109 | if: "${{ default() }}" | 109 | if: "${{ default() }}" |
| 110 | - runs-on: [dedicate-hosted, x64, small] | 110 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 111 | container: | 111 | container: |
| 112 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} | 112 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} |
| 113 | JOB_antiposion: | 113 | JOB_antiposion: |
| @@ -135,7 +135,7 @@ jobs: | |||
| 135 | cd CI/scripts | 135 | cd CI/scripts |
| 136 | python3 anti_virus_gitcode.py --access_key ${{secrets.ANTI_AK}} --secret_access_key ${{secrets.ANTI_SK}} --access_key_get ${{secrets.ANTI_AK_GET}} --secret_access_key_get ${{secrets.ANTI_SK_GET}} --org_name ${org_name} --pr_id ${MERGE_ID} --repo ${repo_name} --commit_id ${{ atomgit.event.pull_request.merge_commit_sha }} | 136 | python3 anti_virus_gitcode.py --access_key ${{secrets.ANTI_AK}} --secret_access_key ${{secrets.ANTI_SK}} --access_key_get ${{secrets.ANTI_AK_GET}} --secret_access_key_get ${{secrets.ANTI_SK_GET}} --org_name ${org_name} --pr_id ${MERGE_ID} --repo ${repo_name} --commit_id ${{ atomgit.event.pull_request.merge_commit_sha }} |
| 137 | if: "${{ default() }}" | 137 | if: "${{ default() }}" |
| 138 | - runs-on: [dedicate-hosted, x64, small] | 138 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 139 | container: | 139 | container: |
| 140 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} | 140 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} |
| 141 | JOB_codecheck: | 141 | JOB_codecheck: |
| @@ -163,6 +163,6 @@ jobs: | |||
| 163 | cd CI/scripts | 163 | cd CI/scripts |
| 164 | python3 codecheck_gitcode.py --access_key ${{secrets.CODECHECK_AK}} --secret_access_key ${{secrets.CODECHECK_SK}} --access_key_get ${{secrets.CODECHECK_AK_GET}} --secret_access_key_get ${{secrets.CODECHECK_SK_GET}} --org_name ${org_name} --pr_id ${MERGE_ID} --repo ${repo_name} --commit_id ${{ atomgit.event.pull_request.merge_commit_sha }} | 164 | python3 codecheck_gitcode.py --access_key ${{secrets.CODECHECK_AK}} --secret_access_key ${{secrets.CODECHECK_SK}} --access_key_get ${{secrets.CODECHECK_AK_GET}} --secret_access_key_get ${{secrets.CODECHECK_SK_GET}} --org_name ${org_name} --pr_id ${MERGE_ID} --repo ${repo_name} --commit_id ${{ atomgit.event.pull_request.merge_commit_sha }} |
| 165 | if: "${{ default() }}" | 165 | if: "${{ default() }}" |
| 166 | - runs-on: [dedicate-hosted, x64, small] | 166 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 167 | container: | 167 | container: |
| 168 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} | 168 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.codecheck_image_version }} |
| @@ -66,14 +66,20 @@ jobs: | |||
| 66 | name: rename_package | 66 | name: rename_package |
| 67 | if: ${{ inputs.package_name != '' }} | 67 | if: ${{ inputs.package_name != '' }} |
| 68 | run: | | 68 | run: | |
| 69 | - cd ${{ steps.process_checkout.outputs.path }}/build_out | 69 | + mkdir -p "${{ steps.process_checkout.outputs.path }}/build_out" |
| 70 | - for f in *.run; do | 70 | + cd "${{ steps.process_checkout.outputs.path }}/build_out" |
| 71 | - [ -f "$f" ] || continue | 71 | + if [[ "${{ inputs.task_name }}" == compile_single ]]; then |
| 72 | - [ "$f" = "${{ inputs.package_name }}" ] && continue | 72 | + mv ../single.tar.gz ${{ inputs.package_name }} |
| 73 | - mv "$f" "${{ inputs.package_name }}" | 73 | + echo "mv: ../single.tar.gz -> ${{ inputs.package_name }}" |
| 74 | - echo "Renamed: $f -> ${{ inputs.package_name }}" | 74 | + else |
| 75 | - break | 75 | + for f in *.run; do |
| 76 | - done | 76 | + [ -f "$f" ] || continue |
| 77 | + [ "$f" = "${{ inputs.package_name }}" ] && continue | ||
| 78 | + mv "$f" "${{ inputs.package_name }}" | ||
| 79 | + echo "Renamed: $f -> ${{ inputs.package_name }}" | ||
| 80 | + break | ||
| 81 | + done | ||
| 82 | + fi | ||
| 77 | - | 83 | - |
| 78 | name: api-check | 84 | name: api-check |
| 79 | identifier: api-check | 85 | identifier: api-check |
| @@ -103,8 +109,8 @@ jobs: | |||
| 103 | object-prefix: ${{ env.obs_path }}/ | 109 | object-prefix: ${{ env.obs_path }}/ |
| 104 | if: "${{ default() }}" | 110 | if: "${{ default() }}" |
| 105 | runs-on: | 111 | runs-on: |
| 106 | - - dedicate-hosted | 112 | + - self-hosted |
| 107 | - - ${{ inputs.arch }} | 113 | + - arch=${{ inputs.arch }} |
| 108 | - - xlarge | 114 | + - spec=xlarge |
| 109 | container: | 115 | container: |
| 110 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.image_version }} | 116 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.image_version }} |
| @@ -18,12 +18,12 @@ on: | |||
| 18 | keyword: '^(?:\/)?compile*' | 18 | keyword: '^(?:\/)?compile*' |
| 19 | 19 | ||
| 20 | env: | 20 | env: |
| 21 | - org_name: "cann" | 21 | + org_name: "${{ vars.ORG_NAME }}" |
| 22 | - repo_name: "ops-nn" | 22 | + repo_name: ${{atomgit.event.repository.name}} |
| 23 | MERGE_ID: ${{atomgit.event.pull_request.number}} | 23 | MERGE_ID: ${{atomgit.event.pull_request.number}} |
| 24 | + obs_path: "${{ env.org_name }}/${{ env.repo_name }}/ci/package/${{ env.MERGE_ID }}" | ||
| 24 | TARGET_BRANCH: ${{atomgit.ref_name}} | 25 | TARGET_BRANCH: ${{atomgit.ref_name}} |
| 25 | SOURCE_BRANCH: ${{atomgit.head_ref}} | 26 | SOURCE_BRANCH: ${{atomgit.head_ref}} |
| 26 | - obs_path: "${{ vars.OBS_PATH }}/${{ env.MERGE_ID }}" | ||
| 27 | obs_smoke_path: "${{ env.obs_path }}/presmoke/2" | 27 | obs_smoke_path: "${{ env.obs_path }}/presmoke/2" |
| 28 | online: ${{ vars.APPLY_LABEL }} | 28 | online: ${{ vars.APPLY_LABEL }} |
| 29 | 29 | ||
| @@ -46,7 +46,7 @@ stages: | |||
| 46 | run: | | 46 | run: | |
| 47 | echo "image: ${{ steps.revise_image.outputs.Compile_Ascend_X86 }}" | 47 | echo "image: ${{ steps.revise_image.outputs.Compile_Ascend_X86 }}" |
| 48 | if: "${{ default() }}" | 48 | if: "${{ default() }}" |
| 49 | - runs-on: ["codearts-hosted", "ubuntu-latest", "x64", "small"] | 49 | + runs-on: ["self-hosted", "arch=x64", "spec=small"] |
| 50 | JOB_pr: | 50 | JOB_pr: |
| 51 | name: Test_get-pr | 51 | name: Test_get-pr |
| 52 | steps: | 52 | steps: |
| @@ -123,7 +123,7 @@ stages: | |||
| 123 | - name: associate-pr-comment | 123 | - name: associate-pr-comment |
| 124 | uses: associate-pr-comment | 124 | uses: associate-pr-comment |
| 125 | if: env.online == 'true' | 125 | if: env.online == 'true' |
| 126 | - runs-on: [dedicate-hosted, x64, small] | 126 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 127 | container: | 127 | container: |
| 128 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/ubuntu20.04.05_x86:k8s_v1.1006 | 128 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/ubuntu20.04.05_x86:k8s_v1.1006 |
| 129 | pre: | 129 | pre: |
| @@ -337,15 +337,6 @@ stages: | |||
| 337 | uses: checkout | 337 | uses: checkout |
| 338 | with: | 338 | with: |
| 339 | token: ${{secrets.GIT_TOKEN}} | 339 | token: ${{secrets.GIT_TOKEN}} |
| 340 | - path: "./runner" | ||
| 341 | - - | ||
| 342 | - name: Checkout gitcode | ||
| 343 | - identifier: process_checkout_gitcode | ||
| 344 | - uses: checkout | ||
| 345 | - with: | ||
| 346 | - repository: "https://gitcode.com/cann/.gitcode.git" | ||
| 347 | - ref: master | ||
| 348 | - path: "./runner/ci" | ||
| 349 | - | 340 | - |
| 350 | name: download | 341 | name: download |
| 351 | uses: obs-download | 342 | uses: obs-download |
| @@ -360,37 +351,13 @@ stages: | |||
| 360 | ${{ env.obs_path }}/update_file_detail.txt | 351 | ${{ env.obs_path }}/update_file_detail.txt |
| 361 | ${{ env.obs_path }}/pre_smoke.sh | 352 | ${{ env.obs_path }}/pre_smoke.sh |
| 362 | path: ${{ steps.process_checkout.outputs.path }} | 353 | path: ${{ steps.process_checkout.outputs.path }} |
| 363 | - - | ||
| 364 | - name: tar businesscode | ||
| 365 | - run: | | ||
| 366 | - echo "############${{ steps.process_checkout.outputs.path }}#################" | ||
| 367 | - echo "#####image: swr.cn-south-1.myhuaweicloud.com/pre_smoke/${{ jobs.JOB_image.outputs.PreSmoke_A900 }}#####" | ||
| 368 | - cd ${{ steps.process_checkout.outputs.path }} | ||
| 369 | - tar -zcf ../smoke_data.tar.gz . | ||
| 370 | - mv ../smoke_data.tar.gz ./ | ||
| 371 | - - | ||
| 372 | - name: upload | ||
| 373 | - identifier: process_upload | ||
| 374 | - uses: obs-upload | ||
| 375 | - with: | ||
| 376 | - endpoint: "https://obs.cn-north-4.myhuaweicloud.com" | ||
| 377 | - bucket: "ascend-ci" | ||
| 378 | - access-key: ${{secrets.AK}} | ||
| 379 | - secret-key: ${{secrets.SK}} | ||
| 380 | - artifact-path: | | ||
| 381 | - ${{ steps.process_checkout.outputs.path }}/smoke_data.tar.gz | ||
| 382 | - object-prefix: ${{ env.obs_smoke_path }}/ | ||
| 383 | - | 354 | - |
| 384 | name: smoke executor | 355 | name: smoke executor |
| 385 | timeout-minutes: 30 | 356 | timeout-minutes: 30 |
| 386 | - uses: manifest-management-plugin | 357 | + run: | |
| 387 | - with: | ||
| 388 | - action: DEPLOY | ||
| 389 | - repo: ${{ steps.process_checkout.outputs.path }} | ||
| 390 | - file_path: ${{ steps.process_checkout.outputs.path }}/ci/smoke-conf/smoke-A2.yaml | ||
| 391 | - manifest_image: swr.cn-south-1.myhuaweicloud.com/pre_smoke/${{ jobs.JOB_image.outputs.PreSmoke_A900 }} | ||
| 392 | - custom_shell_script: |- | ||
| 393 | set -e | 358 | set -e |
| 359 | + # set env | ||
| 360 | + export WORKSPACE=${{ steps.process_checkout.outputs.path }} | ||
| 394 | export single_tar_url=${{jobs.JOB_compile_single.outputs.arm_run_url}} | 361 | export single_tar_url=${{jobs.JOB_compile_single.outputs.arm_run_url}} |
| 395 | export experimental_run_url=${{jobs.JOB_Compile_Ascend_experimental_ubuntu24.outputs.arm_run_url}} | 362 | export experimental_run_url=${{jobs.JOB_Compile_Ascend_experimental_ubuntu24.outputs.arm_run_url}} |
| 396 | export fatrelu_run_url=${{jobs.JOB_Pre_compile.outputs.arm_run_url}} | 363 | export fatrelu_run_url=${{jobs.JOB_Pre_compile.outputs.arm_run_url}} |
| @@ -398,21 +365,20 @@ stages: | |||
| 398 | export pr_id=${{ env.MERGE_ID }} | 365 | export pr_id=${{ env.MERGE_ID }} |
| 399 | export AK=${{secrets.AK}} | 366 | export AK=${{secrets.AK}} |
| 400 | export SK=${{secrets.SK}} | 367 | export SK=${{secrets.SK}} |
| 401 | - mkdir -p /home/taskspace && cd /home/taskspace | 368 | + bash ${{ steps.process_checkout.outputs.path }}/pre_smoke.sh |
| 402 | - wget -nv ${{ steps.process_upload.outputs.primary-url }} | 369 | + - name: upload |
| 403 | - tar -zxf $(basename "${{ steps.process_upload.outputs.primary-url }}") | 370 | + uses: obs-upload |
| 404 | - bash /home/taskspace/pre_smoke.sh | ||
| 405 | - - | ||
| 406 | - name: smoke resource clean | ||
| 407 | - uses: manifest-management-plugin | ||
| 408 | - if: ${{ always() }} | ||
| 409 | with: | 371 | with: |
| 410 | - action: CRUSH | 372 | + endpoint: "https://obs.cn-north-4.myhuaweicloud.com" |
| 411 | - repo: ${{ steps.process_checkout.outputs.path }} | 373 | + bucket: "ascend-ci" |
| 412 | - file_path: ${{ steps.process_checkout.outputs.path }}/ci/smoke-conf/smoke-A2.yaml | 374 | + access-key: ${{ secrets.AK }} |
| 413 | - | 375 | + secret-key: ${{ secrets.SK }} |
| 414 | - if: env.TARGET_BRANCH == 'master' | 376 | + artifact-path: "${{ steps.process_checkout.outputs.path }}/slog.tar.gz" |
| 415 | - runs-on: ['self-hosted','arch=arm','smoke=204'] | 377 | + object-prefix: ${obs_smoke_path}/plog/ |
| 378 | + if: "${{ default() }}" | ||
| 379 | + runs-on: ['self-hosted','npu=1','smoke=204'] | ||
| 380 | + container: | ||
| 381 | + image: swr.cn-south-1.myhuaweicloud.com/pre_smoke/${{ jobs.JOB_image.outputs.PreSmoke_A900 }} | ||
| 416 | pre: | 382 | pre: |
| 417 | - type: auto | 383 | - type: auto |
| 418 | fail-fast: true | 384 | fail-fast: true |
| @@ -0,0 +1,93 @@ | |||
| 1 | +name: st_test_950_action | ||
| 2 | + | ||
| 3 | +on: | ||
| 4 | + pr_comment: | ||
| 5 | + types: [created] | ||
| 6 | + keyword: '^(?:\/)?st_950\b' | ||
| 7 | + pull_request_comment: | ||
| 8 | + types: [created] | ||
| 9 | + branches: ['*'] | ||
| 10 | + comments: ['^(?:\/)?st_950\b'] | ||
| 11 | + workflow_call: | ||
| 12 | + inputs: | ||
| 13 | + x86_run_key: | ||
| 14 | + type: string | ||
| 15 | + required: false | ||
| 16 | + | ||
| 17 | +env: | ||
| 18 | + org_name: ${{ vars.ORG_NAME }} | ||
| 19 | + repo_name: "ops-nn" | ||
| 20 | + MERGE_ID: ${{atomgit.event.pull_request.number}} | ||
| 21 | + TARGET_BRANCH: ${{atomgit.ref_name}} | ||
| 22 | + SOURCE_BRANCH: ${{atomgit.head_ref}} | ||
| 23 | + obs_path: "${{ env.org_name }}/${{ env.repo_name }}/ci/package/${{ env.MERGE_ID }}" | ||
| 24 | + run_package_name: "cann-ops-nn-custom_linux-x86_64_950.run" | ||
| 25 | + | ||
| 26 | +jobs: | ||
| 27 | + JOB_st_test_950: | ||
| 28 | + name: ST_test_950 | ||
| 29 | + steps: | ||
| 30 | + - | ||
| 31 | + name: Checkout | ||
| 32 | + identifier: process_checkout | ||
| 33 | + uses: checkout | ||
| 34 | + with: | ||
| 35 | + ref: ${{ atomgit.event.pull_request.merge_commit_sha || atomgit.sha }} | ||
| 36 | + token: ${{secrets.GIT_TOKEN}} | ||
| 37 | + - | ||
| 38 | + name: download_pr_filelist | ||
| 39 | + uses: obs-download | ||
| 40 | + with: | ||
| 41 | + endpoint: "https://obs.cn-north-4.myhuaweicloud.com" | ||
| 42 | + bucket: "ascend-ci" | ||
| 43 | + access-key: ${{ secrets.AK }} | ||
| 44 | + secret-key: ${{ secrets.SK }} | ||
| 45 | + key: | | ||
| 46 | + ${{ env.obs_path }}/pr_filelist.txt | ||
| 47 | + path: ${{ steps.process_checkout.outputs.path }} | ||
| 48 | + - | ||
| 49 | + name: download_compiled_package | ||
| 50 | + uses: obs-download | ||
| 51 | + with: | ||
| 52 | + endpoint: "https://obs.cn-north-4.myhuaweicloud.com" | ||
| 53 | + bucket: "ascend-ci" | ||
| 54 | + access-key: ${{ secrets.AK }} | ||
| 55 | + secret-key: ${{ secrets.SK }} | ||
| 56 | + key: | | ||
| 57 | + ${{ env.obs_path }}/${{ env.run_package_name }} | ||
| 58 | + path: ${{ steps.process_checkout.outputs.path }} | ||
| 59 | + - | ||
| 60 | + name: install_run_package | ||
| 61 | + run: | | ||
| 62 | + cd ${{ steps.process_checkout.outputs.path }} | ||
| 63 | + if [[ -f "${{ env.run_package_name }}" ]]; then | ||
| 64 | + echo "Installing compiled package: ${{ env.run_package_name }}" | ||
| 65 | + chmod +x "${{ env.run_package_name }}" | ||
| 66 | + source /usr/local/Ascend/cann/bin/setenv.bash 2>/dev/null || true | ||
| 67 | + echo 'y' | bash "${{ env.run_package_name }}" --quiet | ||
| 68 | + else | ||
| 69 | + echo "ERROR: compiled package not found: ${{ env.run_package_name }}" | ||
| 70 | + exit 1 | ||
| 71 | + fi | ||
| 72 | + - | ||
| 73 | + name: run_st_test | ||
| 74 | + identifier: st_test | ||
| 75 | + run: | | ||
| 76 | + export WORKSPACE=${{ steps.process_checkout.outputs.path }} | ||
| 77 | + cd ${{ steps.process_checkout.outputs.path }} | ||
| 78 | + source /usr/local/Ascend/cann/bin/setenv.bash 2>/dev/null || true | ||
| 79 | + export CI_ONLINE_ST=1 | ||
| 80 | + bash scripts/ci/ops_st_test.sh --pr_filelist=./pr_filelist.txt --soc_version=ascend950 | ||
| 81 | + - | ||
| 82 | + name: upload_results | ||
| 83 | + uses: obs-upload | ||
| 84 | + with: | ||
| 85 | + endpoint: "https://obs.cn-north-4.myhuaweicloud.com" | ||
| 86 | + bucket: "ascend-ci" | ||
| 87 | + access-key: ${{secrets.AK}} | ||
| 88 | + secret-key: ${{secrets.SK}} | ||
| 89 | + artifact-path: | | ||
| 90 | + ${{ steps.process_checkout.outputs.path }}/st/log/**/* | ||
| 91 | + object-prefix: ${{ env.obs_path }}/st_results/ | ||
| 92 | + if: "${{ default() }}" | ||
| 93 | + runs-on: ['self-hosted', 'os=ubuntu', 'evb=a5', 'repo=nn'] | ||
| @@ -61,6 +61,6 @@ jobs: | |||
| 61 | ${{ steps.process_checkout.outputs.path }}/StaticCheck_*.json | 61 | ${{ steps.process_checkout.outputs.path }}/StaticCheck_*.json |
| 62 | object-prefix: ${{ env.obs_path }}/ | 62 | object-prefix: ${{ env.obs_path }}/ |
| 63 | if: "${{ default() }}" | 63 | if: "${{ default() }}" |
| 64 | - runs-on: [dedicate-hosted, x64, small] | 64 | + runs-on: [self-hosted, arch=x64, spec=small] |
| 65 | container: | 65 | container: |
| 66 | image: swr.cn-north-4.myhuaweicloud.com/static_check/${{ inputs.image_version }} | 66 | image: swr.cn-north-4.myhuaweicloud.com/static_check/${{ inputs.image_version }} |
| @@ -69,6 +69,6 @@ jobs: | |||
| 69 | ${{ steps.process_checkout.outputs.path }}/${{ inputs.ut_package }} | 69 | ${{ steps.process_checkout.outputs.path }}/${{ inputs.ut_package }} |
| 70 | object-prefix: ${{ env.obs_path }}/ | 70 | object-prefix: ${{ env.obs_path }}/ |
| 71 | if: "${{ default() }}" | 71 | if: "${{ default() }}" |
| 72 | - runs-on: [dedicate-hosted, x64, xlarge] | 72 | + runs-on: [self-hosted, arch=x64, spec=xlarge] |
| 73 | container: | 73 | container: |
| 74 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.image_version }} | 74 | image: swr.cn-north-4.myhuaweicloud.com/ci_cann/${{ inputs.image_version }} |
| @@ -123,6 +123,7 @@ if(DOWNLOAD_OPS_TEST_KIT) | |||
| 123 | include(cmake/third_party/ops_test_kit.cmake) | 123 | include(cmake/third_party/ops_test_kit.cmake) |
| 124 | endif() | 124 | endif() |
| 125 | include(cmake/dependencies.cmake) | 125 | include(cmake/dependencies.cmake) |
| 126 | +init_cann_project() | ||
| 126 | include(cmake/third_party/ops-tensor.cmake) | 127 | include(cmake/third_party/ops-tensor.cmake) |
| 127 | add_cann_third_party(json) | 128 | add_cann_third_party(json) |
| 128 | add_cann_third_party(abseil-cpp) | 129 | add_cann_third_party(abseil-cpp) |
| @@ -139,7 +140,6 @@ if(ENABLE_CUSTOM AND ENABLE_ASC_BUILD) | |||
| 139 | include(cmake/custom_kernel.cmake) | 140 | include(cmake/custom_kernel.cmake) |
| 140 | endif() | 141 | endif() |
| 141 | 142 | ||
| 142 | -init_cann_project() | ||
| 143 | if(BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG) | 143 | if(BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG) |
| 144 | check_cann_pkg_build_deps("ops-nn") | 144 | check_cann_pkg_build_deps("ops-nn") |
| 145 | endif() | 145 | endif() |
| @@ -9,9 +9,13 @@ | |||
| 9 | # ----------------------------------------------------------------------------------------------------------- | 9 | # ----------------------------------------------------------------------------------------------------------- |
| 10 | 10 | ||
| 11 | __all__ = [ | 11 | __all__ = [ |
| 12 | + "situ_glu", | ||
| 13 | + "situ_glu_grad", | ||
| 12 | "swiglu_group", | 14 | "swiglu_group", |
| 13 | "swiglu_group_quant", | 15 | "swiglu_group_quant", |
| 14 | ] | 16 | ] |
| 15 | 17 | ||
| 18 | +from .situ_glu import situ_glu | ||
| 19 | +from .situ_glu_grad import situ_glu_grad | ||
| 16 | from .swiglu_group import swiglu_group | 20 | from .swiglu_group import swiglu_group |
| 17 | from .swiglu_group_quant import swiglu_group_quant | 21 | from .swiglu_group_quant import swiglu_group_quant |
| @@ -1,44 +1,44 @@ | |||
| 1 | -/** | 1 | +/** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | + * Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 3 | - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 4 | - * CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | - * Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. |
| 6 | - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 7 | - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 8 | - * See LICENSE in the root of the software repository for the full text of the License. | 8 | + * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | - */ | 9 | + */ |
| 10 | - | 10 | + |
| 11 | -#include "onnx_common.h" | 11 | +#include "onnx_common.h" |
| 12 | - | 12 | + |
| 13 | -namespace domi { | 13 | +namespace domi { |
| 14 | -using NodeProto = ge::onnx::NodeProto; | 14 | +using NodeProto = ge::onnx::NodeProto; |
| 15 | -static Status ParseParamsCelu(const Message* op_src, ge::Operator& op_dest) | 15 | +static Status ParseParamsCelu(const Message* op_src, ge::Operator& op_dest) |
| 16 | -{ | 16 | +{ |
| 17 | - const NodeProto* node = reinterpret_cast<const NodeProto*>(op_src); | 17 | + const NodeProto* node = reinterpret_cast<const NodeProto*>(op_src); |
| 18 | - if (node == nullptr) { | 18 | + if (node == nullptr) { |
| 19 | - OP_LOGE(GetOpName(op_dest).c_str(), "Dynamic cast op_src to NodeProto failed."); | 19 | + OP_LOGE(GetOpName(op_dest).c_str(), "Dynamic cast op_src to NodeProto failed."); |
| 20 | - return FAILED; | 20 | + return FAILED; |
| 21 | - } | 21 | + } |
| 22 | - float alpha_value = 1.0; | 22 | + float alpha_value = 1.0; |
| 23 | - op_dest.SetAttr("alpha", alpha_value); | 23 | + op_dest.SetAttr("alpha", alpha_value); |
| 24 | - for (const auto& attr : node->attribute()) { | 24 | + for (const auto& attr : node->attribute()) { |
| 25 | - if (attr.name() == "alpha" && attr.type() == ge::onnx::AttributeProto::FLOAT) { | 25 | + if (attr.name() == "alpha" && attr.type() == ge::onnx::AttributeProto::FLOAT) { |
| 26 | - alpha_value = attr.f(); | 26 | + alpha_value = attr.f(); |
| 27 | - op_dest.SetAttr("alpha1", alpha_value); | 27 | + op_dest.SetAttr("alpha1", alpha_value); |
| 28 | - op_dest.SetAttr("alpha2", alpha_value); | 28 | + op_dest.SetAttr("alpha2", alpha_value); |
| 29 | - } | 29 | + } |
| 30 | - } | 30 | + } |
| 31 | - return SUCCESS; | 31 | + return SUCCESS; |
| 32 | -} | 32 | +} |
| 33 | -// register Celu op info to GE | 33 | +// register Celu op info to GE |
| 34 | -REGISTER_CUSTOM_OP("Celu") | 34 | +REGISTER_CUSTOM_OP("Celu") |
| 35 | - .FrameworkType(ONNX) | 35 | + .FrameworkType(ONNX) |
| 36 | - .OriginOpType({ge::AscendString("ai.onnx::8::Celu"), ge::AscendString("ai.onnx::9::Celu"), | 36 | + .OriginOpType({ge::AscendString("ai.onnx::8::Celu"), ge::AscendString("ai.onnx::9::Celu"), |
| 37 | - ge::AscendString("ai.onnx::10::Celu"), ge::AscendString("ai.onnx::11::Celu"), | 37 | + ge::AscendString("ai.onnx::10::Celu"), ge::AscendString("ai.onnx::11::Celu"), |
| 38 | - ge::AscendString("ai.onnx::12::Celu"), ge::AscendString("ai.onnx::13::Celu"), | 38 | + ge::AscendString("ai.onnx::12::Celu"), ge::AscendString("ai.onnx::13::Celu"), |
| 39 | - ge::AscendString("ai.onnx::14::Celu"), ge::AscendString("ai.onnx::15::Celu"), | 39 | + ge::AscendString("ai.onnx::14::Celu"), ge::AscendString("ai.onnx::15::Celu"), |
| 40 | - ge::AscendString("ai.onnx::16::Celu"), ge::AscendString("ai.onnx::17::Celu"), | 40 | + ge::AscendString("ai.onnx::16::Celu"), ge::AscendString("ai.onnx::17::Celu"), |
| 41 | - ge::AscendString("ai.onnx::18::Celu")}) | 41 | + ge::AscendString("ai.onnx::18::Celu")}) |
| 42 | - .ParseParamsFn(ParseParamsCelu) | 42 | + .ParseParamsFn(ParseParamsCelu) |
| 43 | - .ImplyType(ImplyType::TVM); | 43 | + .ImplyType(ImplyType::TVM); |
| 44 | -} // namespace domi | 44 | +} // namespace domi |
| @@ -60,18 +60,18 @@ __aicore__ inline void ReduceAllVf(LocalTensor<int64_t>& reduceSumUb, LocalTenso | |||
| 60 | AscendC::MicroAPI::MaskReg mask = AscendC::MicroAPI::CreateMask<int64_t, MicroAPI::MaskPattern::ALL>(); | 60 | AscendC::MicroAPI::MaskReg mask = AscendC::MicroAPI::CreateMask<int64_t, MicroAPI::MaskPattern::ALL>(); |
| 61 | for (uint16_t i = 0; i < times; i++) { | 61 | for (uint16_t i = 0; i < times; i++) { |
| 62 | AscendC::MicroAPI::AddrReg srcIdxOffset = AscendC::MicroAPI::CreateAddrReg<int64_t>(i, vfTidx); | 62 | AscendC::MicroAPI::AddrReg srcIdxOffset = AscendC::MicroAPI::CreateAddrReg<int64_t>(i, vfTidx); |
| 63 | - AscendC::MicroAPI::DataCopy(srcReg, srcAddr, srcIdxOffset); | 63 | + AscendC::MicroAPI::LoadAlign(srcReg, srcAddr, srcIdxOffset); |
| 64 | AscendC::MicroAPI::Add(addReg, addReg, srcReg, mask); | 64 | AscendC::MicroAPI::Add(addReg, addReg, srcReg, mask); |
| 65 | } | 65 | } |
| 66 | - AscendC::MicroAPI::ReduceSum(reduceSumReg, addReg, mask); | 66 | + AscendC::MicroAPI::Reduce<ReduceType::SUM>(reduceSumReg, addReg, mask); |
| 67 | for (uint16_t j = 0; j < tailTimes; j++) { | 67 | for (uint16_t j = 0; j < tailTimes; j++) { |
| 68 | AscendC::MicroAPI::MaskReg maskT = AscendC::MicroAPI::UpdateMask<int64_t>(tailNum); | 68 | AscendC::MicroAPI::MaskReg maskT = AscendC::MicroAPI::UpdateMask<int64_t>(tailNum); |
| 69 | - AscendC::MicroAPI::DataCopy(srcReg, srcAddr1); | 69 | + AscendC::MicroAPI::LoadAlign(srcReg, srcAddr1); |
| 70 | - AscendC::MicroAPI::ReduceSum(reduceSumTReg, srcReg, maskT); | 70 | + AscendC::MicroAPI::Reduce<ReduceType::SUM>(reduceSumTReg, srcReg, maskT); |
| 71 | AscendC::MicroAPI::Add(reduceSumReg, reduceSumTReg, reduceSumReg, maskT); | 71 | AscendC::MicroAPI::Add(reduceSumReg, reduceSumTReg, reduceSumReg, maskT); |
| 72 | } | 72 | } |
| 73 | AscendC::MicroAPI::MaskReg maskOne = AscendC::MicroAPI::CreateMask<int64_t, MicroAPI::MaskPattern::VL1>(); | 73 | AscendC::MicroAPI::MaskReg maskOne = AscendC::MicroAPI::CreateMask<int64_t, MicroAPI::MaskPattern::VL1>(); |
| 74 | - AscendC::MicroAPI::DataCopy(dstAddr, reduceSumReg, maskOne); | 74 | + AscendC::MicroAPI::StoreAlign(dstAddr, reduceSumReg, maskOne); |
| 75 | } | 75 | } |
| 76 | } | 76 | } |
| 77 | 77 | ||
| @@ -85,11 +85,10 @@ public: | |||
| 85 | 85 | ||
| 86 | private: | 86 | private: |
| 87 | __aicore__ inline void ComputeTiling(); | 87 | __aicore__ inline void ComputeTiling(); |
| 88 | - __aicore__ inline void UbDataCopy(__local_mem__ T* inAddr, __local_mem__ T* outAddr, int64_t onceNum); | 88 | + __aicore__ inline void UbStoreAlign(__ubuf__ T* inAddr, __ubuf__ T* outAddr, int64_t onceNum); |
| 89 | __aicore__ inline void CopyIn(int64_t gmOffset, int64_t count, int64_t blockLen); | 89 | __aicore__ inline void CopyIn(int64_t gmOffset, int64_t count, int64_t blockLen); |
| 90 | - __aicore__ inline void ComputeVfSwiglu(__local_mem__ T* x1UbAddr, __local_mem__ T* x2UbAddr, | 90 | + __aicore__ inline void ComputeVfSwiglu(__ubuf__ T* x1UbAddr, __ubuf__ T* x2UbAddr, __ubuf__ T* swigluUbAddr, |
| 91 | - __local_mem__ T* swigluUbAddr, int64_t dim0OnceSize, int64_t dim1OnceSize, | 91 | + int64_t dim0OnceSize, int64_t dim1OnceSize, int64_t alignDim1In); |
| 92 | - int64_t alignDim1In); | ||
| 93 | __aicore__ inline void CopyOut(int64_t gmOffset, int64_t count, int64_t blockLen); | 92 | __aicore__ inline void CopyOut(int64_t gmOffset, int64_t count, int64_t blockLen); |
| 94 | 93 | ||
| 95 | private: | 94 | private: |
| @@ -238,7 +237,7 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::Process() | |||
| 238 | inQueX_.FreeTensor(inputUb); | 237 | inQueX_.FreeTensor(inputUb); |
| 239 | LocalTensor<T> outUb = outQueY_.AllocTensor<T>(); | 238 | LocalTensor<T> outUb = outQueY_.AllocTensor<T>(); |
| 240 | auto outUbAddr = (__ubuf__ T*)outUb.GetPhyAddr(); | 239 | auto outUbAddr = (__ubuf__ T*)outUb.GetPhyAddr(); |
| 241 | - UbDataCopy(swigluAddr, outUbAddr, onceNum); | 240 | + UbStoreAlign(swigluAddr, outUbAddr, onceNum); |
| 242 | outQueY_.EnQue(outUb); | 241 | outQueY_.EnQue(outUb); |
| 243 | CopyOut(outGmOffset, 1, onceNum); | 242 | CopyOut(outGmOffset, 1, onceNum); |
| 244 | } | 243 | } |
| @@ -261,7 +260,7 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::Process() | |||
| 261 | inQueX_.FreeTensor(inputUb); | 260 | inQueX_.FreeTensor(inputUb); |
| 262 | LocalTensor<T> outUb = outQueY_.AllocTensor<T>(); | 261 | LocalTensor<T> outUb = outQueY_.AllocTensor<T>(); |
| 263 | auto outUbAddr = (__ubuf__ T*)outUb.GetPhyAddr(); | 262 | auto outUbAddr = (__ubuf__ T*)outUb.GetPhyAddr(); |
| 264 | - UbDataCopy(swigluAddr, outUbAddr, onceBNum * alignDim1In); | 263 | + UbStoreAlign(swigluAddr, outUbAddr, onceBNum * alignDim1In); |
| 265 | outQueY_.EnQue(outUb); | 264 | outQueY_.EnQue(outUb); |
| 266 | int64_t outGmOffset = (bCoreOffset + bi * bUbFactor_) * dimH_ + hCoreOffset + hi * hUbFactor_; | 265 | int64_t outGmOffset = (bCoreOffset + bi * bUbFactor_) * dimH_ + hCoreOffset + hi * hUbFactor_; |
| 267 | CopyOut(outGmOffset, onceBNum, onceHNum); | 266 | CopyOut(outGmOffset, onceBNum, onceHNum); |
| @@ -295,9 +294,9 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::CopyIn(in | |||
| 295 | } | 294 | } |
| 296 | 295 | ||
| 297 | template <typename T, bool isInterleaved, bool isGroup> | 296 | template <typename T, bool isInterleaved, bool isGroup> |
| 298 | -__aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::UbDataCopy(__local_mem__ T* inAddr, | 297 | +__aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::UbStoreAlign(__ubuf__ T* inAddr, |
| 299 | - __local_mem__ T* outAddr, | 298 | + __ubuf__ T* outAddr, |
| 300 | - int64_t onceNum) | 299 | + int64_t onceNum) |
| 301 | { | 300 | { |
| 302 | uint32_t size = onceNum; | 301 | uint32_t size = onceNum; |
| 303 | uint32_t vfLen = vfLenT_; | 302 | uint32_t vfLen = vfLenT_; |
| @@ -309,16 +308,16 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::UbDataCop | |||
| 309 | for (uint16_t i = 0; i < times; i++) { | 308 | for (uint16_t i = 0; i < times; i++) { |
| 310 | mask = MicroAPI::UpdateMask<T>(size); | 309 | mask = MicroAPI::UpdateMask<T>(size); |
| 311 | AscendC::MicroAPI::AddrReg srcIdxOffset = AscendC::MicroAPI::CreateAddrReg<T>(i, vfLen); | 310 | AscendC::MicroAPI::AddrReg srcIdxOffset = AscendC::MicroAPI::CreateAddrReg<T>(i, vfLen); |
| 312 | - AscendC::MicroAPI::DataCopy(xReg, inAddr, srcIdxOffset); | 311 | + AscendC::MicroAPI::LoadAlign(xReg, inAddr, srcIdxOffset); |
| 313 | - AscendC::MicroAPI::DataCopy(outAddr, xReg, srcIdxOffset, mask); | 312 | + AscendC::MicroAPI::StoreAlign(outAddr, xReg, srcIdxOffset, mask); |
| 314 | } | 313 | } |
| 315 | } | 314 | } |
| 316 | } | 315 | } |
| 317 | 316 | ||
| 318 | template <typename T, bool isInterleaved, bool isGroup> | 317 | template <typename T, bool isInterleaved, bool isGroup> |
| 319 | __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVfSwiglu( | 318 | __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVfSwiglu( |
| 320 | - __local_mem__ T* x1UbAddr, __local_mem__ T* x2UbAddr, __local_mem__ T* swigluUbAddr, int64_t dim0OnceSize, | 319 | + __ubuf__ T* x1UbAddr, __ubuf__ T* x2UbAddr, __ubuf__ T* swigluUbAddr, int64_t dim0OnceSize, int64_t dim1OnceSize, |
| 321 | - int64_t dim1OnceSize, int64_t alignDim1In) | 320 | + int64_t alignDim1In) |
| 322 | { | 321 | { |
| 323 | float clampLimit = limit_; | 322 | float clampLimit = limit_; |
| 324 | float negClampLimit = -limit_; | 323 | float negClampLimit = -limit_; |
| @@ -344,9 +343,9 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVf | |||
| 344 | if (tail > 0) { | 343 | if (tail > 0) { |
| 345 | tailTimes = 1; | 344 | tailTimes = 1; |
| 346 | } | 345 | } |
| 347 | - __local_mem__ T* x1UbAddrT = x1UbAddr + dim1VfTimes * vfLen; | 346 | + __ubuf__ T* x1UbAddrT = x1UbAddr + dim1VfTimes * vfLen; |
| 348 | - __local_mem__ T* x2UbAddrT = x2UbAddr + dim1VfTimes * vfLen; | 347 | + __ubuf__ T* x2UbAddrT = x2UbAddr + dim1VfTimes * vfLen; |
| 349 | - __local_mem__ T* swigluUbAddrT = swigluUbAddr + dim1VfTimes * VF_LEN_FP32; | 348 | + __ubuf__ T* swigluUbAddrT = swigluUbAddr + dim1VfTimes * VF_LEN_FP32; |
| 350 | __VEC_SCOPE__ | 349 | __VEC_SCOPE__ |
| 351 | { | 350 | { |
| 352 | AscendC::MicroAPI::RegTensor<T> vregX1; | 351 | AscendC::MicroAPI::RegTensor<T> vregX1; |
| @@ -371,30 +370,30 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVf | |||
| 371 | dim0vfLoopIdx, alignDim1In, dim1vfLoopIdx, vfLen); | 370 | dim0vfLoopIdx, alignDim1In, dim1vfLoopIdx, vfLen); |
| 372 | if constexpr (isInterleaved) { | 371 | if constexpr (isInterleaved) { |
| 373 | if constexpr (sizeof(T) == sizeof(half)) { | 372 | if constexpr (sizeof(T) == sizeof(half)) { |
| 374 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddr, | 373 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddr, |
| 375 | - srcIdxOffset); | 374 | + srcIdxOffset); |
| 376 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddr, | 375 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddr, |
| 377 | - srcIdxOffset); | 376 | + srcIdxOffset); |
| 378 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1F, vregX1, mask); | 377 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1F, vregX1, mask); |
| 379 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2F, vregX2, mask); | 378 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2F, vregX2, mask); |
| 380 | } else { | 379 | } else { |
| 381 | // float | 380 | // float |
| 382 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX1F, x1UbAddr, srcIdxOffset); | 381 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX1F, x1UbAddr, srcIdxOffset); |
| 383 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX2F, x2UbAddr, srcIdxOffset); | 382 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX2F, x2UbAddr, srcIdxOffset); |
| 384 | } | 383 | } |
| 385 | AscendC::MicroAPI::DeInterleave(vregX1DeF, vregX2DeF, vregX1F, vregX2F); | 384 | AscendC::MicroAPI::DeInterleave(vregX1DeF, vregX2DeF, vregX1F, vregX2F); |
| 386 | } else { | 385 | } else { |
| 387 | if constexpr (sizeof(T) == sizeof(half)) { | 386 | if constexpr (sizeof(T) == sizeof(half)) { |
| 388 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddr, | 387 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddr, |
| 389 | - srcIdxOffset); | 388 | + srcIdxOffset); |
| 390 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddr, | 389 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddr, |
| 391 | - srcIdxOffset); | 390 | + srcIdxOffset); |
| 392 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1DeF, vregX1, mask); | 391 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1DeF, vregX1, mask); |
| 393 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2DeF, vregX2, mask); | 392 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2DeF, vregX2, mask); |
| 394 | } else { | 393 | } else { |
| 395 | // float | 394 | // float |
| 396 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX1DeF, x1UbAddr, srcIdxOffset); | 395 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX1DeF, x1UbAddr, srcIdxOffset); |
| 397 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX2DeF, x2UbAddr, srcIdxOffset); | 396 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX2DeF, x2UbAddr, srcIdxOffset); |
| 398 | } | 397 | } |
| 399 | } | 398 | } |
| 400 | AscendC::MicroAPI::Mins(minsReg, vregX1DeF, clampLimit, mask); | 399 | AscendC::MicroAPI::Mins(minsReg, vregX1DeF, clampLimit, mask); |
| @@ -412,9 +411,9 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVf | |||
| 412 | dim1vfLoopIdx, VF_LEN_FP32); | 411 | dim1vfLoopIdx, VF_LEN_FP32); |
| 413 | if constexpr (sizeof(T) == sizeof(half)) { | 412 | if constexpr (sizeof(T) == sizeof(half)) { |
| 414 | AscendC::MicroAPI::Cast<T, float, CAST_FP32_TO_FP16_BF16>(outTReg, outFReg, mask); | 413 | AscendC::MicroAPI::Cast<T, float, CAST_FP32_TO_FP16_BF16>(outTReg, outFReg, mask); |
| 415 | - DataCopy<T, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(swigluUbAddr, outTReg, outOffset, mask); | 414 | + StoreAlign<T, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(swigluUbAddr, outTReg, outOffset, mask); |
| 416 | } else { | 415 | } else { |
| 417 | - DataCopy(swigluUbAddr, (MicroAPI::RegTensor<T>&)outFReg, outOffset, mask); | 416 | + StoreAlign(swigluUbAddr, (MicroAPI::RegTensor<T>&)outFReg, outOffset, mask); |
| 418 | } | 417 | } |
| 419 | } | 418 | } |
| 420 | AscendC::MicroAPI::AddrReg srcIdxOffset1 = AscendC::MicroAPI::CreateAddrReg<T>(dim0vfLoopIdx, alignDim1In); | 419 | AscendC::MicroAPI::AddrReg srcIdxOffset1 = AscendC::MicroAPI::CreateAddrReg<T>(dim0vfLoopIdx, alignDim1In); |
| @@ -422,30 +421,30 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVf | |||
| 422 | for (uint16_t ti = 0; ti < tailTimes; ti++) { | 421 | for (uint16_t ti = 0; ti < tailTimes; ti++) { |
| 423 | if constexpr (isInterleaved) { | 422 | if constexpr (isInterleaved) { |
| 424 | if constexpr (sizeof(T) == sizeof(half)) { | 423 | if constexpr (sizeof(T) == sizeof(half)) { |
| 425 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddrT, | 424 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddrT, |
| 426 | - srcIdxOffset1); | 425 | + srcIdxOffset1); |
| 427 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddrT, | 426 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddrT, |
| 428 | - srcIdxOffset1); | 427 | + srcIdxOffset1); |
| 429 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1F, vregX1, mask); | 428 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1F, vregX1, mask); |
| 430 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2F, vregX2, mask); | 429 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2F, vregX2, mask); |
| 431 | } else { | 430 | } else { |
| 432 | // float | 431 | // float |
| 433 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX1F, x1UbAddrT, srcIdxOffset1); | 432 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX1F, x1UbAddrT, srcIdxOffset1); |
| 434 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX2F, x2UbAddrT, srcIdxOffset1); | 433 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX2F, x2UbAddrT, srcIdxOffset1); |
| 435 | } | 434 | } |
| 436 | AscendC::MicroAPI::DeInterleave(vregX1DeF, vregX2DeF, vregX1F, vregX2F); | 435 | AscendC::MicroAPI::DeInterleave(vregX1DeF, vregX2DeF, vregX1F, vregX2F); |
| 437 | } else { | 436 | } else { |
| 438 | if constexpr (sizeof(T) == sizeof(half)) { | 437 | if constexpr (sizeof(T) == sizeof(half)) { |
| 439 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddrT, | 438 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX1, x1UbAddrT, |
| 440 | - srcIdxOffset1); | 439 | + srcIdxOffset1); |
| 441 | - AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddrT, | 440 | + AscendC::MicroAPI::LoadAlign<T, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vregX2, x2UbAddrT, |
| 442 | - srcIdxOffset1); | 441 | + srcIdxOffset1); |
| 443 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1DeF, vregX1, mask); | 442 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX1DeF, vregX1, mask); |
| 444 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2DeF, vregX2, mask); | 443 | AscendC::MicroAPI::Cast<float, T, CAST_BF16_FP16_TO_FP32>(vregX2DeF, vregX2, mask); |
| 445 | } else { | 444 | } else { |
| 446 | // float | 445 | // float |
| 447 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX1DeF, x1UbAddrT, srcIdxOffset1); | 446 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX1DeF, x1UbAddrT, srcIdxOffset1); |
| 448 | - AscendC::MicroAPI::DataCopy((MicroAPI::RegTensor<T>&)vregX2DeF, x2UbAddrT, srcIdxOffset1); | 447 | + AscendC::MicroAPI::LoadAlign((MicroAPI::RegTensor<T>&)vregX2DeF, x2UbAddrT, srcIdxOffset1); |
| 449 | } | 448 | } |
| 450 | } | 449 | } |
| 451 | AscendC::MicroAPI::Mins(minsReg, vregX1DeF, clampLimit, maskT); | 450 | AscendC::MicroAPI::Mins(minsReg, vregX1DeF, clampLimit, maskT); |
| @@ -461,9 +460,10 @@ __aicore__ inline void ClippedSwigluKernel<T, isInterleaved, isGroup>::ComputeVf | |||
| 461 | AscendC::MicroAPI::Mul(outFReg, sigmoidReg, vregX2DeF, maskT); | 460 | AscendC::MicroAPI::Mul(outFReg, sigmoidReg, vregX2DeF, maskT); |
| 462 | if constexpr (sizeof(T) == sizeof(half)) { | 461 | if constexpr (sizeof(T) == sizeof(half)) { |
| 463 | AscendC::MicroAPI::Cast<T, float, CAST_FP32_TO_FP16_BF16>(outTReg, outFReg, maskT); | 462 | AscendC::MicroAPI::Cast<T, float, CAST_FP32_TO_FP16_BF16>(outTReg, outFReg, maskT); |
| 464 | - DataCopy<T, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(swigluUbAddrT, outTReg, outOffset1, maskT); | 463 | + StoreAlign<T, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(swigluUbAddrT, outTReg, outOffset1, |
| 464 | + maskT); | ||
| 465 | } else { | 465 | } else { |
| 466 | - DataCopy(swigluUbAddrT, (MicroAPI::RegTensor<T>&)outFReg, outOffset1, maskT); | 466 | + StoreAlign(swigluUbAddrT, (MicroAPI::RegTensor<T>&)outFReg, outOffset1, maskT); |
| 467 | } | 467 | } |
| 468 | } | 468 | } |
| 469 | } | 469 | } |
| @@ -2,10 +2,10 @@ | |||
| 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
| 3 | # ---------------------------------------------------------------------------- | 3 | # ---------------------------------------------------------------------------- |
| 4 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 4 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 5 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 6 | # CANN Open Software License Agreement Version 2.0 (the "License"). | 6 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 7 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 7 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | 8 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 9 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 9 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 10 | # See LICENSE in the root of the software repository for the full text of the License. | 10 | # See LICENSE in the root of the software repository for the full text of the License. |
| 11 | # ---------------------------------------------------------------------------- | 11 | # ---------------------------------------------------------------------------- |
| @@ -13,7 +13,8 @@ | |||
| 13 | import sys | 13 | import sys |
| 14 | import numpy as np | 14 | import numpy as np |
| 15 | import torch | 15 | import torch |
| 16 | -import tensorflow as tf | 16 | +from ml_dtypes import bfloat16 |
| 17 | + | ||
| 17 | 18 | ||
| 18 | def do_clippedSwiglu(x, group_index, dim, alpha, limit, bias, interleaved): | 19 | def do_clippedSwiglu(x, group_index, dim, alpha, limit, bias, interleaved): |
| 19 | shape = x.shape | 20 | shape = x.shape |
| @@ -25,7 +26,7 @@ def do_clippedSwiglu(x, group_index, dim, alpha, limit, bias, interleaved): | |||
| 25 | group = x.shape[0] | 26 | group = x.shape[0] |
| 26 | if group_index is not None: | 27 | if group_index is not None: |
| 27 | group = min(group_index.sum(), x.shape[0]) | 28 | group = min(group_index.sum(), x.shape[0]) |
| 28 | - | 29 | + |
| 29 | x_tensor = x[:group] | 30 | x_tensor = x[:group] |
| 30 | if interleaved: | 31 | if interleaved: |
| 31 | x_glu = x_tensor[..., ::2] | 32 | x_glu = x_tensor[..., ::2] |
| @@ -48,27 +49,27 @@ def do_clippedSwiglu(x, group_index, dim, alpha, limit, bias, interleaved): | |||
| 48 | 49 | ||
| 49 | return res | 50 | return res |
| 50 | 51 | ||
| 52 | + | ||
| 51 | params_info = { | 53 | params_info = { |
| 52 | "test_case_bf16_shortH": {"x_shape": [3200, 5760], "x_dtype": torch.bfloat16}, | 54 | "test_case_bf16_shortH": {"x_shape": [3200, 5760], "x_dtype": torch.bfloat16}, |
| 53 | "test_case_fp16_shortH": {"x_shape": [3200, 5760], "x_dtype": torch.float16}, | 55 | "test_case_fp16_shortH": {"x_shape": [3200, 5760], "x_dtype": torch.float16}, |
| 54 | "test_case_fp32_shortH": {"x_shape": [3200, 5760], "x_dtype": torch.float32}, | 56 | "test_case_fp32_shortH": {"x_shape": [3200, 5760], "x_dtype": torch.float32}, |
| 55 | "test_case_bf16_longH": {"x_shape": [3200, 23040], "x_dtype": torch.bfloat16}, | 57 | "test_case_bf16_longH": {"x_shape": [3200, 23040], "x_dtype": torch.bfloat16}, |
| 56 | "test_case_fp16_longH": {"x_shape": [3200, 23040], "x_dtype": torch.float16}, | 58 | "test_case_fp16_longH": {"x_shape": [3200, 23040], "x_dtype": torch.float16}, |
| 57 | - "test_case_fp32_longH": {"x_shape": [3200, 23040], "x_dtype": torch.float32} | 59 | + "test_case_fp32_longH": {"x_shape": [3200, 23040], "x_dtype": torch.float32}, |
| 58 | - } | 60 | +} |
| 59 | 61 | ||
| 60 | 62 | ||
| 61 | def gen_golden_data_simple(params_list): | 63 | def gen_golden_data_simple(params_list): |
| 62 | # np.random.seed(1) | 64 | # np.random.seed(1) |
| 63 | x_shape = params_list["x_shape"] | 65 | x_shape = params_list["x_shape"] |
| 64 | - x_dtype = params_list["x_dtype"] | ||
| 65 | data_x = torch.randn(x_shape, dtype=torch.float32) | 66 | data_x = torch.randn(x_shape, dtype=torch.float32) |
| 66 | group_index = torch.randint(low=1, high=11, size=(10,)) | 67 | group_index = torch.randint(low=1, high=11, size=(10,)) |
| 67 | - out_list = do_clippedSwiglu(data_x, group_index, -1, 1.702, 7.0, 1.0, True) | 68 | + do_clippedSwiglu(data_x, group_index, -1, 1.702, 7.0, 1.0, True) |
| 68 | - | 69 | + |
| 69 | data_x = data_x.cpu().numpy() | 70 | data_x = data_x.cpu().numpy() |
| 70 | if params_list["x_dtype"] == torch.bfloat16: | 71 | if params_list["x_dtype"] == torch.bfloat16: |
| 71 | - data_x = data_x.astype(tf.bfloat16.as_numpy_dtype) | 72 | + data_x = data_x.astype(bfloat16) |
| 72 | elif params_list["x_dtype"] == torch.float16: | 73 | elif params_list["x_dtype"] == torch.float16: |
| 73 | data_x = data_x.astype(np.float16) | 74 | data_x = data_x.astype(np.float16) |
| 74 | elif params_list["x_dtype"] == torch.float32: | 75 | elif params_list["x_dtype"] == torch.float32: |
| @@ -77,9 +78,6 @@ def gen_golden_data_simple(params_list): | |||
| 77 | group_index.cpu().numpy().tofile("./input_group_index.bin") | 78 | group_index.cpu().numpy().tofile("./input_group_index.bin") |
| 78 | 79 | ||
| 79 | 80 | ||
| 80 | - | ||
| 81 | - | ||
| 82 | - | ||
| 83 | if __name__ == "__main__": | 81 | if __name__ == "__main__": |
| 84 | params_list = params_info[sys.argv[1]] | 82 | params_list = params_info[sys.argv[1]] |
| 85 | - gen_golden_data_simple(params_list) | 83 | + gen_golden_data_simple(params_list) |
| @@ -0,0 +1,20 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ---------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") | ||
| 12 | +file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | +if(NOT ENABLE_TEST AND NOT BENCHMARK) | ||
| 14 | + list(REMOVE_ITEM CURRENT_DIRS tests) | ||
| 15 | +endif() | ||
| 16 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 17 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | + add_subdirectory(${SUB_DIR}) | ||
| 19 | + endif() | ||
| 20 | +endforeach() | ||
| @@ -0,0 +1,67 @@ | |||
| 1 | +# ClippedSwigluGrad | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +|产品 | 是否支持 | | ||
| 6 | +|:-------------------------|:----------:| | ||
| 7 | +| <term>Ascend 950PR/Ascend 950DT</term> | √ | | ||
| 8 | +| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | | ||
| 9 | +| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ | | ||
| 10 | +| <term>Atlas 200I/500 A2 推理产品</term> | × | | ||
| 11 | +| <term>Atlas 推理系列产品</term> | × | | ||
| 12 | +| <term>Atlas 训练系列产品</term> | × | | ||
| 13 | + | ||
| 14 | +## 功能说明 | ||
| 15 | + | ||
| 16 | +- 接口功能:aclnnClippedSwiglu的反向算子,计算输入x的梯度`gradXOut`。 | ||
| 17 | + | ||
| 18 | +- 计算公式: | ||
| 19 | + | ||
| 20 | + 对给定的正向输入张量x(维度为[a,b,c,d,e,f,g…])和输出梯度gradY,ClippedSwigluGrad对其进行以下计算: | ||
| 21 | + | ||
| 22 | + 1. 将x基于输入参数dim进行合轴,合轴后维度为[pre, dim2H];gradY合轴后维度为[pre, dim2H//2]。 | ||
| 23 | + | ||
| 24 | + 2. 根据输入参数group_index,对x的pre轴进行过滤处理,仅前group行参与计算,其余行梯度为0。 | ||
| 25 | + | ||
| 26 | + 3. 根据输入参数interleaved,对x进行切分,得到a和b两部分(与正向一致)。 | ||
| 27 | + | ||
| 28 | + 4. 重算正向中间量: | ||
| 29 | + - A = clamp(a, max=limit) | ||
| 30 | + - B = clamp(b, -limit, limit) | ||
| 31 | + - s = sigmoid(alpha * A) | ||
| 32 | + | ||
| 33 | + 5. 计算反向梯度: | ||
| 34 | + - maskX0 = (a <= limit) | ||
| 35 | + - maskX1 = (-limit <= b <= limit) | ||
| 36 | + - da = gradY * (B + bias) * s * (1 + alpha * A * (1 - s)) * maskX0 | ||
| 37 | + - db = gradY * A * s * maskX1 | ||
| 38 | + | ||
| 39 | + 6. 将da、db散回dx: | ||
| 40 | + - interleaved为true时:dx[..., ::2] = da,dx[..., 1::2] = db | ||
| 41 | + - interleaved为false时:dx[..., :h] = da,dx[..., h:] = db | ||
| 42 | + | ||
| 43 | + 7. 重塑输出张量grad_x的维度与x一致。 | ||
| 44 | + | ||
| 45 | +## 参数说明 | ||
| 46 | + | ||
| 47 | +|参数名|输入/输出/属性|描述|数据类型|数据格式| | ||
| 48 | +|---|---|---|---|---| | ||
| 49 | +|grad_y|输入|正向输出y的梯度。维度在dim轴上为x的一半,其他维度与x一致。|FLOAT、FLOAT16、BFLOAT16|ND| | ||
| 50 | +|x|输入|正向输入x。|FLOAT、FLOAT16、BFLOAT16|ND| | ||
| 51 | +|group_index|可选输入|分组索引。1维,元素个数不超过8192。|INT64|-| | ||
| 52 | +|dim|可选属性|合轴以及切分的维度序号。取值范围[-x.dim(), x.dim()-1]。默认-1。|INT64|-| | ||
| 53 | +|alpha|可选属性|SwiGLU激活系数。默认1.702。|FLOAT|-| | ||
| 54 | +|limit|可选属性|截断门限值。必须大于0。默认7.0。|FLOAT|-| | ||
| 55 | +|bias|可选属性|线性计算偏差。默认1.0。|FLOAT|-| | ||
| 56 | +|interleaved|可选属性|切分方式。true=奇偶切分,false=前后切分。默认true。|BOOL|-| | ||
| 57 | +|grad_x|输出|x的梯度,与x同shape。|FLOAT、FLOAT16、BFLOAT16|ND| | ||
| 58 | + | ||
| 59 | +## 约束说明 | ||
| 60 | + | ||
| 61 | +无。 | ||
| 62 | + | ||
| 63 | +## 调用说明 | ||
| 64 | + | ||
| 65 | +| 调用方式 | 调用样例 | 说明 | | ||
| 66 | +|---|---|---| | ||
| 67 | +| aclnn调用 | [test_aclnn_clipped_swiglu_grad](./examples/test_aclnn_clipped_swiglu_grad.cpp) | 通过[aclnnClippedSwigluGrad](./docs/aclnnClippedSwigluGrad.md)接口方式调用ClippedSwigluGrad算子。 | | ||
| @@ -0,0 +1,539 @@ | |||
| 1 | +# aclnnClippedSwigluGrad | ||
| 2 | + | ||
| 3 | +[📄 查看源码](https://gitcode.com/cann/ops-nn/tree/master/activation/clipped_swiglu_grad) | ||
| 4 | + | ||
| 5 | +## 产品支持情况 | ||
| 6 | + | ||
| 7 | +<!-- npu="950" id1 --> | ||
| 8 | +- <term>Ascend 950PR/Ascend 950DT</term>:支持 | ||
| 9 | +<!-- end id1 --> | ||
| 10 | +<!-- npu="A3" id2 --> | ||
| 11 | +- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持 | ||
| 12 | +<!-- end id2 --> | ||
| 13 | +<!-- npu="910b" id3 --> | ||
| 14 | +- <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term>:支持 | ||
| 15 | +<!-- end id3 --> | ||
| 16 | +<!-- npu="310b" id4 --> | ||
| 17 | +- <term>Atlas 200I/500 A2 推理产品</term>:不支持 | ||
| 18 | +<!-- end id4 --> | ||
| 19 | +<!-- npu="310p" id5 --> | ||
| 20 | +- <term>Atlas 推理系列产品</term>:不支持 | ||
| 21 | +<!-- end id5 --> | ||
| 22 | +<!-- npu="910" id6 --> | ||
| 23 | +- <term>Atlas 训练系列产品</term>:不支持 | ||
| 24 | +<!-- end id6 --> | ||
| 25 | + | ||
| 26 | +## 功能说明 | ||
| 27 | + | ||
| 28 | +- 接口功能:aclnnClippedSwiglu的反向算子,计算输入x的梯度`gradXOut`。 | ||
| 29 | + | ||
| 30 | +- 计算流程: | ||
| 31 | + - 步骤一:合轴与切分(将x合轴并切分为x0和x1) | ||
| 32 | + - 步骤二:GroupIndex处理(可选)→ 计算有效行数 | ||
| 33 | + - 步骤三:重算正向中间量 | ||
| 34 | + - 步骤四:Clamp反向传播掩码计算 | ||
| 35 | + - 步骤五:SwiGLU反向梯度计算 | ||
| 36 | + - 步骤六:梯度拼接输出 | ||
| 37 | + - 步骤七:GroupIndex置零处理(可选) | ||
| 38 | + | ||
| 39 | +- 合轴与切分公式: | ||
| 40 | + | ||
| 41 | + 将x基于输入参数`dim`进行合轴,合轴后维度为[pre, cut, after]。其中cut轴为需要切分的轴,pre和after可以等于1。由于after轴的元素为连续存放且计算操作为逐元素的,将cut轴与after轴合并,得到x的维度为[pre, cut]。`gradY`合轴后维度为[pre, cut/2]。 | ||
| 42 | + | ||
| 43 | + 根据`interleaved`参数对x进行切分: | ||
| 44 | + | ||
| 45 | + 当`interleaved`为true时,表示奇偶切分: | ||
| 46 | + | ||
| 47 | + $$ | ||
| 48 | + \mathbf{x}_0[p, h] = \mathbf{x}[p, 2h], \quad h \in [0, \text{cut}/2) | ||
| 49 | + $$ | ||
| 50 | + | ||
| 51 | + $$ | ||
| 52 | + \mathbf{x}_1[p, h] = \mathbf{x}[p, 2h+1], \quad h \in [0, \text{cut}/2) | ||
| 53 | + $$ | ||
| 54 | + | ||
| 55 | + 当`interleaved`为false时,表示前后切分: | ||
| 56 | + | ||
| 57 | + $$ | ||
| 58 | + H = \text{cut} / 2 | ||
| 59 | + $$ | ||
| 60 | + | ||
| 61 | + $$ | ||
| 62 | + \mathbf{x}_0[p, h] = \mathbf{x}[p, h], \quad h \in [0, H) | ||
| 63 | + $$ | ||
| 64 | + | ||
| 65 | + $$ | ||
| 66 | + \mathbf{x}_1[p, h] = \mathbf{x}[p, h + H], \quad h \in [0, H) | ||
| 67 | + $$ | ||
| 68 | + | ||
| 69 | + 其中$p$为pre维索引,$h$为切分后半宽索引。 | ||
| 70 | + | ||
| 71 | +- GroupIndex处理公式(当提供`groupIndex`时): | ||
| 72 | + | ||
| 73 | + $$ | ||
| 74 | + \text{trunc} = \sum_{g=0}^{G-1} \text{groupIndex}[g] | ||
| 75 | + $$ | ||
| 76 | + | ||
| 77 | + $$ | ||
| 78 | + \text{validRows} = \min(\text{trunc}, \text{pre}) | ||
| 79 | + $$ | ||
| 80 | + | ||
| 81 | + 其中:$G$为groupIndex的元素个数,后续所有步骤仅处理前$\text{validRows}$行数据。当不提供`groupIndex`时,$\text{validRows} = \text{pre}$。 | ||
| 82 | + | ||
| 83 | +- 重算正向中间量公式: | ||
| 84 | + | ||
| 85 | + $$ | ||
| 86 | + \mathbf{x}_0' = \min(\mathbf{x}_0, l) | ||
| 87 | + $$ | ||
| 88 | + | ||
| 89 | + $$ | ||
| 90 | + \mathbf{x}_1' = \min(\max(\mathbf{x}_1, -l), l) | ||
| 91 | + $$ | ||
| 92 | + | ||
| 93 | + $$ | ||
| 94 | + s = \sigma(\alpha \times \mathbf{x}_0') = \frac{1}{1 + e^{-\alpha \times \mathbf{x}_0'}} | ||
| 95 | + $$ | ||
| 96 | + | ||
| 97 | + 其中:$\mathbf{x}_0'$为对$\mathbf{x}_0$仅做上界截断,$\mathbf{x}_1'$为对$\mathbf{x}_1$做双向截断,$s$为sigmoid激活值,$\alpha$为`alpha`参数,$l$为`limit`参数。 | ||
| 98 | + | ||
| 99 | +- Clamp反向传播掩码公式: | ||
| 100 | + | ||
| @@ -0,0 +1,131 @@ | |||
| 1 | +# clipped_swiglu_grad | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +<!-- npu="950" id1 --> | ||
| 6 | +- <term>Ascend 950PR/Ascend 950DT</term>:支持 | ||
| 7 | +<!-- end id1 --> | ||
| 8 | +<!-- npu="A3" id2 --> | ||
| 9 | +- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:支持 | ||
| 10 | +<!-- end id2 --> | ||
| 11 | +<!-- npu="910b" id3 --> | ||
| 12 | +- <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term>:支持 | ||
| 13 | +<!-- end id3 --> | ||
| 14 | +<!-- npu="310b" id4 --> | ||
| 15 | +- <term>Atlas 200I/500 A2 推理产品</term>:不支持 | ||
| 16 | +<!-- end id4 --> | ||
| 17 | +<!-- npu="310p" id5 --> | ||
| 18 | +- <term>Atlas推理系列产品</term>:不支持 | ||
| 19 | +<!-- end id5 --> | ||
| 20 | +<!-- npu="910" id6 --> | ||
| 21 | +- <term>Atlas训练系列产品</term>:不支持 | ||
| 22 | +<!-- end id6 --> | ||
| 23 | + | ||
| 24 | +## 功能说明 | ||
| 25 | + | ||
| 26 | +- 接口功能: | ||
| 27 | + | ||
| 28 | + `ClippedSwigluGrad`是`ClippedSwiglu`算子的反向梯度计算算子。根据正向输出`y`的梯度`grad_y`、前向输入`x`以及可选的分组索引`group_index`,反向计算输入`x`的梯度`grad_x`。底层封装`aclnnClippedSwigluGrad`。 | ||
| 29 | + | ||
| 30 | +- 计算流程: | ||
| 31 | + | ||
| 32 | + 1. 将`x`基于参数`dim`进行合轴,合轴后维度为`[pre, dim2H]`;`grad_y`合轴后维度为`[pre, dim2H // 2]`。 | ||
| 33 | + 2. 根据`group_index`,对`x`的`pre`轴进行过滤处理,仅前`group`行参与计算,其余行梯度为 0。 | ||
| 34 | + 3. 根据`interleaved`,对`x`进行切分,得到`x0`和`x1`两部分(与正向一致)。 | ||
| 35 | + 4. 重算正向中间量: | ||
| 36 | + - $\mathbf{x}_0' = \min(\mathbf{x}_0, \text{limit})$ | ||
| 37 | + - $\mathbf{x}_1' = \min(\max(\mathbf{x}_1, -\text{limit}), \text{limit})$ | ||
| 38 | + - $s = \sigma(\alpha \times \mathbf{x}_0') = \frac{1}{1 + e^{-\alpha \times \mathbf{x}_0'}}$ | ||
| 39 | + 5. 计算反向梯度: | ||
| 40 | + - $\text{mask}_{x_0} = (\mathbf{x}_0 \le \text{limit})$ | ||
| 41 | + - $\text{mask}_{x_1} = (-\text{limit} \le \mathbf{x}_1 \le \text{limit})$ | ||
| 42 | + - $\mathbf{grad}_{x_0} = \text{grad\_y} \times (\mathbf{x}_1' + \text{bias}) \times s \times (1 + \alpha \times \mathbf{x}_0' \times (1 - s)) \times \text{mask}_{x_0}$ | ||
| 43 | + - $\mathbf{grad}_{x_1} = \text{grad\_y} \times \mathbf{x}_0' \times s \times \text{mask}_{x_1}$ | ||
| 44 | + 6. 将`grad_x0`、`grad_x1`散回`dx`(与切分方式对应),重塑输出维度与`x`一致。 | ||
| 45 | + | ||
| 46 | +## 函数原型 | ||
| 47 | + | ||
| 48 | +```python | ||
| 49 | +cann_ops_nn.clipped_swiglu_grad( | ||
| 50 | + grad_y, | ||
| 51 | + x, | ||
| 52 | + *, | ||
| 53 | + group_index=None, | ||
| 54 | + dim=-1, | ||
| 55 | + alpha=1.702, | ||
| 56 | + limit=7.0, | ||
| 57 | + bias=1.0, | ||
| 58 | + interleaved=True, | ||
| 59 | + clamp_mode=0, | ||
| 60 | +) -> Tensor | ||
| 61 | +``` | ||
| 62 | + | ||
| 63 | +## 参数说明 | ||
| 64 | + | ||
| 65 | +| 参数名 | 参数类型 | 可选/必选 | 描述 | 数据类型 | 维度(shape) | | ||
| 66 | +| --- | --- | --- | --- | --- | --- | | ||
| 67 | +| `grad_y` | Tensor | 必选 | 正向输出`y`的梯度,`dim`维为`x`的一半。 | `torch.float16`、`torch.bfloat16`、`torch.float32` | 与`x`相同,但`dim`维为`x`对应维度的一半 | | ||
| 68 | +| `x` | Tensor | 必选 | 正向输入,用于重算正向中间量。 | `torch.float16`、`torch.bfloat16`、`torch.float32` | 1-8维,`dim`维大小为偶数 | | ||
| 69 | +| `group_index` | Tensor | 可选 | 分组索引,第`i`个元素表示第`i`组处理的batch数量。 | `torch.int64` | 1维,元素个数不超过 8192 | | ||
| 70 | +| `dim` | int | 可选 | 合轴及切分的维度序号,取值范围`[-x.dim(), x.dim()-1]`,默认`-1`。 | - | - | | ||
| 71 | +| `alpha` | float | 可选 | SwiGLU激活系数,默认`1.702`。 | - | - | | ||
| 72 | +| `limit` | float | 可选 | 截断门限值,必须大于 0,默认`7.0`。 | - | - | | ||
| 73 | +| `bias` | float | 可选 | 线性计算偏差,默认`1.0`。 | - | - | | ||
| 74 | +| `interleaved` | bool | 可选 | 切分方式。`true`=奇偶切分,`false`=前后切分,默认`true`。 | - | - | | ||
| 75 | +| `clamp_mode` | int | 可选 | clamp位置控制,默认`0`。当前仅支持`0`(clamp在silu之前),后续版本将支持`1`(clamp移至silu之后)。 | - | - | | ||
| 76 | + | ||
| 77 | +## 返回值说明 | ||
| 78 | + | ||
| 79 | +| 参数名 | 参数类型 | 描述 | 数据类型 | 维度(shape) | | ||
| 80 | +| --- | --- | --- | --- | --- | | ||
| 81 | +| `grad_x` | Tensor | 输入`x`的梯度。 | 与`x`相同 | 与`x`相同 | | ||
| 82 | + | ||
| 83 | +## 约束说明 | ||
| 84 | + | ||
| 85 | +- 该接口支持单算子模式和TorchAir图模式调用。 | ||
| 86 | +- `grad_y`、`x`均需为NPU Tensor;`group_index`可传`None`。 | ||
| 87 | +- `grad_y`与`x`的数据类型必须一致。 | ||
| 88 | +- `x`的rank必须大于 0,`dim`维大小必须为偶数。 | ||
| 89 | +- `grad_y`的`dim`维大小必须等于`x`对应维度的一半,其余维度与`x`一致。 | ||
| 90 | +- `limit`必须大于 0。 | ||
| 91 | +- `clamp_mode`当前仅支持取值`0`。 | ||
| 92 | +- 不支持空Tensor和非连续Tensor。 | ||
| 93 | + | ||
| 94 | +## 确定性计算 | ||
| 95 | + | ||
| 96 | +默认支持确定性计算。 | ||
| 97 | + | ||
| 98 | +## 调用说明 | ||
| 99 | + | ||
| 100 | +- 单算子模式调用: | ||
| 101 | + | ||
| 102 | + ```python | ||
| 103 | + import torch | ||
| 104 | + import torch_npu | ||
| 105 | + import cann_ops_nn.ops | ||
| 106 | + | ||
| 107 | + x = torch.randn(8, 512, dtype=torch.float16).npu() | ||
| 108 | + grad_y = torch.randn(8, 256, dtype=torch.float16).npu() | ||
| 109 | + | ||
| 110 | + grad_x = torch.ops.cann_ops_nn.clipped_swiglu_grad( | ||
| 111 | + grad_y, x, dim=-1, alpha=1.702, limit=7.0, bias=1.0, interleaved=True) | ||
| 112 | + print(grad_x.shape, grad_x.dtype) | ||
| 113 | + ``` | ||
| 114 | + | ||
| 115 | +- 图模式(torchair)调用: | ||
| 116 | + | ||
| 117 | + ```python | ||
| 118 | + import torch | ||
| 119 | + import torch_npu | ||
| 120 | + import torchair | ||
| 121 | + import cann_ops_nn.ops | ||
| 122 | + | ||
| 123 | + class Model(torch.nn.Module): | ||
| 124 | + def forward(self, grad_y, x): | ||
| 125 | + return torch.ops.cann_ops_nn.clipped_swiglu_grad(grad_y, x) | ||
| 126 | + | ||
| 127 | + model = torch.compile(Model().npu(), backend=torchair.get_npu_backend(), dynamic=False) | ||
| 128 | + grad_y = torch.randn(8, 256, dtype=torch.float16).npu() | ||
| 129 | + x = torch.randn(8, 512, dtype=torch.float16).npu() | ||
| 130 | + grad_x = model(grad_y, x) | ||
| 131 | + ``` | ||
| @@ -0,0 +1,143 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <iostream> | ||
| 12 | +#include <vector> | ||
| 13 | +#include "acl/acl.h" | ||
| 14 | +#include "aclnnop/aclnn_clipped_swiglu_grad.h" | ||
| 15 | + | ||
| 16 | +#define CHECK_RET(cond, return_expr) \ | ||
| 17 | + do { \ | ||
| 18 | + if (!(cond)) { \ | ||
| 19 | + return_expr; \ | ||
| 20 | + } \ | ||
| 21 | + } while (0) | ||
| 22 | + | ||
| 23 | +#define LOG_PRINT(message, ...) \ | ||
| 24 | + do { \ | ||
| 25 | + printf(message, ##__VA_ARGS__); \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) | ||
| 29 | +{ | ||
| 30 | + int64_t shapeSize = 1; | ||
| 31 | + for (auto i : shape) { | ||
| 32 | + shapeSize *= i; | ||
| 33 | + } | ||
| 34 | + return shapeSize; | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +int Init(int32_t deviceId, aclrtStream* stream) | ||
| 38 | +{ | ||
| 39 | + auto ret = aclInit(nullptr); | ||
| 40 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 41 | + ret = aclrtSetDevice(deviceId); | ||
| 42 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 43 | + ret = aclrtCreateStream(stream); | ||
| 44 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 45 | + return 0; | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +template <typename T> | ||
| 49 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | ||
| 50 | + aclDataType dataType, aclTensor** tensor) | ||
| 51 | +{ | ||
| 52 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 53 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 54 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 55 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 56 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 57 | + | ||
| 58 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 59 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 60 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, | ||
| 64 | + shape.data(), shape.size(), *deviceAddr); | ||
| 65 | + return 0; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +int main() | ||
| 69 | +{ | ||
| 70 | + int32_t deviceId = 0; | ||
| 71 | + aclrtStream stream; | ||
| 72 | + auto ret = Init(deviceId, &stream); | ||
| 73 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 74 | + | ||
| 75 | + // x shape [2, 32], grad_y shape [2, 16], grad_x shape [2, 32] | ||
| 76 | + std::vector<int64_t> xShape = {2, 32}; | ||
| 77 | + std::vector<int64_t> gradYShape = {2, 16}; | ||
| 78 | + std::vector<int64_t> gradXOutShape = {2, 32}; | ||
| 79 | + void* xDeviceAddr = nullptr; | ||
| 80 | + void* gradYDeviceAddr = nullptr; | ||
| 81 | + void* gradXOutDeviceAddr = nullptr; | ||
| 82 | + aclTensor* x = nullptr; | ||
| 83 | + aclTensor* gradY = nullptr; | ||
| 84 | + aclTensor* gradXOut = nullptr; | ||
| 85 | + | ||
| 86 | + std::vector<float> xHostData(64, 1.0f); | ||
| 87 | + std::vector<float> gradYHostData(32, 1.0f); | ||
| 88 | + std::vector<float> gradXOutHostData(64, 0.0f); | ||
| 89 | + | ||
| 90 | + int dim = -1; | ||
| 91 | + float alpha = 1.702; | ||
| 92 | + float limit = 7.0; | ||
| 93 | + float bias = 1.0; | ||
| 94 | + bool interleaved = true; | ||
| 95 | + | ||
| 96 | + ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_FLOAT, &x); | ||
| 97 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 98 | + ret = CreateAclTensor(gradYHostData, gradYShape, &gradYDeviceAddr, aclDataType::ACL_FLOAT, &gradY); | ||
| 99 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 100 | + ret = CreateAclTensor(gradXOutHostData, gradXOutShape, &gradXOutDeviceAddr, aclDataType::ACL_FLOAT, &gradXOut); | ||
| 101 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 102 | + | ||
| 103 | + uint64_t workspaceSize = 0; | ||
| 104 | + aclOpExecutor* executor; | ||
| 105 | + ret = aclnnClippedSwigluGradGetWorkspaceSize(gradY, x, nullptr, dim, alpha, limit, bias, interleaved, gradXOut, | ||
| 106 | + &workspaceSize, &executor); | ||
| 107 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnClippedSwigluGradGetWorkspaceSize failed. ERROR: %d\n", ret); | ||
| 108 | + return ret); | ||
| 109 | + | ||
| 110 | + void* workspaceAddr = nullptr; | ||
| 111 | + if (workspaceSize > 0) { | ||
| 112 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 113 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 114 | + } | ||
| 115 | + ret = aclnnClippedSwigluGrad(workspaceAddr, workspaceSize, executor, stream); | ||
| 116 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnClippedSwigluGrad failed. ERROR: %d\n", ret); return ret); | ||
| 117 | + | ||
| 118 | + ret = aclrtSynchronizeStream(stream); | ||
| 119 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 120 | + | ||
| 121 | + auto size = GetShapeSize(gradXOutShape); | ||
| 122 | + std::vector<float> resultData(size, 0); | ||
| 123 | + ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), gradXOutDeviceAddr, | ||
| 124 | + size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 125 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 126 | + for (int64_t i = 0; i < size; i++) { | ||
| 127 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + aclDestroyTensor(x); | ||
| 131 | + aclDestroyTensor(gradY); | ||
| 132 | + aclDestroyTensor(gradXOut); | ||
| 133 | + aclrtFree(xDeviceAddr); | ||
| 134 | + aclrtFree(gradYDeviceAddr); | ||
| 135 | + aclrtFree(gradXOutDeviceAddr); | ||
| 136 | + if (workspaceSize > 0) { | ||
| 137 | + aclrtFree(workspaceAddr); | ||
| 138 | + } | ||
| 139 | + aclrtDestroyStream(stream); | ||
| 140 | + aclrtResetDevice(deviceId); | ||
| 141 | + aclFinalize(); | ||
| 142 | + return 0; | ||
| 143 | +} | ||
| @@ -0,0 +1,11 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ---------------------------------------------------------------------------- | ||
| 10 | +message(STATUS "=== Debug: start ops.fusedop.clipped_swiglu_grad.op_graph.CMakeLists.txt ") | ||
| 11 | +add_graph_plugin_sources() | ||
| @@ -0,0 +1,64 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file clipped_swiglu_grad_proto.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#ifndef OPS_BUILT_IN_OP_PROTO_INC_CLIPPED_SWIGLU_GRAD_PROTO_H_ | ||
| 17 | +#define OPS_BUILT_IN_OP_PROTO_INC_CLIPPED_SWIGLU_GRAD_PROTO_H_ | ||
| 18 | + | ||
| 19 | +#include "graph/operator_reg.h" | ||
| 20 | + | ||
| 21 | +namespace ge { | ||
| 22 | +/** | ||
| 23 | +* @brief Compute the ClippedSwigluGrad, | ||
| 24 | +* where the activations function in GLU is SwishGrad. | ||
| 25 | + | ||
| 26 | +* @par Inputs: | ||
| 27 | +* Three inputs, including: | ||
| 28 | +* @li grad_y: A Tensor, which is the output gradient of forward operator and which | ||
| 29 | +* has the same shape as "x" except for the dimension specified by the "dim" parameter. | ||
| 30 | +* The dimension size specified by "dim" is half of the corresponding dimension of x. | ||
| 31 | +* Must be one of the following types: bfloat16, float16, float32. | ||
| 32 | +* @li x: A Tensor. Must be one of the following types: bfloat16, float16, float32. | ||
| 33 | +* @li group_index: An optional tensor. Shape is (N,). Type is int64. | ||
| 34 | + | ||
| 35 | +* @par Outputs: | ||
| 36 | +* one Output, including: | ||
| 37 | +* grad_x: A Tensor, which is the gradient of x and has the same shape as "x". | ||
| 38 | +* Must be one of the following types: bfloat16, float16, float32. | ||
| 39 | + | ||
| 40 | +* @par Attributes: | ||
| 41 | +* Five attributes, including: | ||
| 42 | +* @li dim: An optional int. The dimension to be split, value in [-xDim, xDim-1], default is -1. | ||
| 43 | +* @li alpha: An optional float. The activation coefficient for the GLU activation function, default is 1.702. | ||
| 44 | +* @li limit: An optional float. The threshold limit for SWIGLU input, default is 7.0. | ||
| 45 | +* @li bias: An optional float. The bias applied during SWIGLU linear computation, default is 1.0. | ||
| 46 | + * @li interleaved: An optional bool. The way of splitting x: true for interleaved splitting, | ||
| 47 | + * false for front-back splitting, default is true. | ||
| 48 | +* @par Attention Constraints: | ||
| 49 | +* The dim dimension of x must be divisible by 2, and the dim dimension of grad_y must be equal | ||
| 50 | +* to the dim dimension of x divided by 2. | ||
| 51 | +*/ | ||
| 52 | +REG_OP(ClippedSwigluGrad) | ||
| 53 | + .INPUT(grad_y, TensorType({DT_BF16, DT_FLOAT16, DT_FLOAT})) | ||
| 54 | + .INPUT(x, TensorType({DT_BF16, DT_FLOAT16, DT_FLOAT})) | ||
| 55 | + .OPTIONAL_INPUT(group_index, TensorType({DT_INT64})) | ||
| 56 | + .OUTPUT(grad_x, TensorType({DT_BF16, DT_FLOAT16, DT_FLOAT})) | ||
| 57 | + .ATTR(dim, Int, -1) | ||
| 58 | + .ATTR(alpha, Float, 1.702) | ||
| 59 | + .ATTR(limit, Float, 7.0) | ||
| 60 | + .ATTR(bias, Float, 1.0) | ||
| 61 | + .ATTR(interleaved, Bool, true) | ||
| 62 | + .OP_END_FACTORY_REG(ClippedSwigluGrad) | ||
| 63 | +} // namespace ge | ||
| 64 | +#endif // OPS_BUILT_IN_OP_PROTO_INC_CLIPPED_SWIGLU_GRAD_PROTO_H_ | ||
The file is empty
| @@ -1,9 +1,12 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 1 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 2 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 3 | # CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 4 | # Please refer to the License for details. You may not use this file except in compliance with the License. | 5 | # Please refer to the License for details. You may not use this file except in compliance with the License. |
| 5 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 6 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. |
| 7 | # See LICENSE in the root of the software repository for the full text of the License. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | +# ---------------------------------------------------------------------------- | ||
| 8 | 10 | ||
| 9 | -add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE dynamic_rnn ACLNNTYPE aclnn_exclude) | 11 | +message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") |
| 12 | +add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE clipped_swiglu_grad ACLNNTYPE aclnn DEPENDENCIES clipped_swiglu) | ||
| @@ -0,0 +1,74 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file clipped_swiglu_grad_def.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | +#include <register/op_def_registry.h> | ||
| 16 | + | ||
| 17 | +namespace ops { | ||
| 18 | +constexpr float DEFAULT_ALPHA = 1.702; | ||
| 19 | +constexpr float DEFAULT_LIMIT = 7.0; | ||
| 20 | + | ||
| 21 | +static const std::vector<ge::DataType> xDtype = {ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16}; | ||
| 22 | +static const std::vector<ge::DataType> groupIndexDtype = {ge::DT_INT64, ge::DT_INT64, ge::DT_INT64}; | ||
| 23 | +static const std::vector<ge::Format> xFormat = {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}; | ||
| 24 | + | ||
| 25 | +class ClippedSwigluGrad : public OpDef { | ||
| 26 | +public: | ||
| 27 | + explicit ClippedSwigluGrad(const char* name) : OpDef(name) | ||
| 28 | + { | ||
| 29 | + this->Input("grad_y").ParamType(REQUIRED).DataType(xDtype).Format(xFormat).UnknownShapeFormat(xFormat); | ||
| 30 | + this->Input("x").ParamType(REQUIRED).DataType(xDtype).Format(xFormat).UnknownShapeFormat(xFormat); | ||
| 31 | + this->Input("group_index") | ||
| 32 | + .ParamType(OPTIONAL) | ||
| 33 | + .DataType(groupIndexDtype) | ||
| 34 | + .Format(xFormat) | ||
| 35 | + .UnknownShapeFormat(xFormat); | ||
| 36 | + this->Output("grad_x").ParamType(REQUIRED).DataType(xDtype).Format(xFormat).UnknownShapeFormat(xFormat); | ||
| 37 | + this->Attr("dim").AttrType(OPTIONAL).Int(-1); | ||
| 38 | + this->Attr("alpha").AttrType(OPTIONAL).Float(DEFAULT_ALPHA); | ||
| 39 | + this->Attr("limit").AttrType(OPTIONAL).Float(DEFAULT_LIMIT); | ||
| 40 | + this->Attr("bias").AttrType(OPTIONAL).Float(1.0); | ||
| 41 | + this->Attr("interleaved").AttrType(OPTIONAL).Bool(true); | ||
| 42 | + | ||
| 43 | + this->AICore().AddConfig("ascend910b"); | ||
| 44 | + this->AICore().AddConfig("ascend910_93"); | ||
| 45 | + | ||
| 46 | + OpAICoreConfig regbaseConfig; | ||
| 47 | + regbaseConfig.Input("grad_y") | ||
| 48 | + .ParamType(REQUIRED) | ||
| 49 | + .DataType(xDtype) | ||
| 50 | + .Format(xFormat) | ||
| 51 | + .UnknownShapeFormat(xFormat) | ||
| 52 | + .AutoContiguous(); | ||
| 53 | + regbaseConfig.Input("x") | ||
| 54 | + .ParamType(REQUIRED) | ||
| 55 | + .DataType(xDtype) | ||
| 56 | + .Format(xFormat) | ||
| 57 | + .UnknownShapeFormat(xFormat) | ||
| 58 | + .AutoContiguous(); | ||
| 59 | + regbaseConfig.Input("group_index") | ||
| 60 | + .ParamType(OPTIONAL) | ||
| 61 | + .DataType(groupIndexDtype) | ||
| 62 | + .Format(xFormat) | ||
| 63 | + .UnknownShapeFormat(xFormat) | ||
| 64 | + .AutoContiguous(); | ||
| 65 | + regbaseConfig.Output("grad_x").ParamType(REQUIRED).DataType(xDtype).Format(xFormat).UnknownShapeFormat(xFormat); | ||
| 66 | + regbaseConfig.DynamicCompileStaticFlag(true) | ||
| 67 | + .DynamicRankSupportFlag(true) | ||
| 68 | + .DynamicShapeSupportFlag(true) | ||
| 69 | + .ExtendCfgInfo("opFile.value", "clipped_swiglu_grad_apt"); | ||
| 70 | + this->AICore().AddConfig("ascend950", regbaseConfig); | ||
| 71 | + } | ||
| 72 | +}; | ||
| 73 | +OP_ADD(ClippedSwigluGrad); | ||
| 74 | +} // namespace ops | ||
| @@ -0,0 +1,79 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file clipped_swiglu_grad_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "log/log.h" | ||
| 17 | +#include "register/op_impl_registry.h" | ||
| 18 | +#include "error_util.h" | ||
| 19 | +#include "util/shape_util.h" | ||
| 20 | +using namespace ge; | ||
| 21 | + | ||
| 22 | +namespace { | ||
| 23 | +constexpr size_t GRAD_IN_X = 1; // x is the second input (index 1) | ||
| 24 | +constexpr size_t GRAD_OUT_GRAD_X = 0; // grad_x is the first output (index 0) | ||
| 25 | +constexpr size_t GRAD_ATTR_DIM = 0; | ||
| 26 | +const size_t SPLIT_NUM = 2; | ||
| 27 | +} // namespace | ||
| 28 | + | ||
| 29 | +namespace ops { | ||
| 30 | +static ge::graphStatus InferShapeForClippedSwigluGrad(gert::InferShapeContext* context) | ||
| 31 | +{ | ||
| 32 | + OP_LOGD(context->GetNodeName(), "Begin to do InferShapeForClippedSwigluGrad"); | ||
| 33 | + auto xShape = context->GetInputShape(GRAD_IN_X); | ||
| 34 | + OPS_CHECK_NULL_WITH_CONTEXT(context, xShape); | ||
| 35 | + auto gradXOutShape = context->GetOutputShape(GRAD_OUT_GRAD_X); | ||
| 36 | + OPS_CHECK_NULL_WITH_CONTEXT(context, gradXOutShape); | ||
| 37 | + auto attrs = context->GetAttrs(); | ||
| 38 | + OPS_CHECK_NULL_WITH_CONTEXT(context, attrs); | ||
| 39 | + | ||
| 40 | + auto splitDimPtr = attrs->GetAttrPointer<int64_t>(GRAD_ATTR_DIM); | ||
| 41 | + OPS_CHECK_NULL_WITH_CONTEXT(context, splitDimPtr); | ||
| 42 | + if (Ops::Base::IsUnknownRank(*xShape)) { | ||
| 43 | + Ops::Base::SetUnknownRank(*gradXOutShape); | ||
| 44 | + return ge::GRAPH_SUCCESS; | ||
| 45 | + } | ||
| 46 | + auto splitDim = *splitDimPtr; | ||
| 47 | + if (splitDim < 0) { | ||
| 48 | + splitDim += xShape->GetDimNum(); | ||
| 49 | + } | ||
| 50 | + if (splitDim < 0 || splitDim >= static_cast<int64_t>(xShape->GetDimNum())) { | ||
| 51 | + OP_LOGE("ClippedSwigluGrad", "The value of attr [dim] must be in the range [-%zu, %zu], but got [%ld].", | ||
| 52 | + xShape->GetDimNum(), xShape->GetDimNum() - 1, splitDim); | ||
| 53 | + return GRAPH_FAILED; | ||
| 54 | + } | ||
| 55 | + int64_t splitDimSize = xShape->GetDim(splitDim); | ||
| 56 | + if (splitDimSize >= 0 && splitDimSize % static_cast<int64_t>(SPLIT_NUM) != 0) { | ||
| 57 | + OP_LOGE("ClippedSwigluGrad", "The size of x[dim] must be divisible by %zu, but got [%ld].", SPLIT_NUM, | ||
| 58 | + splitDimSize); | ||
| 59 | + return GRAPH_FAILED; | ||
| 60 | + } | ||
| 61 | + OP_LOGD(context->GetNodeName(), "Begin to generate gradXOutShape"); | ||
| 62 | + // grad_x has the same shape as x | ||
| 63 | + *gradXOutShape = *xShape; | ||
| 64 | + return ge::GRAPH_SUCCESS; | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +static ge::graphStatus InferDataTypeForClippedSwigluGrad(gert::InferDataTypeContext* context) | ||
| 68 | +{ | ||
| 69 | + OP_LOGD(context->GetNodeName(), "Begin to do InferDataTypeForClippedSwigluGrad"); | ||
| 70 | + const ge::DataType dtype = context->GetInputDataType(1); // x is index 1 | ||
| 71 | + ge::graphStatus ret = context->SetOutputDataType(0, dtype); | ||
| 72 | + OP_LOGD(context->GetNodeName(), "End to do InferDataTypeForClippedSwigluGrad"); | ||
| 73 | + return ret; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +IMPL_OP_INFERSHAPE(ClippedSwigluGrad) | ||
| 77 | + .InferShape(InferShapeForClippedSwigluGrad) | ||
| 78 | + .InferDataType(InferDataTypeForClippedSwigluGrad); | ||
| 79 | +} // namespace ops | ||
| @@ -0,0 +1,366 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file clipped_swiglu_grad_tiling.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | +#include "clipped_swiglu_grad_tiling.h" | ||
| 16 | +#include "../op_kernel/clipped_swiglu_grad_tiling_key.h" | ||
| 17 | + | ||
| 18 | +using Ops::NN::Optiling::TilingRegistry; | ||
| 19 | +using namespace ge; | ||
| 20 | +namespace optiling { | ||
| 21 | +constexpr int64_t Y_GRAD_INDEX = 0; | ||
| 22 | +constexpr int64_t X_INDEX = 1; | ||
| 23 | +constexpr int64_t GROUP_INDEX_INDEX = 2; | ||
| 24 | +constexpr int64_t GRAD_X_INDEX = 0; | ||
| 25 | +constexpr int64_t DIM_INDEX = 0; | ||
| 26 | +constexpr int64_t ALPHA_INDEX = 1; | ||
| 27 | +constexpr int64_t LIMIT_INDEX = 2; | ||
| 28 | +constexpr int64_t BIAS_INDEX = 3; | ||
| 29 | +constexpr int64_t INTERLEAVED_INDEX = 4; | ||
| 30 | + | ||
| 31 | +constexpr int64_t BLOCK_SIZE = 32; | ||
| 32 | +constexpr int64_t BITS_PER_BYTE = 8; | ||
| 33 | +constexpr int64_t SWI_FACTOR = 2; | ||
| 34 | +constexpr int64_t UB_RESERVE = 1024; | ||
| 35 | +constexpr int64_t DB_BUFFER = 2; | ||
| 36 | +constexpr int64_t SIZE_OF_FP32 = sizeof(float); | ||
| 37 | + | ||
| 38 | +static int64_t AlignUp(int64_t value, int64_t align) { return (value + align - 1) / align * align; } | ||
| 39 | + | ||
| 40 | +constexpr float DEFAULT_LIMIT = 7.0; | ||
| 41 | +constexpr float DEFAULT_ALPHA = 1.702; | ||
| 42 | +constexpr float DEFAULT_BIAS = 1.0; | ||
| 43 | + | ||
| 44 | +static const std::set<ge::DataType> SUPPORT_DTYPE = {ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_BF16}; | ||
| 45 | + | ||
| 46 | +ge::graphStatus ClippedSwigluGradTiling::GetShapeAttrsInfo() | ||
| 47 | +{ | ||
| 48 | + OP_CHECK_IF(CheckAndGetXAndAttrs() != ge::GRAPH_SUCCESS, | ||
| 49 | + OP_LOGE(context_->GetNodeName(), "check x and attrs failed."), return ge::GRAPH_FAILED); | ||
| 50 | + OP_CHECK_IF(CheckAndGetGroupIndex() != ge::GRAPH_SUCCESS, | ||
| 51 | + OP_LOGE(context_->GetNodeName(), "check group_index param failed."), return ge::GRAPH_FAILED); | ||
| 52 | + OP_CHECK_IF(CheckGradX() != ge::GRAPH_SUCCESS, OP_LOGE(context_->GetNodeName(), "check grad_x param failed."), | ||
| 53 | + return ge::GRAPH_FAILED); | ||
| 54 | + return ge::GRAPH_SUCCESS; | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +ge::graphStatus ClippedSwigluGradTiling::GetPlatformInfo() | ||
| 58 | +{ | ||
| 59 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 60 | + if (platformInfo == nullptr) { | ||
| 61 | + auto compileInfoPtr = context_->GetCompileInfo<ClippedSwigluGradCompileInfo>(); | ||
| 62 | + OP_CHECK_IF(compileInfoPtr == nullptr, OP_LOGE(context_, "compile info is null"), return ge::GRAPH_FAILED); | ||
| 63 | + coreNumAll_ = compileInfoPtr->coreNum; | ||
| 64 | + ubSize_ = compileInfoPtr->ubSize; | ||
| 65 | + } else { | ||
| 66 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 67 | + coreNumAll_ = ascendcPlatform.GetCoreNumAiv(); | ||
| 68 | + uint64_t ubSizePlatForm; | ||
| 69 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSizePlatForm); | ||
| 70 | + ubSize_ = ubSizePlatForm; | ||
| 71 | + } | ||
| 72 | + return ge::GRAPH_SUCCESS; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +bool ClippedSwigluGradTiling::IsCapable() | ||
| 76 | +{ | ||
| 77 | + // 第一版统一实现,所有平台共用一套 tiling,不区分 arch35 | ||
| 78 | + return true; | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +ge::graphStatus ClippedSwigluGradTiling::DoOpTiling() | ||
| 82 | +{ | ||
| 83 | + CountMaxPair(); | ||
| 84 | + SetTilingData(); | ||
| 85 | + return ge::GRAPH_SUCCESS; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +void ClippedSwigluGradTiling::SetTilingData() | ||
| 89 | +{ | ||
| 90 | + tilingData_.set_coreNumAll(coreNumAll_); | ||
| 91 | + tilingData_.set_dimBatchSize(dimBatchSize_); | ||
| 92 | + tilingData_.set_dim2H(dim2H_); | ||
| 93 | + tilingData_.set_isLongH(isLongH_); | ||
| 94 | + tilingData_.set_isGroup(isGroup_); | ||
| 95 | + tilingData_.set_isInterleaved(isInterleaved_); | ||
| 96 | + tilingData_.set_alpha(alpha_); | ||
| 97 | + tilingData_.set_limit(limit_); | ||
| 98 | + tilingData_.set_bias(bias_); | ||
| 99 | + tilingData_.set_ubMaxPair(ubMaxPair_); | ||
| 100 | + tilingData_.set_groupNum(groupNum_); | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +ge::graphStatus ClippedSwigluGradTiling::DoLibApiTiling() { return ge::GRAPH_SUCCESS; } | ||
| 104 | + | ||
| 105 | +ge::graphStatus ClippedSwigluGradTiling::GetWorkspaceSize() { return ge::GRAPH_SUCCESS; } | ||
| 106 | + | ||
| 107 | +ge::graphStatus ClippedSwigluGradTiling::PostTiling() | ||
| 108 | +{ | ||
| 109 | + context_->SetTilingKey(GetTilingKey()); | ||
| 110 | + context_->SetBlockDim(coreNumAll_); | ||
| 111 | + tilingData_.SaveToBuffer(context_->GetRawTilingData()->GetData(), context_->GetRawTilingData()->GetCapacity()); | ||
| 112 | + context_->GetRawTilingData()->SetDataSize(tilingData_.GetDataSize()); | ||
| 113 | + return ge::GRAPH_SUCCESS; | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +uint64_t ClippedSwigluGradTiling::GetTilingKey() const | ||
| 117 | +{ | ||
| 118 | + using namespace ClippedSwigluGradArch35Op; | ||
| 119 | + uint64_t isInterleavedKey = (isInterleaved_ != 0) ? TPL_GRAD_INTERLEAVED_TRUE : TPL_GRAD_INTERLEAVED_FALSE; | ||
| 120 | + uint64_t isGroupKey = (isGroup_ != 0) ? TPL_GRAD_GROUP_INDEX : TPL_GRAD_NO_GROUP_INDEX; | ||
| 121 | + return GET_TPL_TILING_KEY(isInterleavedKey, isGroupKey); | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +void ClippedSwigluGradTiling::DumpTilingInfo() | ||
| 125 | +{ | ||
| 126 | + std::ostringstream info; | ||
| 127 | + info << ", coreNumAll: " << tilingData_.get_coreNumAll(); | ||
| 128 | + info << ", ubSize_: " << ubSize_; | ||
| 129 | + info << ", xDims_: " << xDims_; | ||
| 130 | + info << ", cutDim_: " << cutDim_; | ||
| 131 | + info << ", dimBatchSize: " << tilingData_.get_dimBatchSize(); | ||
| 132 | + info << ", dim2H: " << tilingData_.get_dim2H(); | ||
| 133 | + info << ", isLongH: " << tilingData_.get_isLongH(); | ||
| 134 | + info << ", xCutDimNum_: " << xCutDimNum_; | ||
| 135 | + info << ", isGroup: " << tilingData_.get_isGroup(); | ||
| 136 | + info << ", isInterleaved: " << tilingData_.get_isInterleaved(); | ||
| 137 | + info << ", limit: " << tilingData_.get_limit(); | ||
| 138 | + info << ", alpha: " << tilingData_.get_alpha(); | ||
| 139 | + info << ", bias: " << tilingData_.get_bias(); | ||
| 140 | + info << ", ubMaxPair: " << tilingData_.get_ubMaxPair(); | ||
| 141 | + info << ", groupNum: " << tilingData_.get_groupNum(); | ||
| 142 | + OP_LOGI(context_->GetNodeName(), "%s", info.str().c_str()); | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +ge::graphStatus ClippedSwigluGradTiling::CheckAndGetXAndAttrs() | ||
| 146 | +{ | ||
| 147 | + auto* attrs = context_->GetAttrs(); | ||
| 148 | + OP_CHECK_NULL_WITH_CONTEXT(context_, attrs); | ||
| 149 | + auto* attrDim = attrs->GetAttrPointer<int>(DIM_INDEX); | ||
| 150 | + cutDim_ = attrDim == nullptr ? -1 : *attrDim; | ||
| 151 | + auto* attrAlpha = attrs->GetAttrPointer<float>(ALPHA_INDEX); | ||
| 152 | + alpha_ = attrAlpha == nullptr ? DEFAULT_ALPHA : *attrAlpha; | ||
| 153 | + auto* attrLimit = attrs->GetAttrPointer<float>(LIMIT_INDEX); | ||
| 154 | + limit_ = attrLimit == nullptr ? DEFAULT_LIMIT : *attrLimit; | ||
| 155 | + auto* attrBias = attrs->GetAttrPointer<float>(BIAS_INDEX); | ||
| 156 | + bias_ = attrBias == nullptr ? DEFAULT_BIAS : *attrBias; | ||
| 157 | + auto* attrInterleaved = attrs->GetAttrPointer<bool>(INTERLEAVED_INDEX); | ||
| 158 | + bool interleaved = attrInterleaved == nullptr ? true : *attrInterleaved; | ||
| 159 | + isInterleaved_ = interleaved ? 1 : 0; | ||
| 160 | + OP_CHECK_IF((limit_ <= 0.0f), OP_LOGE(context_->GetNodeName(), "limit must be > 0, but got %f.", limit_), | ||
| 161 | + return ge::GRAPH_FAILED); | ||
| 162 | + auto shapeX = context_->GetInputShape(X_INDEX); | ||
| 163 | + OP_CHECK_NULL_WITH_CONTEXT(context_, shapeX); | ||
| 164 | + const gert::Shape& inputShapeX = shapeX->GetStorageShape(); | ||
| 165 | + xDims_ = inputShapeX.GetDimNum(); | ||
| 166 | + OP_CHECK_IF( | ||
| 167 | + (cutDim_ > (xDims_ - 1) || cutDim_ < -1 * xDims_), | ||
| 168 | + OP_LOGE(context_->GetNodeName(), "dim should in [-%ld, %ld], but get %ld,", xDims_, xDims_ - 1, cutDim_), | ||
| 169 | + return ge::GRAPH_FAILED); | ||
| 170 | + cutDim_ = cutDim_ < 0 ? (cutDim_ + xDims_) : cutDim_; | ||
| 171 | + xCutDimNum_ = inputShapeX.GetDim(cutDim_); | ||
| 172 | + if (xDims_ == 1) { | ||
| 173 | + dimBatchSize_ = 1; | ||
| 174 | + dim2H_ = inputShapeX.GetDim(0); | ||
| 175 | + } else { | ||
| 176 | + for (int64_t i = 0; i < cutDim_; i++) { | ||
| 177 | + dimBatchSize_ *= inputShapeX.GetDim(i); | ||
| 178 | + } | ||
| 179 | + for (int64_t j = cutDim_; j < xDims_; j++) { | ||
| 180 | + dim2H_ *= inputShapeX.GetDim(j); | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + OP_CHECK_IF( | ||
| 184 | + (inputShapeX.GetDim(cutDim_) % 2 == 1), | ||
| 185 | + OP_LOGE(context_->GetNodeName(), "x[dim] should be divisible by 2, but get %ld", inputShapeX.GetDim(cutDim_)), | ||
| 186 | + return ge::GRAPH_FAILED); | ||
| 187 | + auto descX = context_->GetInputDesc(X_INDEX); | ||
| 188 | + OP_CHECK_NULL_WITH_CONTEXT(context_, descX); | ||
| 189 | + xDtype_ = descX->GetDataType(); | ||
| 190 | + OP_CHECK_IF((SUPPORT_DTYPE.find(xDtype_) == SUPPORT_DTYPE.end()), | ||
| 191 | + OP_LOGE(context_->GetNodeName(), "x dtype only support float, half or bfloat16, please check."), | ||
| 192 | + return ge::GRAPH_FAILED); | ||
| 193 | + auto shapeGradY = context_->GetInputShape(Y_GRAD_INDEX); | ||
| 194 | + OP_CHECK_NULL_WITH_CONTEXT(context_, shapeGradY); | ||
| 195 | + const gert::Shape& inputShapeGradY = shapeGradY->GetStorageShape(); | ||
| 196 | + OP_CHECK_IF((inputShapeGradY.GetDimNum() != xDims_), | ||
| 197 | + OP_LOGE(context_->GetNodeName(), "grad_y rank (%ld) should be equal to x rank (%ld).", | ||
| 198 | + inputShapeGradY.GetDimNum(), xDims_), | ||
| 199 | + return ge::GRAPH_FAILED); | ||
| 200 | + for (int64_t i = 0; i < xDims_; i++) { | ||
| 201 | + if (i == cutDim_) { | ||
| 202 | + OP_CHECK_IF((inputShapeGradY.GetDim(i) != inputShapeX.GetDim(i) / 2), | ||
| 203 | + OP_LOGE(context_->GetNodeName(), "grad_y dim %ld (%ld) should be half of x dim %ld (%ld).", i, | ||
| 204 | + inputShapeGradY.GetDim(i), i, inputShapeX.GetDim(i)), | ||
| 205 | + return ge::GRAPH_FAILED); | ||
| 206 | + } else { | ||
| 207 | + OP_CHECK_IF((inputShapeGradY.GetDim(i) != inputShapeX.GetDim(i)), | ||
| 208 | + OP_LOGE(context_->GetNodeName(), "grad_y dim %ld (%ld) should be equal to x dim %ld (%ld).", i, | ||
| 209 | + inputShapeGradY.GetDim(i), i, inputShapeX.GetDim(i)), | ||
| 210 | + return ge::GRAPH_FAILED); | ||
| 211 | + } | ||
| 212 | + } | ||
| 213 | + auto descGradY = context_->GetInputDesc(Y_GRAD_INDEX); | ||
| 214 | + OP_CHECK_NULL_WITH_CONTEXT(context_, descGradY); | ||
| 215 | + OP_CHECK_IF((descGradY->GetDataType() != xDtype_), | ||
| 216 | + OP_LOGE(context_->GetNodeName(), "grad_y dtype should be the same as x, please check."), | ||
| 217 | + return ge::GRAPH_FAILED); | ||
| 218 | + return ge::GRAPH_SUCCESS; | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | +ge::graphStatus ClippedSwigluGradTiling::CheckAndGetGroupIndex() | ||
| 222 | +{ | ||
| 223 | + auto shapeGroupIndex = context_->GetInputShape(GROUP_INDEX_INDEX); | ||
| 224 | + if (shapeGroupIndex == nullptr) { | ||
| 225 | + isGroup_ = 0; | ||
| 226 | + } else { | ||
| 227 | + const gert::Shape& inputShapeGroupIndex = shapeGroupIndex->GetStorageShape(); | ||
| 228 | + int64_t groupIndexDim = inputShapeGroupIndex.GetDimNum(); | ||
| 229 | + auto descGroupIndex = context_->GetInputDesc(GROUP_INDEX_INDEX); | ||
| 230 | + OP_CHECK_NULL_WITH_CONTEXT(context_, descGroupIndex); | ||
| 231 | + auto groupIndexDtype = descGroupIndex->GetDataType(); | ||
| 232 | + groupNum_ = inputShapeGroupIndex.GetDim(0); | ||
| 233 | + OP_LOGI(context_->GetNodeName(), "group_index: dim=%ld, groupNum=%ld, isNull=%d", groupIndexDim, groupNum_, | ||
| 234 | + shapeGroupIndex == nullptr); | ||
| 235 | + OP_CHECK_IF((groupIndexDim != 1), | ||
| 236 | + OP_LOGE(context_->GetNodeName(), | ||
| 237 | + "the number of dimensions of group_index should be 1, but get %ld.", groupIndexDim), | ||
| 238 | + return ge::GRAPH_FAILED); | ||
| 239 | + OP_CHECK_IF((groupIndexDtype != ge::DT_INT64), | ||
| 240 | + OP_LOGE(context_->GetNodeName(), "groupIndex dtype only support int64, please check."), | ||
| 241 | + return ge::GRAPH_FAILED); | ||
| 242 | + if (groupNum_ == 0) { | ||
| 243 | + isGroup_ = 0; | ||
| 244 | + } else { | ||
| 245 | + isGroup_ = 1; | ||
| 246 | + } | ||
| 247 | + } | ||
| 248 | + return ge::GRAPH_SUCCESS; | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | +ge::graphStatus ClippedSwigluGradTiling::CheckGradX() | ||
| 252 | +{ | ||
| 253 | + auto shapeGradX = context_->GetOutputShape(GRAD_X_INDEX); | ||
| 254 | + OP_CHECK_NULL_WITH_CONTEXT(context_, shapeGradX); | ||
| 255 | + const gert::Shape& outputShapeGradX = shapeGradX->GetStorageShape(); | ||
| 256 | + int64_t gradXDims = outputShapeGradX.GetDimNum(); | ||
| 257 | + auto descGradX = context_->GetInputDesc(GRAD_X_INDEX); | ||
| 258 | + OP_CHECK_NULL_WITH_CONTEXT(context_, descGradX); | ||
| 259 | + auto gradXDtype = descGradX->GetDataType(); | ||
| 260 | + OP_CHECK_IF( | ||
| 261 | + (gradXDims != xDims_), | ||
| 262 | + OP_LOGE(context_->GetNodeName(), | ||
| 263 | + "the number of dimensions of grad_x should be equal to dimensions of x, but get %ld.", gradXDims), | ||
| 264 | + return ge::GRAPH_FAILED); | ||
| 265 | + OP_CHECK_IF((gradXDtype != xDtype_), | ||
| 266 | + OP_LOGE(context_->GetNodeName(), "grad_x dtype should be the same as x, please cheack."), | ||
| 267 | + return ge::GRAPH_FAILED); | ||
| 268 | + return ge::GRAPH_SUCCESS; | ||
| 269 | +} | ||
| 270 | + | ||
| 271 | +ge::graphStatus ClippedSwigluGradTiling::CountMaxPair() | ||
| 272 | +{ | ||
| 273 | + ubMaxPair_ = 1; | ||
| 274 | + // UB 预算系数(单位:sizeof(float)=4 bytes per pair) | ||
| 275 | + // xBuffer: x (双缓冲, A+B两半) = DB*SWI = 4 | ||
| 276 | + // dyBuffer: dy (双缓冲, 半宽) = DB = 2 | ||
| 277 | + // dxBuffer: dx (单缓冲, 全宽) = SWI = 2 | ||
| 278 | + // tmpBuffer1/2: 中间计算量 (A+B两半) = SWI = 2 | ||
| 279 | + int64_t xBuffer = DB_BUFFER * SWI_FACTOR; | ||
| 280 | + int64_t dyBuffer = DB_BUFFER; | ||
| 281 | + int64_t dxBuffer = SWI_FACTOR; | ||
| 282 | + int64_t tmpBuffer1 = SWI_FACTOR; | ||
| 283 | + int64_t tmpBuffer2 = SWI_FACTOR; | ||
| 284 | + int64_t totalCoeff = xBuffer + dyBuffer + dxBuffer + tmpBuffer1 + tmpBuffer2; | ||
| 285 | + | ||
| 286 | + // group_index 直接从 GM GetValue 读取,不占用 UB | ||
| 287 | + int64_t numeratorNoMask = static_cast<int64_t>(ubSize_) - UB_RESERVE; | ||
| 288 | + int64_t prelimPair = ((numeratorNoMask / totalCoeff / BLOCK_SIZE * BLOCK_SIZE) - (BLOCK_SIZE - 1)) / SIZE_OF_FP32; | ||
| 289 | + | ||
| 290 | + // 第二步:用初步值算 mask buffer 大小 | ||
| 291 | + // CompareScalar 输出为 bitmask,1 bit/element,2 个 mask,对齐到 32B | ||
| 292 | + int64_t maskBytes = (prelimPair + BITS_PER_BYTE - 1) / BITS_PER_BYTE; | ||
| 293 | + int64_t maskBufSize = AlignUp(maskBytes, BLOCK_SIZE); | ||
| 294 | + if (maskBufSize < BLOCK_SIZE) { | ||
| 295 | + maskBufSize = BLOCK_SIZE; | ||
| 296 | + } | ||
| 297 | + int64_t maskBuffer = SWI_FACTOR * maskBufSize; | ||
| 298 | + | ||
| 299 | + // 第三步:减去 mask buffer,重新计算最终 ubMaxPair | ||
| 300 | + int64_t numerator = numeratorNoMask - maskBuffer; | ||
| 301 | + ubMaxPair_ = ((numerator / totalCoeff / BLOCK_SIZE * BLOCK_SIZE) - (BLOCK_SIZE - 1)) / SIZE_OF_FP32; | ||
| 302 | + | ||
| 303 | + // 对齐 ubMaxPair_ 到 64(CompareScalar 的 CMP_ALIGN),避免 alignedCount 越界 | ||
| 304 | + ubMaxPair_ = ubMaxPair_ / 64 * 64; | ||
| 305 | + | ||
| 306 | + // interleaved 路径限制 ubMaxPair_,避免 SetValue 标量循环过多导致精度问题 | ||
| 307 | + // interleaved 路径限制 ubMaxPair_,避免 SetValue 标量循环过多导致精度问题 | ||
| 308 | + if (isInterleaved_ == 1) { | ||
| 309 | + int64_t ilMaxPair = 2000; | ||
| 310 | + if (ubMaxPair_ > ilMaxPair) { | ||
| 311 | + ubMaxPair_ = ilMaxPair; | ||
| 312 | + } | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + OP_CHECK_IF((numerator <= 0 || ubMaxPair_ <= 0), | ||
| 316 | + OP_LOGE(context_->GetNodeName(), "Input not supported, groupNum is too large."), | ||
| 317 | + return ge::GRAPH_FAILED); | ||
| 318 | + isLongH_ = ubMaxPair_ * SWI_FACTOR < dim2H_ ? 1 : 0; | ||
| 319 | + if (isInterleaved_ == 0 && isLongH_ == 0) { | ||
| 320 | + int64_t sizeofT = (xDtype_ == ge::DT_FLOAT) ? 4 : 2; | ||
| 321 | + int64_t dimH = dim2H_ / SWI_FACTOR; | ||
| 322 | + if ((dimH * sizeofT) % BLOCK_SIZE != 0) { | ||
| 323 | + isLongH_ = 1; | ||
| 324 | + } | ||
| 325 | + } | ||
| 326 | + return ge::GRAPH_SUCCESS; | ||
| 327 | +} | ||
| 328 | + | ||
| 329 | +REGISTER_TILING_TEMPLATE("ClippedSwigluGrad", ClippedSwigluGradTiling, 20000); | ||
| 330 | + | ||
| 331 | +ge::graphStatus TilingForClippedSwigluGrad(gert::TilingContext* context) | ||
| 332 | +{ | ||
| 333 | + // 第一版统一实现,所有平台共用一套 tiling,不区分 arch35 | ||
| 334 | + return TilingRegistry::GetInstance().DoTilingImpl(context); | ||
| 335 | +} | ||
| 336 | + | ||
| 337 | +ge::graphStatus TilingPrepareForClippedSwigluGrad(gert::TilingParseContext* context) | ||
| 338 | +{ | ||
| 339 | + OP_LOGD(context, "TilingPrepareForClippedSwigluGrad enter."); | ||
| 340 | + auto compileInfo = context->GetCompiledInfo<ClippedSwigluGradCompileInfo>(); | ||
| 341 | + OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | ||
| 342 | + auto platformInfo = context->GetPlatformInfo(); | ||
| 343 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | ||
| 344 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 345 | + compileInfo->coreNum = ascendcPlatform.GetCoreNumAiv(); | ||
| 346 | + OP_CHECK_IF((compileInfo->coreNum <= 0), | ||
| 347 | + OP_LOGE(context->GetNodeName(), "Get core num failed, core num: %u", | ||
| 348 | + static_cast<uint32_t>(compileInfo->coreNum)), | ||
| 349 | + return ge::GRAPH_FAILED); | ||
| 350 | + | ||
| 351 | + uint64_t ubSize; | ||
| 352 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); | ||
| 353 | + compileInfo->ubSize = ubSize; | ||
| 354 | + OP_CHECK_IF( | ||
| 355 | + (compileInfo->ubSize <= 0), | ||
| 356 | + OP_LOGE(context->GetNodeName(), "Get ub size failed, ub size: %u", static_cast<uint32_t>(compileInfo->ubSize)), | ||
| 357 | + return ge::GRAPH_FAILED); | ||
| 358 | + | ||
| 359 | + OP_LOGD(context, "TilingPrepareForClippedSwigluGrad exit."); | ||
| 360 | + return ge::GRAPH_SUCCESS; | ||
| 361 | +} | ||
| 362 | + | ||
| 363 | +IMPL_OP_OPTILING(ClippedSwigluGrad) | ||
| 364 | + .Tiling(TilingForClippedSwigluGrad) | ||
| 365 | + .TilingParse<ClippedSwigluGradCompileInfo>(TilingPrepareForClippedSwigluGrad); | ||
| 366 | +} // namespace optiling | ||
| @@ -0,0 +1,95 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file clipped_swiglu_grad_tiling.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | +#ifndef AIR_CXX_RUNTIME_V2_OP_IMPL_CLIPPED_SWIGLU_GRAD_H_ | ||
| 16 | +#define AIR_CXX_RUNTIME_V2_OP_IMPL_CLIPPED_SWIGLU_GRAD_H_ | ||
| 17 | + | ||
| 18 | +#include "register/op_impl_registry.h" | ||
| 19 | +#include "util/math_util.h" | ||
| 20 | +#include "log/log.h" | ||
| 21 | +#include "tiling/platform/platform_ascendc.h" | ||
| 22 | +#include "platform/platform_infos_def.h" | ||
| 23 | +#include "register/tilingdata_base.h" | ||
| 24 | +#include "tiling/tiling_api.h" | ||
| 25 | +#include "../op_graph/clipped_swiglu_grad_proto.h" | ||
| 26 | +#include "op_host/tiling_base.h" | ||
| 27 | +#include "op_host/tiling_templates_registry.h" | ||
| 28 | +#include "op_host/tiling_util.h" | ||
| 29 | + | ||
| 30 | +namespace optiling { | ||
| 31 | +using Ops::NN::Optiling::TilingBaseClass; | ||
| 32 | +BEGIN_TILING_DATA_DEF(ClippedSwigluGradTilingData) | ||
| 33 | +TILING_DATA_FIELD_DEF(int64_t, coreNumAll); | ||
| 34 | +TILING_DATA_FIELD_DEF(int64_t, dimBatchSize); | ||
| 35 | +TILING_DATA_FIELD_DEF(int64_t, dim2H); | ||
| 36 | +TILING_DATA_FIELD_DEF(int64_t, isLongH); | ||
| 37 | +TILING_DATA_FIELD_DEF(int64_t, isGroup); | ||
| 38 | +TILING_DATA_FIELD_DEF(int64_t, isInterleaved); | ||
| 39 | +TILING_DATA_FIELD_DEF(float, alpha); | ||
| 40 | +TILING_DATA_FIELD_DEF(float, limit); | ||
| 41 | +TILING_DATA_FIELD_DEF(float, bias); | ||
| 42 | +TILING_DATA_FIELD_DEF(int64_t, ubMaxPair); | ||
| 43 | +TILING_DATA_FIELD_DEF(int64_t, groupNum); | ||
| 44 | +END_TILING_DATA_DEF; | ||
| 45 | + | ||
| 46 | +REGISTER_TILING_DATA_CLASS(ClippedSwigluGrad, ClippedSwigluGradTilingData) | ||
| 47 | + | ||
| 48 | +struct ClippedSwigluGradCompileInfo { | ||
| 49 | + uint64_t coreNum = 0; | ||
| 50 | + uint64_t ubSize = 0; | ||
| 51 | +}; | ||
| 52 | + | ||
| 53 | +class ClippedSwigluGradTiling : public TilingBaseClass { | ||
| 54 | +public: | ||
| 55 | + explicit ClippedSwigluGradTiling(gert::TilingContext* tilingContext) : TilingBaseClass(tilingContext) {} | ||
| 56 | + ~ClippedSwigluGradTiling() override {} | ||
| 57 | + | ||
| 58 | +protected: | ||
| 59 | + bool IsCapable() override; | ||
| 60 | + ge::graphStatus GetPlatformInfo() override; | ||
| 61 | + ge::graphStatus GetShapeAttrsInfo() override; | ||
| 62 | + ge::graphStatus DoOpTiling() override; | ||
| 63 | + ge::graphStatus DoLibApiTiling() override; | ||
| 64 | + uint64_t GetTilingKey() const override; | ||
| 65 | + ge::graphStatus GetWorkspaceSize() override; | ||
| 66 | + ge::graphStatus PostTiling() override; | ||
| 67 | + void DumpTilingInfo() override; | ||
| 68 | + ge::graphStatus CheckAndGetXAndAttrs(); | ||
| 69 | + ge::graphStatus CheckAndGetGroupIndex(); | ||
| 70 | + ge::graphStatus CheckGradX(); | ||
| 71 | + ge::graphStatus CountMaxPair(); | ||
| 72 | + void SetTilingData(); | ||
| 73 | + | ||
| 74 | +private: | ||
| 75 | + ClippedSwigluGradTilingData tilingData_; | ||
| 76 | + uint64_t coreNumAll_ = 0; | ||
| 77 | + uint64_t ubSize_ = 0; | ||
| 78 | + int64_t xDims_ = 0; | ||
| 79 | + int64_t cutDim_ = 0; | ||
| 80 | + int64_t dimBatchSize_ = 1; | ||
| 81 | + int64_t dim2H_ = 1; | ||
| 82 | + int64_t isLongH_ = 0; | ||
| 83 | + int64_t xCutDimNum_ = 0; | ||
| 84 | + ge::DataType xDtype_ = ge::DT_FLOAT; | ||
| 85 | + int64_t isGroup_ = 0; | ||
| 86 | + int64_t isInterleaved_ = 1; | ||
| 87 | + float limit_ = 0.0; | ||
| 88 | + float alpha_ = 0.0; | ||
| 89 | + float bias_ = 0.0; | ||
| 90 | + int64_t ubMaxPair_ = 0; | ||
| 91 | + int64_t groupNum_ = 0; | ||
| 92 | +}; | ||
| 93 | + | ||
| 94 | +} // namespace optiling | ||
| 95 | +#endif // AIR_CXX_RUNTIME_V2_OP_IMPL_CLIPPED_SWIGLU_GRAD_H_ | ||
| @@ -0,0 +1,87 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "ClippedSwigluGrad", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "ClippedSwigluGrad_fp16", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "y_grad", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "float16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [-2] | ||
| 14 | + }, | ||
| 15 | + { | ||
| 16 | + "name": "x", | ||
| 17 | + "index": 1, | ||
| 18 | + "dtype": "float16", | ||
| 19 | + "format": "ND", | ||
| 20 | + "paramType": "required", | ||
| 21 | + "shape": [-2] | ||
| 22 | + }, | ||
| 23 | + { | ||
| 24 | + "name": "group_index", | ||
| 25 | + "index": 2, | ||
| 26 | + "dtype": "int64", | ||
| 27 | + "format": "ND", | ||
| 28 | + "paramType": "optional", | ||
| 29 | + "shape": [-2] | ||
| 30 | + } | ||
| 31 | + ], | ||
| 32 | + "outputs": [ | ||
| 33 | + { | ||
| 34 | + "name": "x_grad", | ||
| 35 | + "index": 0, | ||
| 36 | + "dtype": "float16", | ||
| 37 | + "format": "ND", | ||
| 38 | + "paramType": "required", | ||
| 39 | + "shape": [-2] | ||
| 40 | + } | ||
| 41 | + ], | ||
| 42 | + "attrs": [ | ||
| 43 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 44 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 45 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 46 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 47 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 48 | + ] | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + "bin_filename": "ClippedSwigluGrad_fp32", | ||
| 52 | + "inputs": [ | ||
| 53 | + { "name": "y_grad", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 54 | + { "name": "x", "index": 1, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 55 | + { "name": "group_index", "index": 2, "dtype": "int64", "format": "ND", "paramType": "optional", "shape": [-2] } | ||
| 56 | + ], | ||
| 57 | + "outputs": [ | ||
| 58 | + { "name": "x_grad", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] } | ||
| 59 | + ], | ||
| 60 | + "attrs": [ | ||
| 61 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 62 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 63 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 64 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 65 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 66 | + ] | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + "bin_filename": "ClippedSwigluGrad_bf16", | ||
| 70 | + "inputs": [ | ||
| 71 | + { "name": "y_grad", "index": 0, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 72 | + { "name": "x", "index": 1, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 73 | + { "name": "group_index", "index": 2, "dtype": "int64", "format": "ND", "paramType": "optional", "shape": [-2] } | ||
| 74 | + ], | ||
| 75 | + "outputs": [ | ||
| 76 | + { "name": "x_grad", "index": 0, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] } | ||
| 77 | + ], | ||
| 78 | + "attrs": [ | ||
| 79 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 80 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 81 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 82 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 83 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 84 | + ] | ||
| 85 | + } | ||
| 86 | + ] | ||
| 87 | +} | ||
| @@ -0,0 +1,87 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "ClippedSwigluGrad", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "ClippedSwigluGrad_fp16", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "y_grad", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "float16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [-2] | ||
| 14 | + }, | ||
| 15 | + { | ||
| 16 | + "name": "x", | ||
| 17 | + "index": 1, | ||
| 18 | + "dtype": "float16", | ||
| 19 | + "format": "ND", | ||
| 20 | + "paramType": "required", | ||
| 21 | + "shape": [-2] | ||
| 22 | + }, | ||
| 23 | + { | ||
| 24 | + "name": "group_index", | ||
| 25 | + "index": 2, | ||
| 26 | + "dtype": "int64", | ||
| 27 | + "format": "ND", | ||
| 28 | + "paramType": "optional", | ||
| 29 | + "shape": [-2] | ||
| 30 | + } | ||
| 31 | + ], | ||
| 32 | + "outputs": [ | ||
| 33 | + { | ||
| 34 | + "name": "x_grad", | ||
| 35 | + "index": 0, | ||
| 36 | + "dtype": "float16", | ||
| 37 | + "format": "ND", | ||
| 38 | + "paramType": "required", | ||
| 39 | + "shape": [-2] | ||
| 40 | + } | ||
| 41 | + ], | ||
| 42 | + "attrs": [ | ||
| 43 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 44 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 45 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 46 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 47 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 48 | + ] | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + "bin_filename": "ClippedSwigluGrad_fp32", | ||
| 52 | + "inputs": [ | ||
| 53 | + { "name": "y_grad", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 54 | + { "name": "x", "index": 1, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 55 | + { "name": "group_index", "index": 2, "dtype": "int64", "format": "ND", "paramType": "optional", "shape": [-2] } | ||
| 56 | + ], | ||
| 57 | + "outputs": [ | ||
| 58 | + { "name": "x_grad", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] } | ||
| 59 | + ], | ||
| 60 | + "attrs": [ | ||
| 61 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 62 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 63 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 64 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 65 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 66 | + ] | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + "bin_filename": "ClippedSwigluGrad_bf16", | ||
| 70 | + "inputs": [ | ||
| 71 | + { "name": "y_grad", "index": 0, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 72 | + { "name": "x", "index": 1, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 73 | + { "name": "group_index", "index": 2, "dtype": "int64", "format": "ND", "paramType": "optional", "shape": [-2] } | ||
| 74 | + ], | ||
| 75 | + "outputs": [ | ||
| 76 | + { "name": "x_grad", "index": 0, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] } | ||
| 77 | + ], | ||
| 78 | + "attrs": [ | ||
| 79 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 80 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 81 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 82 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 83 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 84 | + ] | ||
| 85 | + } | ||
| 86 | + ] | ||
| 87 | +} | ||
| @@ -0,0 +1,87 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "ClippedSwigluGrad", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "ClippedSwigluGrad_fp16", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "y_grad", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "float16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [-2] | ||
| 14 | + }, | ||
| 15 | + { | ||
| 16 | + "name": "x", | ||
| 17 | + "index": 1, | ||
| 18 | + "dtype": "float16", | ||
| 19 | + "format": "ND", | ||
| 20 | + "paramType": "required", | ||
| 21 | + "shape": [-2] | ||
| 22 | + }, | ||
| 23 | + { | ||
| 24 | + "name": "group_index", | ||
| 25 | + "index": 2, | ||
| 26 | + "dtype": "int64", | ||
| 27 | + "format": "ND", | ||
| 28 | + "paramType": "optional", | ||
| 29 | + "shape": [-2] | ||
| 30 | + } | ||
| 31 | + ], | ||
| 32 | + "outputs": [ | ||
| 33 | + { | ||
| 34 | + "name": "x_grad", | ||
| 35 | + "index": 0, | ||
| 36 | + "dtype": "float16", | ||
| 37 | + "format": "ND", | ||
| 38 | + "paramType": "required", | ||
| 39 | + "shape": [-2] | ||
| 40 | + } | ||
| 41 | + ], | ||
| 42 | + "attrs": [ | ||
| 43 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 44 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 45 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 46 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 47 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 48 | + ] | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + "bin_filename": "ClippedSwigluGrad_fp32", | ||
| 52 | + "inputs": [ | ||
| 53 | + { "name": "y_grad", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 54 | + { "name": "x", "index": 1, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 55 | + { "name": "group_index", "index": 2, "dtype": "int64", "format": "ND", "paramType": "optional", "shape": [-2] } | ||
| 56 | + ], | ||
| 57 | + "outputs": [ | ||
| 58 | + { "name": "x_grad", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [-2] } | ||
| 59 | + ], | ||
| 60 | + "attrs": [ | ||
| 61 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 62 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 63 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 64 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 65 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 66 | + ] | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + "bin_filename": "ClippedSwigluGrad_bf16", | ||
| 70 | + "inputs": [ | ||
| 71 | + { "name": "y_grad", "index": 0, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 72 | + { "name": "x", "index": 1, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] }, | ||
| 73 | + { "name": "group_index", "index": 2, "dtype": "int64", "format": "ND", "paramType": "optional", "shape": [-2] } | ||
| 74 | + ], | ||
| 75 | + "outputs": [ | ||
| 76 | + { "name": "x_grad", "index": 0, "dtype": "bfloat16", "format": "ND", "paramType": "required", "shape": [-2] } | ||
| 77 | + ], | ||
| 78 | + "attrs": [ | ||
| 79 | + { "name": "dim", "dtype": "int64", "value": -1 }, | ||
| 80 | + { "name": "alpha", "dtype": "float32", "value": 1.702 }, | ||
| 81 | + { "name": "limit", "dtype": "float32", "value": 7.0 }, | ||
| 82 | + { "name": "bias", "dtype": "float32", "value": 1.0 }, | ||
| 83 | + { "name": "interleaved", "dtype": "bool", "value": true } | ||
| 84 | + ] | ||
| 85 | + } | ||
| 86 | + ] | ||
| 87 | +} | ||
Rcommon/src/framework/logsoftmax_onnx_plugin.cpp→activation/log_softmax_v2/framework/logsoftmax_onnx_plugin.cpp+44-44
Rtorch_extension/tests/utils/common.py→activation/situ_glu/tests/pytest/test_situ_glu_network.py+64-27
Rindex/scatter_nd_update/tests/st/aclnnScatterNd/executor_aclnnScatterNd.py→activation/situ_glu/tests/st/aclnnSituGlu/executor_aclnnSituGlu.py+75-56File content is under review, please try again later
Rindex/scatter_nd_update/examples/test_aclnn_scatter_nd.cpp→index/scatter_nd/examples/test_aclnn_scatter_nd.cpp+0-0
Rindex/scatter_nd_update/tests/ut/op_api/test_aclnn_scatter_nd.cpp→index/scatter_nd/tests/ut/op_api/test_aclnn_scatter_nd.cpp+1-1
Rcommon/src/framework/unique_onnx_plugin.cpp→index/unique_with_counts_and_sorting/framework/unique_onnx_plugin.cpp+0-0
Rcommon/src/framework/batch_matmul_onnx_plugin.cpp→matmul/batch_mat_mul_v3/framework/batch_matmul_onnx_plugin.cpp+37-37
Rcommon/src/framework/matmul_onnx_plugin.cpp→matmul/mat_mul_v3/framework/matmul_onnx_plugin.cpp+67-67
Rcommon/src/framework/batch_normalization_onnx_plugin.cpp→norm/batch_norm/framework/batch_normalization_onnx_plugin.cpp+64-64
Rindex/index_fill_d/op_host/op_api/index_fill.h→norm/bn_training_update_v2/framework/bn_training_update_v2_tf_plugin.cpp+13-16
Rcommon/src/framework/instancenormalization_onnx_plugin.cpp→norm/instance_norm_v3/framework/instancenormalization_onnx_plugin.cpp+47-47
Rindex/scatter_add/op_host/op_api/scatter_add.h→optim/inplace_apply_proximal_adagrad/op_host/arch35/inplace_apply_proximal_adagrad_tiling_arch35.h+14-10
Rcommon/src/framework/adaptive_average_pool2d_onnx_plugin.cpp→pooling/adaptive_avg_pool2d/framework/adaptive_average_pool2d_onnx_plugin.cpp+62-62
Rcommon/src/framework/adaptive_max_pool2d_onnx_plugin.cpp→pooling/adaptive_max_pool2d/framework/adaptive_max_pool2d_onnx_plugin.cpp+62-62
Rloss/multilabel_margin_loss/op_kernel/multilabel_margin_loss.cpp→pooling/avg_pool1_d/op_kernel/arch35/avg_pool1_d.cpp+13-15
Rindex/scatter_nd_update/op_api/aclnn_scatter_nd.h→pooling/avg_pool1_d/tests/ut/op_kernel/avg_pool1_d_tiling_def.h+19-27
Rcommon/src/framework/ascend_anti_quant_onnx_plugin.cpp→quant/ascend_anti_quant/framework/ascend_anti_quant_onnx_plugin.cpp+76-76
Rcommon/src/framework/ascend_dequant_onnx_plugin.cpp→quant/ascend_dequant/framework/ascend_dequant_onnx_plugin.cpp+76-76
Rcommon/src/framework/ascend_quant_onnx_plugin.cpp→quant/ascend_quant/framework/ascend_quant_onnx_plugin.cpp+98-98
Rcommon/src/framework/int8_quantize_onnx_plugin.cpp→quant/ascend_quant/framework/int8_quantize_onnx_plugin.cpp+73-73