已合并
支持下一代cos_stateless_bernoulli_stateless_random_normal_v2算子实现 #548
hawdonz创建于 2025年12月29日
支持下一代cos_stateless_bernoulli_stateless_random_normal_v2算子实现 #548
已合并
共 94 个文件变更+10957-1361
| @@ -1,11 +1,10 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| @@ -13,7 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | -#include "../../../cos/op_host/op_api/cos.h" | 16 | +#include "../../../cos/op_api/cos.h" |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| @@ -1,18 +1,15 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | 1 | +# ----------------------------------------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | -# ---------------------------------------------------------------------------- | 9 | +# ----------------------------------------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +# 设置算子定义时支持的芯片类型 |
| 13 | -list(REMOVE_ITEM CURRENT_DIRS tests) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend910_95") |
| 14 | -foreach(SUB_DIR ${CURRENT_DIRS}) | 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 15 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | 14 | +set(SUPPORT_TILING_DIR "arch35") |
| 16 | - add_subdirectory(${SUB_DIR}) | 15 | +add_all_modules_sources(OPTYPE cos ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) |
| 17 | - endif() | ||
| 18 | -endforeach() | ||
| @@ -1,11 +1,18 @@ | |||
| 1 | # aclnnCos&aclnnInplaceCos | 1 | # aclnnCos&aclnnInplaceCos |
| 2 | 2 | ||
| 3 | +[📄 查看源码](https://gitcode.com/cann/ops-math/tree/master/math/cos) | ||
| 4 | + | ||
| 3 | ## 产品支持情况 | 5 | ## 产品支持情况 |
| 4 | 6 | ||
| 5 | | 产品 | 是否支持 | | 7 | | 产品 | 是否支持 | |
| 6 | | :----------------------------------------------------------- | :------: | | 8 | | :----------------------------------------------------------- | :------: | |
| 9 | +| <term>昇腾910_95 AI处理器</term> | √ | | ||
| 7 | | <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | | 10 | | <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | |
| 8 | -| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ | | 11 | +| <term>Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件</term> | √ | |
| 12 | +| <term>Atlas 200I/500 A2 推理产品</term> | √ | | ||
| 13 | +| <term>Atlas 推理系列产品 </term> | √ | | ||
| 14 | +| <term>Atlas 训练系列产品</term> | √ | | ||
| 15 | +| <term>Atlas 200/300/500 推理产品</term> | × | | ||
| 9 | 16 | ||
| 10 | ## 功能说明 | 17 | ## 功能说明 |
| 11 | 18 | ||
| @@ -123,6 +130,9 @@ aclnnStatus aclnnInplaceCos( | |||
| 123 | </tbody> | 130 | </tbody> |
| 124 | </table> | 131 | </table> |
| 125 | 132 | ||
| 133 | + - <term>Atlas 200I/500 A2 推理产品</term>、<term>Atlas 推理系列产品</term>、<term>Atlas 训练系列产品</term>:数据类型不支持BFLOAT16。 | ||
| 134 | + | ||
| 135 | + | ||
| 126 | - **返回值**: | 136 | - **返回值**: |
| 127 | 137 | ||
| 128 | aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn返回码.md) | 138 | aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn返回码.md) |
| @@ -262,6 +272,9 @@ aclnnStatus aclnnInplaceCos( | |||
| 262 | </tbody> | 272 | </tbody> |
| 263 | </table> | 273 | </table> |
| 264 | 274 | ||
| 275 | + - <term>Atlas 200I/500 A2 推理产品</term>、<term>Atlas 推理系列产品</term>、<term>Atlas 训练系列产品</term>:数据类型不支持BFLOAT16。 | ||
| 276 | + | ||
| 277 | + | ||
| 265 | - **返回值**: | 278 | - **返回值**: |
| 266 | 279 | ||
| 267 | aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn返回码.md) | 280 | aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn返回码.md) |
| @@ -344,7 +357,9 @@ aclnnStatus aclnnInplaceCos( | |||
| 344 | - 确定性计算: | 357 | - 确定性计算: |
| 345 | - aclnnCos&aclnnInplaceCos默认确定性实现。 | 358 | - aclnnCos&aclnnInplaceCos默认确定性实现。 |
| 346 | 359 | ||
| 347 | -- <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:FLOAT、FLOAT16、BFLOAT16数据类型的输入数据范围为[-10^7,10^7]时满足精度要求,超过数值范围无法保证,请使用CPU进行计算。 | 360 | +- <term>Atlas 训练系列产品</term>、<term>Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件</term>、<term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>:FLOAT、FLOAT16、BFLOAT16数据类型的输入数据范围为[-10^7,10^7]时满足精度要求,超过数值范围无法保证,请使用CPU进行计算。 |
| 361 | +- <term>Atlas 推理系列产品</term>、<term>Atlas 200I/500 A2 推理产品</term>:FLOAT、FLOAT16数据类型的输入数据范围为[-65504,65504]时满足精度要求,超过数值范围无法保证,请使用CPU进行计算。 | ||
| 362 | + | ||
| 348 | ## 调用示例 | 363 | ## 调用示例 |
| 349 | 364 | ||
| 350 | 示例代码如下,仅供参考,具体编译和执行过程请参考[编译与运行样例](../../../docs/zh/context/编译与运行样例.md)。 | 365 | 示例代码如下,仅供参考,具体编译和执行过程请参考[编译与运行样例](../../../docs/zh/context/编译与运行样例.md)。 |
| @@ -0,0 +1,178 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_aclnn_cos.cpp | ||
| 13 | + * \brief test_aclnn_cos | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + do { \ | ||
| 23 | + if (!(cond)) { \ | ||
| 24 | + return_expr; \ | ||
| 25 | + } \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + do { \ | ||
| 30 | + printf(message, ##__VA_ARGS__); \ | ||
| 31 | + } while (0) | ||
| 32 | + | ||
| 33 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) { | ||
| 34 | + int64_t shapeSize = 1; | ||
| 35 | + for (auto i : shape) { | ||
| 36 | + shapeSize *= i; | ||
| 37 | + } | ||
| 38 | + return shapeSize; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +int Init(int32_t deviceId, aclrtStream* stream) { | ||
| 42 | + // 固定写法,AscendCL初始化 | ||
| 43 | + auto ret = aclInit(nullptr); | ||
| 44 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 45 | + ret = aclrtSetDevice(deviceId); | ||
| 46 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 47 | + ret = aclrtCreateStream(stream); | ||
| 48 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 49 | + return 0; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +template <typename T> | ||
| 53 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | ||
| 54 | + aclDataType dataType, aclTensor** tensor) { | ||
| 55 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 56 | + // 调用aclrtMalloc申请device侧内存 | ||
| 57 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 58 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 59 | + | ||
| 60 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | ||
| 61 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 62 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 63 | + | ||
| 64 | + // 计算连续tensor的strides | ||
| 65 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 66 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 67 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + // 调用aclCreateTensor接口创建aclTensor | ||
| 71 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, | ||
| 72 | + shape.data(), shape.size(), *deviceAddr); | ||
| 73 | + return 0; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +int main() { | ||
| 77 | + // 1. (固定写法)device/stream初始化,参考AscendCL对外接口列表 | ||
| 78 | + // 根据自己的实际device填写deviceId | ||
| 79 | + int32_t deviceId = 0; | ||
| 80 | + aclrtStream stream; | ||
| 81 | + auto ret = Init(deviceId, &stream); | ||
| 82 | + // check根据自己的需要处理 | ||
| 83 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 84 | + | ||
| 85 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 | ||
| 86 | + std::vector<int64_t> selfShape = {4, 2}; | ||
| 87 | + std::vector<int64_t> outShape = {4, 2}; | ||
| 88 | + void* selfDeviceAddr = nullptr; | ||
| 89 | + void* outDeviceAddr = nullptr; | ||
| 90 | + aclTensor* self = nullptr; | ||
| 91 | + aclTensor* out = nullptr; | ||
| 92 | + std::vector<float> selfHostData = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8}; | ||
| 93 | + std::vector<float> outHostData = {0, 0, 0, 0, 0, 0, 0, 0}; | ||
| 94 | + // 创建self aclTensor | ||
| 95 | + ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); | ||
| 96 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 97 | + // 创建out aclTensor | ||
| 98 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | ||
| 99 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 100 | + | ||
| 101 | + uint64_t workspaceSize = 0; | ||
| 102 | + aclOpExecutor* executor; | ||
| 103 | + | ||
| 104 | + // aclnnCos接口调用示例 | ||
| 105 | + LOG_PRINT("test aclnnCos\n"); | ||
| 106 | + | ||
| 107 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 | ||
| 108 | + // 调用aclnnCos第一段接口 | ||
| 109 | + ret = aclnnCosGetWorkspaceSize(self, out, &workspaceSize, &executor); | ||
| 110 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnCosGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); | ||
| 111 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 112 | + void* workspaceAddr = nullptr; | ||
| 113 | + if (workspaceSize > 0) { | ||
| 114 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 115 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 116 | + } | ||
| 117 | + // 调用aclnnCos第二段接口 | ||
| 118 | + ret = aclnnCos(workspaceAddr, workspaceSize, executor, stream); | ||
| 119 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnCos failed. ERROR: %d\n", ret); return ret); | ||
| 120 | + | ||
| 121 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 122 | + ret = aclrtSynchronizeStream(stream); | ||
| 123 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 124 | + | ||
| 125 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | ||
| 126 | + auto size = GetShapeSize(outShape); | ||
| 127 | + std::vector<float> resultData(size, 0); | ||
| 128 | + ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, | ||
| 129 | + size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 130 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 131 | + for (int64_t i = 0; i < size; i++) { | ||
| 132 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + // aclnnInplaceCos接口调用示例 | ||
| 136 | + LOG_PRINT("\ntest aclnnInplaceCos\n"); | ||
| 137 | + | ||
| 138 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 | ||
| 139 | + // 调用aclnnInplaceCos第一段接口 | ||
| 140 | + ret = aclnnInplaceCosGetWorkspaceSize(self, &workspaceSize, &executor); | ||
| 141 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnInplaceCosGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); | ||
| 142 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 143 | + if (workspaceSize > 0) { | ||
| 144 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 145 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 146 | + } | ||
| 147 | + // 调用aclnnInplaceCos第二段接口 | ||
| 148 | + ret = aclnnInplaceCos(workspaceAddr, workspaceSize, executor, stream); | ||
| 149 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnInplaceCos failed. ERROR: %d\n", ret); return ret); | ||
| 150 | + | ||
| 151 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 152 | + ret = aclrtSynchronizeStream(stream); | ||
| 153 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 154 | + | ||
| 155 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | ||
| 156 | + ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), selfDeviceAddr, | ||
| 157 | + size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 158 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 159 | + for (int64_t i = 0; i < size; i++) { | ||
| 160 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + // 6. 释放aclTensor,需要根据具体API的接口定义修改 | ||
| 164 | + aclDestroyTensor(self); | ||
| 165 | + aclDestroyTensor(out); | ||
| 166 | + | ||
| 167 | + // 7. 释放device资源 | ||
| 168 | + aclrtFree(selfDeviceAddr); | ||
| 169 | + aclrtFree(outDeviceAddr); | ||
| 170 | + if (workspaceSize > 0) { | ||
| 171 | + aclrtFree(workspaceAddr); | ||
| 172 | + } | ||
| 173 | + aclrtDestroyStream(stream); | ||
| 174 | + aclrtResetDevice(deviceId); | ||
| 175 | + aclFinalize(); | ||
| 176 | + | ||
| 177 | + return 0; | ||
| 178 | +} | ||
| @@ -12,14 +12,12 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | - | ||
| 16 | 15 | ||
| 17 | 16 | ||
| 18 | 17 | ||
| 19 | 18 | ||
| 20 | 19 | ||
| 21 | 20 | ||
| 22 | - | ||
| 23 | 21 | ||
| 24 | 22 | ||
| 25 | 23 | ||
| @@ -174,5 +172,6 @@ aclnnStatus aclnnInplaceCos(void* workspace, uint64_t workspaceSize, aclOpExecut | |||
| 174 | 172 | ||
| 175 | 173 | ||
| 176 | } | 174 | } |
| 175 | + | ||
| 177 | 176 | ||
| 178 | 177 | ||
Rrandom/stateless_random_normal_v2/op_host/op_api/stateless_random_normal_v2.h→math/cos/op_graph/cos_proto.h+34-9
| @@ -7,15 +7,40 @@ | |||
| 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 | - | ||
| 11 | - | ||
| 12 | 10 | ||
| 13 | -#include "opdev/op_executor.h" | 11 | +/*! |
| 12 | + * \file cos_proto.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 14 | 15 | ||
| 15 | -namespace l0op { | 16 | +#ifndef OPS_MATH_COS_GRAPH_PLUGIN_COS_PROTO_H_ |
| 16 | -const aclTensor* StatelessRandomNormalV2( | 17 | +#define OPS_MATH_COS_GRAPH_PLUGIN_COS_PROTO_H_ |
| 17 | - const aclTensor* result, const aclIntArray* key, const aclIntArray* counter, const aclTensor* alg, | 18 | + |
| 18 | - aclOpExecutor* executor); | 19 | +#include "graph/operator_reg.h" |
| 19 | -} | 20 | +#include "graph/types.h" |
| 21 | + | ||
| 22 | +namespace ge { | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | +* @brief Computes cosine of "x" element-wise. | ||
| 26 | + | ||
| 27 | +* @par Inputs: | ||
| 28 | +* x: A ND Tensor of type bfloat16, float16, float32, double, complex64, complex128. | ||
| 29 | +* the format can be [NCHW,NHWC,ND] | ||
| 30 | + | ||
| 31 | +* @par Outputs: | ||
| 32 | +* y: A ND Tensor of the same dtype as "x". \n | ||
| 33 | + | ||
| 34 | +* @par Third-party framework compatibility | ||
| 35 | +* Compatible with the TensorFlow operator Cos. \n | ||
| 36 | + | ||
| 37 | +*/ | ||
| 38 | +REG_OP(Cos) | ||
| 39 | + .INPUT(x, TensorType::UnaryDataType()) | ||
| 40 | + .OUTPUT(y, TensorType::UnaryDataType()) | ||
| 41 | + .OP_END_FACTORY_REG(Cos) | ||
| 42 | + | ||
| 43 | +} // namespace ge | ||
| 44 | + | ||
| 45 | + | ||
| 20 | 46 | ||
| 21 | - | ||
| @@ -1,12 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -add_modules_sources(OPTYPE cos ACLNNTYPE aclnn_exclude) | ||
| @@ -0,0 +1,160 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file cos_tiling_arch35.cpp | ||
| 13 | + * \brief cos_tiling_arch35 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +namespace optiling | ||
| 25 | +{ | ||
| 26 | +using namespace Ops::Base; | ||
| 27 | +const int64_t ASCEND_WORKSPACE = 16777216; // 16M | ||
| 28 | +const int64_t ASCEND_API_BUFFER = 122880; //120K | ||
| 29 | +const int64_t DCACHE_SIZE = 32768; | ||
| 30 | + | ||
| 31 | +ge::graphStatus CosTiling::SetTilingData() | ||
| 32 | +{ | ||
| 33 | + OP_LOGD(tilingContext->GetNodeName(), "CosTiling SetTilingData enter."); | ||
| 34 | + | ||
| 35 | + size_t* currentWorkspace = tilingContext->GetWorkspaceSizes(1); | ||
| 36 | + currentWorkspace[0] = static_cast<size_t>(ASCEND_WORKSPACE); | ||
| 37 | + | ||
| 38 | + const uint64_t tilingKey = GET_TPL_TILING_KEY(tiling->baseTiling.scheMode, dType); | ||
| 39 | + OP_LOGD(tilingContext->GetNodeName(), "[TilingData] : tilingKey=%lu", tilingKey); | ||
| 40 | + tilingContext->SetTilingKey(tilingKey); | ||
| 41 | + tilingContext->SetBlockDim(tiling->baseTiling.blockNum); | ||
| 42 | + | ||
| 43 | + uint64_t ubSize = 0; | ||
| 44 | + auto platformInfo = tilingContext->GetPlatformInfo(); | ||
| 45 | + if (platformInfo == nullptr) { | ||
| 46 | + auto compileInfoPtr = reinterpret_cast<const ElewiseCompileInfo*>(tilingContext->GetCompileInfo()); | ||
| 47 | + OP_CHECK_IF(compileInfoPtr == nullptr, OP_LOGE(tilingContext, "compile info is null"), | ||
| 48 | + return ge::GRAPH_FAILED); | ||
| 49 | + ubSize = compileInfoPtr->ubSize; | ||
| 50 | + } else { | ||
| 51 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 52 | + uint64_t ubSizePlatForm = 0; | ||
| 53 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSizePlatForm); | ||
| 54 | + ubSize = ubSizePlatForm; | ||
| 55 | + } | ||
| 56 | + tilingContext->SetLocalMemorySize(static_cast<uint32_t>(ubSize - DCACHE_SIZE)); | ||
| 57 | + return ge::GRAPH_SUCCESS; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +ge::graphStatus CosTiling::CalcInputDtype() | ||
| 61 | +{ | ||
| 62 | + OP_LOGD(tilingContext->GetNodeName(), "CosTiling CalcInputDtype enter."); | ||
| 63 | + auto inputDesc = tilingContext->GetInputDesc(0); | ||
| 64 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDesc); | ||
| 65 | + this->inputDtype = inputDesc->GetDataType(); | ||
| 66 | + OP_CHECK_IF( | ||
| 67 | + this->inputDtype != ge::DT_FLOAT16 && this->inputDtype != ge::DT_BF16 && this->inputDtype != ge::DT_FLOAT, | ||
| 68 | + OP_LOGE(tilingContext->GetNodeName(), "input x dtype not support"), | ||
| 69 | + return ge::GRAPH_FAILED); | ||
| 70 | + return ge::GRAPH_SUCCESS; | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +ge::graphStatus CosTiling::CheckShape() | ||
| 74 | +{ | ||
| 75 | + OP_LOGD(tilingContext->GetNodeName(), "CosTiling CheckShape enter."); | ||
| 76 | + auto inputStorageShape = tilingContext->GetInputShape(0); | ||
| 77 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputStorageShape); | ||
| 78 | + const gert::Shape& inputYShape = Ops::Base::EnsureNotScalar(inputStorageShape->GetStorageShape()); | ||
| 79 | + | ||
| 80 | + auto outputStorageShape = tilingContext->GetOutputShape(0); | ||
| 81 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputStorageShape); | ||
| 82 | + const gert::Shape& outputZShape = Ops::Base::EnsureNotScalar(outputStorageShape->GetStorageShape()); | ||
| 83 | + | ||
| 84 | + OP_CHECK_IF(inputYShape != outputZShape, | ||
| 85 | + OP_LOGE(tilingContext->GetNodeName(), "input x and output y shape not same"), | ||
| 86 | + return ge::GRAPH_FAILED); | ||
| 87 | + return ge::GRAPH_SUCCESS; | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +ge::graphStatus CosTiling::CalcOutputDtype() | ||
| 91 | +{ | ||
| 92 | + OP_LOGD(tilingContext->GetNodeName(), "CosTiling CalcOutputDtype enter."); | ||
| 93 | + auto outputDesc = tilingContext->GetOutputDesc(0); | ||
| 94 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDesc); | ||
| 95 | + this->outputDtype = outputDesc->GetDataType(); | ||
| 96 | + OP_CHECK_IF(this->outputDtype != this->inputDtype, | ||
| 97 | + OP_LOGE(tilingContext->GetNodeName(), "output y dtype not same as input x"), | ||
| 98 | + return ge::GRAPH_FAILED); | ||
| 99 | + return ge::GRAPH_SUCCESS; | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +ge::graphStatus CosTiling::RunTiling() | ||
| 103 | +{ | ||
| 104 | + OP_LOGD(tilingContext->GetNodeName(), "CosTiling RunTiling enter."); | ||
| 105 | + Ops::Base::ElewiseBaseTiling elewiseBaseTiling(tilingContext); | ||
| 106 | + OP_CHECK_IF(CalcInputDtype() == ge::GRAPH_FAILED, | ||
| 107 | + OP_LOGE(tilingContext, "get input dtype failed"), return ge::GRAPH_FAILED); | ||
| 108 | + OP_CHECK_IF(CalcOutputDtype() == ge::GRAPH_FAILED, | ||
| 109 | + OP_LOGE(tilingContext, "get output dtype failed"), return ge::GRAPH_FAILED); | ||
| 110 | + OP_CHECK_IF(CheckShape() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "check shape failed"), | ||
| 111 | + return ge::GRAPH_FAILED); | ||
| 112 | + | ||
| 113 | + tiling = tilingContext->GetTilingData<CosTilingData>(); | ||
| 114 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, tiling); | ||
| 115 | + ge::graphStatus baseTilingResult = ge::GRAPH_FAILED; | ||
| 116 | + if (this->outputDtype == ge::DT_FLOAT16) { | ||
| 117 | + dType = TPL_FP16; | ||
| 118 | + baseTilingResult = elewiseBaseTiling.DoTiling<CosOp::CosDAG<Ops::Base::half>::OpDag>(tiling->baseTiling, ASCEND_API_BUFFER + DCACHE_SIZE); | ||
| 119 | + } else if (this->outputDtype == ge::DT_BF16) { | ||
| 120 | + dType = TPL_BF16; | ||
| 121 | + baseTilingResult = elewiseBaseTiling.DoTiling<CosOp::CosDAG<Ops::Base::bfloat16_t>::OpDag>(tiling->baseTiling, ASCEND_API_BUFFER + DCACHE_SIZE); | ||
| 122 | + } else if (this->outputDtype == ge::DT_FLOAT) { | ||
| 123 | + dType = TPL_FP32; | ||
| 124 | + baseTilingResult = elewiseBaseTiling.DoTiling<CosOp::CosDAG<float>::OpDag>(tiling->baseTiling, ASCEND_API_BUFFER + DCACHE_SIZE); | ||
| 125 | + } else { | ||
| 126 | + OP_LOGE(tilingContext->GetNodeName(), "output dtype not support"); | ||
| 127 | + return ge::GRAPH_FAILED; | ||
| 128 | + } | ||
| 129 | + OP_CHECK_IF(baseTilingResult == ge::GRAPH_FAILED, | ||
| 130 | + OP_LOGE(tilingContext, "elewiseBaseTiling failed"), return ge::GRAPH_FAILED); | ||
| 131 | + | ||
| 132 | + return SetTilingData(); | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +static ge::graphStatus TilingForCos(gert::TilingContext* tilingContextGen) | ||
| 136 | +{ | ||
| 137 | + OP_LOGD(tilingContextGen->GetNodeName(), "TilingForCos rt2.0 is running."); | ||
| 138 | + auto compileInfo = reinterpret_cast<const ElewiseCompileInfo*>(tilingContextGen->GetCompileInfo()); | ||
| 139 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContextGen, compileInfo); | ||
| 140 | + CosTiling baseOpTiling(tilingContextGen); | ||
| 141 | + return baseOpTiling.RunTiling(); | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +ge::graphStatus TilingPrepareForCos(gert::TilingParseContext* context) | ||
| 145 | +{ | ||
| 146 | + OP_LOGD(context->GetNodeName(), "TilingPrepareForCos is running."); | ||
| 147 | + auto compileInfo = context->GetCompiledInfo<ElewiseCompileInfo>(); | ||
| 148 | + OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | ||
| 149 | + auto platformInfo = context->GetPlatformInfo(); | ||
| 150 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo); | ||
| 151 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 152 | + compileInfo->coreNum = ascendcPlatform.GetCoreNumAiv(); | ||
| 153 | + uint64_t ubSize; | ||
| 154 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize); | ||
| 155 | + compileInfo->ubSize = static_cast<int64_t>(ubSize); | ||
| 156 | + return ge::GRAPH_SUCCESS; | ||
| 157 | +} | ||
| 158 | + | ||
| 159 | +IMPL_OP_OPTILING(Cos).Tiling(TilingForCos).TilingParse<ElewiseCompileInfo>(TilingPrepareForCos); | ||
| 160 | +} // namespace optiling | ||
| @@ -0,0 +1,44 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file cos_tiling_arch35.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling { | ||
| 23 | + | ||
| 24 | +class CosTiling | ||
| 25 | +{ | ||
| 26 | +public: | ||
| 27 | + explicit CosTiling(gert::TilingContext* context) : tilingContext(context) {}; | ||
| 28 | + ge::graphStatus RunTiling(); | ||
| 29 | + CosTilingData *tiling = nullptr; | ||
| 30 | + | ||
| 31 | +protected: | ||
| 32 | + ge::graphStatus CalcOutputDtype(); | ||
| 33 | + ge::graphStatus CalcInputDtype(); | ||
| 34 | + ge::graphStatus CheckShape(); | ||
| 35 | + ge::graphStatus SetTilingData(); | ||
| 36 | + | ||
| 37 | +private: | ||
| 38 | + gert::TilingContext* tilingContext; | ||
| 39 | + ge::DataType outputDtype; | ||
| 40 | + ge::DataType inputDtype; | ||
| 41 | + uint64_t dType = 0; | ||
| 42 | +}; | ||
| 43 | +} // namespace optiling | ||
| 44 | + | ||
| @@ -0,0 +1,92 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "Cos", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "Cos_d2db1a80c523e7e59a032c95969880af", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "float16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + } | ||
| 18 | + ], | ||
| 19 | + "outputs": [ | ||
| 20 | + { | ||
| 21 | + "name": "y", | ||
| 22 | + "index": 0, | ||
| 23 | + "dtype": "float16", | ||
| 24 | + "format": "ND", | ||
| 25 | + "paramType": "required", | ||
| 26 | + "shape": [ | ||
| 27 | + -2 | ||
| 28 | + ], | ||
| 29 | + "format_match_mode": "FormatAgnostic" | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | + }, | ||
| 33 | + { | ||
| 34 | + "bin_filename": "Cos_d2db1a80c523e7e59a032c95969bbbb", | ||
| 35 | + "inputs": [ | ||
| 36 | + { | ||
| 37 | + "name": "x", | ||
| 38 | + "index": 0, | ||
| 39 | + "dtype": "bfloat16", | ||
| 40 | + "format": "ND", | ||
| 41 | + "paramType": "required", | ||
| 42 | + "shape": [ | ||
| 43 | + -2 | ||
| 44 | + ], | ||
| 45 | + "format_match_mode": "FormatAgnostic" | ||
| 46 | + } | ||
| 47 | + ], | ||
| 48 | + "outputs": [ | ||
| 49 | + { | ||
| 50 | + "name": "y", | ||
| 51 | + "index": 0, | ||
| 52 | + "dtype": "bfloat16", | ||
| 53 | + "format": "ND", | ||
| 54 | + "paramType": "required", | ||
| 55 | + "shape": [ | ||
| 56 | + -2 | ||
| 57 | + ], | ||
| 58 | + "format_match_mode": "FormatAgnostic" | ||
| 59 | + } | ||
| 60 | + ] | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + "bin_filename": "Cos_5c5e58e043224cccf51a06108010ae13", | ||
| 64 | + "inputs": [ | ||
| 65 | + { | ||
| 66 | + "name": "x", | ||
| 67 | + "index": 0, | ||
| 68 | + "dtype": "float32", | ||
| 69 | + "format": "ND", | ||
| 70 | + "paramType": "required", | ||
| 71 | + "shape": [ | ||
| 72 | + -2 | ||
| 73 | + ], | ||
| 74 | + "format_match_mode": "FormatAgnostic" | ||
| 75 | + } | ||
| 76 | + ], | ||
| 77 | + "outputs": [ | ||
| 78 | + { | ||
| 79 | + "name": "y", | ||
| 80 | + "index": 0, | ||
| 81 | + "dtype": "float32", | ||
| 82 | + "format": "ND", | ||
| 83 | + "paramType": "required", | ||
| 84 | + "shape": [ | ||
| 85 | + -2 | ||
| 86 | + ], | ||
| 87 | + "format_match_mode": "FormatAgnostic" | ||
| 88 | + } | ||
| 89 | + ] | ||
| 90 | + } | ||
| 91 | + ] | ||
| 92 | +} | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示: | ||
| 2 | +; [某算子] | ||
| 3 | +; default=xx | ||
| 4 | +; ascendxx=xx | ||
| 5 | +; 其中,default为默认mode,ascnedxx为可选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 | +[Cos] | ||
| 13 | +default=0 | ||
| @@ -0,0 +1,49 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file cos_def.cpp | ||
| 13 | + * \brief cos def | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +namespace ops { | ||
| 20 | +class Cos : public OpDef { | ||
| 21 | +public: | ||
| 22 | + explicit Cos(const char* name) : OpDef(name) | ||
| 23 | + { | ||
| 24 | + this->Input("x") | ||
| 25 | + .ParamType(REQUIRED) | ||
| 26 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 27 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 28 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 29 | + this->Output("y") | ||
| 30 | + .ParamType(REQUIRED) | ||
| 31 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 32 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 33 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 34 | + | ||
| 35 | + OpAICoreConfig aicoreConfig; | ||
| 36 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 37 | + .DynamicFormatFlag(false) | ||
| 38 | + .DynamicRankSupportFlag(true) | ||
| 39 | + .DynamicShapeSupportFlag(true) | ||
| 40 | + .NeedCheckSupportFlag(false) | ||
| 41 | + .PrecisionReduceFlag(true) | ||
| 42 | + .ExtendCfgInfo("opFile.value", "cos_apt"); | ||
| 43 | + this->AICore().AddConfig("ascend910_95", aicoreConfig); | ||
| 44 | + this->AICore().AddConfig("mc62cm12a", aicoreConfig); | ||
| 45 | + } | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +OP_ADD(Cos); | ||
| 49 | +} // namespace ops | ||
Rrandom/stateless_bernoulli/tests/ut/op_host/op_api/test_aclnn_bernoulli_tensor_l0.cpp→math/cos/op_host/cos_infershape.cpp+13-0
| @@ -7,3 +7,16 @@ | |||
| 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 | + | ||
| 11 | +/*! | ||
| 12 | + * \file cos_infershape.cpp | ||
| 13 | + * \brief cos_infershape | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +namespace ops | ||
| 19 | +{ | ||
| 20 | +IMPL_OP_INFERSHAPE(Cos) | ||
| 21 | + .InferShape(Ops::Base::InferShape4Elewise); | ||
| 22 | +} // namespace ops | ||
| @@ -0,0 +1,64 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file cos_dag.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace CosOp | ||
| 23 | +{ | ||
| 24 | +using namespace AscendC; | ||
| 25 | +using namespace Ops::Base; | ||
| 26 | +const int CAST_MODE_NONE = 0; | ||
| 27 | +const int CAST_MODE_RINT = 1; | ||
| 28 | +constexpr uint32_t THREAD_NUM = 1024; | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +template<typename T> | ||
| 32 | +__simt_vf__ __aicore__ LAUNCH_BOUND(THREAD_NUM) inline void CosSimtCompute(__ubuf__ T* x, __ubuf__ T* y, const int64_t totalNum) | ||
| 33 | +{ | ||
| 34 | + for(int64_t i = Simt::GetThreadIdx(); i < totalNum; i += Simt::GetThreadNum()){ | ||
| 35 | + y[i] = Simt::Cos(x[i]); | ||
| 36 | + } | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +template<class T> | ||
| 41 | +struct CosCustom : public Vec::ElemwiseUnaryOP<T, T> { | ||
| 42 | + __aicore__ inline CosCustom(LocalTensor<T> &dst, LocalTensor<T> &src, uint32_t count) { | ||
| 43 | + | ||
| 44 | + __ubuf__ T* srcAddr = (__ubuf__ T*)src.GetPhyAddr(); | ||
| 45 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 46 | + Simt::VF_CALL<CosSimtCompute<T>>(Simt::Dim3(THREAD_NUM),srcAddr,dstAddr,count); | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | +}; | ||
| 50 | + | ||
| 51 | +template <typename U, typename T = float> | ||
| 52 | +struct CosDAG { | ||
| 53 | + using OpCopyIn0 = Bind<Vec::CopyIn<U>, Placeholder::In0<U>>; | ||
| 54 | + using OpCopyIn0Cast = Bind<Vec::Cast<T, U, CAST_MODE_NONE>, OpCopyIn0>; | ||
| 55 | + using OpResult1 = Bind<CosCustom<T>, OpCopyIn0Cast>; | ||
| 56 | + using OpResultCast = Bind<Vec::Cast<U, T, CAST_MODE_RINT>, OpResult1>; | ||
| 57 | + using OpCopyOut = Bind<Vec::CopyOut<U>, Placeholder::Out0<U>, OpResultCast>; | ||
| 58 | + | ||
| 59 | + using Outputs = Elems<OpCopyOut>; | ||
| 60 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 61 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 62 | +}; | ||
| 63 | +} | ||
| 64 | + | ||
| @@ -0,0 +1,47 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file cos_struct.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +ASCENDC_TPL_ARGS_DECL(Cos, | ||
| 29 | + ASCENDC_TPL_UINT_DECL(schMode, 1, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 30 | + ASCENDC_TPL_DTYPE_DECL(dType, TPL_FP16, TPL_BF16, TPL_FP32) | ||
| 31 | +); | ||
| 32 | + | ||
| 33 | +ASCENDC_TPL_SEL( | ||
| 34 | + ASCENDC_TPL_ARGS_SEL( | ||
| 35 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 36 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP16) | ||
| 37 | + ), | ||
| 38 | + ASCENDC_TPL_ARGS_SEL( | ||
| 39 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 40 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_BF16) | ||
| 41 | + ), | ||
| 42 | + ASCENDC_TPL_ARGS_SEL( | ||
| 43 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 44 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP32) | ||
| 45 | + ) | ||
| 46 | +); | ||
| 47 | + | ||
Rrandom/stateless_bernoulli/op_host/op_api/stateless_bernoulli.h→math/cos/op_kernel/arch35/cos_tilingdata.h+27-27
| @@ -1,27 +1,27 @@ | |||
| 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 | -/*! | 11 | +/* ! |
| 12 | - * \file stateless_bernoulli.h | 12 | + * \file cos_tilingdata.h |
| 13 | - * \brief | 13 | + * \brief |
| 14 | - */ | 14 | + */ |
| 15 | - | 15 | + |
| 16 | -#ifndef OP_API_INC_LEVEL0_OP_STATELESS_BERNOULLI_OP_H_ | 16 | + |
| 17 | -#define OP_API_INC_LEVEL0_OP_STATELESS_BERNOULLI_OP_H_ | 17 | +#ifndef __COS_TILINGDATA_H__ |
| 18 | - | 18 | +#define __COS_TILINGDATA_H__ |
| 19 | -#include "opdev/op_executor.h" | 19 | + |
| 20 | - | 20 | +#include "atvoss/elewise/elewise_base_struct.h" |
| 21 | -namespace l0op { | 21 | + |
| 22 | -const aclTensor* StatelessBernoulli( | 22 | +struct CosTilingData { |
| 23 | - const aclTensor* input, const aclTensor* prob, int64_t seed, int64_t offset, aclOpExecutor* executor); | 23 | + Ops::Base::EleBaseTilingData baseTiling; |
| 24 | - | 24 | +}; |
| 25 | -} | 25 | + |
| 26 | - | 26 | + |
| 27 | -#endif // OP_API_INC_LEVEL0_OP_STATELESS_BERNOULLI_OP_H_ | 27 | +#endif // __COS_TILINGDATA_H__ |
| @@ -0,0 +1,45 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file cos.cpp | ||
| 13 | + * \brief z = cos(x) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +using namespace AscendC; | ||
| 25 | +template <uint64_t schMode, uint64_t dType> | ||
| 26 | +__global__ __aicore__ void cos(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) { | ||
| 27 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 28 | + REGISTER_TILING_DEFAULT(CosTilingData); | ||
| 29 | + GET_TILING_DATA_WITH_STRUCT(CosTilingData, tilingData, tiling); | ||
| 30 | + TPipe pipe; | ||
| 31 | + if constexpr(dType == TPL_FP16) { | ||
| 32 | + Ops::Base::ElementwiseSch<schMode, CosOp::CosDAG<half>::OpDag> sch(&(tilingData.baseTiling), &pipe); | ||
| 33 | + sch.Init(x, y); | ||
| 34 | + sch.Process(); | ||
| 35 | + } else if constexpr(dType == TPL_BF16) { | ||
| 36 | + Ops::Base::ElementwiseSch<schMode, CosOp::CosDAG<bfloat16_t>::OpDag> sch(&(tilingData.baseTiling), &pipe); | ||
| 37 | + sch.Init(x, y); | ||
| 38 | + sch.Process(); | ||
| 39 | + } else if constexpr(dType == TPL_FP32) { | ||
| 40 | + Ops::Base::ElementwiseSch<schMode, CosOp::CosDAG<float>::OpDag> sch(&(tilingData.baseTiling), &pipe); | ||
| 41 | + sch.Init(x, y); | ||
| 42 | + sch.Process(); | ||
| 43 | + } | ||
| 44 | + return; | ||
| 45 | +} | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
Rmath/cos/tests/ut/op_host/op_api/test_aclnn_cos.cpp→math/cos/tests/ut/op_api/test_aclnn_cos.cpp+1-3
| @@ -11,9 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | - | 14 | +#include "../../../op_api/aclnn_cos.h" |
| 15 | - | ||
| 16 | - | ||
| 17 | 15 | ||
| 18 | 16 | ||
| 19 | 17 | ||
| @@ -1,20 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| 18 | - | ||
| 19 | -if(OP_API_UT OR (UT_TEST_ALL AND NOT AICPU_ONLY)) | ||
| 20 | -endif() | ||
| @@ -0,0 +1,49 @@ | |||
| 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 | + /*! | ||
| 12 | + * \file test_cos_tiling.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +using namespace std; | ||
| 23 | +class CosTilingTest : public testing::Test { | ||
| 24 | + protected: | ||
| 25 | + static void SetUpTestCase() { | ||
| 26 | + std::cout << "CosTilingTest SetUp" << std::endl; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + static void TearDownTestCase() { | ||
| 30 | + std::cout << "CosTilingTest TearDown" << std::endl; | ||
| 31 | + } | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +TEST_F(CosTilingTest, Cos_test_tiling_001) | ||
| 35 | +{ | ||
| 36 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 262144}; | ||
| 37 | + gert::TilingContextPara tilingContextPara( | ||
| 38 | + "Cos", | ||
| 39 | + { | ||
| 40 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 41 | + }, | ||
| 42 | + { | ||
| 43 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 44 | + }, | ||
| 45 | + &compileInfo); | ||
| 46 | + uint64_t expectTilingKey = 3; | ||
| 47 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 48 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectWorkspaces); | ||
| 49 | +} | ||
| @@ -1,10 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| @@ -0,0 +1,44 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_cos_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +class CosInfershape : public testing::Test { | ||
| 22 | + protected: | ||
| 23 | + static void SetUpTestCase() { | ||
| 24 | + std::cout << "Cos SetUp" << std::endl; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + static void TearDownTestCase() { | ||
| 28 | + std::cout << "Cos TearDown" << std::endl; | ||
| 29 | + } | ||
| 30 | +}; | ||
| 31 | + | ||
| 32 | +TEST_F(CosInfershape, cos_infershape_test1) | ||
| 33 | +{ | ||
| 34 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 35 | + "Cos", | ||
| 36 | + { | ||
| 37 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 41 | + }); | ||
| 42 | + std::vector<std::vector<int64_t>> expectOutputShape = {{4, 3, 4}}; | ||
| 43 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 44 | +} | ||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | -#include "random/stateless_bernoulli/op_host/op_api/stateless_bernoulli.h" | 19 | +#include "random/stateless_bernoulli/op_api/stateless_bernoulli.h" |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | -#include "random/stateless_random_normal_v2/op_host/op_api/stateless_random_normal_v2.h" | 14 | +#include "random/stateless_random_normal_v2/op_api/stateless_random_normal_v2.h" |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| @@ -1,20 +1,19 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +#设置算子定义时支持的芯片类型 |
| 13 | -if(NOT ENABLE_TEST AND NOT BENCHMARK) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend910_95") |
| 14 | - list(REMOVE_ITEM CURRENT_DIRS tests) | 13 | + |
| 15 | -endif() | 14 | +#设置每种芯片类型对应的tiling文件目录 |
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | 15 | +set(SUPPORT_TILING_DIR "arch35") |
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | 16 | + |
| 18 | - add_subdirectory(${SUB_DIR}) | 17 | +#编译 |
| 19 | - endif() | 18 | +add_all_modules_sources(OPTYPE stateless_bernoulli ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE DEPENDENCIES dsa_gen_bit_mask) |
| 20 | -endforeach() | 19 | + |
| @@ -0,0 +1,81 @@ | |||
| 1 | +# aclnnBernoulliTensor&aclnnInplaceBernoulliTensor | ||
| 2 | + | ||
| 3 | +## 产品支持情况 | ||
| 4 | + | ||
| 5 | +| 产品 | 是否支持 | | ||
| 6 | +| :----------------------------------------------------------- | :------: | | ||
| 7 | +| <term>昇腾910_95 AI处理器</term> | √ | | ||
| 8 | +| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ | | ||
| 9 | +| <term>Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件</term> | √ | | ||
| 10 | +| <term>Atlas 200I/500 A2 推理产品</term> | × | | ||
| 11 | +| <term>Atlas 推理系列产品 </term> | × | | ||
| 12 | +| <term>Atlas 训练系列产品</term> | √ | | ||
| 13 | +| <term>Atlas 200/300/500 推理产品</term> | × | | ||
| 14 | + | ||
| 15 | +## 功能说明 | ||
| 16 | + | ||
| 17 | +- 算子功能: | ||
| 18 | + 从伯努利分布中提取二进制随机数(0 或 1),prob为生成二进制随机数的概率,输入的张量用于指定shape。 | ||
| 19 | + | ||
| 20 | +- 计算公式: | ||
| 21 | + | ||
| 22 | + $$ | ||
| 23 | + out∼Bernoulli(prob) | ||
| 24 | + $$ | ||
| 25 | + | ||
| 26 | + 其中,当使用aclnnBernoulliTensor时,公式中的prob对应第一段接口中的prob,公式中的out对应第一段接口中的out;当使用aclnnInplaceBernoulliTensor时,公式中的prob对应第一段接口中的prob,公式中的out对应第一段接口中的selfRef。 | ||
| 27 | + | ||
| 28 | +## 函数原型 | ||
| 29 | + | ||
| 30 | + - aclnnBernoulliTensor和aclnnInplaceBernoulliTensor实现相同的功能,使用区别如下,请根据自身实际场景选择合适的算子。 | ||
| 31 | + - aclnnBernoulliTensor:需新建一个输出张量对象存储计算结果。 | ||
| 32 | + - aclnnInplaceBernoulliTensor:无需新建输出张量对象,直接在输入张量的内存中存储计算结果。 | ||
| 33 | + - 每个算子分为[两段式接口](common/两段式接口.md),必须先调用“aclnnBernoulliTensorGetWorkspaceSize”或者“aclnnInplaceBernoulliTensorGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnBernoulliTensor”或者“aclnnInplaceBernoulliTensor”接口执行计算。 | ||
| 34 | + | ||
| 35 | + - `aclnnStatus aclnnBernoulliTensorGetWorkspaceSize(const aclTensor* self, const aclTensor* prob, int64_t seed, int64_t offset, aclTensor* out, uint64_t* workspaceSize, aclOpExecutor** executor)` | ||
| 36 | + - `aclnnStatus aclnnBernoulliTensor(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream)` | ||
| 37 | + - `aclnnStatus aclnnInplaceBernoulliTensorGetWorkspaceSize(const aclTensor* selfRef, const aclTensor* prob, int64_t seed, int64_t offset, uint64_t* workspaceSize, aclOpExecutor** executor)` | ||
| 38 | + - `aclnnStatus aclnnInplaceBernoulliTensor(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream)` | ||
| 39 | + | ||
| 40 | +## aclnnBernoulliTensorGetWorkspaceSize | ||
| 41 | + | ||
| 42 | + - **参数说明:** | ||
| 43 | + - self(aclTensor*,计算输入):用于指定输出out的shape,Device侧的aclTensor,shape支持0-8维,shape需要与out的shape一致,支持[非连续的Tensor](common/非连续的Tensor.md),[数据格式](common/数据格式.md)支持ND。 | ||
| 44 | + - <term>Atlas 训练系列产品</term>:数据类型支持FLOAT16、FLOAT、DOUBLE、UINT8、INT8、INT16、INT32、INT64、BOOL。 | ||
| 45 | + - <term>Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件</term>、<term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>、<term>昇腾910_95 AI处理器</term>:数据类型支持FLOAT16、FLOAT、DOUBLE、UINT8、INT8、INT16、INT32、INT64、BOOL、BFLOAT16。 | ||
| 46 | + - prob(aclTensor*,计算输入):公式中的prob,Device侧的aclTensor,满足0≤prob≤1,shape支持0-8维,支持[非连续的Tensor](common/非连续的Tensor.md),且[数据格式](common/数据格式.md)需要与self一致。 | ||
| 47 | + - <term>Atlas 训练系列产品</term>:数据类型支持FLOAT16、FLOAT、DOUBLE。 | ||
| 48 | + - <term>Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件</term>、<term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>、<term>昇腾910_95 AI处理器</term>:数据类型支持FLOAT16、FLOAT、DOUBLE、BFLOAT16。 | ||
| 49 | + - seed(int64_t,计算输入):Host侧的整型,设置随机数生成器的种子。 | ||
| 50 | + - offset(int64_t,计算输入):Host侧的整型,设置随机数偏移量。 | ||
| 51 | + - out(aclTensor*,计算输出):公式中的out,Device侧的aclTensor,shape支持0-8维,shape需要与self的shape一致,数据类型与self一致,支持[非连续的Tensor](common/非连续的Tensor.md),[数据格式](common/数据格式.md)支持ND。 | ||
| 52 | + - <term>Atlas 训练系列产品</term>:数据类型支持FLOAT16、FLOAT、DOUBLE、UINT8、INT8、INT16、INT32、INT64、BOOL。 | ||
| 53 | + - <term>Atlas A2 训练系列产品/Atlas 800I A2 推理产品/A200I A2 Box 异构组件</term>、<term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term>、<term>昇腾910_95 AI处理器</term>:数据类型支持FLOAT16、FLOAT、DOUBLE、UINT8、INT8、INT16、INT32、INT64、BOOL、BFLOAT16。 | ||
| 54 | + - workspaceSize(uint64_t*,出参):返回需要在Device侧申请的workspace大小。 | ||
| 55 | + - executor(aclOpExecutor**,出参):返回op执行器,包含了算子计算流程。 | ||
| 56 | + | ||
| 57 | + - **返回值:** | ||
| 58 | + | ||
| 59 | + aclnnStatus:返回状态码,具体参见[aclnn返回码](common/aclnn返回码.md)。 | ||
| 60 | + | ||
| 61 | + ``` | ||
| 62 | + 第一段接口完成入参校验,出现如下场景时报错: | ||
| 63 | + 返回161001(ACLNN_ERR_PARAM_NULLPTR):1. 传入的self、prob或out是空指针。 | ||
| 64 | + 返回161002(ACLNN_ERR_PARAM_INVALID):1. self、prob或out的数据类型和数据格式不在支持的范围之内。 | ||
| 65 | + 2. self和out的数据类型不一致。 | ||
| 66 | + 3. self、prob或out的维度大于8。 | ||
| 67 | + 4. self和out的shape不一致。 | ||
| 68 | + ``` | ||
| 69 | + | ||
| 70 | +## aclnnBernoulliTensor | ||
| 71 | + | ||
| 72 | + - **参数说明:** | ||
| 73 | + - workspace(void*,入参):在Device侧申请的workspace内存地址。 | ||
| 74 | + - workspaceSize(uint64_t,入参):在Device侧申请的workspace大小,由第一段接口aclnnBernoulliTensorGetWorkspaceSize获取。 | ||
| 75 | + - executor(aclOpExecutor*,入参):op执行器,包含了算子计算流程。 | ||
| 76 | + - stream(aclrtStream,入参):指定执行任务的Stream。 | ||
| 77 | + | ||
| 78 | + - **返回值:** | ||
| 79 | + | ||
| 80 | + aclnnStatus:返回状态码,具体参见[aclnn返回码](common/aclnn返回码.md)。 | ||
| 81 | + | ||
| @@ -0,0 +1,158 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 test_aclnn_bernoulli_tensor.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + do { \ | ||
| 23 | + if (!(cond)) { \ | ||
| 24 | + return_expr; \ | ||
| 25 | + } \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + do { \ | ||
| 30 | + printf(message, ##__VA_ARGS__); \ | ||
| 31 | + } while (0) | ||
| 32 | + | ||
| 33 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) { | ||
| 34 | + int64_t shapeSize = 1; | ||
| 35 | + for (auto i : shape) { | ||
| 36 | + shapeSize *= i; | ||
| 37 | + } | ||
| 38 | + return shapeSize; | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +int Init(int32_t deviceId, aclrtStream* stream) { | ||
| 42 | + // 固定写法,资源初始化 | ||
| 43 | + auto ret = aclInit(nullptr); | ||
| 44 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 45 | + ret = aclrtSetDevice(deviceId); | ||
| 46 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 47 | + ret = aclrtCreateStream(stream); | ||
| 48 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 49 | + return 0; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +template <typename T> | ||
| 53 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | ||
| 54 | + aclDataType dataType, aclTensor** tensor) { | ||
| 55 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 56 | + // 调用aclrtMalloc申请Device侧内存 | ||
| 57 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 58 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 59 | + | ||
| 60 | + // 调用aclrtMemcpy将Host侧数据拷贝到Device侧内存上 | ||
| 61 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 62 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 63 | + | ||
| 64 | + // 计算连续tensor的strides | ||
| 65 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 66 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 67 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + // 调用aclCreateTensor接口创建aclTensor | ||
| 71 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, | ||
| 72 | + shape.data(), shape.size(), *deviceAddr); | ||
| 73 | + return 0; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +int main() { | ||
| 77 | + // 1. (固定写法)device/stream初始化,参考acl API手册 | ||
| 78 | + // 根据自己的实际device填写deviceId | ||
| 79 | + int32_t deviceId = 0; | ||
| 80 | + aclrtStream stream; | ||
| 81 | + auto ret = Init(deviceId, &stream); | ||
| 82 | + // check根据自己的需要处理 | ||
| 83 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 84 | + | ||
| 85 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 | ||
| 86 | + std::vector<int64_t> selfShape = {4, 4}; | ||
| 87 | + std::vector<int64_t> probShape = {4, 4}; | ||
| 88 | + std::vector<int64_t> outShape = {4, 4}; | ||
| 89 | + void* selfDeviceAddr = nullptr; | ||
| 90 | + void* probDeviceAddr = nullptr; | ||
| 91 | + void* outDeviceAddr = nullptr; | ||
| 92 | + aclTensor* self = nullptr; | ||
| 93 | + aclTensor* prob = nullptr; | ||
| 94 | + aclTensor* out = nullptr; | ||
| 95 | + std::vector<float> selfHostData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; | ||
| 96 | + std::vector<float> probHostData = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; | ||
| 97 | + std::vector<float> outHostData(16, 0); | ||
| 98 | + int64_t seed = 0; | ||
| 99 | + int64_t offset = 0; | ||
| 100 | + // 创建self aclTensor | ||
| 101 | + ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); | ||
| 102 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 103 | + // 创建prob aclTensor | ||
| 104 | + ret = CreateAclTensor(probHostData, probShape, &probDeviceAddr, aclDataType::ACL_FLOAT, &prob); | ||
| 105 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 106 | + // 创建out aclTensor | ||
| 107 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | ||
| 108 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 109 | + | ||
| 110 | + uint64_t workspaceSize = 0; | ||
| 111 | + aclOpExecutor* executor; | ||
| 112 | + | ||
| 113 | + // aclnnBernoulliTensor接口调用示例 | ||
| 114 | + // 3. 调用CANN算子库API | ||
| 115 | + // 调用aclnnBernoulliTensor第一段接口 | ||
| 116 | + ret = aclnnBernoulliTensorGetWorkspaceSize(self, prob, seed, offset, out, &workspaceSize, &executor); | ||
| 117 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnBernoulliTensorGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); | ||
| 118 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 119 | + void* workspaceAddr = nullptr; | ||
| 120 | + if (workspaceSize > 0) { | ||
| 121 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 122 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 123 | + } | ||
| 124 | + // 调用aclnnBernoulliTensor第二段接口 | ||
| 125 | + ret = aclnnBernoulliTensor(workspaceAddr, workspaceSize, executor, stream); | ||
| 126 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnBernoulliTensor failed. ERROR: %d\n", ret); return ret); | ||
| 127 | + | ||
| 128 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 129 | + ret = aclrtSynchronizeStream(stream); | ||
| 130 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 131 | + | ||
| 132 | + // 5. 获取输出的值,将Device侧内存上的结果拷贝至Host侧,需要根据具体API的接口定义修改 | ||
| 133 | + auto size = GetShapeSize(outShape); | ||
| 134 | + std::vector<float> resultData(size, 0); | ||
| 135 | + ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, | ||
| 136 | + size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 137 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 138 | + for (int64_t i = 0; i < size; i++) { | ||
| 139 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 | ||
| 143 | + aclDestroyTensor(self); | ||
| 144 | + aclDestroyTensor(prob); | ||
| 145 | + aclDestroyTensor(out); | ||
| 146 | + | ||
| 147 | + // 7. 释放device资源,需要根据具体API的接口定义修改 | ||
| 148 | + aclrtFree(selfDeviceAddr); | ||
| 149 | + aclrtFree(probDeviceAddr); | ||
| 150 | + aclrtFree(outDeviceAddr); | ||
| 151 | + if (workspaceSize > 0) { | ||
| 152 | + aclrtFree(workspaceAddr); | ||
| 153 | + } | ||
| 154 | + aclrtDestroyStream(stream); | ||
| 155 | + aclrtResetDevice(deviceId); | ||
| 156 | + aclFinalize(); | ||
| 157 | + return 0; | ||
| 158 | +} | ||
| @@ -0,0 +1,96 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | +using namespace op; | ||
| 26 | + | ||
| 27 | +namespace l0op { | ||
| 28 | + | ||
| 29 | +OP_TYPE_REGISTER(StatelessBernoulli); | ||
| 30 | + | ||
| 31 | +static const std::initializer_list<DataType> AICORE_DTYPE_SUPPORT_LIST = { | ||
| 32 | + DataType::DT_INT8, DataType::DT_UINT8, DataType::DT_INT16, DataType::DT_UINT16, | ||
| 33 | + DataType::DT_INT32, DataType::DT_UINT32, DataType::DT_INT64, DataType::DT_UINT64, | ||
| 34 | + DataType::DT_FLOAT, DataType::DT_FLOAT16, DataType::DT_BF16, DataType::DT_BOOL | ||
| 35 | +}; | ||
| 36 | + | ||
| 37 | +static const std::initializer_list<DataType> AICORE_PROB_DTYPE_SUPPORT_LIST = { | ||
| 38 | + DataType::DT_FLOAT, DataType::DT_FLOAT16, DataType::DT_BF16 | ||
| 39 | +}; | ||
| 40 | + | ||
| 41 | +// 根据芯片型号,dtype 判断AICore 是否支持 | ||
| 42 | +static inline bool IsAiCoreSupport(DataType yDtype, DataType pDtype) | ||
| 43 | +{ | ||
| 44 | + if (GetCurrentPlatformInfo().GetSocVersion() == op::SocVersion::ASCEND910_95) { | ||
| 45 | + return CheckType(yDtype, AICORE_DTYPE_SUPPORT_LIST) && CheckType(pDtype, AICORE_PROB_DTYPE_SUPPORT_LIST); | ||
| 46 | + } | ||
| 47 | + return false; | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +// AICPU算子kernel | ||
| 51 | +static const aclTensor *StatelessBernoulliAiCpu(const aclTensor *shapeTensor, const aclTensor *prob, | ||
| 52 | + const aclTensor *seed, const aclTensor *offset, aclTensor *out, | ||
| 53 | + aclOpExecutor *executor) { | ||
| 54 | + L0_DFX(StatelessBernoulliAiCpu, shapeTensor, prob, seed, offset, out); | ||
| 55 | + | ||
| 56 | + static internal::AicpuTaskSpace space("StatelessBernoulli"); | ||
| 57 | + ADD_TO_LAUNCHER_LIST_AICPU(StatelessBernoulli, | ||
| 58 | + OP_ATTR_NAMES({"dtype"}), | ||
| 59 | + OP_INPUT(shapeTensor, prob, seed, offset), | ||
| 60 | + OP_OUTPUT(out), | ||
| 61 | + OP_ATTR(out->GetDataType())); | ||
| 62 | + return out; | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +// AICORE算子kernel | ||
| 66 | +static const aclTensor *StatelessBernoulliAiCore(const aclTensor *shapeTensor, const aclTensor *prob, | ||
| 67 | + const aclTensor *seed, const aclTensor *offset, const aclTensor *out, | ||
| 68 | + aclOpExecutor *executor) { | ||
| 69 | + L0_DFX(StatelessBernoulliAiCore, shapeTensor, prob, seed, offset, out); | ||
| 70 | + | ||
| 71 | + // 使用框架宏 ADD_TO_LAUNCHER_LIST_AICORE | ||
| 72 | + ADD_TO_LAUNCHER_LIST_AICORE(StatelessBernoulli, | ||
| 73 | + OP_ATTR_NAMES({"dtype"}), | ||
| 74 | + OP_INPUT(shapeTensor, prob, seed, offset), | ||
| 75 | + OP_OUTPUT(out), | ||
| 76 | + OP_ATTR(out->GetDataType())); | ||
| 77 | + return out; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +const aclTensor *StatelessBernoulli(const aclTensor *input, const aclTensor *prob, int64_t seed, int64_t offset, | ||
| 81 | + aclOpExecutor *executor) { | ||
| 82 | + auto inputShape = op::ToShapeVector(input->GetViewShape()); | ||
| 83 | + auto sizeArr = executor->AllocIntArray(inputShape.data(), inputShape.size()); | ||
| 84 | + auto shapeTensor = executor->ConvertToTensor(sizeArr, DataType::DT_INT32); | ||
| 85 | + auto seedTensor = executor->ConvertToTensor(executor->AllocScalar(seed), op::DataType::DT_INT64); | ||
| 86 | + auto offsetTensor = executor->ConvertToTensor(executor->AllocScalar(offset), op::DataType::DT_INT64); | ||
| 87 | + | ||
| 88 | + auto out = executor->AllocTensor(input->GetViewShape(), input->GetDataType(), input->GetViewFormat()); | ||
| 89 | + if (IsAiCoreSupport(out->GetDataType(), prob->GetDataType())) { | ||
| 90 | + return StatelessBernoulliAiCore(shapeTensor, prob, seedTensor, offsetTensor, out, executor); | ||
| 91 | + } else { | ||
| 92 | + return StatelessBernoulliAiCpu(shapeTensor, prob, seedTensor, offsetTensor, out, executor); | ||
| 93 | + } | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | +} // namespace l0op | ||
| @@ -0,0 +1,27 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace l0op { | ||
| 22 | +const aclTensor *StatelessBernoulli(const aclTensor *input, const aclTensor *prob, int64_t seed, int64_t offset, | ||
| 23 | + aclOpExecutor *executor); | ||
| 24 | + | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | + | ||
The file is empty
| @@ -0,0 +1,39 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +using namespace ge; | ||
| 21 | + | ||
| 22 | +namespace ops { | ||
| 23 | +const int32_t INDEX_OUTPUT_Y = 0; | ||
| 24 | +const int32_t INDEX_ATTR = 0; | ||
| 25 | + | ||
| 26 | +static ge::graphStatus InferDataType4StatelessBernoulli(gert::InferDataTypeContext* context) | ||
| 27 | +{ | ||
| 28 | + OP_LOGD(context->GetNodeName(), " InferDataType4StatelessBernoulli runtime2.0 is begin."); | ||
| 29 | + auto attrPtr = context->GetAttrs(); | ||
| 30 | + OP_CHECK_NULL_WITH_CONTEXT(context, attrPtr); | ||
| 31 | + auto dTypePtr = attrPtr->GetAttrPointer<int32_t>(INDEX_ATTR); | ||
| 32 | + OP_CHECK_NULL_WITH_CONTEXT(context, dTypePtr); | ||
| 33 | + ge::DataType outDtype = static_cast<ge::DataType>(*dTypePtr); | ||
| 34 | + context->SetOutputDataType(INDEX_OUTPUT_Y, outDtype); | ||
| 35 | + return ge::GRAPH_SUCCESS; | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +IMPL_OP(StatelessBernoulli).InferDataType(InferDataType4StatelessBernoulli); | ||
| 39 | +} // namespace ops | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli_proto.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace ge { | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | +* @brief Generate bernoulli distribution for tensor input . \n | ||
| 26 | + | ||
| 27 | +* @par Inputs: | ||
| 28 | +include: | ||
| 29 | +* @li shape: 1-D. The shape of the input tensor. A tensor of type int32, int64. | ||
| 30 | +* @li prob: 0-D. A tensor of type float16, float32, double, bfloat16. | ||
| 31 | +* Probability of bernoulli distribution, the value range from 0 to 1. | ||
| 32 | +* @li seed: If seed is set to be -1, and offset is set to be 0, the random number | ||
| 33 | +* generator is seeded by a random seed. Otherwise, it is seeded by the given seed. | ||
| 34 | +* A tensor of type int64. | ||
| 35 | +* @li offset: To avoid seed collision. A tensor of type int64. | ||
| 36 | + | ||
| 37 | +* @par Attributes: | ||
| 38 | +* dtype: The data type for the elements of the output tensor. | ||
| 39 | + | ||
| 40 | +* @par Outputs: | ||
| 41 | +* y: A tensor. The tensor of type support int8, uint8, int16, uint16, | ||
| 42 | +* int32, uint32, int64, uint64, bool, float16, float, double, bf16. \n | ||
| 43 | +*/ | ||
| 44 | +REG_OP(StatelessBernoulli) | ||
| 45 | + .INPUT(shape, TensorType({ DT_INT32, DT_INT64})) | ||
| 46 | + .INPUT(prob, TensorType({ DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BF16})) | ||
| 47 | + .INPUT(seed, TensorType({ DT_INT64 })) | ||
| 48 | + .INPUT(offset, TensorType({ DT_INT64 })) | ||
| 49 | + .OUTPUT(y, TensorType({ DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_UINT32, | ||
| 50 | + DT_INT64, DT_UINT64, DT_BOOL, DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BF16})) | ||
| 51 | + .ATTR(dtype, Type, DT_FLOAT) | ||
| 52 | + .OP_END_FACTORY_REG(StatelessBernoulli) | ||
| 53 | + | ||
| 54 | +} // namespace ge | ||
| 55 | + | ||
| @@ -1,11 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | -add_modules_sources(OPTYPE stateless_bernoulli ACLNNTYPE aclnn_exclude) | ||
| @@ -0,0 +1,146 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli_tiling_arch35.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +namespace optiling { | ||
| 24 | +constexpr uint16_t ALG_KEY_SIZE = 2; | ||
| 25 | +constexpr uint16_t ALG_COUNTER_SIZE = 4; | ||
| 26 | + | ||
| 27 | +BEGIN_TILING_DATA_DEF(StatelessBernoulliTilingData) | ||
| 28 | +TILING_DATA_FIELD_DEF(uint64_t, blockNum); // 使用核数 | ||
| 29 | +TILING_DATA_FIELD_DEF(uint64_t, blockTilingSize); // 非尾核处理元素个数 | ||
| 30 | +TILING_DATA_FIELD_DEF(uint64_t, tailBlockTilingSize); // 尾核处理元素个数 | ||
| 31 | +TILING_DATA_FIELD_DEF(uint64_t, blockLoopCount); // 非尾核核内loop次数 | ||
| 32 | +TILING_DATA_FIELD_DEF(uint64_t, tailBlockLoopCount); // 尾核核内loop次数 | ||
| 33 | +TILING_DATA_FIELD_DEF(uint64_t, ubTilingSize); // 单次loop处理元素个数 | ||
| 34 | +TILING_DATA_FIELD_DEF(uint64_t, probTensorSize); // probTensor元素个数 | ||
| 35 | +TILING_DATA_FIELD_DEF(uint64_t, outputSize); // 输出元素个数 | ||
| 36 | +TILING_DATA_FIELD_DEF(uint64_t, isProbScalar); // prob是否为scalar | ||
| 37 | +TILING_DATA_FIELD_DEF_ARR(uint32_t, ALG_KEY_SIZE, key); // 输入key数组 | ||
| 38 | +TILING_DATA_FIELD_DEF_ARR(uint32_t, ALG_COUNTER_SIZE, counter); // 输入counter数组 | ||
| 39 | +END_TILING_DATA_DEF; | ||
| 40 | + | ||
| 41 | +REGISTER_TILING_DATA_CLASS(StatelessBernoulli, StatelessBernoulliTilingData) | ||
| 42 | + | ||
| 43 | +struct StatelessBernoulliCompileInfoArch35 { | ||
| 44 | + uint64_t aivNum; | ||
| 45 | + uint64_t ubSize; | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +class StatelessBernoulliTiling : public Ops::Math::OpTiling::TilingBaseClass { | ||
| 49 | +public: | ||
| 50 | + explicit StatelessBernoulliTiling(gert::TilingContext *context) : TilingBaseClass(context) { | ||
| 51 | + Reset(); | ||
| 52 | + } | ||
| 53 | + ~StatelessBernoulliTiling() override = default; | ||
| 54 | + void Reset(gert::TilingContext *context) override | ||
| 55 | + { | ||
| 56 | + TilingBaseClass::Reset(context); | ||
| 57 | + Reset(); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + enum class Algorithm : int { | ||
| 61 | + RNG_ALG_PHILOX = 1, | ||
| 62 | + RNG_ALG_THREEFRY = 2, | ||
| 63 | + RNG_ALG_AUTO_SELECT = 3 | ||
| 64 | + }; | ||
| 65 | + | ||
| 66 | +protected: | ||
| 67 | + bool IsCapable() override | ||
| 68 | + { | ||
| 69 | + return true; | ||
| 70 | + } | ||
| 71 | + // 顺序执行1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 | ||
| 72 | + // 1、获取平台信息比如CoreNum、UB/L1/L0C资源大小 | ||
| 73 | + ge::graphStatus GetPlatformInfo() override; | ||
| 74 | + // 2、获取INPUT/OUTPUT/ATTR信息 | ||
| 75 | + ge::graphStatus GetShapeAttrsInfo() override; | ||
| 76 | + // 3、计算数据切分TilingData | ||
| 77 | + ge::graphStatus DoOpTiling() override; | ||
| 78 | + // 4、计算高阶API的TilingData | ||
| 79 | + ge::graphStatus DoLibApiTiling() override; | ||
| 80 | + // 5、计算TilingKey | ||
| 81 | + uint64_t GetTilingKey() const override; | ||
| 82 | + // 6、计算Workspace 大小 | ||
| 83 | + ge::graphStatus GetWorkspaceSize() override; | ||
| 84 | + // 7、保存Tiling数据 | ||
| 85 | + ge::graphStatus PostTiling() override; | ||
| 86 | + // 8、dump日志 | ||
| 87 | + void DumpTilingInfo() override; | ||
| 88 | + // 9、reset重置 | ||
| 89 | + void Reset(); | ||
| 90 | + | ||
| 91 | +private: | ||
| 92 | + static constexpr uint64_t BUFFER_NUM = 2; | ||
| 93 | + static constexpr uint64_t EXIST_NODE_NUM = 4; | ||
| 94 | + static constexpr uint64_t CORE_ALIGN_SIZE = 512; | ||
| 95 | + static constexpr uint64_t BLOCK_SIZE_BYTES = 32; | ||
| 96 | + static constexpr uint64_t MIN_TILING_SIZE = 256; | ||
| 97 | + static constexpr uint64_t DEFAULT_WORKSPACE_SIZE = 16 * 1024 * 1024; | ||
| 98 | + | ||
| 99 | + template <typename T> | ||
| 100 | + ge::graphStatus GetIntValue(const gert::Tensor *constTensor, gert::Shape &constShape); | ||
| 101 | + ge::graphStatus GetIntToShape(const int64_t constIdx, gert::Shape &constShape); | ||
| 102 | + | ||
| 103 | + inline uint64_t GetBytePerData(const ge::DataType& dtype); | ||
| 104 | + ge::graphStatus GetInputInfo(); | ||
| 105 | + ge::graphStatus GetOutputInfo(); | ||
| 106 | + ge::graphStatus GetAttrInfo(); | ||
| 107 | + ge::graphStatus GetInputKeyCounter(); | ||
| 108 | + int64_t GetCounterSize(Algorithm alg) const; | ||
| 109 | + void GetKeyFromMem(const int64_t key); | ||
| 110 | + void GetCounterFromMem(const std::vector<int64_t> &counter); | ||
| 111 | + void BlockTiling(); | ||
| 112 | + ge::graphStatus UbTiling(); | ||
| 113 | + void SetTilingData(); | ||
| 114 | + ge::graphStatus GetIntValueFromProb(const gert::Shape &originShape, gert::Shape &constShape, size_t shapeSize); | ||
| 115 | + | ||
| 116 | +private: | ||
| 117 | + gert::Shape inputShape_; | ||
| 118 | + gert::Shape inputSeed_; | ||
| 119 | + gert::Shape inputOffset_; | ||
| 120 | + ge::DataType probDtype_; | ||
| 121 | + ge::DataType inputDtype_; | ||
| 122 | + ge::DataType outputDtype_; | ||
| 123 | + | ||
| 124 | + uint64_t coreNum_ = 0; | ||
| 125 | + uint64_t ubSize_ = 0; | ||
| 126 | + uint64_t inputSize_ = 1; | ||
| 127 | + uint64_t inputDtypeSize_ = 0; | ||
| 128 | + uint64_t blockNum_ = 0; | ||
| 129 | + uint64_t blockTilingSize_ = 0; | ||
| 130 | + uint64_t tailBlockTilingSize_ = 0; | ||
| 131 | + uint64_t blockLoopCount_ = 0; | ||
| 132 | + uint64_t tailBlockLoopCount_ = 0; | ||
| 133 | + uint64_t ubTilingSize_ = 0; | ||
| 134 | + uint64_t probTensorSize_ = 0; | ||
| 135 | + uint64_t outputSize_ = 1; | ||
| 136 | + uint64_t isProbScalar_ = 1; | ||
| 137 | + | ||
| 138 | + Algorithm alg_ = Algorithm::RNG_ALG_PHILOX; | ||
| 139 | + uint32_t key_[ALG_KEY_SIZE] = {0, 0}; | ||
| 140 | + uint32_t counter_[ALG_COUNTER_SIZE] = {0, 0, 0, 0}; | ||
| 141 | + | ||
| 142 | + const char *opName_ = ""; | ||
| 143 | + StatelessBernoulliTilingData m_tilingData_; | ||
| 144 | +}; | ||
| 145 | +} // namespace optiling | ||
| 146 | + | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示: | ||
| 2 | +; [某算子] | ||
| 3 | +; default=xx | ||
| 4 | +; ascendxx=xx | ||
| 5 | +; 其中,default为默认mode,ascnedxx为可选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 | +[StatelessBernoulli] | ||
| 13 | +default=0 | ||
| @@ -1,93 +0,0 @@ | |||
| 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 | -/*! | ||
| 12 | - * \file stateless_bernoulli.cpp | ||
| 13 | - * \brief | ||
| 14 | - */ | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - | ||
| 23 | - | ||
| 24 | - | ||
| 25 | -using namespace op; | ||
| 26 | - | ||
| 27 | -namespace l0op { | ||
| 28 | - | ||
| 29 | -OP_TYPE_REGISTER(StatelessBernoulli); | ||
| 30 | - | ||
| 31 | -static const std::initializer_list<DataType> AICORE_DTYPE_SUPPORT_LIST = { | ||
| 32 | - DataType::DT_INT8, DataType::DT_UINT8, DataType::DT_INT16, DataType::DT_UINT16, | ||
| 33 | - DataType::DT_INT32, DataType::DT_UINT32, DataType::DT_INT64, DataType::DT_UINT64, | ||
| 34 | - DataType::DT_FLOAT, DataType::DT_FLOAT16, DataType::DT_BF16, DataType::DT_BOOL}; | ||
| 35 | - | ||
| 36 | -static const std::initializer_list<DataType> AICORE_PROB_DTYPE_SUPPORT_LIST = { | ||
| 37 | - DataType::DT_FLOAT, DataType::DT_FLOAT16, DataType::DT_BF16}; | ||
| 38 | - | ||
| 39 | -// 根据芯片型号,dtype 判断AICore 是否支持 | ||
| 40 | -static inline bool IsAiCoreSupport(DataType yDtype, DataType pDtype) | ||
| 41 | -{ | ||
| 42 | - if (GetCurrentPlatformInfo().GetSocVersion() == op::SocVersion::ASCEND910_95) { | ||
| 43 | - return CheckType(yDtype, AICORE_DTYPE_SUPPORT_LIST) && CheckType(pDtype, AICORE_PROB_DTYPE_SUPPORT_LIST); | ||
| 44 | - } | ||
| 45 | - return false; | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | -// AICPU算子kernel | ||
| 49 | -static const aclTensor* StatelessBernoulliAiCpu( | ||
| 50 | - const aclTensor* shapeTensor, const aclTensor* prob, const aclTensor* seed, const aclTensor* offset, aclTensor* out, | ||
| 51 | - aclOpExecutor* executor) | ||
| 52 | -{ | ||
| 53 | - L0_DFX(StatelessBernoulliAiCpu, shapeTensor, prob, seed, offset, out); | ||
| 54 | - | ||
| 55 | - static internal::AicpuTaskSpace space("StatelessBernoulli"); | ||
| 56 | - ADD_TO_LAUNCHER_LIST_AICPU( | ||
| 57 | - StatelessBernoulli, OP_ATTR_NAMES({"dtype"}), OP_INPUT(shapeTensor, prob, seed, offset), OP_OUTPUT(out), | ||
| 58 | - OP_ATTR(out->GetDataType())); | ||
| 59 | - return out; | ||
| 60 | -} | ||
| 61 | - | ||
| 62 | -// AICORE算子kernel | ||
| 63 | -static const aclTensor* StatelessBernoulliAiCore( | ||
| 64 | - const aclTensor* shapeTensor, const aclTensor* prob, const aclTensor* seed, const aclTensor* offset, | ||
| 65 | - const aclTensor* out, aclOpExecutor* executor) | ||
| 66 | -{ | ||
| 67 | - L0_DFX(StatelessBernoulliAiCore, shapeTensor, prob, seed, offset, out); | ||
| 68 | - | ||
| 69 | - // 使用框架宏 ADD_TO_LAUNCHER_LIST_AICORE | ||
| 70 | - ADD_TO_LAUNCHER_LIST_AICORE( | ||
| 71 | - StatelessBernoulli, OP_ATTR_NAMES({"dtype"}), OP_INPUT(shapeTensor, prob, seed, offset), OP_OUTPUT(out), | ||
| 72 | - OP_ATTR(out->GetDataType())); | ||
| 73 | - return out; | ||
| 74 | -} | ||
| 75 | - | ||
| 76 | -const aclTensor* StatelessBernoulli( | ||
| 77 | - const aclTensor* input, const aclTensor* prob, int64_t seed, int64_t offset, aclOpExecutor* executor) | ||
| 78 | -{ | ||
| 79 | - auto inputShape = op::ToShapeVector(input->GetViewShape()); | ||
| 80 | - auto sizeArr = executor->AllocIntArray(inputShape.data(), inputShape.size()); | ||
| 81 | - auto shapeTensor = executor->ConvertToTensor(sizeArr, DataType::DT_INT32); | ||
| 82 | - auto seedTensor = executor->ConvertToTensor(executor->AllocScalar(seed), op::DataType::DT_INT64); | ||
| 83 | - auto offsetTensor = executor->ConvertToTensor(executor->AllocScalar(offset), op::DataType::DT_INT64); | ||
| 84 | - | ||
| 85 | - auto out = executor->AllocTensor(input->GetViewShape(), input->GetDataType(), input->GetViewFormat()); | ||
| 86 | - if (IsAiCoreSupport(out->GetDataType(), prob->GetDataType())) { | ||
| 87 | - return StatelessBernoulliAiCore(shapeTensor, prob, seedTensor, offsetTensor, out, executor); | ||
| 88 | - } else { | ||
| 89 | - return StatelessBernoulliAiCpu(shapeTensor, prob, seedTensor, offsetTensor, out, executor); | ||
| 90 | - } | ||
| 91 | -} | ||
| 92 | - | ||
| 93 | -} // namespace l0op | ||
| @@ -0,0 +1,131 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli_def.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +namespace ops { | ||
| 18 | +class StatelessBernoulli : public OpDef { | ||
| 19 | + public: | ||
| 20 | + const std::vector<ge::DataType> inputDataType = { | ||
| 21 | + ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, | ||
| 22 | + ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, | ||
| 23 | + ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, | ||
| 24 | + ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, | ||
| 25 | + ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, | ||
| 26 | + ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, | ||
| 27 | + | ||
| 28 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 29 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 30 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 31 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 32 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 33 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64}; | ||
| 34 | + | ||
| 35 | + const std::vector<ge::DataType> probDataType = { | ||
| 36 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 37 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 38 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 39 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 40 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 41 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 42 | + | ||
| 43 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 44 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 45 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 46 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 47 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 48 | + ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16}; | ||
| 49 | + | ||
| 50 | + const std::vector<ge::DataType> baseDataType = { | ||
| 51 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 52 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 53 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 54 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 55 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 56 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 57 | + | ||
| 58 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 59 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 60 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 61 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 62 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, | ||
| 63 | + ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT64}; | ||
| 64 | + | ||
| 65 | + const std::vector<ge::DataType> outputDataType = { | ||
| 66 | + ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, ge::DT_UINT64, ge::DT_BOOL, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 67 | + ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, ge::DT_UINT64, ge::DT_BOOL, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 68 | + ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, ge::DT_UINT64, ge::DT_BOOL, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 69 | + ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, ge::DT_UINT64, ge::DT_BOOL, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 70 | + ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, ge::DT_UINT64, ge::DT_BOOL, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, | ||
| 71 | + ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, ge::DT_UINT64, ge::DT_BOOL, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16}; | ||
| 72 | + | ||
| 73 | + const std::vector<ge::Format> baseFormat = { | ||
| 74 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 75 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 76 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 77 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 78 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 79 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 80 | + | ||
| 81 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 82 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 83 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 84 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 85 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 86 | + ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}; | ||
| 87 | + | ||
| 88 | + explicit StatelessBernoulli(const char* name) : OpDef(name) { | ||
| 89 | + this->Input("shape") | ||
| 90 | + .ParamType(REQUIRED) | ||
| 91 | + .DataType(inputDataType) | ||
| 92 | + .Format(baseFormat) | ||
| 93 | + .UnknownShapeFormat(baseFormat) | ||
| 94 | + .ValueDepend(OPTIONAL); | ||
| 95 | + this->Input("prob") | ||
| 96 | + .ParamType(REQUIRED) | ||
| 97 | + .DataType(probDataType) | ||
| 98 | + .Format(baseFormat) | ||
| 99 | + .UnknownShapeFormat(baseFormat); | ||
| 100 | + this->Input("seed") | ||
| 101 | + .ParamType(REQUIRED) | ||
| 102 | + .DataType(baseDataType) | ||
| 103 | + .Format(baseFormat) | ||
| 104 | + .UnknownShapeFormat(baseFormat) | ||
| 105 | + .ValueDepend(OPTIONAL); | ||
| 106 | + this->Input("offset") | ||
| 107 | + .ParamType(OPTIONAL) | ||
| 108 | + .DataType(baseDataType) | ||
| 109 | + .Format(baseFormat) | ||
| 110 | + .UnknownShapeFormat(baseFormat) | ||
| 111 | + .ValueDepend(OPTIONAL); | ||
| 112 | + this->Output("y") | ||
| 113 | + .ParamType(REQUIRED) | ||
| 114 | + .DataType(outputDataType) | ||
| 115 | + .Format(baseFormat) | ||
| 116 | + .UnknownShapeFormat(baseFormat); | ||
| 117 | + this->Attr("dtype").AttrType(OPTIONAL).Int(); | ||
| 118 | + | ||
| 119 | + OpAICoreConfig aicoreConfig; | ||
| 120 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 121 | + .DynamicFormatFlag(false) | ||
| 122 | + .DynamicRankSupportFlag(true) | ||
| 123 | + .DynamicShapeSupportFlag(true) | ||
| 124 | + .NeedCheckSupportFlag(false) | ||
| 125 | + .PrecisionReduceFlag(true); | ||
| 126 | + this->AICore().AddConfig("ascend910_95"); | ||
| 127 | + } | ||
| 128 | +}; | ||
| 129 | + | ||
| 130 | +OP_ADD(StatelessBernoulli); | ||
| 131 | +} // namespace ops | ||
| @@ -0,0 +1,127 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 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 stateless_bernoulli_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +using namespace ge; | ||
| 21 | + | ||
| 22 | +namespace ops { | ||
| 23 | +const int32_t INDEX_INPUT_SHAPE = 0; | ||
| 24 | +const int32_t INDEX_INPUT_PROB = 1; | ||
| 25 | +const int32_t INDEX_INPUT_SEED = 2; | ||
| 26 | +const int32_t INDEX_INPUT_OFFSET = 3; | ||
| 27 | +const int32_t INDEX_OUTPUT_Y = 0; | ||
| 28 | +const int32_t INDEX_ATTR = 0; | ||
| 29 | + | ||
| 30 | +template <typename T> | ||
| 31 | +graphStatus InferShapeImpl(const T* shapeData, gert::Shape& outputShape, size_t shapeSize) | ||
| 32 | +{ | ||
| 33 | + outputShape.SetDimNum(shapeSize); | ||
| 34 | + for (size_t i = 0U; i < shapeSize; i++) { | ||
| 35 | + outputShape.SetDim(i, shapeData[i]); | ||
| 36 | + } | ||
| 37 | + return ge::GRAPH_SUCCESS; | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +graphStatus InferShapeImplFromProb(const gert::Shape* probShape, gert::Shape& outputShape, size_t shapeSize) | ||
| 41 | +{ | ||
| 42 | + outputShape.SetDimNum(shapeSize); | ||
| 43 | + for (size_t i = 0U; i < shapeSize; i++) { | ||
| 44 | + outputShape.SetDim(i, probShape->GetDim(i)); | ||
| 45 | + } | ||
| 46 | + return ge::GRAPH_SUCCESS; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +template <typename T> | ||
| 50 | +graphStatus InferShapeCheckShapeAndProb( | ||
| 51 | + const T* shapeData, const gert::Shape* probShape, size_t shapeSize, uint64_t* checkFlag) | ||
| 52 | +{ | ||
| 53 | + *checkFlag = 0; | ||
| 54 | + bool allShapeMinusOne = true; | ||
| 55 | + for (size_t i = 0U; i < shapeSize; i++) { | ||
| 56 | + if (shapeData[i] != -1) { | ||
| 57 | + allShapeMinusOne = false; | ||
| 58 | + break; | ||
| 59 | + } | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + bool allProbNotMinusOne = true; | ||
| 63 | + for (size_t i = 0U; i < shapeSize; i++) { | ||
| 64 | + if (probShape->GetDim(i) == -1) { | ||
| 65 | + allProbNotMinusOne = false; | ||
| 66 | + break; | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + if (allShapeMinusOne && allProbNotMinusOne) { | ||
| 70 | + *checkFlag = 1; | ||
| 71 | + } | ||
| 72 | + return ge::GRAPH_SUCCESS; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +static ge::graphStatus InferShape4StatelessBernoulli(gert::InferShapeContext* context) | ||
| 76 | +{ | ||
| 77 | + OP_LOGD(context->GetNodeName(), " StatelessBernoulli runtime2.0 is begin."); | ||
| 78 | + const gert::Tensor* shapeTensor = context->GetInputTensor(INDEX_INPUT_SHAPE); | ||
| 79 | + auto probShape = context->GetInputShape(INDEX_INPUT_PROB); | ||
| 80 | + OP_CHECK_NULL_WITH_CONTEXT(context, shapeTensor); | ||
| 81 | + ge::DataType shapeDtype = shapeTensor->GetDataType(); | ||
| 82 | + gert::Shape* yShape = context->GetOutputShape(INDEX_OUTPUT_Y); | ||
| 83 | + auto xShapeSize = shapeTensor->GetShapeSize(); | ||
| 84 | + if (xShapeSize < 0) { | ||
| 85 | + return ge::GRAPH_FAILED; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + uint64_t checkFlag = 0; | ||
| 89 | + switch (shapeDtype) { | ||
| 90 | + case ge::DT_INT32: { | ||
| 91 | + Ops::Base::GetValueToShape<int32_t>(shapeTensor, *yShape); | ||
| 92 | + auto shapeData = shapeTensor->GetData<int32_t>(); | ||
| 93 | + OP_CHECK_IF(InferShapeCheckShapeAndProb<int32_t>( | ||
| 94 | + shapeData, probShape, static_cast<size_t>(xShapeSize), &checkFlag) != ge::GRAPH_SUCCESS, | ||
| 95 | + OP_LOGE(context->GetNodeName(), "Check shape(int32) and prob failed."), return ge::GRAPH_FAILED;); | ||
| 96 | + break; | ||
| 97 | + } | ||
| 98 | + case ge::DT_INT64: { | ||
| 99 | + Ops::Base::GetValueToShape<int64_t>(shapeTensor, *yShape); | ||
| 100 | + auto shapeData = shapeTensor->GetData<int64_t>(); | ||
| 101 | + OP_CHECK_IF(InferShapeCheckShapeAndProb<int64_t>( | ||
| 102 | + shapeData, probShape, static_cast<size_t>(xShapeSize), &checkFlag) != ge::GRAPH_SUCCESS, | ||
| 103 | + OP_LOGE(context->GetNodeName(), "Check shape(int64) and prob failed."), return ge::GRAPH_FAILED;); | ||
| 104 | + break; | ||
| 105 | + } | ||
| 106 | + default: | ||
| 107 | + OP_LOGE_WITH_INVALID_INPUT_DTYPE( | ||
| 108 | + "shape",context->GetNodeName(),Ops::Base::ToString(shapeDtype).c_str(),"[int32, int64]"); | ||
| 109 | + return ge::GRAPH_FAILED; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + InferShapeImplFromProb(probShape, *yShape, static_cast<size_t>(xShapeSize)); | ||
| 113 | + | ||
| 114 | + if (shapeTensor->GetDataType() == ge::DT_INT32) { | ||
| 115 | + auto shapeData = shapeTensor->GetData<int32_t>(); | ||
| 116 | + return InferShapeImpl<int32_t>(shapeData, *yShape, static_cast<size_t>(xShapeSize)); | ||
| 117 | + } else { | ||
| 118 | + auto shapeData = shapeTensor->GetData<int64_t>(); | ||
| 119 | + return InferShapeImpl<int64_t>(shapeData, *yShape, static_cast<size_t>(xShapeSize)); | ||
| 120 | + } | ||
| 121 | + return GRAPH_SUCCESS; | ||
| 122 | +} | ||
| 123 | + | ||
| 124 | +IMPL_OP_INFERSHAPE(StatelessBernoulli) | ||
| 125 | + .InferShape(InferShape4StatelessBernoulli) | ||
| 126 | + .InputsDataDependency({INDEX_INPUT_SHAPE}); | ||
| 127 | +} // namespace ops | ||
| @@ -1,12 +1,12 @@ | |||
| 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 | /* ! | 11 | /* ! |
| 12 | * \file stateless_bernoulli.h | 12 | * \file stateless_bernoulli.h |
| @@ -15,7 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | -#include "../inc/platform.h" | 18 | +#include "kernel_operator.h" |
| 19 | + | ||
| 19 | 20 | ||
| 20 | namespace StatelessBernoulli { | 21 | namespace StatelessBernoulli { |
| 21 | 22 | ||
| @@ -23,13 +24,12 @@ template <typename T, typename U> | |||
| 23 | class StatelessBernoulliKernel { | 24 | class StatelessBernoulliKernel { |
| 24 | public: | 25 | public: |
| 25 | __aicore__ inline StatelessBernoulliKernel(){}; | 26 | __aicore__ inline StatelessBernoulliKernel(){}; |
| 26 | - __aicore__ inline void Init( | 27 | + __aicore__ inline void Init(GM_ADDR shape, GM_ADDR prob, GM_ADDR y, GM_ADDR workspace, |
| 27 | - GM_ADDR shape, GM_ADDR prob, GM_ADDR y, GM_ADDR workspace, | 28 | + const StatelessBernoulliTilingData *__restrict tilingData, AscendC::TPipe *pipeIn); |
| 28 | - const StatelessBernoulliTilingData* __restrict tilingData, AscendC::TPipe* pipeIn); | 29 | + __aicore__ inline void Process(const StatelessBernoulliTilingData *__restrict tilingData); |
| 29 | - __aicore__ inline void Process(const StatelessBernoulliTilingData* __restrict tilingData); | ||
| 30 | 30 | ||
| 31 | private: | 31 | private: |
| 32 | - __aicore__ inline void ParseTilingData(const StatelessBernoulliTilingData* __restrict tilingData); | 32 | + __aicore__ inline void ParseTilingData(const StatelessBernoulliTilingData *__restrict tilingData); |
| 33 | __aicore__ inline void RandUniformUint32(uint32_t calCount); | 33 | __aicore__ inline void RandUniformUint32(uint32_t calCount); |
| 34 | __aicore__ inline void SelectValidMaskScalar(uint32_t calCount); | 34 | __aicore__ inline void SelectValidMaskScalar(uint32_t calCount); |
| 35 | __aicore__ inline void SelectValidMaskTensor(uint32_t calCount); | 35 | __aicore__ inline void SelectValidMaskTensor(uint32_t calCount); |
| @@ -39,12 +39,11 @@ private: | |||
| 39 | __aicore__ inline uint8_t PadAlignByte32(uint32_t param); | 39 | __aicore__ inline uint8_t PadAlignByte32(uint32_t param); |
| 40 | __aicore__ inline void Skip(uint64_t count); | 40 | __aicore__ inline void Skip(uint64_t count); |
| 41 | __aicore__ inline void CopyIn(uint32_t loopIdx, uint32_t calCount); | 41 | __aicore__ inline void CopyIn(uint32_t loopIdx, uint32_t calCount); |
| 42 | - __aicore__ inline void Compute( | 42 | + __aicore__ inline void Compute(uint32_t loopIdx, uint32_t calCount, const StatelessBernoulliTilingData *__restrict tilingData); |
| 43 | - uint32_t loopIdx, uint32_t calCount, const StatelessBernoulliTilingData* __restrict tilingData); | ||
| 44 | __aicore__ inline void CopyOut(uint32_t loopIdx, uint32_t calCount); | 43 | __aicore__ inline void CopyOut(uint32_t loopIdx, uint32_t calCount); |
| 45 | 44 | ||
| 46 | private: | 45 | private: |
| 47 | - AscendC::TPipe* pipe_; | 46 | + AscendC::TPipe *pipe_; |
| 48 | constexpr static int64_t BUFFER_NUM = 2; | 47 | constexpr static int64_t BUFFER_NUM = 2; |
| 49 | constexpr static uint32_t ALG_KEY_SIZE = 2; | 48 | constexpr static uint32_t ALG_KEY_SIZE = 2; |
| 50 | constexpr static uint32_t ALG_COUNTER_SIZE = 4; | 49 | constexpr static uint32_t ALG_COUNTER_SIZE = 4; |
| @@ -86,17 +85,23 @@ private: | |||
| 86 | uint8_t rightPadding_ = 0; | 85 | uint8_t rightPadding_ = 0; |
| 87 | 86 | ||
| 88 | static constexpr AscendC::MicroAPI::CastTrait castTraitB64ToB32 = { | 87 | static constexpr AscendC::MicroAPI::CastTrait castTraitB64ToB32 = { |
| 89 | - AscendC::MicroAPI::RegLayout::ZERO, AscendC::MicroAPI::SatMode::UNKNOWN, | 88 | + AscendC::MicroAPI::RegLayout::ZERO, |
| 90 | - AscendC::MicroAPI::MaskMergeMode::ZEROING, AscendC::RoundMode::CAST_RINT}; | 89 | + AscendC::MicroAPI::SatMode::UNKNOWN, |
| 90 | + AscendC::MicroAPI::MaskMergeMode::ZEROING, | ||
| 91 | + AscendC::RoundMode::CAST_RINT | ||
| 92 | + }; | ||
| 91 | 93 | ||
| 92 | static constexpr AscendC::MicroAPI::CastTrait castTraitB16ToB32 = { | 94 | static constexpr AscendC::MicroAPI::CastTrait castTraitB16ToB32 = { |
| 93 | - AscendC::MicroAPI::RegLayout::ZERO, AscendC::MicroAPI::SatMode::UNKNOWN, | 95 | + AscendC::MicroAPI::RegLayout::ZERO, |
| 94 | - AscendC::MicroAPI::MaskMergeMode::ZEROING, AscendC::RoundMode::UNKNOWN}; | 96 | + AscendC::MicroAPI::SatMode::UNKNOWN, |
| 97 | + AscendC::MicroAPI::MaskMergeMode::ZEROING, | ||
| 98 | + AscendC::RoundMode::UNKNOWN | ||
| 99 | + }; | ||
| 95 | }; | 100 | }; |
| 96 | 101 | ||
| 97 | template <typename T, typename U> | 102 | template <typename T, typename U> |
| 98 | __aicore__ inline void StatelessBernoulliKernel<T, U>::ParseTilingData( | 103 | __aicore__ inline void StatelessBernoulliKernel<T, U>::ParseTilingData( |
| 99 | - const StatelessBernoulliTilingData* __restrict tilingData) | 104 | + const StatelessBernoulliTilingData *__restrict tilingData) |
| 100 | { | 105 | { |
| 101 | ubTilingSize_ = tilingData->ubTilingSize; | 106 | ubTilingSize_ = tilingData->ubTilingSize; |
| 102 | for (uint32_t i = 0; i < ALG_KEY_SIZE; i++) { | 107 | for (uint32_t i = 0; i < ALG_KEY_SIZE; i++) { |
| @@ -144,9 +149,8 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::Skip(uint64_t count) | |||
| 144 | } | 149 | } |
| 145 | 150 | ||
| 146 | template <typename T, typename U> | 151 | template <typename T, typename U> |
| 147 | -__aicore__ inline void StatelessBernoulliKernel<T, U>::Init( | 152 | +__aicore__ inline void StatelessBernoulliKernel<T, U>::Init(GM_ADDR shape, GM_ADDR prob, GM_ADDR y, GM_ADDR workspace, |
| 148 | - GM_ADDR shape, GM_ADDR prob, GM_ADDR y, GM_ADDR workspace, | 153 | + const StatelessBernoulliTilingData *__restrict tilingData, AscendC::TPipe *pipeIn) |
| 149 | - const StatelessBernoulliTilingData* __restrict tilingData, AscendC::TPipe* pipeIn) | ||
| 150 | { | 154 | { |
| 151 | // Init tiling data | 155 | // Init tiling data |
| 152 | ParseTilingData(tilingData); | 156 | ParseTilingData(tilingData); |
| @@ -167,8 +171,8 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::Init( | |||
| 167 | } | 171 | } |
| 168 | 172 | ||
| 169 | // SetBuffer | 173 | // SetBuffer |
| 170 | - probInputGm_.SetGlobalBuffer((__gm__ T*)prob); | 174 | + probInputGm_.SetGlobalBuffer((__gm__ T *)prob); |
| 171 | - outputGm_.SetGlobalBuffer((__gm__ U*)y); | 175 | + outputGm_.SetGlobalBuffer((__gm__ U *)y); |
| 172 | if (!tilingData->isProbScalar && tilingData->outputSize > tilingData->probTensorSize) { | 176 | if (!tilingData->isProbScalar && tilingData->outputSize > tilingData->probTensorSize) { |
| 173 | AscendC::InitGlobalMemory(outputGm_, tilingData->outputSize, static_cast<U>(0)); | 177 | AscendC::InitGlobalMemory(outputGm_, tilingData->outputSize, static_cast<U>(0)); |
| 174 | AscendC::SyncAll(); | 178 | AscendC::SyncAll(); |
| @@ -196,9 +200,7 @@ template <typename T, typename U> | |||
| 196 | __aicore__ inline void StatelessBernoulliKernel<T, U>::GenPhiloxRandom(uint32_t calCount) | 200 | __aicore__ inline void StatelessBernoulliKernel<T, U>::GenPhiloxRandom(uint32_t calCount) |
| 197 | { | 201 | { |
| 198 | AscendC::LocalTensor<uint32_t> philoxRes = philoxQueBuf_.Get<uint32_t>(); | 202 | AscendC::LocalTensor<uint32_t> philoxRes = philoxQueBuf_.Get<uint32_t>(); |
| 199 | - AscendC::PhiloxRandom<10>( | 203 | + AscendC::PhiloxRandom<10>(philoxRes, { key_[0], key_[1] }, { counter_[countIndex0_], counter_[countIndex1_], counter_[countIndex2_], counter_[countIndex3_] }, calCount); |
| 200 | - philoxRes, {key_[0], key_[1]}, | ||
| 201 | - {counter_[countIndex0_], counter_[countIndex1_], counter_[countIndex2_], counter_[countIndex3_]}, calCount); | ||
| 202 | } | 204 | } |
| 203 | 205 | ||
| 204 | template <typename T, typename U> | 206 | template <typename T, typename U> |
| @@ -206,11 +208,11 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::RandUniformUint32(uint32_ | |||
| 206 | { | 208 | { |
| 207 | // philox result saved in philoxQueBuf | 209 | // philox result saved in philoxQueBuf |
| 208 | AscendC::LocalTensor<uint32_t> philoxRes = philoxQueBuf_.Get<uint32_t>(); | 210 | AscendC::LocalTensor<uint32_t> philoxRes = philoxQueBuf_.Get<uint32_t>(); |
| 209 | - __ubuf__ int64_t* ubPhilox = (__ubuf__ int64_t*)philoxRes.GetPhyAddr(); | 211 | + __ubuf__ int64_t *ubPhilox = (__ubuf__ int64_t *)philoxRes.GetPhyAddr(); |
| 210 | AscendC::LocalTensor<float> caluData = calcuDataBuf_.Get<float>(); | 212 | AscendC::LocalTensor<float> caluData = calcuDataBuf_.Get<float>(); |
| 211 | - __ubuf__ float* ubOut = (__ubuf__ float*)caluData.GetPhyAddr(); | 213 | + __ubuf__ float *ubOut = (__ubuf__ float *)caluData.GetPhyAddr(); |
| 212 | 214 | ||
| 213 | - uint32_t vfLen = platform::GetVRegSize() / sizeof(int64_t); | 215 | + uint32_t vfLen = Ops::Base::GetVRegSize() / sizeof(int64_t); |
| 214 | uint16_t repeatTimes = RoundUp(calCount, vfLen); | 216 | uint16_t repeatTimes = RoundUp(calCount, vfLen); |
| 215 | 217 | ||
| 216 | __VEC_SCOPE__ | 218 | __VEC_SCOPE__ |
| @@ -228,14 +230,11 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::RandUniformUint32(uint32_ | |||
| 228 | 230 | ||
| 229 | for (uint16_t i = 0; i < repeatTimes; ++i) { | 231 | for (uint16_t i = 0; i < repeatTimes; ++i) { |
| 230 | mask = AscendC::MicroAPI::UpdateMask<int32_t>(sReg1); | 232 | mask = AscendC::MicroAPI::UpdateMask<int32_t>(sReg1); |
| 231 | - AscendC::MicroAPI::DataCopy< | 233 | + AscendC::MicroAPI::DataCopy<int64_t, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B32>(vReg0, ubPhilox, offset / gainCoeff); |
| 232 | - int64_t, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 233 | - AscendC::MicroAPI::LoadDist::DIST_UNPACK_B32>(vReg0, ubPhilox, offset / gainCoeff); | ||
| 234 | AscendC::MicroAPI::Cast<float, int64_t, castTraitB64ToB32>(vReg1, vReg0, mask); | 234 | AscendC::MicroAPI::Cast<float, int64_t, castTraitB64ToB32>(vReg1, vReg0, mask); |
| 235 | AscendC::MicroAPI::Muls<float, float, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vReg2, vReg1, sReg3, mask); | 235 | AscendC::MicroAPI::Muls<float, float, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vReg2, vReg1, sReg3, mask); |
| 236 | AscendC::MicroAPI::Adds<float, float, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vReg3, vReg2, sReg4, mask); | 236 | AscendC::MicroAPI::Adds<float, float, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vReg3, vReg2, sReg4, mask); |
| 237 | - AscendC::MicroAPI::DataCopy< | 237 | + AscendC::MicroAPI::DataCopy<float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK_B64>( |
| 238 | - float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK_B64>( | ||
| 239 | ubOut, vReg3, offset, mask); | 238 | ubOut, vReg3, offset, mask); |
| 240 | } | 239 | } |
| 241 | } | 240 | } |
| @@ -245,12 +244,12 @@ template <typename T, typename U> | |||
| 245 | __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskScalar(uint32_t calCount) | 244 | __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskScalar(uint32_t calCount) |
| 246 | { | 245 | { |
| 247 | AscendC::LocalTensor<float> caluData = calcuDataBuf_.Get<float>(); | 246 | AscendC::LocalTensor<float> caluData = calcuDataBuf_.Get<float>(); |
| 248 | - __ubuf__ float* ubCaluData = (__ubuf__ float*)caluData.GetPhyAddr(); | 247 | + __ubuf__ float *ubCaluData = (__ubuf__ float *)caluData.GetPhyAddr(); |
| 249 | 248 | ||
| 250 | AscendC::LocalTensor<U> yOutput = outQueY_.AllocTensor<U>(); | 249 | AscendC::LocalTensor<U> yOutput = outQueY_.AllocTensor<U>(); |
| 251 | - __ubuf__ U* ubOut = (__ubuf__ U*)yOutput.GetPhyAddr(); | 250 | + __ubuf__ U *ubOut = (__ubuf__ U *)yOutput.GetPhyAddr(); |
| 252 | 251 | ||
| 253 | - uint32_t vfLen = platform::GetVRegSize() / sizeof(int32_t); | 252 | + uint32_t vfLen = Ops::Base::GetVRegSize() / sizeof(int32_t); |
| 254 | uint16_t repeatTimes = RoundUp(calCount, vfLen); | 253 | uint16_t repeatTimes = RoundUp(calCount, vfLen); |
| 255 | 254 | ||
| 256 | __VEC_SCOPE__ | 255 | __VEC_SCOPE__ |
| @@ -267,20 +266,14 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskScalar(uin | |||
| 267 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumTwo> vDstReg0; | 266 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumTwo> vDstReg0; |
| 268 | 267 | ||
| 269 | maskReg = AscendC::MicroAPI::UpdateMask<U, AscendC::MicroAPI::RegTraitNumTwo>(calCount); | 268 | maskReg = AscendC::MicroAPI::UpdateMask<U, AscendC::MicroAPI::RegTraitNumTwo>(calCount); |
| 270 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | 269 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg0, static_cast<U>(1), maskReg); |
| 271 | - vSrcReg0, static_cast<U>(1), maskReg); | 270 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg1, static_cast<U>(0), maskReg); |
| 272 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | ||
| 273 | - vSrcReg1, static_cast<U>(0), maskReg); | ||
| 274 | 271 | ||
| 275 | for (uint16_t i = 0; i < repeatTimes; ++i) { | 272 | for (uint16_t i = 0; i < repeatTimes; ++i) { |
| 276 | - AscendC::MicroAPI::DataCopy< | 273 | + AscendC::MicroAPI::DataCopy<float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>(vCaluReg, ubCaluData, offset); |
| 277 | - float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>( | ||
| 278 | - vCaluReg, ubCaluData, offset); | ||
| 279 | AscendC::MicroAPI::CompareScalar<float, AscendC::CMPMODE::LT>(cmpMaskReg, vCaluReg, pScalar, maskReg); | 274 | AscendC::MicroAPI::CompareScalar<float, AscendC::CMPMODE::LT>(cmpMaskReg, vCaluReg, pScalar, maskReg); |
| 280 | AscendC::MicroAPI::Select<U>(vDstReg0, vSrcReg0, vSrcReg1, cmpMaskReg); | 275 | AscendC::MicroAPI::Select<U>(vDstReg0, vSrcReg0, vSrcReg1, cmpMaskReg); |
| 281 | - AscendC::MicroAPI::DataCopy< | 276 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>(ubOut, vDstReg0, offset, maskReg); |
| 282 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>( | ||
| 283 | - ubOut, vDstReg0, offset, maskReg); | ||
| 284 | } | 277 | } |
| 285 | } else { | 278 | } else { |
| 286 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vSrcReg0; | 279 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vSrcReg0; |
| @@ -288,35 +281,20 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskScalar(uin | |||
| 288 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vDstReg0; | 281 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vDstReg0; |
| 289 | 282 | ||
| 290 | maskReg = AscendC::MicroAPI::UpdateMask<int32_t, AscendC::MicroAPI::RegTraitNumOne>(calCount); | 283 | maskReg = AscendC::MicroAPI::UpdateMask<int32_t, AscendC::MicroAPI::RegTraitNumOne>(calCount); |
| 291 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | 284 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg0, static_cast<U>(1), maskReg); |
| 292 | - vSrcReg0, static_cast<U>(1), maskReg); | 285 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg1, static_cast<U>(0), maskReg); |
| 293 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | ||
| 294 | - vSrcReg1, static_cast<U>(0), maskReg); | ||
| 295 | for (uint16_t i = 0; i < repeatTimes; ++i) { | 286 | for (uint16_t i = 0; i < repeatTimes; ++i) { |
| 296 | - AscendC::MicroAPI::DataCopy< | 287 | + AscendC::MicroAPI::DataCopy<float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>(vCaluReg, ubCaluData, offset); |
| 297 | - float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>( | ||
| 298 | - vCaluReg, ubCaluData, offset); | ||
| 299 | AscendC::MicroAPI::CompareScalar<float, AscendC::CMPMODE::LT>(cmpMaskReg, vCaluReg, pScalar, maskReg); | 288 | AscendC::MicroAPI::CompareScalar<float, AscendC::CMPMODE::LT>(cmpMaskReg, vCaluReg, pScalar, maskReg); |
| 300 | AscendC::MicroAPI::Select<U>(vDstReg0, vSrcReg0, vSrcReg1, cmpMaskReg); | 289 | AscendC::MicroAPI::Select<U>(vDstReg0, vSrcReg0, vSrcReg1, cmpMaskReg); |
| 301 | - if constexpr ( | 290 | + if constexpr (AscendC::IsSameType<U, int32_t>::value || AscendC::IsSameType<U, uint32_t>::value || AscendC::IsSameType<U, float>::value) { |
| 302 | - AscendC::IsSameType<U, int32_t>::value || AscendC::IsSameType<U, uint32_t>::value || | 291 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>(ubOut, vDstReg0, offset, maskReg); |
| 303 | - AscendC::IsSameType<U, float>::value) { | ||
| 304 | - AscendC::MicroAPI::DataCopy< | ||
| 305 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>( | ||
| 306 | - ubOut, vDstReg0, offset, maskReg); | ||
| 307 | } else if constexpr (AscendC::IsSameType<U, half>::value || AscendC::IsSameType<U, bfloat16_t>::value) { | 292 | } else if constexpr (AscendC::IsSameType<U, half>::value || AscendC::IsSameType<U, bfloat16_t>::value) { |
| 308 | - AscendC::MicroAPI::DataCopy< | 293 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg0, offset, maskReg); |
| 309 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | 294 | + } else if constexpr (AscendC::IsSameType<U, int16_t>::value || AscendC::IsSameType<U, uint16_t>::value) { |
| 310 | - AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg0, offset, maskReg); | 295 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg0, offset, maskReg); |
| 311 | - } else if constexpr ( | ||
| 312 | - AscendC::IsSameType<U, int16_t>::value || AscendC::IsSameType<U, uint16_t>::value) { | ||
| 313 | - AscendC::MicroAPI::DataCopy< | ||
| 314 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 315 | - AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg0, offset, maskReg); | ||
| 316 | } else if constexpr (AscendC::IsSameType<U, int8_t>::value || AscendC::IsSameType<U, uint8_t>::value) { | 296 | } else if constexpr (AscendC::IsSameType<U, int8_t>::value || AscendC::IsSameType<U, uint8_t>::value) { |
| 317 | - AscendC::MicroAPI::DataCopy< | 297 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK4_B32>(ubOut, vDstReg0, offset, maskReg); |
| 318 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 319 | - AscendC::MicroAPI::StoreDist::DIST_PACK4_B32>(ubOut, vDstReg0, offset, maskReg); | ||
| 320 | } | 298 | } |
| 321 | } | 299 | } |
| 322 | } | 300 | } |
| @@ -329,15 +307,15 @@ template <typename T, typename U> | |||
| 329 | __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskTensor(uint32_t calCount) | 307 | __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskTensor(uint32_t calCount) |
| 330 | { | 308 | { |
| 331 | AscendC::LocalTensor<float> caluData = calcuDataBuf_.Get<float>(); | 309 | AscendC::LocalTensor<float> caluData = calcuDataBuf_.Get<float>(); |
| 332 | - __ubuf__ float* ubCaluData = (__ubuf__ float*)caluData.GetPhyAddr(); | 310 | + __ubuf__ float *ubCaluData = (__ubuf__ float *)caluData.GetPhyAddr(); |
| 333 | 311 | ||
| 334 | AscendC::LocalTensor<T> probInputUb = probQueX_.DeQue<T>(); | 312 | AscendC::LocalTensor<T> probInputUb = probQueX_.DeQue<T>(); |
| 335 | - __ubuf__ T* ubProbIn = (__ubuf__ T*)probInputUb.GetPhyAddr(); | 313 | + __ubuf__ T *ubProbIn = (__ubuf__ T *)probInputUb.GetPhyAddr(); |
| 336 | 314 | ||
| 337 | AscendC::LocalTensor<U> yOutput = outQueY_.AllocTensor<U>(); | 315 | AscendC::LocalTensor<U> yOutput = outQueY_.AllocTensor<U>(); |
| 338 | - __ubuf__ U* ubOut = (__ubuf__ U*)yOutput.GetPhyAddr(); | 316 | + __ubuf__ U *ubOut = (__ubuf__ U *)yOutput.GetPhyAddr(); |
| 339 | 317 | ||
| 340 | - uint32_t vfLen = platform::GetVRegSize() / sizeof(int32_t); | 318 | + uint32_t vfLen = Ops::Base::GetVRegSize() / sizeof(int32_t); |
| 341 | uint16_t repeatTimes = RoundUp(calCount, vfLen); | 319 | uint16_t repeatTimes = RoundUp(calCount, vfLen); |
| 342 | 320 | ||
| 343 | __VEC_SCOPE__ | 321 | __VEC_SCOPE__ |
| @@ -355,31 +333,21 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskTensor(uin | |||
| 355 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumTwo> vDstReg0; | 333 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumTwo> vDstReg0; |
| 356 | 334 | ||
| 357 | maskReg0 = AscendC::MicroAPI::UpdateMask<U, AscendC::MicroAPI::RegTraitNumTwo>(calCount); | 335 | maskReg0 = AscendC::MicroAPI::UpdateMask<U, AscendC::MicroAPI::RegTraitNumTwo>(calCount); |
| 358 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | 336 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg0, static_cast<U>(1), maskReg0); |
| 359 | - vSrcReg0, static_cast<U>(1), maskReg0); | 337 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg1, static_cast<U>(0), maskReg0); |
| 360 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | ||
| 361 | - vSrcReg1, static_cast<U>(0), maskReg0); | ||
| 362 | 338 | ||
| 363 | for (uint16_t i = 0; i < repeatTimes; ++i) { | 339 | for (uint16_t i = 0; i < repeatTimes; ++i) { |
| 364 | - AscendC::MicroAPI::DataCopy< | 340 | + AscendC::MicroAPI::DataCopy<float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>(vCaluReg, ubCaluData, offset); |
| 365 | - float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>( | ||
| 366 | - vCaluReg, ubCaluData, offset); | ||
| 367 | if constexpr (AscendC::IsSameType<T, float>::value) { | 341 | if constexpr (AscendC::IsSameType<T, float>::value) { |
| 368 | - AscendC::MicroAPI::DataCopy< | 342 | + AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>(vProbRegT, ubProbIn, offset); |
| 369 | - T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>( | ||
| 370 | - vProbRegT, ubProbIn, offset); | ||
| 371 | AscendC::MicroAPI::Adds<float, float>(vProbRegFp, vProbRegT, static_cast<float>(0.0), maskReg0); | 343 | AscendC::MicroAPI::Adds<float, float>(vProbRegFp, vProbRegT, static_cast<float>(0.0), maskReg0); |
| 372 | } else { | 344 | } else { |
| 373 | - AscendC::MicroAPI::DataCopy< | 345 | + AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vProbRegT, ubProbIn, offset); |
| 374 | - T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 375 | - AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vProbRegT, ubProbIn, offset); | ||
| 376 | AscendC::MicroAPI::Cast<float, T, castTraitB16ToB32>(vProbRegFp, vProbRegT, maskReg0); | 346 | AscendC::MicroAPI::Cast<float, T, castTraitB16ToB32>(vProbRegFp, vProbRegT, maskReg0); |
| 377 | } | 347 | } |
| 378 | AscendC::MicroAPI::Compare<float, AscendC::CMPMODE::LT>(cmpMaskReg0, vCaluReg, vProbRegFp, maskReg0); | 348 | AscendC::MicroAPI::Compare<float, AscendC::CMPMODE::LT>(cmpMaskReg0, vCaluReg, vProbRegFp, maskReg0); |
| 379 | AscendC::MicroAPI::Select<U>(vDstReg0, vSrcReg0, vSrcReg1, cmpMaskReg0); | 349 | AscendC::MicroAPI::Select<U>(vDstReg0, vSrcReg0, vSrcReg1, cmpMaskReg0); |
| 380 | - AscendC::MicroAPI::DataCopy< | 350 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>(ubOut, vDstReg0, offset, maskReg0); |
| 381 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>( | ||
| 382 | - ubOut, vDstReg0, offset, maskReg0); | ||
| 383 | } | 351 | } |
| 384 | } else { | 352 | } else { |
| 385 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vSrcReg0; | 353 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vSrcReg0; |
| @@ -387,58 +355,38 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::SelectValidMaskTensor(uin | |||
| 387 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vDstReg; | 355 | AscendC::MicroAPI::RegTensor<U, AscendC::MicroAPI::RegTraitNumOne> vDstReg; |
| 388 | 356 | ||
| 389 | maskReg0 = AscendC::MicroAPI::UpdateMask<int32_t, AscendC::MicroAPI::RegTraitNumOne>(calCount); | 357 | maskReg0 = AscendC::MicroAPI::UpdateMask<int32_t, AscendC::MicroAPI::RegTraitNumOne>(calCount); |
| 390 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | 358 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg0, static_cast<U>(1), maskReg0); |
| 391 | - vSrcReg0, static_cast<U>(1), maskReg0); | 359 | + AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>(vSrcReg1, static_cast<U>(0), maskReg0); |
| 392 | - AscendC::MicroAPI::Duplicate<U, AscendC::MicroAPI::MaskMergeMode::ZEROING>( | ||
| 393 | - vSrcReg1, static_cast<U>(0), maskReg0); | ||
| 394 | for (uint16_t j = 0; j < repeatTimes; ++j) { | 360 | for (uint16_t j = 0; j < repeatTimes; ++j) { |
| 395 | - AscendC::MicroAPI::DataCopy< | 361 | + AscendC::MicroAPI::DataCopy<float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>(vCaluReg, ubCaluData, offset); |
| 396 | - float, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>( | ||
| 397 | - vCaluReg, ubCaluData, offset); | ||
| 398 | if constexpr (AscendC::IsSameType<T, float>::value) { | 362 | if constexpr (AscendC::IsSameType<T, float>::value) { |
| 399 | - AscendC::MicroAPI::DataCopy< | 363 | + AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>(vProbRegT, ubProbIn, offset); |
| 400 | - T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_NORM>( | ||
| 401 | - vProbRegT, ubProbIn, offset); | ||
| 402 | AscendC::MicroAPI::Adds<float, float>(vProbRegFp, vProbRegT, static_cast<float>(0.0), maskReg0); | 364 | AscendC::MicroAPI::Adds<float, float>(vProbRegFp, vProbRegT, static_cast<float>(0.0), maskReg0); |
| 403 | } else { | 365 | } else { |
| 404 | - AscendC::MicroAPI::DataCopy< | 366 | + AscendC::MicroAPI::DataCopy<T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vProbRegT, ubProbIn, offset); |
| 405 | - T, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 406 | - AscendC::MicroAPI::LoadDist::DIST_UNPACK_B16>(vProbRegT, ubProbIn, offset); | ||
| 407 | AscendC::MicroAPI::Cast<float, T, castTraitB16ToB32>(vProbRegFp, vProbRegT, maskReg0); | 367 | AscendC::MicroAPI::Cast<float, T, castTraitB16ToB32>(vProbRegFp, vProbRegT, maskReg0); |
| 408 | } | 368 | } |
| 409 | AscendC::MicroAPI::Compare<float, AscendC::CMPMODE::LT>(cmpMaskReg0, vCaluReg, vProbRegFp, maskReg0); | 369 | AscendC::MicroAPI::Compare<float, AscendC::CMPMODE::LT>(cmpMaskReg0, vCaluReg, vProbRegFp, maskReg0); |
| 410 | AscendC::MicroAPI::Select<U>(vDstReg, vSrcReg0, vSrcReg1, cmpMaskReg0); | 370 | AscendC::MicroAPI::Select<U>(vDstReg, vSrcReg0, vSrcReg1, cmpMaskReg0); |
| 411 | - if constexpr ( | 371 | + if constexpr (AscendC::IsSameType<U, int32_t>::value || AscendC::IsSameType<U, uint32_t>::value || AscendC::IsSameType<U, float>::value) { |
| 412 | - AscendC::IsSameType<U, int32_t>::value || AscendC::IsSameType<U, uint32_t>::value || | 372 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>(ubOut, vDstReg, offset, maskReg0); |
| 413 | - AscendC::IsSameType<U, float>::value) { | ||
| 414 | - AscendC::MicroAPI::DataCopy< | ||
| 415 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_NORM>( | ||
| 416 | - ubOut, vDstReg, offset, maskReg0); | ||
| 417 | } else if constexpr (AscendC::IsSameType<U, half>::value || AscendC::IsSameType<U, bfloat16_t>::value) { | 373 | } else if constexpr (AscendC::IsSameType<U, half>::value || AscendC::IsSameType<U, bfloat16_t>::value) { |
| 418 | - AscendC::MicroAPI::DataCopy< | 374 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg, offset, maskReg0); |
| 419 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | 375 | + } else if constexpr (AscendC::IsSameType<U, int16_t>::value || AscendC::IsSameType<U, uint16_t>::value) { |
| 420 | - AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg, offset, maskReg0); | 376 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg, offset, maskReg0); |
| 421 | - } else if constexpr ( | ||
| 422 | - AscendC::IsSameType<U, int16_t>::value || AscendC::IsSameType<U, uint16_t>::value) { | ||
| 423 | - AscendC::MicroAPI::DataCopy< | ||
| 424 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 425 | - AscendC::MicroAPI::StoreDist::DIST_PACK_B32>(ubOut, vDstReg, offset, maskReg0); | ||
| 426 | } else if constexpr (AscendC::IsSameType<U, int8_t>::value || AscendC::IsSameType<U, uint8_t>::value) { | 377 | } else if constexpr (AscendC::IsSameType<U, int8_t>::value || AscendC::IsSameType<U, uint8_t>::value) { |
| 427 | - AscendC::MicroAPI::DataCopy< | 378 | + AscendC::MicroAPI::DataCopy<U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, AscendC::MicroAPI::StoreDist::DIST_PACK4_B32>(ubOut, vDstReg, offset, maskReg0); |
| 428 | - U, AscendC::MicroAPI::PostLiteral::POST_MODE_UPDATE, | ||
| 429 | - AscendC::MicroAPI::StoreDist::DIST_PACK4_B32>(ubOut, vDstReg, offset, maskReg0); | ||
| 430 | } | 379 | } |
| 431 | } | 380 | } |
| 432 | } | 381 | } |
| 433 | } | 382 | } |
| 434 | - | 383 | + |
| 435 | probQueX_.FreeTensor(probInputUb); | 384 | probQueX_.FreeTensor(probInputUb); |
| 436 | outQueY_.EnQue(yOutput); | 385 | outQueY_.EnQue(yOutput); |
| 437 | } | 386 | } |
| 438 | 387 | ||
| 439 | template <typename T, typename U> | 388 | template <typename T, typename U> |
| 440 | -__aicore__ inline void StatelessBernoulliKernel<T, U>::Compute( | 389 | +__aicore__ inline void StatelessBernoulliKernel<T, U>::Compute(uint32_t loopIdx, uint32_t calCount, const StatelessBernoulliTilingData *__restrict tilingData) |
| 441 | - uint32_t loopIdx, uint32_t calCount, const StatelessBernoulliTilingData* __restrict tilingData) | ||
| 442 | { | 390 | { |
| 443 | GenPhiloxRandom(calCount); | 391 | GenPhiloxRandom(calCount); |
| 444 | RandUniformUint32(calCount); | 392 | RandUniformUint32(calCount); |
| @@ -457,8 +405,8 @@ __aicore__ inline void StatelessBernoulliKernel<T, U>::CopyIn(uint32_t loopIdx, | |||
| 457 | isPadding_ = true; | 405 | isPadding_ = true; |
| 458 | rightPadding_ = PadAlignByte32(calCount); | 406 | rightPadding_ = PadAlignByte32(calCount); |
| 459 | } | 407 | } |
| 460 | - AscendC::DataCopyExtParams copyParams{1, (uint32_t)(calCount * sizeof(T)), 0, 0, 0}; | 408 | + AscendC::DataCopyExtParams copyParams { 1, (uint32_t)(calCount * sizeof(T)), 0, 0, 0 }; |
| 461 | - AscendC::DataCopyPadExtParams<T> padParams{isPadding_, 0, rightPadding_, 0}; | 409 | + AscendC::DataCopyPadExtParams<T> padParams { isPadding_, 0, rightPadding_, 0 }; |
| 462 | AscendC::DataCopyPad(probInputUb, probInputGm_[blockOffset_ + loopIdx * ubTilingSize_], copyParams, padParams); | 410 | AscendC::DataCopyPad(probInputUb, probInputGm_[blockOffset_ + loopIdx * ubTilingSize_], copyParams, padParams); |
| 463 | probQueX_.EnQue<T>(probInputUb); | 411 | probQueX_.EnQue<T>(probInputUb); |
| 464 | } | 412 | } |
| @@ -467,14 +415,13 @@ template <typename T, typename U> | |||
| 467 | __aicore__ inline void StatelessBernoulliKernel<T, U>::CopyOut(uint32_t loopIdx, uint32_t calCount) | 415 | __aicore__ inline void StatelessBernoulliKernel<T, U>::CopyOut(uint32_t loopIdx, uint32_t calCount) |
| 468 | { | 416 | { |
| 469 | AscendC::LocalTensor<U> yOutput = outQueY_.DeQue<U>(); | 417 | AscendC::LocalTensor<U> yOutput = outQueY_.DeQue<U>(); |
| 470 | - AscendC::DataCopyExtParams copyParams{1, (uint32_t)(calCount * sizeof(U)), 0, 0, 0}; | 418 | + AscendC::DataCopyExtParams copyParams { 1, (uint32_t)(calCount * sizeof(U)), 0, 0, 0 }; |
| 471 | AscendC::DataCopyPad(outputGm_[blockOffset_ + loopIdx * ubTilingSize_], yOutput, copyParams); | 419 | AscendC::DataCopyPad(outputGm_[blockOffset_ + loopIdx * ubTilingSize_], yOutput, copyParams); |
| 472 | outQueY_.FreeTensor(yOutput); | 420 | outQueY_.FreeTensor(yOutput); |
| 473 | } | 421 | } |
| 474 | 422 | ||
| 475 | template <typename T, typename U> | 423 | template <typename T, typename U> |
| 476 | -__aicore__ inline void StatelessBernoulliKernel<T, U>::Process( | 424 | +__aicore__ inline void StatelessBernoulliKernel<T, U>::Process(const StatelessBernoulliTilingData *__restrict tilingData) |
| 477 | - const StatelessBernoulliTilingData* __restrict tilingData) | ||
| 478 | { | 425 | { |
| 479 | if (AscendC::GetBlockIdx() >= tilingData->blockNum) { | 426 | if (AscendC::GetBlockIdx() >= tilingData->blockNum) { |
| 480 | return; | 427 | return; |
| @@ -1,12 +1,12 @@ | |||
| 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 | /*! | 11 | /*! |
| 12 | * \file stateless_bernoulli.cpp | 12 | * \file stateless_bernoulli.cpp |
| @@ -19,14 +19,14 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | -KERNEL_API void stateless_bernoulli( | 22 | +__global__ __aicore__ void stateless_bernoulli( |
| 23 | GM_ADDR shape, GM_ADDR prob, GM_ADDR seed, GM_ADDR offset, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) | 23 | GM_ADDR shape, GM_ADDR prob, GM_ADDR seed, GM_ADDR offset, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) |
| 24 | { | 24 | { |
| 25 | GET_TILING_DATA(tilingData, tiling); | 25 | GET_TILING_DATA(tilingData, tiling); |
| 26 | 26 | ||
| 27 | AscendC::TPipe pipe; | 27 | AscendC::TPipe pipe; |
| 28 | KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIV_1_0); | 28 | KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIV_1_0); |
| 29 | - if constexpr (AscendC::IsSameType<DTYPE_Y, bool>::value) { | 29 | + if constexpr(AscendC::IsSameType<DTYPE_Y, bool>::value) { |
| 30 | if (TILING_KEY_IS(TILING_KEY_FP32)) { | 30 | if (TILING_KEY_IS(TILING_KEY_FP32)) { |
| 31 | StatelessBernoulli::StatelessBernoulliKernel<float, int8_t> op; | 31 | StatelessBernoulli::StatelessBernoulliKernel<float, int8_t> op; |
| 32 | op.Init(shape, prob, y, workspace, &tilingData, &pipe); | 32 | op.Init(shape, prob, y, workspace, &tilingData, &pipe); |
| @@ -41,7 +41,7 @@ KERNEL_API void stateless_bernoulli( | |||
| 41 | op.Process(&tilingData); | 41 | op.Process(&tilingData); |
| 42 | } | 42 | } |
| 43 | } else { | 43 | } else { |
| 44 | - if (TILING_KEY_IS(TILING_KEY_FP32)) { | 44 | + if (TILING_KEY_IS(TILING_KEY_FP32)) { |
| 45 | StatelessBernoulli::StatelessBernoulliKernel<float, DTYPE_Y> op; | 45 | StatelessBernoulli::StatelessBernoulliKernel<float, DTYPE_Y> op; |
| 46 | op.Init(shape, prob, y, workspace, &tilingData, &pipe); | 46 | op.Init(shape, prob, y, workspace, &tilingData, &pipe); |
| 47 | op.Process(&tilingData); | 47 | op.Process(&tilingData); |
| @@ -1,14 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 10 | +message(STATUS "=== Debug: start ops.random.stateless_bernoulli.tests.CMakeLists.txt ") | ||
| 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 12 | +message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") | ||
| 12 | foreach(SUB_DIR ${CURRENT_DIRS}) | 13 | foreach(SUB_DIR ${CURRENT_DIRS}) |
| 13 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") |
| 14 | add_subdirectory(${SUB_DIR}) | 15 | add_subdirectory(${SUB_DIR}) |
| @@ -1,15 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | # 每个目录下需要生成的可执行文件,具体参考:ops/build-in/test/CMakeLists.txt: 50~124 | 10 | # 每个目录下需要生成的可执行文件,具体参考:ops/build-in/test/CMakeLists.txt: 50~124 |
| 12 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 12 | +message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") | ||
| 13 | foreach(SUB_DIR ${CURRENT_DIRS}) | 13 | foreach(SUB_DIR ${CURRENT_DIRS}) |
| 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") |
| 15 | add_subdirectory(${SUB_DIR}) | 15 | add_subdirectory(${SUB_DIR}) |
| @@ -1,10 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| @@ -1,10 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| @@ -1,17 +1,21 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 12 | +message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") | ||
| 13 | foreach(SUB_DIR ${CURRENT_DIRS}) | 13 | foreach(SUB_DIR ${CURRENT_DIRS}) |
| 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") |
| 15 | add_subdirectory(${SUB_DIR}) | 15 | add_subdirectory(${SUB_DIR}) |
| 16 | endif() | 16 | endif() |
| 17 | endforeach() | 17 | endforeach() |
| 18 | + | ||
| 19 | +if(TILING_UT OR PROTO_UT OR OP_API_UT OR (UT_TEST_ALL AND NOT AICPU_ONLY)) | ||
| 20 | + add_modules_llt_sources(HOSTNAME ${OPTEST_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 21 | +endif() | ||
| @@ -0,0 +1,60 @@ | |||
| 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 | + /*! | ||
| 12 | + * \file test_stateless_bernoulli_tiling.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +class StatelessBernoulliTiling : public testing::Test { | ||
| 24 | + protected: | ||
| 25 | + static void SetUpTestCase() { | ||
| 26 | + std::cout << "StatelessBernoulliTest SetUp" << std::endl; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + static void TearDownTestCase() { | ||
| 30 | + std::cout << "StatelessBernoulliTest TearDown" << std::endl; | ||
| 31 | + } | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +TEST_F(StatelessBernoulliTiling, stateless_bernoulli_test_0) | ||
| 35 | +{ | ||
| 36 | + optiling::StatelessBernoulliCompileInfoArch35 compileInfo = {64, 253952}; | ||
| 37 | + vector<int64_t> shapeValue = {1}; | ||
| 38 | + vector<float> probValue = {1.0}; | ||
| 39 | + vector<int64_t> seedValue = {2}; | ||
| 40 | + vector<int64_t> offsetValue = {8}; | ||
| 41 | + gert::TilingContextPara tilingContextPara( | ||
| 42 | + "StatelessBernoulli", | ||
| 43 | + { | ||
| 44 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, shapeValue.data()}, | ||
| 45 | + {{{1}, {1}}, ge::DT_FLOAT, ge::FORMAT_ND, true, probValue.data()}, | ||
| 46 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, seedValue.data()}, | ||
| 47 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, offsetValue.data()}, | ||
| 48 | + }, | ||
| 49 | + { | ||
| 50 | + {{{1}, {1}}, ge::DT_UINT8, ge::FORMAT_ND}, | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + {"dtype", Ops::Math::AnyValue::CreateFrom<int64_t>(0)}, | ||
| 54 | + }, | ||
| 55 | + &compileInfo); | ||
| 56 | + uint64_t expectTilingKey = 1001; | ||
| 57 | + string expectTilingData = "1 256 1 1 1 256 1 1 1 2 0 8 "; | ||
| 58 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 59 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 60 | +} | ||
| @@ -1,14 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -if(UT_TEST_ALL OR OP_API_UT) | ||
| 13 | - add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 14 | -endif() | ||
| @@ -0,0 +1,53 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_stateless_bernoulli_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace std; | ||
| 22 | + | ||
| 23 | +class StatelessBernoulliInfershape : public testing::Test { | ||
| 24 | + protected: | ||
| 25 | + static void SetUpTestCase() { | ||
| 26 | + std::cout << "StatelessBernoulli SetUp" << std::endl; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + static void TearDownTestCase() { | ||
| 30 | + std::cout << "StatelessBernoulli TearDown" << std::endl; | ||
| 31 | + } | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +TEST_F(StatelessBernoulliInfershape, stateless_bernoulli_infershape_test1) | ||
| 35 | +{ | ||
| 36 | + vector<int64_t> shapeValue = {1}; | ||
| 37 | + vector<float> probValue = {1.0}; | ||
| 38 | + vector<int64_t> seedValue = {2}; | ||
| 39 | + vector<int64_t> offsetValue = {8}; | ||
| 40 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 41 | + "StatelessBernoulli", | ||
| 42 | + { | ||
| 43 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, shapeValue.data()}, | ||
| 44 | + {{{1}, {1}}, ge::DT_FLOAT, ge::FORMAT_ND, true, probValue.data()}, | ||
| 45 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, seedValue.data()}, | ||
| 46 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, offsetValue.data()}, | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + {{{}, {}}, ge::DT_UINT8, ge::FORMAT_ND}, | ||
| 50 | + }); | ||
| 51 | + std::vector<std::vector<int64_t>> expectOutputShape = {{1}}; | ||
| 52 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 53 | +} | ||
| @@ -1,15 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | file(GLOB CURRENT_SOURCE_DIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | file(GLOB CURRENT_SOURCE_DIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 12 | +message(STATUS "=== Debug: CURRENT_SOURCE_DIRS =${CURRENT_SOURCE_DIRS} ") | ||
| 13 | foreach(SUB_DIR ${CURRENT_SOURCE_DIRS}) | 13 | foreach(SUB_DIR ${CURRENT_SOURCE_DIRS}) |
| 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | 14 | if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") |
| 15 | add_subdirectory(${SUB_DIR}) | 15 | add_subdirectory(${SUB_DIR}) |
| @@ -1,157 +1,157 @@ | |||
| 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 | -/*! | 11 | +/*! |
| 12 | - * \file test_aclnn_stateless_drop_out_gen_mask.cpp | 12 | + * \file test_aclnn_stateless_drop_out_gen_mask.cpp |
| 13 | - * \brief | 13 | + * \brief |
| 14 | - */ | 14 | + */ |
| 15 | -#include <iostream> | 15 | +#include <iostream> |
| 16 | -#include <vector> | 16 | +#include <vector> |
| 17 | -#include "acl/acl.h" | 17 | +#include "acl/acl.h" |
| 18 | -#include "aclnnop/aclnn_dropout_gen_mask.h" | 18 | +#include "aclnnop/aclnn_dropout_gen_mask.h" |
| 19 | - | 19 | + |
| 20 | -#define CHECK_RET(cond, return_expr) \ | 20 | +#define CHECK_RET(cond, return_expr) \ |
| 21 | - do { \ | 21 | + do { \ |
| 22 | - if (!(cond)) { \ | 22 | + if (!(cond)) { \ |
| 23 | - return_expr; \ | 23 | + return_expr; \ |
| 24 | - } \ | 24 | + } \ |
| 25 | - } while (0) | 25 | + } while (0) |
| 26 | - | 26 | + |
| 27 | -#define LOG_PRINT(message, ...) \ | 27 | +#define LOG_PRINT(message, ...) \ |
| 28 | - do { \ | 28 | + do { \ |
| 29 | - printf(message, ##__VA_ARGS__); \ | 29 | + printf(message, ##__VA_ARGS__); \ |
| 30 | - } while (0) | 30 | + } while (0) |
| 31 | - | 31 | + |
| 32 | -int64_t GetShapeSize(const std::vector<int64_t>& shape) { | 32 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) { |
| 33 | - int64_t shapeSize = 1; | 33 | + int64_t shapeSize = 1; |
| 34 | - for (auto i : shape) { | 34 | + for (auto i : shape) { |
| 35 | - shapeSize *= i; | 35 | + shapeSize *= i; |
| 36 | - } | 36 | + } |
| 37 | - return shapeSize; | 37 | + return shapeSize; |
| 38 | -} | 38 | +} |
| 39 | - | 39 | + |
| 40 | -int Init(int32_t deviceId, aclrtStream* stream) { | 40 | +int Init(int32_t deviceId, aclrtStream* stream) { |
| 41 | - // 固定写法,资源初始化 | 41 | + // 固定写法,资源初始化 |
| 42 | - auto ret = aclInit(nullptr); | 42 | + auto ret = aclInit(nullptr); |
| 43 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | 43 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); |
| 44 | - ret = aclrtSetDevice(deviceId); | 44 | + ret = aclrtSetDevice(deviceId); |
| 45 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | 45 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); |
| 46 | - ret = aclrtCreateStream(stream); | 46 | + ret = aclrtCreateStream(stream); |
| 47 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | 47 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); |
| 48 | - | 48 | + |
| 49 | - return 0; | 49 | + return 0; |
| 50 | -} | 50 | +} |
| 51 | - | 51 | + |
| 52 | -template <typename T> | 52 | +template <typename T> |
| 53 | -int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | 53 | +int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 54 | - aclDataType dataType, aclTensor** tensor) { | 54 | + aclDataType dataType, aclTensor** tensor) { |
| 55 | - auto size = GetShapeSize(shape) * sizeof(T); | 55 | + auto size = GetShapeSize(shape) * sizeof(T); |
| 56 | - // 调用aclrtMalloc申请device侧内存 | 56 | + // 调用aclrtMalloc申请device侧内存 |
| 57 | - auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | 57 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); |
| 58 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | 58 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); |
| 59 | - // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | 59 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 |
| 60 | - ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | 60 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); |
| 61 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | 61 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); |
| 62 | - | 62 | + |
| 63 | - // 计算连续tensor的strides | 63 | + // 计算连续tensor的strides |
| 64 | - std::vector<int64_t> strides(shape.size(), 1); | 64 | + std::vector<int64_t> strides(shape.size(), 1); |
| 65 | - for (int64_t i = shape.size() - 2; i >= 0; i--) { | 65 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { |
| 66 | - strides[i] = shape[i + 1] * strides[i + 1]; | 66 | + strides[i] = shape[i + 1] * strides[i + 1]; |
| 67 | - } | 67 | + } |
| 68 | - | 68 | + |
| 69 | - // 调用aclCreateTensor接口创建aclTensor | 69 | + // 调用aclCreateTensor接口创建aclTensor |
| 70 | - *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, | 70 | + *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, |
| 71 | - shape.data(), shape.size(), *deviceAddr); | 71 | + shape.data(), shape.size(), *deviceAddr); |
| 72 | - return 0; | 72 | + return 0; |
| 73 | -} | 73 | +} |
| 74 | - | 74 | + |
| 75 | -int main() { | 75 | +int main() { |
| 76 | - // 1. (固定写法)device/stream初始化,参考acl对外接口列表 | 76 | + // 1. (固定写法)device/stream初始化,参考acl对外接口列表 |
| 77 | - // 根据自己的实际device填写deviceId | 77 | + // 根据自己的实际device填写deviceId |
| 78 | - int32_t deviceId = 0; | 78 | + int32_t deviceId = 0; |
| 79 | - aclrtStream stream; | 79 | + aclrtStream stream; |
| 80 | - auto ret = Init(deviceId, &stream); | 80 | + auto ret = Init(deviceId, &stream); |
| 81 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | 81 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); |
| 82 | - // 2. 构造输入与输出,需要根据API的接口自定义构造 | 82 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 |
| 83 | - std::vector<int64_t> selfShape = {4, 2}; | 83 | + std::vector<int64_t> selfShape = {4, 2}; |
| 84 | - std::vector<int64_t> outShape = {4, 2}; | 84 | + std::vector<int64_t> outShape = {4, 2}; |
| 85 | - std::vector<int64_t> maskOutShape = {16}; | 85 | + std::vector<int64_t> maskOutShape = {16}; |
| 86 | - void* selfDeviceAddr = nullptr; | 86 | + void* selfDeviceAddr = nullptr; |
| 87 | - void* outDeviceAddr = nullptr; | 87 | + void* outDeviceAddr = nullptr; |
| 88 | - void* maskOutDeviceAddr = nullptr; | 88 | + void* maskOutDeviceAddr = nullptr; |
| 89 | - aclTensor* self = nullptr; | 89 | + aclTensor* self = nullptr; |
| 90 | - aclTensor* out = nullptr; | 90 | + aclTensor* out = nullptr; |
| 91 | - aclTensor* maskOut = nullptr; | 91 | + aclTensor* maskOut = nullptr; |
| 92 | - std::vector<float> selfHostData = {0, 1, 2, 3, 4, 5, 6, 7}; | 92 | + std::vector<float> selfHostData = {0, 1, 2, 3, 4, 5, 6, 7}; |
| 93 | - std::vector<float> outHostData(8, 0); | 93 | + std::vector<float> outHostData(8, 0); |
| 94 | - std::vector<uint8_t> maskOutHostData(16, 0); | 94 | + std::vector<uint8_t> maskOutHostData(16, 0); |
| 95 | - | 95 | + |
| 96 | - double p = 0.5; | 96 | + double p = 0.5; |
| 97 | - int64_t seed = 1234; | 97 | + int64_t seed = 1234; |
| 98 | - int64_t offset = 0; | 98 | + int64_t offset = 0; |
| 99 | - | 99 | + |
| 100 | - aclIntArray* shapeArray = aclCreateIntArray(selfShape.data(), 2); | 100 | + aclIntArray* shapeArray = aclCreateIntArray(selfShape.data(), 2); |
| 101 | - // 创建self aclTensor | 101 | + // 创建self aclTensor |
| 102 | - ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); | 102 | + ret = CreateAclTensor(selfHostData, selfShape, &selfDeviceAddr, aclDataType::ACL_FLOAT, &self); |
| 103 | - CHECK_RET(ret == ACL_SUCCESS, return ret); | 103 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 104 | - // 创建out aclTensor | 104 | + // 创建out aclTensor |
| 105 | - ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | 105 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); |
| 106 | - CHECK_RET(ret == ACL_SUCCESS, return ret); | 106 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 107 | - // 创建maskOut aclTensor | 107 | + // 创建maskOut aclTensor |
| 108 | - ret = CreateAclTensor(maskOutHostData, maskOutShape, &maskOutDeviceAddr, aclDataType::ACL_UINT8, &maskOut); | 108 | + ret = CreateAclTensor(maskOutHostData, maskOutShape, &maskOutDeviceAddr, aclDataType::ACL_UINT8, &maskOut); |
| 109 | - CHECK_RET(ret == ACL_SUCCESS, return ret); | 109 | + CHECK_RET(ret == ACL_SUCCESS, return ret); |
| 110 | - | 110 | + |
| 111 | - // 3. 调用aclnnDropoutGenMask生成mask | 111 | + // 3. 调用aclnnDropoutGenMask生成mask |
| 112 | - uint64_t workspaceSize = 0; | 112 | + uint64_t workspaceSize = 0; |
| 113 | - aclOpExecutor* executor; | 113 | + aclOpExecutor* executor; |
| 114 | - // 调用aclnnDropoutGenMask第一段接口 | 114 | + // 调用aclnnDropoutGenMask第一段接口 |
| 115 | - ret = aclnnDropoutGenMaskGetWorkspaceSize(shapeArray, p, seed, offset, maskOut, &workspaceSize, &executor); | 115 | + ret = aclnnDropoutGenMaskGetWorkspaceSize(shapeArray, p, seed, offset, maskOut, &workspaceSize, &executor); |
| 116 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDropoutGenMaskGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); | 116 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDropoutGenMaskGetWorkspaceSize failed. ERROR: %d\n", ret); return ret); |
| 117 | - // 根据第一段接口计算出的workspaceSize申请device内存 | 117 | + // 根据第一段接口计算出的workspaceSize申请device内存 |
| 118 | - void* workspaceAddr = nullptr; | 118 | + void* workspaceAddr = nullptr; |
| 119 | - if (workspaceSize > 0) { | 119 | + if (workspaceSize > 0) { |
| 120 | - ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | 120 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); |
| 121 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | 121 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); |
| 122 | - } | 122 | + } |
| 123 | - // 调用aclnnDropoutGenMask第二段接口 | 123 | + // 调用aclnnDropoutGenMask第二段接口 |
| 124 | - ret = aclnnDropoutGenMask(workspaceAddr, workspaceSize, executor, stream); | 124 | + ret = aclnnDropoutGenMask(workspaceAddr, workspaceSize, executor, stream); |
| 125 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDropoutGenMask failed. ERROR: %d\n", ret); return ret); | 125 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnDropoutGenMask failed. ERROR: %d\n", ret); return ret); |
| 126 | - | 126 | + |
| 127 | - // 4. (固定写法)同步等待任务执行结束 | 127 | + // 4. (固定写法)同步等待任务执行结束 |
| 128 | - ret = aclrtSynchronizeStream(stream); | 128 | + ret = aclrtSynchronizeStream(stream); |
| 129 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | 129 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); |
| 130 | - // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | 130 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 |
| 131 | - auto size = GetShapeSize(outShape); | 131 | + auto size = GetShapeSize(outShape); |
| 132 | - std::vector<float> resultData(size, 0); | 132 | + std::vector<float> resultData(size, 0); |
| 133 | - ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, | 133 | + ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, |
| 134 | - size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); | 134 | + size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST); |
| 135 | - CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | 135 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); |
| 136 | - for (int64_t i = 0; i < size; i++) { | 136 | + for (int64_t i = 0; i < size; i++) { |
| 137 | - LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | 137 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); |
| 138 | - } | 138 | + } |
| 139 | - | 139 | + |
| 140 | - // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 | 140 | + // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 |
| 141 | - aclDestroyTensor(self); | 141 | + aclDestroyTensor(self); |
| 142 | - aclDestroyTensor(out); | 142 | + aclDestroyTensor(out); |
| 143 | - aclDestroyTensor(maskOut); | 143 | + aclDestroyTensor(maskOut); |
| 144 | - | 144 | + |
| 145 | - // 7. 释放Device资源,需要根据具体API的接口定义修改 | 145 | + // 7. 释放Device资源,需要根据具体API的接口定义修改 |
| 146 | - aclrtFree(selfDeviceAddr); | 146 | + aclrtFree(selfDeviceAddr); |
| 147 | - aclrtFree(outDeviceAddr); | 147 | + aclrtFree(outDeviceAddr); |
| 148 | - aclrtFree(maskOutDeviceAddr); | 148 | + aclrtFree(maskOutDeviceAddr); |
| 149 | - if (workspaceSize > 0) { | 149 | + if (workspaceSize > 0) { |
| 150 | - aclrtFree(workspaceAddr); | 150 | + aclrtFree(workspaceAddr); |
| 151 | - } | 151 | + } |
| 152 | - aclrtDestroyStream(stream); | 152 | + aclrtDestroyStream(stream); |
| 153 | - aclrtResetDevice(deviceId); | 153 | + aclrtResetDevice(deviceId); |
| 154 | - aclFinalize(); | 154 | + aclFinalize(); |
| 155 | - | 155 | + |
| 156 | - return 0; | 156 | + return 0; |
| 157 | } | 157 | } |
| @@ -1,20 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | -# ---------------------------------------------------------------------------- | 9 | +# ----------------------------------------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +# 设置算子定义时支持的芯片类型 |
| 13 | -if(NOT ENABLE_TEST AND NOT BENCHMARK) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend910_95") |
| 14 | - list(REMOVE_ITEM CURRENT_DIRS tests) | 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 15 | -endif() | 14 | +set(SUPPORT_TILING_DIR "arch35") |
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | 15 | +add_all_modules_sources(OPTYPE stateless_random_normal_v2 ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) |
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
| @@ -0,0 +1,148 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_aclnn_normal_float_float.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + do { \ | ||
| 23 | + if (!(cond)) { \ | ||
| 24 | + return_expr; \ | ||
| 25 | + } \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + do { \ | ||
| 30 | + printf(message, ##__VA_ARGS__); \ | ||
| 31 | + } while (0) | ||
| 32 | + | ||
| 33 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) | ||
| 34 | +{ | ||
| 35 | + int64_t shapeSize = 1; | ||
| 36 | + for (auto i : shape) { | ||
| 37 | + shapeSize *= i; | ||
| 38 | + } | ||
| 39 | + return shapeSize; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +int Init(int32_t deviceId, aclrtStream* stream) | ||
| 43 | +{ | ||
| 44 | + // 固定写法,资源初始化 | ||
| 45 | + auto ret = aclInit(nullptr); | ||
| 46 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 47 | + ret = aclrtSetDevice(deviceId); | ||
| 48 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 49 | + ret = aclrtCreateStream(stream); | ||
| 50 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 51 | + return 0; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +template <typename T> | ||
| 55 | +int CreateAclTensor( | ||
| 56 | + const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType, | ||
| 57 | + aclTensor** tensor) | ||
| 58 | +{ | ||
| 59 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 60 | + // 调用aclrtMalloc申请device侧内存 | ||
| 61 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 62 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 63 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | ||
| 64 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 65 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 66 | + | ||
| 67 | + // 计算连续tensor的strides | ||
| 68 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 69 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 70 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + // 调用aclCreateTensor接口创建aclTensor | ||
| 74 | + *tensor = aclCreateTensor( | ||
| 75 | + shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), | ||
| 76 | + *deviceAddr); | ||
| 77 | + return 0; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +int main() | ||
| 81 | +{ | ||
| 82 | + // 1. (固定写法)device/stream初始化,参考acl API手册 | ||
| 83 | + // 根据自己的实际device填写deviceId | ||
| 84 | + int32_t deviceId = 0; | ||
| 85 | + aclrtStream stream; | ||
| 86 | + auto ret = Init(deviceId, &stream); | ||
| 87 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 88 | + | ||
| 89 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 | ||
| 90 | + std::vector<int64_t> outShape = {1, 4}; | ||
| 91 | + void* outDeviceAddr = nullptr; | ||
| 92 | + aclTensor* out = nullptr; | ||
| 93 | + std::vector<float> outHostData({0.0, 0.0, 0.0, 0.0}); | ||
| 94 | + float meanValue = 1.2f; | ||
| 95 | + float stdValue = 2.5f; | ||
| 96 | + int64_t seed = 1; | ||
| 97 | + int64_t offset = 2; | ||
| 98 | + | ||
| 99 | + // 创建out aclTensor | ||
| 100 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | ||
| 101 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 102 | + | ||
| 103 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 | ||
| 104 | + uint64_t workspaceSize = 0; | ||
| 105 | + aclOpExecutor* executor; | ||
| 106 | + // 调用aclnnNormalFloatFloat第一段接口 | ||
| 107 | + ret = aclnnNormalFloatFloatGetWorkspaceSize(meanValue, stdValue, seed, offset, out, &workspaceSize, &executor); | ||
| 108 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalFloatFloatGetWorkspaceSize failed. ERROR: %d\n", ret); | ||
| 109 | + return ret); | ||
| 110 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 111 | + void* workspaceAddr = nullptr; | ||
| 112 | + if (workspaceSize > 0) { | ||
| 113 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 114 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 115 | + } | ||
| 116 | + // 调用aclnnNormalFloatFloat第二段接口 | ||
| 117 | + ret = aclnnNormalFloatFloat(workspaceAddr, workspaceSize, executor, stream); | ||
| 118 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalFloatFloat failed. ERROR: %d\n", ret); return ret); | ||
| 119 | + | ||
| 120 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 121 | + ret = aclrtSynchronizeStream(stream); | ||
| 122 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 123 | + | ||
| 124 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | ||
| 125 | + auto size = GetShapeSize(outShape); | ||
| 126 | + std::vector<float> resultData(size, 0); | ||
| 127 | + ret = aclrtMemcpy( | ||
| 128 | + resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, size * sizeof(resultData[0]), | ||
| 129 | + ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 130 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 131 | + for (int64_t i = 0; i < size; i++) { | ||
| 132 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 | ||
| 136 | + aclDestroyTensor(out); | ||
| 137 | + | ||
| 138 | + // 7. 释放Device资源,需要根据具体API的接口定义修改 | ||
| 139 | + aclrtFree(outDeviceAddr); | ||
| 140 | + if (workspaceSize > 0) { | ||
| 141 | + aclrtFree(workspaceAddr); | ||
| 142 | + } | ||
| 143 | + aclrtDestroyStream(stream); | ||
| 144 | + aclrtResetDevice(deviceId); | ||
| 145 | + aclFinalize(); | ||
| 146 | + | ||
| 147 | + return 0; | ||
| 148 | +} | ||
| @@ -0,0 +1,155 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_aclnn_normal_float_tensor.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + do { \ | ||
| 23 | + if (!(cond)) { \ | ||
| 24 | + return_expr; \ | ||
| 25 | + } \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + do { \ | ||
| 30 | + printf(message, ##__VA_ARGS__); \ | ||
| 31 | + } while (0) | ||
| 32 | + | ||
| 33 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) | ||
| 34 | +{ | ||
| 35 | + int64_t shapeSize = 1; | ||
| 36 | + for (auto i : shape) { | ||
| 37 | + shapeSize *= i; | ||
| 38 | + } | ||
| 39 | + return shapeSize; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +int Init(int32_t deviceId, aclrtStream* stream) | ||
| 43 | +{ | ||
| 44 | + // 固定写法,资源初始化 | ||
| 45 | + auto ret = aclInit(nullptr); | ||
| 46 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 47 | + ret = aclrtSetDevice(deviceId); | ||
| 48 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 49 | + ret = aclrtCreateStream(stream); | ||
| 50 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 51 | + return 0; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +template <typename T> | ||
| 55 | +int CreateAclTensor( | ||
| 56 | + const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType, | ||
| 57 | + aclTensor** tensor) | ||
| 58 | +{ | ||
| 59 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 60 | + // 调用aclrtMalloc申请device侧内存 | ||
| 61 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 62 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 63 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | ||
| 64 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 65 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 66 | + | ||
| 67 | + // 计算连续tensor的strides | ||
| 68 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 69 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 70 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + // 调用aclCreateTensor接口创建aclTensor | ||
| 74 | + *tensor = aclCreateTensor( | ||
| 75 | + shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), | ||
| 76 | + *deviceAddr); | ||
| 77 | + return 0; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +int main() | ||
| 81 | +{ | ||
| 82 | + // 1. (固定写法)device/stream初始化,参考acl API手册 | ||
| 83 | + // 根据自己的实际device填写deviceId | ||
| 84 | + int32_t deviceId = 0; | ||
| 85 | + aclrtStream stream; | ||
| 86 | + auto ret = Init(deviceId, &stream); | ||
| 87 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 88 | + | ||
| 89 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 | ||
| 90 | + std::vector<int64_t> stdShape = {1, 4}; | ||
| 91 | + std::vector<int64_t> outShape = {1, 4}; | ||
| 92 | + void* stdDeviceAddr = nullptr; | ||
| 93 | + void* outDeviceAddr = nullptr; | ||
| 94 | + aclTensor* std = nullptr; | ||
| 95 | + aclTensor* out = nullptr; | ||
| 96 | + std::vector<float> stdHostData = {1.1, 1.2, 1.3, 1.4}; | ||
| 97 | + std::vector<float> outHostData = {0.0, 0.0, 0.0, 0.0}; | ||
| 98 | + float meanValue = 1.2f; | ||
| 99 | + int64_t seed = 1; | ||
| 100 | + int64_t offset = 1; | ||
| 101 | + // 创建self aclTensor | ||
| 102 | + ret = CreateAclTensor(stdHostData, stdShape, &stdDeviceAddr, aclDataType::ACL_FLOAT, &std); | ||
| 103 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 104 | + // 创建out aclTensor | ||
| 105 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | ||
| 106 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 107 | + | ||
| 108 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 | ||
| 109 | + uint64_t workspaceSize = 0; | ||
| 110 | + aclOpExecutor* executor; | ||
| 111 | + // 调用aclnnNormalFloatTensor第一段接口 | ||
| 112 | + ret = aclnnNormalFloatTensorGetWorkspaceSize(meanValue, std, seed, offset, out, &workspaceSize, &executor); | ||
| 113 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalFloatTensorGetWorkspaceSize failed. ERROR: %d\n", ret); | ||
| 114 | + return ret); | ||
| 115 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 116 | + void* workspaceAddr = nullptr; | ||
| 117 | + if (workspaceSize > 0) { | ||
| 118 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 119 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 120 | + } | ||
| 121 | + // 调用aclnnNormalFloatTensor第二段接口 | ||
| 122 | + ret = aclnnNormalFloatTensor(workspaceAddr, workspaceSize, executor, stream); | ||
| 123 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalFloatTensor failed. ERROR: %d\n", ret); return ret); | ||
| 124 | + | ||
| 125 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 126 | + ret = aclrtSynchronizeStream(stream); | ||
| 127 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 128 | + | ||
| 129 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | ||
| 130 | + auto size = GetShapeSize(outShape); | ||
| 131 | + std::vector<float> resultData(size, 0); | ||
| 132 | + ret = aclrtMemcpy( | ||
| 133 | + resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, size * sizeof(resultData[0]), | ||
| 134 | + ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 135 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 136 | + for (int64_t i = 0; i < size; i++) { | ||
| 137 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 | ||
| 141 | + aclDestroyTensor(std); | ||
| 142 | + aclDestroyTensor(out); | ||
| 143 | + | ||
| 144 | + // 7. 释放device 资源 | ||
| 145 | + aclrtFree(stdDeviceAddr); | ||
| 146 | + aclrtFree(outDeviceAddr); | ||
| 147 | + if (workspaceSize > 0) { | ||
| 148 | + aclrtFree(workspaceAddr); | ||
| 149 | + } | ||
| 150 | + aclrtDestroyStream(stream); | ||
| 151 | + aclrtResetDevice(deviceId); | ||
| 152 | + aclFinalize(); | ||
| 153 | + | ||
| 154 | + return 0; | ||
| 155 | +} | ||
| @@ -0,0 +1,155 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_aclnn_normal_tensor_float.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + do { \ | ||
| 23 | + if (!(cond)) { \ | ||
| 24 | + return_expr; \ | ||
| 25 | + } \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + do { \ | ||
| 30 | + printf(message, ##__VA_ARGS__); \ | ||
| 31 | + } while (0) | ||
| 32 | + | ||
| 33 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) | ||
| 34 | +{ | ||
| 35 | + int64_t shapeSize = 1; | ||
| 36 | + for (auto i : shape) { | ||
| 37 | + shapeSize *= i; | ||
| 38 | + } | ||
| 39 | + return shapeSize; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +int Init(int32_t deviceId, aclrtStream* stream) | ||
| 43 | +{ | ||
| 44 | + // 固定写法,资源初始化 | ||
| 45 | + auto ret = aclInit(nullptr); | ||
| 46 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 47 | + ret = aclrtSetDevice(deviceId); | ||
| 48 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 49 | + ret = aclrtCreateStream(stream); | ||
| 50 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 51 | + return 0; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +template <typename T> | ||
| 55 | +int CreateAclTensor( | ||
| 56 | + const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType, | ||
| 57 | + aclTensor** tensor) | ||
| 58 | +{ | ||
| 59 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 60 | + // 调用aclrtMalloc申请device侧内存 | ||
| 61 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 62 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 63 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | ||
| 64 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 65 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 66 | + | ||
| 67 | + // 计算连续tensor的strides | ||
| 68 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 69 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 70 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + // 调用aclCreateTensor接口创建aclTensor | ||
| 74 | + *tensor = aclCreateTensor( | ||
| 75 | + shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), | ||
| 76 | + *deviceAddr); | ||
| 77 | + return 0; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +int main() | ||
| 81 | +{ | ||
| 82 | + // 1. (固定写法)device/stream初始化,参考acl API手册 | ||
| 83 | + // 根据自己的实际device填写deviceId | ||
| 84 | + int32_t deviceId = 0; | ||
| 85 | + aclrtStream stream; | ||
| 86 | + auto ret = Init(deviceId, &stream); | ||
| 87 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 88 | + | ||
| 89 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 | ||
| 90 | + std::vector<int64_t> meanShape = {1, 4}; | ||
| 91 | + std::vector<int64_t> outShape = {1, 4}; | ||
| 92 | + void* meanDeviceAddr = nullptr; | ||
| 93 | + void* outDeviceAddr = nullptr; | ||
| 94 | + aclTensor* mean = nullptr; | ||
| 95 | + aclTensor* out = nullptr; | ||
| 96 | + std::vector<float> meanHostData = {1.1, 1.2, 1.3, 1.4}; | ||
| 97 | + std::vector<float> outHostData = {0.0, 0.0, 0.0, 0.0}; | ||
| 98 | + float stdValue = 1.2f; | ||
| 99 | + int64_t seed = 1; | ||
| 100 | + int64_t offset = 1; | ||
| 101 | + // 创建self aclTensor | ||
| 102 | + ret = CreateAclTensor(meanHostData, meanShape, &meanDeviceAddr, aclDataType::ACL_FLOAT, &mean); | ||
| 103 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 104 | + // 创建out aclTensor | ||
| 105 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | ||
| 106 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 107 | + | ||
| 108 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 | ||
| 109 | + uint64_t workspaceSize = 0; | ||
| 110 | + aclOpExecutor* executor; | ||
| 111 | + // 调用aclnnNormalTensorFloat第一段接口 | ||
| 112 | + ret = aclnnNormalTensorFloatGetWorkspaceSize(mean, stdValue, seed, offset, out, &workspaceSize, &executor); | ||
| 113 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalTensorFloatGetWorkspaceSize failed. ERROR: %d\n", ret); | ||
| 114 | + return ret); | ||
| 115 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 116 | + void* workspaceAddr = nullptr; | ||
| 117 | + if (workspaceSize > 0) { | ||
| 118 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 119 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 120 | + } | ||
| 121 | + // 调用aclnnNormalTensorFloat第二段接口 | ||
| 122 | + ret = aclnnNormalTensorFloat(workspaceAddr, workspaceSize, executor, stream); | ||
| 123 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalTensorFloat failed. ERROR: %d\n", ret); return ret); | ||
| 124 | + | ||
| 125 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 126 | + ret = aclrtSynchronizeStream(stream); | ||
| 127 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 128 | + | ||
| 129 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | ||
| 130 | + auto size = GetShapeSize(outShape); | ||
| 131 | + std::vector<float> resultData(size, 0); | ||
| 132 | + ret = aclrtMemcpy( | ||
| 133 | + resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, size * sizeof(resultData[0]), | ||
| 134 | + ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 135 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 136 | + for (int64_t i = 0; i < size; i++) { | ||
| 137 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 | ||
| 141 | + aclDestroyTensor(mean); | ||
| 142 | + aclDestroyTensor(out); | ||
| 143 | + | ||
| 144 | + // 7. 释放device 资源 | ||
| 145 | + aclrtFree(meanDeviceAddr); | ||
| 146 | + aclrtFree(outDeviceAddr); | ||
| 147 | + if (workspaceSize > 0) { | ||
| 148 | + aclrtFree(workspaceAddr); | ||
| 149 | + } | ||
| 150 | + aclrtDestroyStream(stream); | ||
| 151 | + aclrtResetDevice(deviceId); | ||
| 152 | + aclFinalize(); | ||
| 153 | + | ||
| 154 | + return 0; | ||
| 155 | +} | ||
| @@ -0,0 +1,164 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_aclnn_normal_tensor_tensor.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + do { \ | ||
| 23 | + if (!(cond)) { \ | ||
| 24 | + return_expr; \ | ||
| 25 | + } \ | ||
| 26 | + } while (0) | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + do { \ | ||
| 30 | + printf(message, ##__VA_ARGS__); \ | ||
| 31 | + } while (0) | ||
| 32 | + | ||
| 33 | +int64_t GetShapeSize(const std::vector<int64_t>& shape) | ||
| 34 | +{ | ||
| 35 | + int64_t shapeSize = 1; | ||
| 36 | + for (auto i : shape) { | ||
| 37 | + shapeSize *= i; | ||
| 38 | + } | ||
| 39 | + return shapeSize; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +int Init(int32_t deviceId, aclrtStream* stream) | ||
| 43 | +{ | ||
| 44 | + // 固定写法,资源初始化 | ||
| 45 | + auto ret = aclInit(nullptr); | ||
| 46 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret); | ||
| 47 | + ret = aclrtSetDevice(deviceId); | ||
| 48 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret); | ||
| 49 | + ret = aclrtCreateStream(stream); | ||
| 50 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret); | ||
| 51 | + return 0; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +template <typename T> | ||
| 55 | +int CreateAclTensor( | ||
| 56 | + const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType, | ||
| 57 | + aclTensor** tensor) | ||
| 58 | +{ | ||
| 59 | + auto size = GetShapeSize(shape) * sizeof(T); | ||
| 60 | + // 调用aclrtMalloc申请device侧内存 | ||
| 61 | + auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 62 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | ||
| 63 | + // 调用aclrtMemcpy将host侧数据拷贝到device侧内存上 | ||
| 64 | + ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE); | ||
| 65 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret); | ||
| 66 | + | ||
| 67 | + // 计算连续tensor的strides | ||
| 68 | + std::vector<int64_t> strides(shape.size(), 1); | ||
| 69 | + for (int64_t i = shape.size() - 2; i >= 0; i--) { | ||
| 70 | + strides[i] = shape[i + 1] * strides[i + 1]; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + // 调用aclCreateTensor接口创建aclTensor | ||
| 74 | + *tensor = aclCreateTensor( | ||
| 75 | + shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(), | ||
| 76 | + *deviceAddr); | ||
| 77 | + return 0; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +int main() | ||
| 81 | +{ | ||
| 82 | + // 1. (固定写法)device/stream初始化,参考acl API手册 | ||
| 83 | + // 根据自己的实际device填写deviceId | ||
| 84 | + int32_t deviceId = 0; | ||
| 85 | + aclrtStream stream; | ||
| 86 | + auto ret = Init(deviceId, &stream); | ||
| 87 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret); | ||
| 88 | + | ||
| 89 | + // 2. 构造输入与输出,需要根据API的接口自定义构造 | ||
| 90 | + std::vector<int64_t> meanShape = {1, 4}; | ||
| 91 | + std::vector<int64_t> stdShape = {1, 4}; | ||
| 92 | + std::vector<int64_t> outShape = {1, 4}; | ||
| 93 | + void* meanDeviceAddr = nullptr; | ||
| 94 | + void* stdDeviceAddr = nullptr; | ||
| 95 | + void* outDeviceAddr = nullptr; | ||
| 96 | + aclTensor* mean = nullptr; | ||
| 97 | + aclTensor* std = nullptr; | ||
| 98 | + aclTensor* out = nullptr; | ||
| 99 | + std::vector<float> meanHostData = {1.1, 1.2, 1.3, 1.4}; | ||
| 100 | + std::vector<float> stdHostData = {0.5, 0.6, 0.4, 0.5}; | ||
| 101 | + std::vector<float> outHostData = {0.0, 0.0, 0.0, 0.0}; | ||
| 102 | + int64_t seed = 1; | ||
| 103 | + int64_t offset = 1; | ||
| 104 | + | ||
| 105 | + // 创建mean aclTensor | ||
| 106 | + ret = CreateAclTensor(meanHostData, meanShape, &meanDeviceAddr, aclDataType::ACL_FLOAT, &mean); | ||
| 107 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 108 | + // 创建std aclTensor | ||
| 109 | + ret = CreateAclTensor(stdHostData, stdShape, &stdDeviceAddr, aclDataType::ACL_FLOAT, &std); | ||
| 110 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 111 | + // 创建out aclTensor | ||
| 112 | + ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT, &out); | ||
| 113 | + CHECK_RET(ret == ACL_SUCCESS, return ret); | ||
| 114 | + | ||
| 115 | + // 3. 调用CANN算子库API,需要修改为具体的Api名称 | ||
| 116 | + uint64_t workspaceSize = 0; | ||
| 117 | + aclOpExecutor* executor; | ||
| 118 | + // 调用aclnnNormalTensorTensor第一段接口 | ||
| 119 | + ret = aclnnNormalTensorTensorGetWorkspaceSize(mean, std, seed, offset, out, &workspaceSize, &executor); | ||
| 120 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalTensorTensorGetWorkspaceSize failed. ERROR: %d\n", ret); | ||
| 121 | + return ret); | ||
| 122 | + // 根据第一段接口计算出的workspaceSize申请device内存 | ||
| 123 | + void* workspaceAddr = nullptr; | ||
| 124 | + if (workspaceSize > 0) { | ||
| 125 | + ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST); | ||
| 126 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret); | ||
| 127 | + } | ||
| 128 | + // 调用aclnnNormalTensorTensor第二段接口 | ||
| 129 | + ret = aclnnNormalTensorTensor(workspaceAddr, workspaceSize, executor, stream); | ||
| 130 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnNormalTensorTensor failed. ERROR: %d\n", ret); return ret); | ||
| 131 | + | ||
| 132 | + // 4. (固定写法)同步等待任务执行结束 | ||
| 133 | + ret = aclrtSynchronizeStream(stream); | ||
| 134 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret); | ||
| 135 | + | ||
| 136 | + // 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改 | ||
| 137 | + auto size = GetShapeSize(outShape); | ||
| 138 | + std::vector<float> resultData(size, 0); | ||
| 139 | + ret = aclrtMemcpy( | ||
| 140 | + resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr, size * sizeof(resultData[0]), | ||
| 141 | + ACL_MEMCPY_DEVICE_TO_HOST); | ||
| 142 | + CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret); | ||
| 143 | + for (int64_t i = 0; i < size; i++) { | ||
| 144 | + LOG_PRINT("result[%ld] is: %f\n", i, resultData[i]); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + // 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改 | ||
| 148 | + aclDestroyTensor(mean); | ||
| 149 | + aclDestroyTensor(std); | ||
| 150 | + aclDestroyTensor(out); | ||
| 151 | + | ||
| 152 | + // 7. 释放device 资源 | ||
| 153 | + aclrtFree(meanDeviceAddr); | ||
| 154 | + aclrtFree(stdDeviceAddr); | ||
| 155 | + aclrtFree(outDeviceAddr); | ||
| 156 | + if (workspaceSize > 0) { | ||
| 157 | + aclrtFree(workspaceAddr); | ||
| 158 | + } | ||
| 159 | + aclrtDestroyStream(stream); | ||
| 160 | + aclrtResetDevice(deviceId); | ||
| 161 | + aclFinalize(); | ||
| 162 | + | ||
| 163 | + return 0; | ||
| 164 | +} | ||
Rrandom/stateless_random_normal_v2/op_host/op_api/aclnn_normal_out.cpp→random/stateless_random_normal_v2/op_api/aclnn_normal_out.cpp+22-9
| @@ -1,12 +1,12 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
| @@ -223,8 +223,21 @@ aclnnStatus CommonLogicGeneralNormal( | |||
| 223 | auto mulOut = l0op::Mul(stateLessOut, std, uniqueExecutor.get()); | 223 | auto mulOut = l0op::Mul(stateLessOut, std, uniqueExecutor.get()); |
| 224 | CHECK_RET(mulOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | 224 | CHECK_RET(mulOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 225 | 225 | ||
| 226 | + // 如果类型不一致,先做类型提升,再进行ADD算子运算 | ||
| 227 | + auto meanCast = mean; | ||
| 228 | + auto mulOutCast = mulOut; | ||
| 229 | + auto meanType = mean->GetDataType(); | ||
| 230 | + auto mulOutType = mulOut->GetDataType(); | ||
| 231 | + if (meanType != mulOutType) { | ||
| 232 | + auto promoteType = op::PromoteType(meanType, mulOutType); | ||
| 233 | + meanCast = l0op::Cast(mean, promoteType, uniqueExecutor.get()); | ||
| 234 | + CHECK_RET(meanCast != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 235 | + mulOutCast = l0op::Cast(mulOut, promoteType, uniqueExecutor.get()); | ||
| 236 | + CHECK_RET(mulOutCast != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| 237 | + } | ||
| 238 | + | ||
| 226 | // 调用add_算子kernel function(AI Core算子) | 239 | // 调用add_算子kernel function(AI Core算子) |
| 227 | - auto addOut = l0op::Add(mulOut, mean, uniqueExecutor.get()); | 240 | + auto addOut = l0op::Add(mulOutCast, meanCast, uniqueExecutor.get()); |
| 228 | CHECK_RET(addOut != nullptr, ACLNN_ERR_INNER_NULLPTR); | 241 | CHECK_RET(addOut != nullptr, ACLNN_ERR_INNER_NULLPTR); |
| 229 | 242 | ||
| 230 | // 固定写法,将计算结果转换成输出self的数据类型 | 243 | // 固定写法,将计算结果转换成输出self的数据类型 |
Rrandom/stateless_random_normal_v2/op_host/op_api/aclnn_normal_out.h→random/stateless_random_normal_v2/op_api/aclnn_normal_out.h+8-8
| @@ -1,12 +1,12 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
Rrandom/stateless_random_normal_v2/op_host/op_api/stateless_random_normal_v2.cpp→random/stateless_random_normal_v2/op_api/stateless_random_normal_v2.cpp+8-8
| @@ -1,12 +1,12 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
| @@ -0,0 +1,22 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +namespace l0op { | ||
| 17 | +const aclTensor* StatelessRandomNormalV2( | ||
| 18 | + const aclTensor* result, const aclIntArray* key, const aclIntArray* counter, const aclTensor* alg, | ||
| 19 | + aclOpExecutor* executor); | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | + | ||
The file is empty
| @@ -0,0 +1,58 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file stateless_random_normal_v2_proto.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace ge { | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | +* @brief Outputs deterministic pseudorandom values from a normal distribution. \n | ||
| 25 | + | ||
| 26 | +* @par Inputs: | ||
| 27 | +* @li shape: 1-D. The shape of the output tensor. Must be one of the following types: int32, int64. | ||
| 28 | +* @li key: 1-D. Key for the counter-based RNG algorithm. Must be one of the following types: uint64. | ||
| 29 | +* @li counter: 1-D. Initial counter for the counter-based RNG algorithm. Must be one of the following types: uint64. | ||
| 30 | +* @li alg: 0-D. The RNG(random number generator) algorithm. Must be one of the following types: int32. \n | ||
| 31 | + | ||
| 32 | +* @par Attributes: | ||
| 33 | +* dtype:Output data type. Must be one of the following types: float16, bfloat16, float32, double. | ||
| 34 | +* Defaults to float32. \n | ||
| 35 | + | ||
| 36 | +* @par Outputs: | ||
| 37 | +* y: Returns Random values with specified shape. | ||
| 38 | +* Must be one of the following types: float16, bfloat16, float32, double. \n | ||
| 39 | + | ||
| 40 | +* @attention Constraints: | ||
| 41 | +* The following constraints apply only to the Ascend 910_95 AI processor. \n | ||
| 42 | +* The input of counter must contain two values. If the input of counter contains | ||
| 43 | +* only one value, the high-order counter value is set to 0. \n | ||
| 44 | + | ||
| 45 | +* @par Third-party framework compatibility | ||
| 46 | +* Compatible with TensorFlow StatelessRandomNormalV2 operator. | ||
| 47 | +*/ | ||
| 48 | +REG_OP(StatelessRandomNormalV2) | ||
| 49 | + .INPUT(shape, TensorType({DT_INT32, DT_INT64})) | ||
| 50 | + .INPUT(key, TensorType({DT_UINT64})) | ||
| 51 | + .INPUT(counter, TensorType({DT_UINT64})) | ||
| 52 | + .INPUT(alg, TensorType({DT_INT32})) | ||
| 53 | + .OUTPUT(y, TensorType({DT_FLOAT16, DT_BF16, DT_FLOAT, DT_DOUBLE})) | ||
| 54 | + .ATTR(dtype, Type, DT_FLOAT) | ||
| 55 | + .OP_END_FACTORY_REG(StatelessRandomNormalV2) | ||
| 56 | + | ||
| 57 | +} // namespace ge | ||
| 58 | + | ||
| @@ -1,11 +1,10 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | add_modules_sources(OPTYPE stateless_random_normal_v2 ACLNNTYPE aclnn_exclude) | 10 | add_modules_sources(OPTYPE stateless_random_normal_v2 ACLNNTYPE aclnn_exclude) |
Arandom/stateless_random_normal_v2/op_host/arch35/stateless_random_normal_v2_tiling_arch35.cpp+315-0
| @@ -0,0 +1,315 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file stateless_random_normal_v2_tiling_arch35.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +namespace optiling { | ||
| 21 | + | ||
| 22 | +static const std::unordered_map<ge::DataType, uint32_t> OUTPUT_DATA_TYPE_TO_INT{ | ||
| 23 | + {ge::DataType::DT_FLOAT, 1}, {ge::DataType::DT_FLOAT16, 2}, {ge::DataType::DT_BF16, 3}}; | ||
| 24 | + | ||
| 25 | +static constexpr uint16_t INPUT_IDX_SHAPE = 0; | ||
| 26 | +static constexpr uint16_t INPUT_IDX_KEY = 1; | ||
| 27 | +static constexpr uint16_t INPUT_IDX_COUNTER = 2; | ||
| 28 | +static constexpr uint16_t INPUT_IDX_ALG = 3; | ||
| 29 | +static constexpr uint16_t OUTPUT_IDX_Y = 0; | ||
| 30 | +static constexpr uint16_t SIZE_OF_FLOAT = 4; | ||
| 31 | +static constexpr uint16_t SPLIT_UB_NUM = 5; | ||
| 32 | +static constexpr int64_t COUNTER_NUMBER_LOW_BOUND = 1; | ||
| 33 | + | ||
| 34 | +ge::graphStatus StatelessRandomNormalV2Tiling::GetPlatformInfo() | ||
| 35 | +{ | ||
| 36 | + auto platformInfo = context_->GetPlatformInfo(); | ||
| 37 | + if (platformInfo == nullptr) { | ||
| 38 | + auto compileInfoPtr = reinterpret_cast<const StatelessRandomNormalV2CompileInfo*>(context_->GetCompileInfo()); | ||
| 39 | + OP_CHECK_IF(compileInfoPtr == nullptr, OP_LOGE(context_, "compile info is null"), return ge::GRAPH_FAILED); | ||
| 40 | + coreNum_ = compileInfoPtr->aivNum; | ||
| 41 | + ubSize_ = compileInfoPtr->ubSize - REGBASE_CCEC_CACHE_SIZE; | ||
| 42 | + } else { | ||
| 43 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 44 | + auto aivNum = ascendcPlatform.GetCoreNumAiv(); | ||
| 45 | + OP_CHECK_IF( | ||
| 46 | + (aivNum <= 0), OP_LOGE(opName, "StatelessRandomNormalV2Tiling fail to get coreNum."), | ||
| 47 | + return ge::GRAPH_FAILED); | ||
| 48 | + coreNum_ = aivNum; | ||
| 49 | + uint64_t ubSizePlatForm; | ||
| 50 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSizePlatForm); | ||
| 51 | + OP_CHECK_IF( | ||
| 52 | + (ubSizePlatForm <= REGBASE_CCEC_CACHE_SIZE), | ||
| 53 | + OP_LOGE(opName, "ub size less than REGBASE_CCEC_CACHE_SIZE Size. please check"), return ge::GRAPH_FAILED); | ||
| 54 | + ubSize_ = ubSizePlatForm - REGBASE_CCEC_CACHE_SIZE; | ||
| 55 | + } | ||
| 56 | + return ge::GRAPH_SUCCESS; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +ge::graphStatus StatelessRandomNormalV2Tiling::GetShapeAttrsInfo() | ||
| 60 | +{ | ||
| 61 | + auto res = GetInputInfo(); | ||
| 62 | + if (res != ge::GRAPH_SUCCESS) { | ||
| 63 | + return ge::GRAPH_FAILED; | ||
| 64 | + } | ||
| 65 | + res = GetOutputInfo(); | ||
| 66 | + if (res != ge::GRAPH_SUCCESS) { | ||
| 67 | + return ge::GRAPH_FAILED; | ||
| 68 | + } | ||
| 69 | + return ge::GRAPH_SUCCESS; | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +int64_t StatelessRandomNormalV2Tiling::GetCounterSize(Algorithm alg) const | ||
| 73 | +{ | ||
| 74 | + if (alg == Algorithm::RNG_ALG_PHILOX) { | ||
| 75 | + return 2; // 2 if for philox | ||
| 76 | + } else if (alg == Algorithm::RNG_ALG_THREEFRY) { | ||
| 77 | + return 1; | ||
| 78 | + } | ||
| 79 | + return 2; // 2 is for philox | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +void StatelessRandomNormalV2Tiling::GetKeyFromMem(const uint64_t key) | ||
| 83 | +{ | ||
| 84 | + key_[0] = static_cast<uint32_t>(key); | ||
| 85 | + key_[1] = static_cast<uint32_t>(key >> 32); // 32 for lower 32 bits | ||
| 86 | +} | ||
| 87 | +void StatelessRandomNormalV2Tiling::GetCounterFromMem(const std::vector<uint64_t>& counter) | ||
| 88 | +{ | ||
| 89 | + counter_[0] = static_cast<uint32_t>(counter[0]); | ||
| 90 | + counter_[1] = static_cast<uint32_t>(counter[0] >> 32); // 32 for lower 32 bits | ||
| 91 | + counter_[2] = static_cast<uint32_t>(counter[1]); | ||
| 92 | + counter_[3] = static_cast<uint32_t>(counter[1] >> 32); // 32 for lower 32 bits | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +ge::graphStatus StatelessRandomNormalV2Tiling::GetInputKeyCounter() | ||
| 96 | +{ | ||
| 97 | + auto keyDesc = context_->GetInputDesc(INPUT_IDX_KEY); | ||
| 98 | + OP_CHECK_NULL_WITH_CONTEXT(context_, keyDesc); | ||
| 99 | + auto keyDtype = keyDesc->GetDataType(); | ||
| 100 | + if (keyDtype != ge::DataType::DT_UINT64) { | ||
| 101 | + OP_LOGE(opName, "input key Dtype should be uint64, but got [%d]", keyDtype); | ||
| 102 | + return ge::GRAPH_FAILED; | ||
| 103 | + } | ||
| 104 | + auto keyShape = context_->GetInputShape(INPUT_IDX_KEY); | ||
| 105 | + OP_CHECK_NULL_WITH_CONTEXT(context_, keyShape); | ||
| 106 | + if (keyShape->GetStorageShape().GetShapeSize() != 1) { | ||
| 107 | + OP_LOGE(opName, "input key number should be 1, but got [%ld]", keyShape->GetStorageShape().GetShapeSize()); | ||
| 108 | + return ge::GRAPH_FAILED; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + auto counterDesc = context_->GetInputDesc(INPUT_IDX_COUNTER); | ||
| 112 | + OP_CHECK_NULL_WITH_CONTEXT(context_, counterDesc); | ||
| 113 | + auto counterDtype = counterDesc->GetDataType(); | ||
| 114 | + if (counterDtype != ge::DataType::DT_UINT64) { | ||
| 115 | + OP_LOGE(opName, "input counter Dtype should be uint64, but got [%d]", counterDtype); | ||
| 116 | + return ge::GRAPH_FAILED; | ||
| 117 | + } | ||
| 118 | + // input key has one uint64, Philox counter need 2 element. | ||
| 119 | + std::vector<uint64_t> counter = {0, 0}; | ||
| 120 | + auto keyTensor = context_->GetInputTensor(INPUT_IDX_KEY); | ||
| 121 | + OP_CHECK_NULL_WITH_CONTEXT(context_, keyTensor); | ||
| 122 | + int32_t keyNum = keyTensor->GetShapeSize(); | ||
| 123 | + OP_CHECK_IF( | ||
| 124 | + keyNum != 1, OP_LOGE(opName, "key data must be 1 tensor scalar, but get %d.", keyNum), return ge::GRAPH_FAILED); | ||
| 125 | + const uint64_t* key = keyTensor->GetData<uint64_t>(); | ||
| 126 | + OP_CHECK_NULL_WITH_CONTEXT(context_, key); | ||
| 127 | + | ||
| 128 | + auto counterTensor = context_->GetInputTensor(INPUT_IDX_COUNTER); | ||
| 129 | + OP_CHECK_NULL_WITH_CONTEXT(context_, counterTensor); | ||
| 130 | + int64_t counterNum = static_cast<int64_t>(counterTensor->GetShapeSize()); | ||
| 131 | + OP_CHECK_IF( | ||
| 132 | + !counterNum, OP_LOGE(opName, "counter tensor elements number should not be 0."), return ge::GRAPH_FAILED); | ||
| 133 | + const uint64_t* counterVal = counterTensor->GetData<uint64_t>(); | ||
| 134 | + OP_CHECK_NULL_WITH_CONTEXT(context_, counterVal); | ||
| 135 | + counter[0] = counterVal[0]; | ||
| 136 | + if (counterNum == COUNTER_NUMBER_LOW_BOUND) { | ||
| 137 | + counter[1] = 0; | ||
| 138 | + } else { | ||
| 139 | + counter[1] = counterVal[1]; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + OP_LOGD(opName, "key = %ld, counter value is [%lu, %lu]", key[0], counter[0], counter[1]); | ||
| 143 | + | ||
| 144 | + GetKeyFromMem(key[0]); | ||
| 145 | + GetCounterFromMem(counter); | ||
| 146 | + return ge::GRAPH_SUCCESS; | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +ge::graphStatus StatelessRandomNormalV2Tiling::GetInputInfo() | ||
| 150 | +{ | ||
| 151 | + auto outputShape = context_->GetOutputShape(OUTPUT_IDX_Y); | ||
| 152 | + OP_CHECK_NULL_WITH_CONTEXT(context_, outputShape); | ||
| 153 | + auto shapeValue = outputShape->GetStorageShape(); | ||
| 154 | + uint32_t shapeRank = shapeValue.GetDimNum(); | ||
| 155 | + for (uint32_t idx = 0; idx < shapeRank; idx++) { | ||
| 156 | + outputSize_ *= shapeValue.GetDim(idx); | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + auto algTensor = context_->GetInputTensor(INPUT_IDX_ALG); | ||
| 160 | + OP_CHECK_NULL_WITH_CONTEXT(context_, algTensor); | ||
| 161 | + if (algTensor->GetShapeSize() != 1) { | ||
| 162 | + OP_LOGE(opName, "alg data must be 1 tensor scalar, but got [%ld]", algTensor->GetShapeSize()); | ||
| 163 | + return ge::GRAPH_FAILED; | ||
| 164 | + } | ||
| 165 | + const int32_t* algVal = algTensor->GetData<int32_t>(); | ||
| 166 | + OP_CHECK_NULL_WITH_CONTEXT(context_, algVal); | ||
| 167 | + alg_ = Algorithm(algVal[0]); | ||
| 168 | + if (alg_ == Algorithm::RNG_ALG_AUTO_SELECT) { | ||
| 169 | + alg_ = Algorithm::RNG_ALG_PHILOX; | ||
| 170 | + } | ||
| 171 | + OP_CHECK_IF( | ||
| 172 | + alg_ != Algorithm::RNG_ALG_PHILOX, | ||
| 173 | + OP_LOGE( | ||
| 174 | + opName, "alg only support %d, but got %d.", static_cast<int32_t>(Algorithm::RNG_ALG_PHILOX), | ||
| 175 | + static_cast<int32_t>(alg_)), | ||
| 176 | + return ge::GRAPH_FAILED); | ||
| 177 | + | ||
| 178 | + auto res = GetInputKeyCounter(); | ||
| 179 | + if (res != ge::GRAPH_SUCCESS) { | ||
| 180 | + return ge::GRAPH_FAILED; | ||
| 181 | + } | ||
| 182 | + return ge::GRAPH_SUCCESS; | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +ge::graphStatus StatelessRandomNormalV2Tiling::GetOutputInfo() | ||
| 186 | +{ | ||
| 187 | + auto outputDesc = context_->GetOutputDesc(OUTPUT_IDX_Y); | ||
| 188 | + OP_CHECK_NULL_WITH_CONTEXT(context_, outputDesc); | ||
| 189 | + outputDtype_ = outputDesc->GetDataType(); | ||
| 190 | + auto iter = OUTPUT_DATA_TYPE_TO_INT.find(outputDtype_); | ||
| 191 | + if (iter != OUTPUT_DATA_TYPE_TO_INT.end()) { | ||
| 192 | + outputDtypeVal_ = iter->second; | ||
| 193 | + } else { | ||
| 194 | + OP_LOGE(opName, "output dtype = %d not supported, please check.", outputDtype_); | ||
| 195 | + return ge::GRAPH_FAILED; | ||
| 196 | + } | ||
| 197 | + return ge::GRAPH_SUCCESS; | ||
| 198 | +} | ||
| 199 | + | ||
| 200 | +template <typename T1, typename T2> | ||
| 201 | +inline T1 StatelessRandomNormalV2Tiling::CeilDiv(const T1 a, const T2 b) const | ||
| 202 | +{ | ||
| 203 | + if (b == 0) { | ||
| 204 | + return a; | ||
| 205 | + } | ||
| 206 | + return (a + b - 1) / b; | ||
| 207 | +} | ||
| 208 | + | ||
| 209 | +void StatelessRandomNormalV2Tiling::BlockTiling() | ||
| 210 | +{ | ||
| 211 | + outputDtypeSize_ = SIZE_OF_FLOAT; | ||
| 212 | + auto coreAlignFactor = CORE_ALIGN_SIZE / outputDtypeSize_; | ||
| 213 | + auto blockFactor = CeilDiv(outputSize_, coreNum_); | ||
| 214 | + auto blockAlignFactor = CeilDiv(blockFactor, coreAlignFactor) * coreAlignFactor; | ||
| 215 | + auto minTilingSize = MIN_TILING_SIZE; | ||
| 216 | + blockTilingSize_ = std::max(static_cast<uint32_t>(blockAlignFactor), minTilingSize); | ||
| 217 | + blockNum_ = CeilDiv(outputSize_, blockTilingSize_); | ||
| 218 | + tailBlockTilingSize_ = outputSize_ - blockTilingSize_ * (blockNum_ - 1); | ||
| 219 | + OP_LOGD( | ||
| 220 | + opName, | ||
| 221 | + "outputSize = %lld, blockFactor = %lld, blockAlignFactor = %lld," | ||
| 222 | + "blockTilingSize = %d, tailBlockTilingSize = %d", | ||
| 223 | + outputSize_, blockFactor, blockAlignFactor, blockTilingSize_, tailBlockTilingSize_); | ||
| 224 | + return; | ||
| 225 | +} | ||
| 226 | + | ||
| 227 | +ge::graphStatus StatelessRandomNormalV2Tiling::UbTiling() | ||
| 228 | +{ | ||
| 229 | + // splitUbSize: 2 for double buffer; 3 for data converse | ||
| 230 | + auto splitUbSize = ubSize_ / SPLIT_UB_NUM; | ||
| 231 | + auto alignFactor = BLOCK_SIZE_BYTES / outputDtypeSize_; | ||
| 232 | + ubTilingSize_ = CeilDiv(splitUbSize / outputDtypeSize_, alignFactor) * alignFactor; | ||
| 233 | + OP_LOGD(opName, "splitUbSize = %u, ubTilingSize = %u", splitUbSize, ubTilingSize_); | ||
| 234 | + return ge::GRAPH_SUCCESS; | ||
| 235 | +} | ||
| 236 | + | ||
| 237 | +ge::graphStatus StatelessRandomNormalV2Tiling::DoOpTiling() | ||
| 238 | +{ | ||
| 239 | + BlockTiling(); | ||
| 240 | + ge::graphStatus res = UbTiling(); | ||
| 241 | + if (res == ge::GRAPH_FAILED) { | ||
| 242 | + return ge::GRAPH_FAILED; | ||
| 243 | + } | ||
| 244 | + SetTilingData(); | ||
| 245 | + return ge::GRAPH_SUCCESS; | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | +ge::graphStatus StatelessRandomNormalV2Tiling::DoLibApiTiling() | ||
| 249 | +{ | ||
| 250 | + return ge::GRAPH_SUCCESS; | ||
| 251 | +} | ||
| 252 | + | ||
| 253 | +uint64_t StatelessRandomNormalV2Tiling::GetTilingKey() const | ||
| 254 | +{ | ||
| 255 | + uint64_t tilingKey = 100; | ||
| 256 | + tilingKey += outputDtypeVal_; | ||
| 257 | + OP_LOGD(opName, "tilingKey = %lld.", tilingKey); | ||
| 258 | + return tilingKey; | ||
| 259 | +} | ||
| 260 | + | ||
| 261 | +ge::graphStatus StatelessRandomNormalV2Tiling::GetWorkspaceSize() | ||
| 262 | +{ | ||
| 263 | + workspaceSize_ = DEFAULT_WORKSPACE_SIZE; | ||
| 264 | + return ge::GRAPH_SUCCESS; | ||
| 265 | +} | ||
| 266 | + | ||
| 267 | +ge::graphStatus StatelessRandomNormalV2Tiling::PostTiling() | ||
| 268 | +{ | ||
| 269 | + auto workspaces = context_->GetWorkspaceSizes(1); | ||
| 270 | + workspaces[0] = workspaceSize_; | ||
| 271 | + context_->SetTilingKey(GetTilingKey()); | ||
| 272 | + context_->SetBlockDim(blockNum_); | ||
| 273 | + tilingData.SaveToBuffer(context_->GetRawTilingData()->GetData(), context_->GetRawTilingData()->GetCapacity()); | ||
| 274 | + context_->GetRawTilingData()->SetDataSize(tilingData.GetDataSize()); | ||
| 275 | + return ge::GRAPH_SUCCESS; | ||
| 276 | +} | ||
| 277 | + | ||
| 278 | +void StatelessRandomNormalV2Tiling::SetTilingData() | ||
| 279 | +{ | ||
| 280 | + tilingData.set_blockNum(blockNum_); | ||
| 281 | + tilingData.set_blockTilingSize(blockTilingSize_); | ||
| 282 | + tilingData.set_tailBlockTilingSize(tailBlockTilingSize_); | ||
| 283 | + tilingData.set_ubTilingSize(ubTilingSize_); | ||
| 284 | + tilingData.set_alg(static_cast<uint32_t>(alg_)); | ||
| 285 | + tilingData.set_key(key_); | ||
| 286 | + tilingData.set_counter(counter_); | ||
| 287 | + return; | ||
| 288 | +} | ||
| 289 | + | ||
| 290 | +ge::graphStatus Tiling4StatelessRandomNormalV2(gert::TilingContext* context) | ||
| 291 | +{ | ||
| 292 | + StatelessRandomNormalV2Tiling tilingObj(context); | ||
| 293 | + return tilingObj.DoTiling(); | ||
| 294 | +} | ||
| 295 | + | ||
| 296 | +static ge::graphStatus TilingPrepare4StatelessRandomNormalV2(gert::TilingParseContext* context) | ||
| 297 | +{ | ||
| 298 | + fe::PlatFormInfos* platformInfoPtr = context->GetPlatformInfo(); | ||
| 299 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr); | ||
| 300 | + | ||
| 301 | + auto compileInfoPtr = context->GetCompiledInfo<StatelessRandomNormalV2CompileInfo>(); | ||
| 302 | + OP_CHECK_NULL_WITH_CONTEXT(context, platformInfoPtr); | ||
| 303 | + | ||
| 304 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfoPtr); | ||
| 305 | + compileInfoPtr->aivNum = ascendcPlatform.GetCoreNumAiv(); | ||
| 306 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, compileInfoPtr->ubSize); | ||
| 307 | + return ge::GRAPH_SUCCESS; | ||
| 308 | +} | ||
| 309 | + | ||
| 310 | +IMPL_OP_OPTILING(StatelessRandomNormalV2) | ||
| 311 | + .Tiling(Tiling4StatelessRandomNormalV2) | ||
| 312 | + .TilingParse<StatelessRandomNormalV2CompileInfo>(TilingPrepare4StatelessRandomNormalV2) | ||
| 313 | + .TilingInputsDataDependency({INPUT_IDX_KEY, INPUT_IDX_COUNTER, INPUT_IDX_ALG}); | ||
| 314 | + | ||
| 315 | +} // namespace optiling | ||
| @@ -0,0 +1,113 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file stateless_random_normal_v2_tiling_arch35.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling { | ||
| 23 | +constexpr uint16_t ALG_KEY_SIZE = 2; | ||
| 24 | +constexpr uint16_t ALG_COUNTER_SIZE = 4; | ||
| 25 | + | ||
| 26 | +BEGIN_TILING_DATA_DEF(StatelessRandomNormalV2TilingData) | ||
| 27 | +TILING_DATA_FIELD_DEF(uint32_t, blockNum); | ||
| 28 | +TILING_DATA_FIELD_DEF(uint32_t, blockTilingSize); | ||
| 29 | +TILING_DATA_FIELD_DEF(uint32_t, tailBlockTilingSize); | ||
| 30 | +TILING_DATA_FIELD_DEF(uint32_t, ubTilingSize); | ||
| 31 | +TILING_DATA_FIELD_DEF(uint32_t, alg); | ||
| 32 | +TILING_DATA_FIELD_DEF_ARR(uint32_t, ALG_KEY_SIZE, key); | ||
| 33 | +TILING_DATA_FIELD_DEF_ARR(uint32_t, ALG_COUNTER_SIZE, counter); | ||
| 34 | +END_TILING_DATA_DEF; | ||
| 35 | + | ||
| 36 | +REGISTER_TILING_DATA_CLASS(StatelessRandomNormalV2, StatelessRandomNormalV2TilingData) | ||
| 37 | + | ||
| 38 | +struct StatelessRandomNormalV2CompileInfo { | ||
| 39 | + uint64_t aivNum; | ||
| 40 | + uint64_t ubSize; | ||
| 41 | +}; | ||
| 42 | + | ||
| 43 | +class StatelessRandomNormalV2Tiling : public Ops::Math::OpTiling::TilingBaseClass { | ||
| 44 | +public: | ||
| 45 | + explicit StatelessRandomNormalV2Tiling(gert::TilingContext* context) : TilingBaseClass(context) | ||
| 46 | + {} | ||
| 47 | + | ||
| 48 | + enum class Algorithm : int32_t | ||
| 49 | + { | ||
| 50 | + RNG_ALG_PHILOX = 1, | ||
| 51 | + RNG_ALG_THREEFRY = 2, | ||
| 52 | + RNG_ALG_AUTO_SELECT = 3 | ||
| 53 | + }; | ||
| 54 | + | ||
| 55 | +protected: | ||
| 56 | + bool IsCapable() override | ||
| 57 | + { | ||
| 58 | + return true; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + // 1、获取平台信息比如CoreNum、UB/L1/L0C资源大小 | ||
| 62 | + ge::graphStatus GetPlatformInfo() override; | ||
| 63 | + // 2、获取INPUT/OUTPUT/ATTR信息 | ||
| 64 | + ge::graphStatus GetShapeAttrsInfo() override; | ||
| 65 | + // 3、计算数据切分TilingData | ||
| 66 | + ge::graphStatus DoOpTiling() override; | ||
| 67 | + // 4、计算高阶API的TilingData | ||
| 68 | + ge::graphStatus DoLibApiTiling() override; | ||
| 69 | + // 5、计算TilingKey | ||
| 70 | + uint64_t GetTilingKey() const override; | ||
| 71 | + // 6、计算Workspace 大小 | ||
| 72 | + ge::graphStatus GetWorkspaceSize() override; | ||
| 73 | + // 7、保存Tiling数据 | ||
| 74 | + ge::graphStatus PostTiling() override; | ||
| 75 | + | ||
| 76 | +private: | ||
| 77 | + static constexpr uint32_t CORE_ALIGN_SIZE = 512; | ||
| 78 | + static constexpr uint32_t BLOCK_SIZE_BYTES = 32; | ||
| 79 | + static constexpr uint32_t MIN_TILING_SIZE = 256; | ||
| 80 | + static constexpr uint32_t REGBASE_CCEC_CACHE_SIZE = 8 * 1024; | ||
| 81 | + static constexpr uint32_t DEFAULT_WORKSPACE_SIZE = 16 * 1024 * 1024; | ||
| 82 | + | ||
| 83 | + template <typename T1, typename T2> | ||
| 84 | + inline T1 CeilDiv(const T1 a, const T2 b) const; | ||
| 85 | + ge::graphStatus GetInputInfo(); | ||
| 86 | + ge::graphStatus GetOutputInfo(); | ||
| 87 | + ge::graphStatus GetInputKeyCounter(); | ||
| 88 | + int64_t GetCounterSize(Algorithm alg) const; | ||
| 89 | + void GetKeyFromMem(const uint64_t key); | ||
| 90 | + void GetCounterFromMem(const std::vector<uint64_t>& counter); | ||
| 91 | + void BlockTiling(); | ||
| 92 | + ge::graphStatus UbTiling(); | ||
| 93 | + void SetTilingData(); | ||
| 94 | + | ||
| 95 | +private: | ||
| 96 | + uint32_t coreNum_ = 0; | ||
| 97 | + uint32_t ubSize_ = 0; | ||
| 98 | + ge::DataType outputDtype_; | ||
| 99 | + uint32_t outputDtypeVal_ = 0; | ||
| 100 | + uint64_t outputSize_ = 1; | ||
| 101 | + uint32_t outputDtypeSize_ = 0; | ||
| 102 | + uint32_t blockNum_ = 0; | ||
| 103 | + uint32_t blockTilingSize_ = 0; | ||
| 104 | + uint32_t tailBlockTilingSize_ = 0; | ||
| 105 | + uint32_t ubTilingSize_ = 0; | ||
| 106 | + Algorithm alg_ = Algorithm::RNG_ALG_PHILOX; | ||
| 107 | + uint32_t key_[ALG_KEY_SIZE] = {0}; | ||
| 108 | + uint32_t counter_[ALG_COUNTER_SIZE] = {0}; | ||
| 109 | + const char* opName = "StatelessRandomNormalV2"; | ||
| 110 | + StatelessRandomNormalV2TilingData tilingData; | ||
| 111 | +}; | ||
| 112 | + | ||
| 113 | +} // namespace optiling | ||
Arandom/stateless_random_normal_v2/op_host/config/ascend910_95/stateless_random_normal_v2_binary.json+389-0
| @@ -0,0 +1,389 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "StatelessRandomNormalV2", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "StatelessRandomNormalV2_1ea4bdp73cd9df67072d9z7aaec9c583", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "shape", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "int32", | ||
| 11 | + "format": "ND", | ||
| 12 | + "shape": [ | ||
| 13 | + -2 | ||
| 14 | + ], | ||
| 15 | + "paramType": "required" | ||
| 16 | + }, | ||
| 17 | + { | ||
| 18 | + "name": "key", | ||
| 19 | + "index": 1, | ||
| 20 | + "dtype": "uint64", | ||
| 21 | + "format": "ND", | ||
| 22 | + "shape": [ | ||
| 23 | + -2 | ||
| 24 | + ], | ||
| 25 | + "paramType": "required" | ||
| 26 | + }, | ||
| 27 | + { | ||
| 28 | + "name": "counter", | ||
| 29 | + "index": 2, | ||
| 30 | + "dtype": "uint64", | ||
| 31 | + "format": "ND", | ||
| 32 | + "shape": [ | ||
| 33 | + -2 | ||
| 34 | + ], | ||
| 35 | + "paramType": "required" | ||
| 36 | + }, | ||
| 37 | + { | ||
| 38 | + "name": "alg", | ||
| 39 | + "index": 3, | ||
| 40 | + "dtype": "int32", | ||
| 41 | + "format": "ND", | ||
| 42 | + "shape": [ | ||
| 43 | + -2 | ||
| 44 | + ], | ||
| 45 | + "paramType": "required" | ||
| 46 | + } | ||
| 47 | + ], | ||
| 48 | + "outputs": [ | ||
| 49 | + { | ||
| 50 | + "name": "y", | ||
| 51 | + "index": 0, | ||
| 52 | + "dtype": "float32", | ||
| 53 | + "format": "ND", | ||
| 54 | + "shape": [ | ||
| 55 | + -2 | ||
| 56 | + ], | ||
| 57 | + "paramType": "required" | ||
| 58 | + } | ||
| 59 | + ], | ||
| 60 | + "attrs": [ | ||
| 61 | + { | ||
| 62 | + "name": "dtype", | ||
| 63 | + "dtype": "int", | ||
| 64 | + "value": null | ||
| 65 | + } | ||
| 66 | + ] | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + "bin_filename": "StatelessRandomNormalV2_1ea4bd0e3cd9df67072d9z7akyc9c583", | ||
| 70 | + "inputs": [ | ||
| 71 | + { | ||
| 72 | + "name": "shape", | ||
| 73 | + "index": 0, | ||
| 74 | + "dtype": "int32", | ||
| 75 | + "format": "ND", | ||
| 76 | + "shape": [ | ||
| 77 | + -2 | ||
| 78 | + ], | ||
| 79 | + "paramType": "required" | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + "name": "key", | ||
| 83 | + "index": 1, | ||
| 84 | + "dtype": "uint64", | ||
| 85 | + "format": "ND", | ||
| 86 | + "shape": [ | ||
| 87 | + -2 | ||
| 88 | + ], | ||
| 89 | + "paramType": "required" | ||
| 90 | + }, | ||
| 91 | + { | ||
| 92 | + "name": "counter", | ||
| 93 | + "index": 2, | ||
| 94 | + "dtype": "uint64", | ||
| 95 | + "format": "ND", | ||
| 96 | + "shape": [ | ||
| 97 | + -2 | ||
| 98 | + ], | ||
| 99 | + "paramType": "required" | ||
| 100 | + }, | ||
| 101 | + { | ||
| 102 | + "name": "alg", | ||
| 103 | + "index": 3, | ||
| 104 | + "dtype": "int32", | ||
| 105 | + "format": "ND", | ||
| 106 | + "shape": [ | ||
| 107 | + -2 | ||
| 108 | + ], | ||
| 109 | + "paramType": "required" | ||
| 110 | + } | ||
| 111 | + ], | ||
| 112 | + "outputs": [ | ||
| 113 | + { | ||
| 114 | + "name": "y", | ||
| 115 | + "index": 0, | ||
| 116 | + "dtype": "float16", | ||
| 117 | + "format": "ND", | ||
| 118 | + "shape": [ | ||
| 119 | + -2 | ||
| 120 | + ], | ||
| 121 | + "paramType": "required" | ||
| 122 | + } | ||
| 123 | + ], | ||
| 124 | + "attrs": [ | ||
| 125 | + { | ||
| 126 | + "name": "dtype", | ||
| 127 | + "dtype": "int", | ||
| 128 | + "value": null | ||
| 129 | + } | ||
| 130 | + ] | ||
| 131 | + }, | ||
| 132 | + { | ||
| 133 | + "bin_filename": "StatelessRandomNormalV2_1ea4bd9g3cd9df67072d9z7amgc9c733", | ||
| 134 | + "inputs": [ | ||
| 135 | + { | ||
| 136 | + "name": "shape", | ||
| 137 | + "index": 0, | ||
| 138 | + "dtype": "int32", | ||
| 139 | + "format": "ND", | ||
| 140 | + "shape": [ | ||
| 141 | + -2 | ||
| 142 | + ], | ||
| 143 | + "paramType": "required" | ||
| 144 | + }, | ||
| 145 | + { | ||
| 146 | + "name": "key", | ||
| 147 | + "index": 1, | ||
| 148 | + "dtype": "uint64", | ||
| 149 | + "format": "ND", | ||
| 150 | + "shape": [ | ||
| 151 | + -2 | ||
| 152 | + ], | ||
| 153 | + "paramType": "required" | ||
| 154 | + }, | ||
| 155 | + { | ||
| 156 | + "name": "counter", | ||
| 157 | + "index": 2, | ||
| 158 | + "dtype": "uint64", | ||
| 159 | + "format": "ND", | ||
| 160 | + "shape": [ | ||
| 161 | + -2 | ||
| 162 | + ], | ||
| 163 | + "paramType": "required" | ||
| 164 | + }, | ||
| 165 | + { | ||
| 166 | + "name": "alg", | ||
| 167 | + "index": 3, | ||
| 168 | + "dtype": "int32", | ||
| 169 | + "format": "ND", | ||
| 170 | + "shape": [ | ||
| 171 | + -2 | ||
| 172 | + ], | ||
| 173 | + "paramType": "required" | ||
| 174 | + } | ||
| 175 | + ], | ||
| 176 | + "outputs": [ | ||
| 177 | + { | ||
| 178 | + "name": "y", | ||
| 179 | + "index": 0, | ||
| 180 | + "dtype": "bfloat16", | ||
| 181 | + "format": "ND", | ||
| 182 | + "shape": [ | ||
| 183 | + -2 | ||
| 184 | + ], | ||
| 185 | + "paramType": "required" | ||
| 186 | + } | ||
| 187 | + ], | ||
| 188 | + "attrs": [ | ||
| 189 | + { | ||
| 190 | + "name": "dtype", | ||
| 191 | + "dtype": "int", | ||
| 192 | + "value": null | ||
| 193 | + } | ||
| 194 | + ] | ||
| 195 | + }, | ||
| 196 | + { | ||
| 197 | + "bin_filename": "StatelessRandomNormalV2_1ea4bd0e3cd9df67072d9z7aaec9c583", | ||
| 198 | + "inputs": [ | ||
| 199 | + { | ||
| 200 | + "name": "shape", | ||
| 201 | + "index": 0, | ||
| 202 | + "dtype": "int64", | ||
| 203 | + "format": "ND", | ||
| 204 | + "shape": [ | ||
| 205 | + -2 | ||
| 206 | + ], | ||
| 207 | + "paramType": "required" | ||
| 208 | + }, | ||
| 209 | + { | ||
| 210 | + "name": "key", | ||
| 211 | + "index": 1, | ||
| 212 | + "dtype": "uint64", | ||
| 213 | + "format": "ND", | ||
| 214 | + "shape": [ | ||
| 215 | + -2 | ||
| 216 | + ], | ||
| 217 | + "paramType": "required" | ||
| 218 | + }, | ||
| 219 | + { | ||
| 220 | + "name": "counter", | ||
| 221 | + "index": 2, | ||
| 222 | + "dtype": "uint64", | ||
| 223 | + "format": "ND", | ||
| 224 | + "shape": [ | ||
| 225 | + -2 | ||
| 226 | + ], | ||
| 227 | + "paramType": "required" | ||
| 228 | + }, | ||
| 229 | + { | ||
| 230 | + "name": "alg", | ||
| 231 | + "index": 3, | ||
| 232 | + "dtype": "int32", | ||
| 233 | + "format": "ND", | ||
| 234 | + "shape": [ | ||
| 235 | + -2 | ||
| 236 | + ], | ||
| 237 | + "paramType": "required" | ||
| 238 | + } | ||
| 239 | + ], | ||
| 240 | + "outputs": [ | ||
| 241 | + { | ||
| 242 | + "name": "y", | ||
| 243 | + "index": 0, | ||
| 244 | + "dtype": "float32", | ||
| 245 | + "format": "ND", | ||
| 246 | + "shape": [ | ||
| 247 | + -2 | ||
| 248 | + ], | ||
| 249 | + "paramType": "required" | ||
| 250 | + } | ||
| 251 | + ], | ||
| 252 | + "attrs": [ | ||
| 253 | + { | ||
| 254 | + "name": "dtype", | ||
| 255 | + "dtype": "int", | ||
| 256 | + "value": null | ||
| 257 | + } | ||
| 258 | + ] | ||
| 259 | + }, | ||
| 260 | + { | ||
| 261 | + "bin_filename": "StatelessRandomNormalV2_1ea4bd0e3cd9df67072d9z7amgc9c583", | ||
| 262 | + "inputs": [ | ||
| 263 | + { | ||
| 264 | + "name": "shape", | ||
| 265 | + "index": 0, | ||
| 266 | + "dtype": "int64", | ||
| 267 | + "format": "ND", | ||
| 268 | + "shape": [ | ||
| 269 | + -2 | ||
| 270 | + ], | ||
| 271 | + "paramType": "required" | ||
| 272 | + }, | ||
| 273 | + { | ||
| 274 | + "name": "key", | ||
| 275 | + "index": 1, | ||
| 276 | + "dtype": "uint64", | ||
| 277 | + "format": "ND", | ||
| 278 | + "shape": [ | ||
| 279 | + -2 | ||
| 280 | + ], | ||
| 281 | + "paramType": "required" | ||
| 282 | + }, | ||
| 283 | + { | ||
| 284 | + "name": "counter", | ||
| 285 | + "index": 2, | ||
| 286 | + "dtype": "uint64", | ||
| 287 | + "format": "ND", | ||
| 288 | + "shape": [ | ||
| 289 | + -2 | ||
| 290 | + ], | ||
| 291 | + "paramType": "required" | ||
| 292 | + }, | ||
| 293 | + { | ||
| 294 | + "name": "alg", | ||
| 295 | + "index": 3, | ||
| 296 | + "dtype": "int32", | ||
| 297 | + "format": "ND", | ||
| 298 | + "shape": [ | ||
| 299 | + -2 | ||
| 300 | + ], | ||
| 301 | + "paramType": "required" | ||
| 302 | + } | ||
| 303 | + ], | ||
| 304 | + "outputs": [ | ||
| 305 | + { | ||
| 306 | + "name": "y", | ||
| 307 | + "index": 0, | ||
| 308 | + "dtype": "float16", | ||
| 309 | + "format": "ND", | ||
| 310 | + "shape": [ | ||
| 311 | + -2 | ||
| 312 | + ], | ||
| 313 | + "paramType": "required" | ||
| 314 | + } | ||
| 315 | + ], | ||
| 316 | + "attrs": [ | ||
| 317 | + { | ||
| 318 | + "name": "dtype", | ||
| 319 | + "dtype": "int", | ||
| 320 | + "value": null | ||
| 321 | + } | ||
| 322 | + ] | ||
| 323 | + }, | ||
| 324 | + { | ||
| 325 | + "bin_filename": "StatelessRandomNormalV2_1ea4bd0e3cd9df67072d9z7amgc9c733", | ||
| 326 | + "inputs": [ | ||
| 327 | + { | ||
| 328 | + "name": "shape", | ||
| 329 | + "index": 0, | ||
| 330 | + "dtype": "int64", | ||
| 331 | + "format": "ND", | ||
| 332 | + "shape": [ | ||
| 333 | + -2 | ||
| 334 | + ], | ||
| 335 | + "paramType": "required" | ||
| 336 | + }, | ||
| 337 | + { | ||
| 338 | + "name": "key", | ||
| 339 | + "index": 1, | ||
| 340 | + "dtype": "uint64", | ||
| 341 | + "format": "ND", | ||
| 342 | + "shape": [ | ||
| 343 | + -2 | ||
| 344 | + ], | ||
| 345 | + "paramType": "required" | ||
| 346 | + }, | ||
| 347 | + { | ||
| 348 | + "name": "counter", | ||
| 349 | + "index": 2, | ||
| 350 | + "dtype": "uint64", | ||
| 351 | + "format": "ND", | ||
| 352 | + "shape": [ | ||
| 353 | + -2 | ||
| 354 | + ], | ||
| 355 | + "paramType": "required" | ||
| 356 | + }, | ||
| 357 | + { | ||
| 358 | + "name": "alg", | ||
| 359 | + "index": 3, | ||
| 360 | + "dtype": "int32", | ||
| 361 | + "format": "ND", | ||
| 362 | + "shape": [ | ||
| 363 | + -2 | ||
| 364 | + ], | ||
| 365 | + "paramType": "required" | ||
| 366 | + } | ||
| 367 | + ], | ||
| 368 | + "outputs": [ | ||
| 369 | + { | ||
| 370 | + "name": "y", | ||
| 371 | + "index": 0, | ||
| 372 | + "dtype": "bfloat16", | ||
| 373 | + "format": "ND", | ||
| 374 | + "shape": [ | ||
| 375 | + -2 | ||
| 376 | + ], | ||
| 377 | + "paramType": "required" | ||
| 378 | + } | ||
| 379 | + ], | ||
| 380 | + "attrs": [ | ||
| 381 | + { | ||
| 382 | + "name": "dtype", | ||
| 383 | + "dtype": "int", | ||
| 384 | + "value": null | ||
| 385 | + } | ||
| 386 | + ] | ||
| 387 | + } | ||
| 388 | + ] | ||
| 389 | +} | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示: | ||
| 2 | +; [某算子] | ||
| 3 | +; default=xx | ||
| 4 | +; ascendxx=xx | ||
| 5 | +; 其中,default为默认mode,ascnedxx为可选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 | +[StatelessRandomNormalV2] | ||
| 13 | +default=0 | ||
| @@ -0,0 +1,62 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file stateless_random_normal_v2_def.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +namespace ops { | ||
| 18 | +class StatelessRandomNormalV2 : public OpDef { | ||
| 19 | +public: | ||
| 20 | + explicit StatelessRandomNormalV2(const char* name) : OpDef(name) | ||
| 21 | + { | ||
| 22 | + this->Input("shape") | ||
| 23 | + .ParamType(REQUIRED) | ||
| 24 | + .DataType({ge::DT_INT64, ge::DT_INT64, ge::DT_INT64, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32}) | ||
| 25 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 26 | + .UnknownShapeFormat( | ||
| 27 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 28 | + this->Input("key") | ||
| 29 | + .ParamType(REQUIRED) | ||
| 30 | + .DataType({ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64}) | ||
| 31 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 32 | + .UnknownShapeFormat( | ||
| 33 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 34 | + .ValueDepend(OPTIONAL); | ||
| 35 | + this->Input("counter") | ||
| 36 | + .ParamType(REQUIRED) | ||
| 37 | + .DataType({ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64, ge::DT_UINT64}) | ||
| 38 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 39 | + .UnknownShapeFormat( | ||
| 40 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 41 | + .ValueDepend(OPTIONAL); | ||
| 42 | + this->Input("alg") | ||
| 43 | + .ParamType(REQUIRED) | ||
| 44 | + .DataType({ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32, ge::DT_INT32}) | ||
| 45 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 46 | + .UnknownShapeFormat( | ||
| 47 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 48 | + .ValueDepend(OPTIONAL); | ||
| 49 | + this->Output("y") | ||
| 50 | + .ParamType(REQUIRED) | ||
| 51 | + .DataType({ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT, ge::DT_BF16, ge::DT_FLOAT16}) | ||
| 52 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 53 | + .UnknownShapeFormat( | ||
| 54 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 55 | + | ||
| 56 | + this->Attr("dtype").AttrType(OPTIONAL).Int(0); | ||
| 57 | + this->AICore().AddConfig("ascend910_95"); | ||
| 58 | + } | ||
| 59 | +}; | ||
| 60 | + | ||
| 61 | +OP_ADD(StatelessRandomNormalV2); | ||
| 62 | +} // namespace ops | ||
| @@ -0,0 +1,53 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file stateless_random_normal_v2_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +using namespace ge; | ||
| 20 | +namespace ops { | ||
| 21 | +template <typename T> | ||
| 22 | +static graphStatus InferShapeImpl(const T* shape_data, gert::Shape& output_shape, size_t shape_size) | ||
| 23 | +{ | ||
| 24 | + output_shape.SetDimNum(shape_size); | ||
| 25 | + for (size_t i = 0U; i < shape_size; i++) { | ||
| 26 | + output_shape.SetDim(i, shape_data[i]); | ||
| 27 | + } | ||
| 28 | + return ge::GRAPH_SUCCESS; | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +static graphStatus StatelessRandomNormalV2InferShapeFunc(gert::InferShapeContext* context) | ||
| 32 | +{ | ||
| 33 | + auto shape_tensor = context->GetInputTensor(0); | ||
| 34 | + auto output_shape = context->GetOutputShape(0); | ||
| 35 | + OP_CHECK_NULL_WITH_CONTEXT(context, shape_tensor); | ||
| 36 | + OP_CHECK_NULL_WITH_CONTEXT(context, output_shape); | ||
| 37 | + | ||
| 38 | + auto x_shape_size = shape_tensor->GetShapeSize(); | ||
| 39 | + if (x_shape_size < 0) { | ||
| 40 | + return ge::GRAPH_FAILED; | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + if (shape_tensor->GetDataType() == ge::DT_INT32) { | ||
| 44 | + auto shape_data = shape_tensor->GetData<int32_t>(); | ||
| 45 | + return InferShapeImpl<int32_t>(shape_data, *output_shape, static_cast<size_t>(x_shape_size)); | ||
| 46 | + } else { | ||
| 47 | + auto shape_data = shape_tensor->GetData<int64_t>(); | ||
| 48 | + return InferShapeImpl<int64_t>(shape_data, *output_shape, static_cast<size_t>(x_shape_size)); | ||
| 49 | + } | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +IMPL_OP_INFERSHAPE(StatelessRandomNormalV2).InputsDataDependency({0}).InferShape(StatelessRandomNormalV2InferShapeFunc); | ||
| 53 | +} // namespace ops | ||
| @@ -1,12 +1,12 @@ | |||
| 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 | /*! | 11 | /*! |
| 12 | * \file stateless_random_normal_v2.h | 12 | * \file stateless_random_normal_v2.h |
| @@ -17,7 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | -#include "../inc/platform.h" | 20 | +#include "op_kernel/platform_util.h" |
| 21 | 21 | ||
| 22 | namespace StatelessRandomNormalV2Simd { | 22 | namespace StatelessRandomNormalV2Simd { |
| 23 | using namespace AscendC; | 23 | using namespace AscendC; |
| @@ -30,7 +30,7 @@ constexpr uint16_t DOUBLE_UNIFORM_RESULT = 2; | |||
| 30 | constexpr uint16_t RESULT_ELEMENT_CNT = 4; | 30 | constexpr uint16_t RESULT_ELEMENT_CNT = 4; |
| 31 | constexpr float DOUBLE_MULTIPLE = 2.0f; | 31 | constexpr float DOUBLE_MULTIPLE = 2.0f; |
| 32 | constexpr float PI = 3.14159265358979323846f; | 32 | constexpr float PI = 3.14159265358979323846f; |
| 33 | -constexpr uint32_t INT32_FLOAT32_ONE_REPEAT = platform::GetVRegSize() / sizeof(int32_t); | 33 | +constexpr uint32_t INT32_FLOAT32_ONE_REPEAT = Ops::Base::GetVRegSize() / sizeof(int32_t); |
| 34 | 34 | ||
| 35 | template <typename T> | 35 | template <typename T> |
| 36 | class StatelessRandomNormalV2 { | 36 | class StatelessRandomNormalV2 { |
| @@ -168,7 +168,7 @@ __aicore__ inline void StatelessRandomNormalV2<T>::Uint32ToFloat( | |||
| 168 | __ubuf__ int32_t* ubPhilox = (__ubuf__ int32_t*)philoxRes.GetPhyAddr(); | 168 | __ubuf__ int32_t* ubPhilox = (__ubuf__ int32_t*)philoxRes.GetPhyAddr(); |
| 169 | __ubuf__ float* ubOut = (__ubuf__ float*)yOutputTmp.GetPhyAddr(); | 169 | __ubuf__ float* ubOut = (__ubuf__ float*)yOutputTmp.GetPhyAddr(); |
| 170 | 170 | ||
| 171 | - uint32_t vfLen = platform::GetVRegSize() / sizeof(int32_t); | 171 | + uint32_t vfLen = Ops::Base::GetVRegSize() / sizeof(int32_t); |
| 172 | uint32_t repeatTimes = CeilDiv(calCount, vfLen); | 172 | uint32_t repeatTimes = CeilDiv(calCount, vfLen); |
| 173 | 173 | ||
| 174 | __VEC_SCOPE__ | 174 | __VEC_SCOPE__ |
| @@ -1,12 +1,12 @@ | |||
| 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 | /*! | 11 | /*! |
| 12 | * \file stateless_random_normal_v2.cpp | 12 | * \file stateless_random_normal_v2.cpp |
| @@ -21,31 +21,31 @@ using namespace StatelessRandomNormalV2Simd; | |||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | -extern "C" __global__ __aicore__ void stateless_random_normal_v2(GM_ADDR shape, GM_ADDR key, GM_ADDR counter, | 24 | +extern "C" __global__ __aicore__ void stateless_random_normal_v2( |
| 25 | - GM_ADDR alg, GM_ADDR y, GM_ADDR workspace, | 25 | + GM_ADDR shape, GM_ADDR key, GM_ADDR counter, GM_ADDR alg, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) |
| 26 | - GM_ADDR tiling) { | 26 | +{ |
| 27 | - if (workspace == nullptr) { | 27 | + if (workspace == nullptr) { |
| 28 | - return; | 28 | + return; |
| 29 | - } | 29 | + } |
| 30 | - SetSysWorkspace(workspace); | 30 | + SetSysWorkspace(workspace); |
| 31 | - GM_ADDR userWS = GetUserWorkspace(workspace); | 31 | + GM_ADDR userWS = GetUserWorkspace(workspace); |
| 32 | - if (userWS == nullptr) { | 32 | + if (userWS == nullptr) { |
| 33 | - return; | 33 | + return; |
| 34 | - } | 34 | + } |
| 35 | - GET_TILING_DATA(tilingData, tiling); | 35 | + GET_TILING_DATA(tilingData, tiling); |
| 36 | - KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | 36 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); |
| 37 | - TPipe pipe; | 37 | + TPipe pipe; |
| 38 | - if (TILING_KEY_IS(FLOAT_TILING_KEY)) { | 38 | + if (TILING_KEY_IS(FLOAT_TILING_KEY)) { |
| 39 | - StatelessRandomNormalV2<float> op; | 39 | + StatelessRandomNormalV2<float> op; |
| 40 | - op.Init(y, &tilingData, &pipe); | 40 | + op.Init(y, &tilingData, &pipe); |
| 41 | - op.Process(); | 41 | + op.Process(); |
| 42 | - } else if (TILING_KEY_IS(FLOAT16_TILING_KEY)) { | 42 | + } else if (TILING_KEY_IS(FLOAT16_TILING_KEY)) { |
| 43 | - StatelessRandomNormalV2<half> op; | 43 | + StatelessRandomNormalV2<half> op; |
| 44 | - op.Init(y, &tilingData, &pipe); | 44 | + op.Init(y, &tilingData, &pipe); |
| 45 | - op.Process(); | 45 | + op.Process(); |
| 46 | - } else if (TILING_KEY_IS(BFLOAT16_TILING_KEY)) { | 46 | + } else if (TILING_KEY_IS(BFLOAT16_TILING_KEY)) { |
| 47 | - StatelessRandomNormalV2<bfloat16_t> op; | 47 | + StatelessRandomNormalV2<bfloat16_t> op; |
| 48 | - op.Init(y, &tilingData, &pipe); | 48 | + op.Init(y, &tilingData, &pipe); |
| 49 | - op.Process(); | 49 | + op.Process(); |
| 50 | - } | 50 | + } |
| 51 | } | 51 | } |
| @@ -1,11 +1,10 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 10 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| @@ -1,13 +1,12 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | -# ---------------------------------------------------------------------------- | 9 | +# ----------------------------------------------------------------------------------------------------------- |
| 11 | # 每个目录下需要生成的可执行文件,具体参考:ops/build-in/test/CMakeLists.txt: 50~124 | 10 | # 每个目录下需要生成的可执行文件,具体参考:ops/build-in/test/CMakeLists.txt: 50~124 |
| 12 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 13 | foreach(SUB_DIR ${CURRENT_DIRS}) | 12 | foreach(SUB_DIR ${CURRENT_DIRS}) |
Rrandom/stateless_random_normal_v2/tests/ut/op_host/op_api/test_aclnn_normal_float_float_l2.cpp→random/stateless_random_normal_v2/tests/ut/op_api/test_aclnn_normal_float_float_l2.cpp+21-9
| @@ -1,19 +1,20 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
| 13 | -#include "random/stateless_random_normal_v2/op_host/op_api/aclnn_normal_out.h" | 13 | +#include "random/stateless_random_normal_v2/op_api/aclnn_normal_out.h" |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | + | ||
| 17 | 18 | ||
| 18 | using namespace op; | 19 | using namespace op; |
| 19 | using namespace std; | 20 | using namespace std; |
| @@ -33,6 +34,7 @@ protected: | |||
| 33 | // float_ND 场景 | 34 | // float_ND 场景 |
| 34 | TEST_F(l2_normal_float_float_test, case_float_ND_001) | 35 | TEST_F(l2_normal_float_float_test, case_float_ND_001) |
| 35 | { | 36 | { |
| 37 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 36 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | 38 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); |
| 37 | float mean = 1.5f; | 39 | float mean = 1.5f; |
| 38 | float std = 2.5f; | 40 | float std = 2.5f; |
| @@ -47,6 +49,7 @@ TEST_F(l2_normal_float_float_test, case_float_ND_001) | |||
| 47 | // float_NCHW 场景 | 49 | // float_NCHW 场景 |
| 48 | TEST_F(l2_normal_float_float_test, case_float_NCHW_002) | 50 | TEST_F(l2_normal_float_float_test, case_float_NCHW_002) |
| 49 | { | 51 | { |
| 52 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 50 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NCHW); | 53 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NCHW); |
| 51 | float mean = 1.8f; | 54 | float mean = 1.8f; |
| 52 | float std = 2.5f; | 55 | float std = 2.5f; |
| @@ -61,6 +64,7 @@ TEST_F(l2_normal_float_float_test, case_float_NCHW_002) | |||
| 61 | // float_NHWC 场景 | 64 | // float_NHWC 场景 |
| 62 | TEST_F(l2_normal_float_float_test, case_float_NHWC_003) | 65 | TEST_F(l2_normal_float_float_test, case_float_NHWC_003) |
| 63 | { | 66 | { |
| 67 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 64 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NHWC); | 68 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NHWC); |
| 65 | float mean = 1.2f; | 69 | float mean = 1.2f; |
| 66 | float std = 2.5f; | 70 | float std = 2.5f; |
| @@ -75,6 +79,7 @@ TEST_F(l2_normal_float_float_test, case_float_NHWC_003) | |||
| 75 | // float_HWCN 场景 | 79 | // float_HWCN 场景 |
| 76 | TEST_F(l2_normal_float_float_test, case_float_NHWC_004) | 80 | TEST_F(l2_normal_float_float_test, case_float_NHWC_004) |
| 77 | { | 81 | { |
| 82 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 78 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_HWCN); | 83 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_HWCN); |
| 79 | float mean = 1.5f; | 84 | float mean = 1.5f; |
| 80 | float std = 2.5f; | 85 | float std = 2.5f; |
| @@ -89,6 +94,7 @@ TEST_F(l2_normal_float_float_test, case_float_NHWC_004) | |||
| 89 | // float_NDHWC 场景 | 94 | // float_NDHWC 场景 |
| 90 | TEST_F(l2_normal_float_float_test, case_float_NDHWC_005) | 95 | TEST_F(l2_normal_float_float_test, case_float_NDHWC_005) |
| 91 | { | 96 | { |
| 97 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 92 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NDHWC); | 98 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NDHWC); |
| 93 | float mean = 1.5f; | 99 | float mean = 1.5f; |
| 94 | float std = 2.5f; | 100 | float std = 2.5f; |
| @@ -103,6 +109,7 @@ TEST_F(l2_normal_float_float_test, case_float_NDHWC_005) | |||
| 103 | // float_NCDHW 场景 | 109 | // float_NCDHW 场景 |
| 104 | TEST_F(l2_normal_float_float_test, case_float_NCDHW_006) | 110 | TEST_F(l2_normal_float_float_test, case_float_NCDHW_006) |
| 105 | { | 111 | { |
| 112 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 106 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NCDHW); | 113 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_NCDHW); |
| 107 | float mean = 1.5f; | 114 | float mean = 1.5f; |
| 108 | float std = 2.5f; | 115 | float std = 2.5f; |
| @@ -117,6 +124,7 @@ TEST_F(l2_normal_float_float_test, case_float_NCDHW_006) | |||
| 117 | // float16_ND 场景 | 124 | // float16_ND 场景 |
| 118 | TEST_F(l2_normal_float_float_test, case_float16_ND_007) | 125 | TEST_F(l2_normal_float_float_test, case_float16_ND_007) |
| 119 | { | 126 | { |
| 127 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 120 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT16, ACL_FORMAT_NCDHW); | 128 | auto outDesc = TensorDesc({2, 3}, ACL_FLOAT16, ACL_FORMAT_NCDHW); |
| 121 | float mean = 1.5f; | 129 | float mean = 1.5f; |
| 122 | float std = 2.5f; | 130 | float std = 2.5f; |
| @@ -131,6 +139,7 @@ TEST_F(l2_normal_float_float_test, case_float16_ND_007) | |||
| 131 | // 指定输出shape的场景 | 139 | // 指定输出shape的场景 |
| 132 | TEST_F(l2_normal_float_float_test, case_float_float64_ND_009) | 140 | TEST_F(l2_normal_float_float_test, case_float_float64_ND_009) |
| 133 | { | 141 | { |
| 142 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 134 | auto outDesc = TensorDesc({2, 2, 6}, ACL_FLOAT, ACL_FORMAT_ND); | 143 | auto outDesc = TensorDesc({2, 2, 6}, ACL_FLOAT, ACL_FORMAT_ND); |
| 135 | float mean = 1.5f; | 144 | float mean = 1.5f; |
| 136 | float std = 2.5f; | 145 | float std = 2.5f; |
| @@ -145,6 +154,7 @@ TEST_F(l2_normal_float_float_test, case_float_float64_ND_009) | |||
| 145 | // dim维度等于8维的场景 | 154 | // dim维度等于8维的场景 |
| 146 | TEST_F(l2_normal_float_float_test, case_8dim_ND_010) | 155 | TEST_F(l2_normal_float_float_test, case_8dim_ND_010) |
| 147 | { | 156 | { |
| 157 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 148 | auto outDesc = TensorDesc({2, 3, 2, 2, 3, 2, 3, 2}, ACL_FLOAT, ACL_FORMAT_ND); | 158 | auto outDesc = TensorDesc({2, 3, 2, 2, 3, 2, 3, 2}, ACL_FLOAT, ACL_FORMAT_ND); |
| 149 | float mean = 1.5f; | 159 | float mean = 1.5f; |
| 150 | float std = 2.5f; | 160 | float std = 2.5f; |
| @@ -159,6 +169,7 @@ TEST_F(l2_normal_float_float_test, case_8dim_ND_010) | |||
| 159 | // mean取值范围是(-1, 1)的场景 | 169 | // mean取值范围是(-1, 1)的场景 |
| 160 | TEST_F(l2_normal_float_float_test, case_mean_1_1_ND_011) | 170 | TEST_F(l2_normal_float_float_test, case_mean_1_1_ND_011) |
| 161 | { | 171 | { |
| 172 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 162 | auto outDesc = TensorDesc({2, 3, 2}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1, 1); | 173 | auto outDesc = TensorDesc({2, 3, 2}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 163 | float mean = 1.5f; | 174 | float mean = 1.5f; |
| 164 | float std = 2.5f; | 175 | float std = 2.5f; |
| @@ -173,6 +184,7 @@ TEST_F(l2_normal_float_float_test, case_mean_1_1_ND_011) | |||
| 173 | // 空tensor的场景 | 184 | // 空tensor的场景 |
| 174 | TEST_F(l2_normal_float_float_test, case_empty1_ND_012) | 185 | TEST_F(l2_normal_float_float_test, case_empty1_ND_012) |
| 175 | { | 186 | { |
| 187 | + op::SetPlatformSocVersion(SocVersion::ASCEND910_95); | ||
| 176 | auto outDesc = TensorDesc({}, ACL_FLOAT, ACL_FORMAT_ND); | 188 | auto outDesc = TensorDesc({}, ACL_FLOAT, ACL_FORMAT_ND); |
| 177 | float mean = 1.5f; | 189 | float mean = 1.5f; |
| 178 | float std = 2.5f; | 190 | float std = 2.5f; |
Rrandom/stateless_random_normal_v2/tests/ut/op_host/op_api/test_aclnn_normal_float_tensor_l2.cpp→random/stateless_random_normal_v2/tests/ut/op_api/test_aclnn_normal_float_tensor_l2.cpp+9-9
| @@ -1,16 +1,16 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
| 13 | -#include "random/stateless_random_normal_v2/op_host/op_api/aclnn_normal_out.h" | 13 | +#include "random/stateless_random_normal_v2/op_api/aclnn_normal_out.h" |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
Rrandom/stateless_random_normal_v2/tests/ut/op_host/op_api/test_aclnn_normal_tensor_float_l2.cpp→random/stateless_random_normal_v2/tests/ut/op_api/test_aclnn_normal_tensor_float_l2.cpp+9-9
| @@ -1,16 +1,16 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
| 13 | -#include "random/stateless_random_normal_v2/op_host/op_api/aclnn_normal_out.h" | 13 | +#include "random/stateless_random_normal_v2/op_api/aclnn_normal_out.h" |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
Rrandom/stateless_random_normal_v2/tests/ut/op_host/op_api/test_aclnn_normal_tensor_tensor_l2.cpp→random/stateless_random_normal_v2/tests/ut/op_api/test_aclnn_normal_tensor_tensor_l2.cpp+9-9
| @@ -1,16 +1,16 @@ | |||
| 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 | 11 | ||
| 12 | 12 | ||
| 13 | -#include "random/stateless_random_normal_v2/op_host/op_api/aclnn_normal_out.h" | 13 | +#include "random/stateless_random_normal_v2/op_api/aclnn_normal_out.h" |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | ||
| @@ -1,11 +1,10 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 6 | # 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. |
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# 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. |
| 9 | # 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. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
Arandom/stateless_random_normal_v2/tests/ut/op_host/arch35/test_stateless_random_normal_v2_tiling.cpp+60-0
| @@ -0,0 +1,60 @@ | |||
| 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 | + /*! | ||
| 12 | + * \file test_stateless_random_normal_v2_tiling.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +class StatelessRandomNormalV2Tiling : public testing::Test { | ||
| 24 | + protected: | ||
| 25 | + static void SetUpTestCase() { | ||
| 26 | + std::cout << "StatelessRandomNormalV2Test SetUp" << std::endl; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + static void TearDownTestCase() { | ||
| 30 | + std::cout << "StatelessRandomNormalV2Test TearDown" << std::endl; | ||
| 31 | + } | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +TEST_F(StatelessRandomNormalV2Tiling, stateless_random_normal_v2_test_tiling_1) | ||
| 35 | +{ | ||
| 36 | + optiling::StatelessRandomNormalV2CompileInfo compileInfo = {40, 196608}; | ||
| 37 | + vector<int64_t> shapeValue = {2}; | ||
| 38 | + vector<uint64_t> keyValue = {1.0}; | ||
| 39 | + vector<int64_t> counterValue = {8, 9}; | ||
| 40 | + vector<int64_t> algsetValue = {1}; | ||
| 41 | + gert::TilingContextPara tilingContextPara( | ||
| 42 | + "StatelessRandomNormalV2", | ||
| 43 | + { | ||
| 44 | + {{{32, 512}, {32, 512}}, ge::DT_INT64, ge::FORMAT_ND, true, shapeValue.data()}, | ||
| 45 | + {{{1,}, {1,}}, ge::DT_UINT64, ge::FORMAT_ND, true, keyValue.data()}, | ||
| 46 | + {{{2,}, {2,}}, ge::DT_UINT64, ge::FORMAT_ND, true, counterValue.data()}, | ||
| 47 | + {{{1,}, {1,}}, ge::DT_INT32, ge::FORMAT_ND, true, algsetValue.data()}, | ||
| 48 | + }, | ||
| 49 | + { | ||
| 50 | + {{{32, 512}, {32, 512}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 51 | + }, | ||
| 52 | + { | ||
| 53 | + {"dtype", Ops::Math::AnyValue::CreateFrom<int64_t>(0)}, | ||
| 54 | + }, | ||
| 55 | + &compileInfo); | ||
| 56 | + uint64_t expectTilingKey = 101; | ||
| 57 | + string expectTilingData = "1099511627840 54563264528640 4294967297 34359738368 38654705664 0 "; | ||
| 58 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 59 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 60 | +} | ||
| @@ -1,14 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | ||
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | -# ---------------------------------------------------------------------------- | ||
| 11 | - | ||
| 12 | -if(UT_TEST_ALL OR OP_API_UT) | ||
| 13 | - add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 14 | -endif() | ||
Arandom/stateless_random_normal_v2/tests/ut/op_host/test_stateless_random_normal_v2_infershape.cpp+53-0
| @@ -0,0 +1,53 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file test_stateless_random_normal_v2_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace std; | ||
| 22 | + | ||
| 23 | +class StatelessRandomNormalV2Infershape : public testing::Test { | ||
| 24 | + protected: | ||
| 25 | + static void SetUpTestCase() { | ||
| 26 | + std::cout << "StatelessRandomNormalV2 SetUp" << std::endl; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + static void TearDownTestCase() { | ||
| 30 | + std::cout << "StatelessRandomNormalV2 TearDown" << std::endl; | ||
| 31 | + } | ||
| 32 | +}; | ||
| 33 | + | ||
| 34 | +TEST_F(StatelessRandomNormalV2Infershape, stateless_random_normal_v2_infershape_test1) | ||
| 35 | +{ | ||
| 36 | + vector<int64_t> shapeValue = {1}; | ||
| 37 | + vector<float> keyValue = {1.0}; | ||
| 38 | + vector<int64_t> counterValue = {2}; | ||
| 39 | + vector<int64_t> algsetValue = {8}; | ||
| 40 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 41 | + "StatelessRandomNormalV2", | ||
| 42 | + { | ||
| 43 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, shapeValue.data()}, | ||
| 44 | + {{{1}, {1}}, ge::DT_FLOAT, ge::FORMAT_ND, true, keyValue.data()}, | ||
| 45 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, counterValue.data()}, | ||
| 46 | + {{{1}, {1}}, ge::DT_INT64, ge::FORMAT_ND, true, algsetValue.data()}, | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + {{{}, {}}, ge::DT_UINT8, ge::FORMAT_ND}, | ||
| 50 | + }); | ||
| 51 | + std::vector<std::vector<int64_t>> expectOutputShape = {{1}}; | ||
| 52 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 53 | +} | ||


代码结构与可维护性: Simt::VF_CALL调用参数之间缺少空格,不符合代码规范。参数列表应该用空格分隔以提高可读性。
问题类型: 代码结构与可维护性 文件路径:
math/cos/op_kernel/arch35/cos_dag.h行号: 46 问题代码:修改建议:
此评论由代码审查工具自动生成