已合并
修改index、index_put_v2算子aclnn接口L2调用点,增加IndexCheck越界检查 #4957
BoyangZhang创建于 5月18日
修改index、index_put_v2算子aclnn接口L2调用点,增加IndexCheck越界检查 #4957
已合并
共 14 个文件变更+104-40
| @@ -11,4 +11,4 @@ | |||
| 11 | set(SUPPORT_COMPUTE_UNIT "ascend950") | 11 | set(SUPPORT_COMPUTE_UNIT "ascend950") |
| 12 | # 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 | 12 | # 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 13 | set(SUPPORT_TILING_DIR "arch35") | 13 | set(SUPPORT_TILING_DIR "arch35") |
| 14 | -add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE index ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE DEPENDENCIES gather_v2) | 14 | +add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE index ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE DEPENDENCIES gather_v2 index_check) |
| @@ -14,6 +14,7 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | 20 | ||
| @@ -427,6 +428,13 @@ const aclTensor* CallKernel(const aclTensor* self, const aclTensor* out, const I | |||
| 427 | auto indicesDimNum = indicesInfo.allDefinedIndices[0]->GetViewShape().GetDimNum(); | 428 | auto indicesDimNum = indicesInfo.allDefinedIndices[0]->GetViewShape().GetDimNum(); |
| 428 | auto perm = GetPerm(indicesInfo.masksNum, indicesInfo.indicesNum, selfDimNum, executor); | 429 | auto perm = GetPerm(indicesInfo.masksNum, indicesInfo.indicesNum, selfDimNum, executor); |
| 429 | selfContiguous = l0op::Transpose(selfContiguous, perm, executor); | 430 | selfContiguous = l0op::Transpose(selfContiguous, perm, executor); |
| 431 | + FVector<int64_t, MAX_SUPPORT_DIMS_NUMS> boundsVec; | ||
| 432 | + for (size_t i = 0; i < selfContiguous->GetViewShape().GetDimNum(); i++) { | ||
| 433 | + boundsVec.emplace_back(selfContiguous->GetViewShape().GetDim(i)); | ||
| 434 | + } | ||
| 435 | + auto boundsArray = executor->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 436 | + auto boundsTensor = executor->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 437 | + l0op::IndexCheck(boundsTensor, IndicesTensorList, executor); | ||
| 430 | opOut = l0op::IndexAiCore( | 438 | opOut = l0op::IndexAiCore( |
| 431 | selfContiguous, indexedSizes, indexedStrides, chooseInfo.outputShape, IndicesTensorList, executor); | 439 | selfContiguous, indexedSizes, indexedStrides, chooseInfo.outputShape, IndicesTensorList, executor); |
| 432 | auto permBack = GetPermBack(indicesInfo.masksNum - indicesInfo.indicesNum, indicesDimNum, outDimNum, executor); | 440 | auto permBack = GetPermBack(indicesInfo.masksNum - indicesInfo.indicesNum, indicesDimNum, outDimNum, executor); |
| @@ -439,13 +447,48 @@ const aclTensor* CallKernel(const aclTensor* self, const aclTensor* out, const I | |||
| 439 | } else if (chooseInfo.isNonContiguous) { | 447 | } else if (chooseInfo.isNonContiguous) { |
| 440 | auto newself = executor->CreateView( | 448 | auto newself = executor->CreateView( |
| 441 | self, self->GetViewShape(), self->GetStorageShape(), self->GetViewStrides(), self->GetViewOffset()); | 449 | self, self->GetViewShape(), self->GetStorageShape(), self->GetViewStrides(), self->GetViewOffset()); |
| 450 | + FVector<int64_t, MAX_SUPPORT_DIMS_NUMS> boundsVec; | ||
| 451 | + for (size_t i = 0; i < newself->GetViewShape().GetDimNum(); i++) { | ||
| 452 | + boundsVec.emplace_back(newself->GetViewShape().GetDim(i)); | ||
| 453 | + } | ||
| 454 | + auto boundsArray = executor->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 455 | + auto boundsTensor = executor->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 456 | + l0op::IndexCheck(boundsTensor, IndicesTensorList, executor); | ||
| 442 | opOut = l0op::IndexAiCore( | 457 | opOut = l0op::IndexAiCore( |
| 443 | newself, indexedSizes, indexedStrides, chooseInfo.outputShape, IndicesTensorList, executor); | 458 | newself, indexedSizes, indexedStrides, chooseInfo.outputShape, IndicesTensorList, executor); |
| 444 | } else { | 459 | } else { |
| 460 | + FVector<int64_t, MAX_SUPPORT_DIMS_NUMS> boundsVec; | ||
| 461 | + for (size_t i = 0; i < selfContiguous->GetViewShape().GetDimNum(); i++) { | ||
| 462 | + boundsVec.emplace_back(selfContiguous->GetViewShape().GetDim(i)); | ||
| 463 | + } | ||
| 464 | + auto boundsArray = executor->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 465 | + auto boundsTensor = executor->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 466 | + l0op::IndexCheck(boundsTensor, IndicesTensorList, executor); | ||
| 445 | opOut = l0op::IndexAiCore( | 467 | opOut = l0op::IndexAiCore( |
| 446 | selfContiguous, indexedSizes, indexedStrides, chooseInfo.outputShape, IndicesTensorList, executor); | 468 | selfContiguous, indexedSizes, indexedStrides, chooseInfo.outputShape, IndicesTensorList, executor); |
| 447 | } | 469 | } |
| 448 | } else { | 470 | } else { |
| 471 | + bool hasBoolIndices = false; | ||
| 472 | + for (size_t i = 0; i < indicesInfo.indicesNum; i++) { | ||
| 473 | + if (indicesInfo.allDefinedIndices[i]->GetDataType() == op::DataType::DT_BOOL) { | ||
| 474 | + hasBoolIndices = true; | ||
| 475 | + break; | ||
| 476 | + } | ||
| 477 | + } | ||
| 478 | + if (!hasBoolIndices) { | ||
| 479 | + FVector<int64_t, MAX_SUPPORT_DIMS_NUMS> boundsVec; | ||
| 480 | + const aclTensor* boundsSelf = selfContiguous; | ||
| 481 | + if (chooseInfo.isNonContiguous) { | ||
| 482 | + boundsSelf = executor->CreateView( | ||
| 483 | + self, self->GetViewShape(), self->GetStorageShape(), self->GetViewStrides(), self->GetViewOffset()); | ||
| 484 | + } | ||
| 485 | + for (size_t i = 0; i < boundsSelf->GetViewShape().GetDimNum(); i++) { | ||
| 486 | + boundsVec.emplace_back(boundsSelf->GetViewShape().GetDim(i)); | ||
| 487 | + } | ||
| 488 | + auto boundsArray = executor->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 489 | + auto boundsTensor = executor->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 490 | + l0op::IndexCheck(boundsTensor, IndicesTensorList, executor); | ||
| 491 | + } | ||
| 449 | if (selfContiguous->GetViewShape().GetDimNum() == 0) { | 492 | if (selfContiguous->GetViewShape().GetDimNum() == 0) { |
| 450 | opOut = selfContiguous; | 493 | opOut = selfContiguous; |
| 451 | } else { | 494 | } else { |
| @@ -1,4 +1,4 @@ | |||
| 1 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 1 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 2 | # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | 2 | # 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"). | 3 | # CANN Open Software License Agreement Version 2.0 (the "License"). |
| 4 | # Please refer to the License for details. You can not use this file except in compliance with the License. | 4 | # Please refer to the License for details. You can not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -1,14 +0,0 @@ | |||
| 1 | -; 该文件主要影响 asc_opc 工具 编译二进制kernel时,--simplified_key_mode 选项中填写的值,格式如下所示: | ||
| 2 | -; [某算子] | ||
| 3 | -; default=xx | ||
| 4 | -; ascendxx=xx | ||
| 5 | -; 其中,default为默认mode,ascendxx为可选mode,如果不同芯片有差异化要求时,需要配置; | ||
| 6 | -; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理 | ||
| 7 | -; 2)如果仅有default配置:各个版本按default配置 | ||
| 8 | -; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理 | ||
| 9 | -; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。 | ||
| 10 | -; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式 | ||
| 11 | -; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定 | ||
| 12 | - | ||
| 13 | -[IndexCheck] | ||
| 14 | -default=0 | ||
| @@ -1,14 +0,0 @@ | |||
| 1 | -; 该文件主要影响 asc_opc 工具 编译二进制kernel时,--simplified_key_mode 选项中填写的值,格式如下所示: | ||
| 2 | -; [某算子] | ||
| 3 | -; default=xx | ||
| 4 | -; ascendxx=xx | ||
| 5 | -; 其中,default为默认mode,ascendxx为可选mode,如果不同芯片有差异化要求时,需要配置; | ||
| 6 | -; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理 | ||
| 7 | -; 2)如果仅有default配置:各个版本按default配置 | ||
| 8 | -; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理 | ||
| 9 | -; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。 | ||
| 10 | -; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式 | ||
| 11 | -; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定 | ||
| 12 | - | ||
| 13 | -[IndexCheck] | ||
| 14 | -default=0 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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. |
| @@ -13,4 +13,4 @@ | |||
| 13 | set(SUPPORT_COMPUTE_UNIT "ascend950") | 13 | set(SUPPORT_COMPUTE_UNIT "ascend950") |
| 14 | # 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 | 14 | # 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 15 | set(SUPPORT_TILING_DIR "arch35") | 15 | set(SUPPORT_TILING_DIR "arch35") |
| 16 | -add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE index_put_v2 ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE DEPENDENCIES index index_put index_put_with_sort index_put_with_sort_v2) | 16 | +add_modules_sources(HOSTNAME ${OPHOST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR} OPTYPE index_put_v2 ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE DEPENDENCIES index index_put index_put_with_sort index_put_with_sort_v2 index_check) |
| @@ -14,6 +14,7 @@ | |||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | 20 | ||
| @@ -461,12 +462,26 @@ static const aclTensor* AicoreCompute(const aclTensor *selfCast, const FVector<c | |||
| 461 | } | 462 | } |
| 462 | auto maskarray = executor->AllocIntArray(masks_final.data(), indicesNum); | 463 | auto maskarray = executor->AllocIntArray(masks_final.data(), indicesNum); |
| 463 | auto masktensor_trans = executor->ConvertToTensor(maskarray, op::ToOpDataType(ACL_INT64)); | 464 | auto masktensor_trans = executor->ConvertToTensor(maskarray, op::ToOpDataType(ACL_INT64)); |
| 465 | + FVector<int64_t, DIMLIMIT> boundsVec; | ||
| 466 | + for (size_t i = 0; i < selfCast->GetViewShape().GetDimNum(); i++) { | ||
| 467 | + boundsVec.emplace_back(selfCast->GetViewShape().GetDim(i)); | ||
| 468 | + } | ||
| 469 | + auto boundsArray = executor->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 470 | + auto boundsTensor = executor->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 471 | + l0op::IndexCheck(boundsTensor, indicesTensorList, executor); | ||
| 464 | indexPutOpOut = l0op::IndexPutV2(selfCast, indicesTensorList, valueBroadcast, masktensor_trans, | 472 | indexPutOpOut = l0op::IndexPutV2(selfCast, indicesTensorList, valueBroadcast, masktensor_trans, |
| 465 | accumulate, out, executor); | 473 | accumulate, out, executor); |
| 466 | auto permback = GetPermBack(masksNum, indicesNum, selfDimNum, executor); | 474 | auto permback = GetPermBack(masksNum, indicesNum, selfDimNum, executor); |
| 467 | indexPutOpOut = l0op::Transpose(indexPutOpOut, permback, executor); | 475 | indexPutOpOut = l0op::Transpose(indexPutOpOut, permback, executor); |
| 468 | } else { | 476 | } else { |
| 469 | aclTensor* out = const_cast<aclTensor*>(selfCast); | 477 | aclTensor* out = const_cast<aclTensor*>(selfCast); |
| 478 | + FVector<int64_t, DIMLIMIT> boundsVec; | ||
| 479 | + for (size_t i = 0; i < selfCast->GetViewShape().GetDimNum(); i++) { | ||
| 480 | + boundsVec.emplace_back(selfCast->GetViewShape().GetDim(i)); | ||
| 481 | + } | ||
| 482 | + auto boundsArray = executor->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 483 | + auto boundsTensor = executor->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 484 | + l0op::IndexCheck(boundsTensor, indicesTensorList, executor); | ||
| 470 | indexPutOpOut = l0op::IndexPutV2(selfCast, indicesTensorList, valueBroadcast, maskTensor, | 485 | indexPutOpOut = l0op::IndexPutV2(selfCast, indicesTensorList, valueBroadcast, maskTensor, |
| 471 | accumulate, out, executor); | 486 | accumulate, out, executor); |
| 472 | } | 487 | } |
| @@ -1380,6 +1395,22 @@ aclnnStatus aclnnIndexPutImplGetWorkspaceSize(aclTensor *selfRef, | |||
| 1380 | // 调用IndexPut算子kernel | 1395 | // 调用IndexPut算子kernel |
| 1381 | bool isSupportAiCpu = IsAiCPUSupport(selfRef, allDefinedIndices, values, accumulate, masks); | 1396 | bool isSupportAiCpu = IsAiCPUSupport(selfRef, allDefinedIndices, values, accumulate, masks); |
| 1382 | if (isSupportAiCpu) { | 1397 | if (isSupportAiCpu) { |
| 1398 | + bool hasBoolIndices = false; | ||
| 1399 | + for (size_t i = 0; i < allDefinedIndices.size(); i++) { | ||
| 1400 | + if (allDefinedIndices[i]->GetDataType() == op::DataType::DT_BOOL) { | ||
| 1401 | + hasBoolIndices = true; | ||
| 1402 | + break; | ||
| 1403 | + } | ||
| 1404 | + } | ||
| 1405 | + if (!hasBoolIndices) { | ||
| 1406 | + FVector<int64_t, DIMLIMIT> boundsVec; | ||
| 1407 | + for (size_t i = 0; i < selfCast->GetViewShape().GetDimNum(); i++) { | ||
| 1408 | + boundsVec.emplace_back(selfCast->GetViewShape().GetDim(i)); | ||
| 1409 | + } | ||
| 1410 | + auto boundsArray = uniqueExecutor.get()->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 1411 | + auto boundsTensor = uniqueExecutor.get()->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 1412 | + l0op::IndexCheck(boundsTensor, indicesTensorList, uniqueExecutor.get()); | ||
| 1413 | + } | ||
| 1383 | aclTensor* out = const_cast<aclTensor*>(selfCast); | 1414 | aclTensor* out = const_cast<aclTensor*>(selfCast); |
| 1384 | if(deterministicValue != 0) { | 1415 | if(deterministicValue != 0) { |
| 1385 | indexPutOpOut = l0op::IndexPutV3(selfCast, indicesTensorList, valuesCast, maskTensor, | 1416 | indexPutOpOut = l0op::IndexPutV3(selfCast, indicesTensorList, valuesCast, maskTensor, |
| @@ -1429,6 +1460,25 @@ aclnnStatus aclnnIndexPutImplGetWorkspaceSize(aclTensor *selfRef, | |||
| 1429 | // values做broadcast操作 | 1460 | // values做broadcast操作 |
| 1430 | auto valueBroadcast = valuesToBroadcast(indicesSize, selfCast, indices, definedIndices, valuesCast, uniqueExecutor.get()); | 1461 | auto valueBroadcast = valuesToBroadcast(indicesSize, selfCast, indices, definedIndices, valuesCast, uniqueExecutor.get()); |
| 1431 | 1462 | ||
| 1463 | + // 添加IndexCheck,确保索引不越界 | ||
| 1464 | + bool hasBoolIndices = false; | ||
| 1465 | + for (size_t i = 0; i < definedIndices.size(); i++) { | ||
| 1466 | + if (definedIndices[i]->GetDataType() == op::DataType::DT_BOOL) { | ||
| 1467 | + hasBoolIndices = true; | ||
| 1468 | + break; | ||
| 1469 | + } | ||
| 1470 | + } | ||
| 1471 | + if (!hasBoolIndices) { | ||
| 1472 | + FVector<int64_t, DIMLIMIT> boundsVec; | ||
| 1473 | + for (size_t i = 0; i < selfCast->GetViewShape().GetDimNum(); i++) { | ||
| 1474 | + boundsVec.emplace_back(selfCast->GetViewShape().GetDim(i)); | ||
| 1475 | + } | ||
| 1476 | + auto boundsArray = uniqueExecutor.get()->AllocIntArray(boundsVec.data(), boundsVec.size()); | ||
| 1477 | + auto boundsTensor = uniqueExecutor.get()->ConvertToTensor(boundsArray, op::ToOpDataType(ACL_INT64)); | ||
| 1478 | + auto definedIndicesTensorList = uniqueExecutor.get()->AllocTensorList(definedIndices.data(), definedIndices.size()); | ||
| 1479 | + l0op::IndexCheck(boundsTensor, definedIndicesTensorList, uniqueExecutor.get()); | ||
| 1480 | + } | ||
| 1481 | + | ||
| 1432 | auto strideTensor = uniqueExecutor.get()->ConvertToTensor(strideTail.data(), strideTail.size(), DataType::DT_INT32); | 1482 | auto strideTensor = uniqueExecutor.get()->ConvertToTensor(strideTail.data(), strideTail.size(), DataType::DT_INT32); |
| 1433 | auto valueSizeTensor = uniqueExecutor.get()->ConvertToTensor(valueSizeTail.data(), valueSizeTail.size(), DataType::DT_INT32); | 1483 | auto valueSizeTensor = uniqueExecutor.get()->ConvertToTensor(valueSizeTail.data(), valueSizeTail.size(), DataType::DT_INT32); |
| 1434 | auto indicesTensorList = uniqueExecutor.get()->AllocTensorList(definedIndices.data(), definedIndices.size()); | 1484 | auto indicesTensorList = uniqueExecutor.get()->AllocTensorList(definedIndices.data(), definedIndices.size()); |
| @@ -1471,5 +1521,4 @@ aclnnStatus aclnnIndexPutImpl(void *workspace, uint64_t workspaceSize, | |||
| 1471 | 1521 | ||
| 1472 | 1522 | ||
| 1473 | } | 1523 | } |
| 1474 | -#endif | 1524 | +#endif |
| 1475 | - | ||