Merged
add all_gather_matmul_v3 operator #10643
王亮培Add on Aug 26
add all_gather_matmul_v3 operator #10643
Merged
Total: 33 files changed+3054-36
| @@ -0,0 +1,21 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | +if(NOT ENABLE_TEST) | ||
| 13 | + list(REMOVE_ITEM CURRENT_DIRS tests) | ||
| 14 | +endif() | ||
| 15 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 16 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 17 | + add_subdirectory(${SUB_DIR}) | ||
| 18 | + endif() | ||
| 19 | +endforeach() | ||
| 20 | + | ||
| 21 | +set(MC2_COMPILE ${SUB_MC2_COMPILE} PARENT_SCOPE) | ||
| @@ -0,0 +1,361 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file aclnn_all_gather_matmul_v3.cpp | ||
| 13 | + * \brief aclnn API implementation for AllGatherMatmulV3 (MX-quant FP8/FP4, apace UDMA path) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include "aclnnInner_all_gather_matmul_v3.h" | ||
| 17 | + | ||
| 18 | +#include <cstring> | ||
| 19 | +#include <initializer_list> | ||
| 20 | + | ||
| 21 | +#include "acl/acl.h" | ||
| 22 | +#include "aclnn/aclnn_base.h" | ||
| 23 | +#include "aclnn_kernels/common/op_error_check.h" | ||
| 24 | +#include "common/op_api/mc2_aclnn_util.h" | ||
| 25 | +#include "common/op_host/op_api/mc2_3rd_matmul_util.h" | ||
| 26 | +#include "mc2_log_compat.h" | ||
| 27 | +#include "graph/types.h" | ||
| 28 | +#include "opdev/op_log.h" | ||
| 29 | +#include "opdev/platform.h" | ||
| 30 | +#include "opdev/op_executor.h" | ||
| 31 | + | ||
| 32 | +using namespace op; | ||
| 33 | + | ||
| 34 | +namespace { | ||
| 35 | + | ||
| 36 | +enum class NnopbaseHcclServerType : uint32_t { | ||
| 37 | + NNOPBASE_HCCL_SERVER_TYPE_AICPU = 0, | ||
| 38 | + NNOPBASE_HCCL_SERVER_TYPE_MTE, | ||
| 39 | + NNOPBASE_HCCL_SERVER_TYPE_CCU, | ||
| 40 | + NNOPBASE_HCCL_SERVER_TYPE_END | ||
| 41 | +}; | ||
| 42 | + | ||
| 43 | +constexpr int64_t TWO_DIMS = 2; | ||
| 44 | +constexpr int64_t SCALE_DIMS = 3; | ||
| 45 | +constexpr int64_t MX_SCALE_BLOCK = 64; | ||
| 46 | +constexpr int64_t SCALE_LAST_DIM = 2; | ||
| 47 | +constexpr size_t HCCL_GROUP_NAME_LENGTH_MAX = 128U; // HCCL group 名长度上限 | ||
| 48 | + | ||
| 49 | +const std::initializer_list<op::DataType> X_DTYPE_SUPPORT_LIST = { | ||
| 50 | + op::DataType::DT_FLOAT8_E4M3FN, op::DataType::DT_FLOAT8_E5M2, op::DataType::DT_FLOAT4_E2M1}; | ||
| 51 | +const std::initializer_list<op::DataType> SCALE_DTYPE_SUPPORT_LIST = {op::DataType::DT_FLOAT8_E8M0}; | ||
| 52 | +const std::initializer_list<op::DataType> OUT_DTYPE_SUPPORT_LIST = {op::DataType::DT_BF16, op::DataType::DT_FLOAT16}; | ||
| 53 | +const std::initializer_list<op::DataType> BIAS_DTYPE_SUPPORT_LIST = {op::DataType::DT_FLOAT}; | ||
| 54 | + | ||
| 55 | +// 用户传 [N,K].t() (viewShape [K,N]) → 翻回 [N,K] 连续视图,保留原始物理存储 | ||
| 56 | +static const aclTensor *TransX2Tensor(const aclTensor *x2) | ||
| 57 | +{ | ||
| 58 | + uint64_t storageDimsNum = x2->GetStorageShape().GetDimNum(); | ||
| 59 | + std::vector<int64_t> storageDims(storageDimsNum); | ||
| 60 | + for (uint64_t i = 0; i < storageDimsNum; i++) { | ||
| 61 | + storageDims[i] = x2->GetStorageShape().GetDim(i); | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + uint64_t viewDimsNum = x2->GetViewShape().GetDimNum(); | ||
| 65 | + std::vector<int64_t> viewDims; | ||
| 66 | + viewDims.resize(viewDimsNum); | ||
| 67 | + for (uint64_t i = 0; i < viewDimsNum; i++) { | ||
| 68 | + viewDims[i] = x2->GetViewShape().GetDim(i); | ||
| 69 | + } | ||
| 70 | + // transpose the viewshape last two dimensions | ||
| 71 | + viewDims[0] = x2->GetViewShape().GetDim(1); | ||
| 72 | + viewDims[1] = x2->GetViewShape().GetDim(0); | ||
| 73 | + | ||
| 74 | + aclDataType dataType = aclDataType::ACL_DT_UNDEFINED; | ||
| 75 | + aclGetDataType(x2, &dataType); | ||
| 76 | + std::vector<int64_t> stride(viewDimsNum); | ||
| 77 | + auto transStride = x2->GetViewStrides(); | ||
| 78 | + stride = std::vector<int64_t>(transStride.begin(), transStride.end()); | ||
| 79 | + // transpose the two dimensions | ||
| 80 | + stride[0] = transStride[1]; | ||
| 81 | + stride[1] = transStride[0]; | ||
| 82 | + auto offset = x2->GetViewOffset(); | ||
| 83 | + aclFormat format = aclFormat::ACL_FORMAT_ND; | ||
| 84 | + | ||
| 85 | + return aclCreateTensor(viewDims.data(), viewDimsNum, dataType, stride.data(), offset, format, storageDims.data(), | ||
| 86 | + storageDimsNum, x2->GetTensor()->GetAddr()); | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +// CheckNullParams: 校验 REQUIRED 输入/输出非空(本次交付不使能 gather_out/amax_out,不做校验) | ||
| 90 | +static bool CheckNullParams(const aclTensor *context, const aclTensor *x1, const aclTensor *x2, const aclTensor *output, | ||
| 91 | + uint64_t *workspaceSize, aclOpExecutor **executor) | ||
| 92 | +{ | ||
| 93 | + if (context == nullptr || x1 == nullptr || x2 == nullptr || output == nullptr || workspaceSize == nullptr || | ||
workspace等空校验不要用op_check_null ![]() ![]() | |||
| 94 | + executor == nullptr) { | ||
| 95 | + if (context == nullptr) | ||
| 96 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "context"); | ||
| 97 | + if (x1 == nullptr) | ||
| 98 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "x1"); | ||
| 99 | + if (x2 == nullptr) | ||
| 100 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "x2"); | ||
| 101 | + if (output == nullptr) | ||
| 102 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "output"); | ||
| 103 | + if (workspaceSize == nullptr) | ||
| 104 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "workspaceSize"); | ||
| 105 | + if (executor == nullptr) | ||
| 106 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "executor"); | ||
| 107 | + return false; | ||
| 108 | + } | ||
| 109 | + return true; | ||
| 110 | +} | ||
| 111 | + | ||
| 112 | +// CheckDtype: dtype 校验 | ||
| 113 | +aclnnStatus CheckDtype(const aclTensor *x1, const aclTensor *x2, const aclTensor *bias, const aclTensor *x1Scale, | ||
| 114 | + const aclTensor *x2Scale, const aclTensor *output) | ||
| 115 | +{ | ||
| 116 | + OP_CHECK_DTYPE_NOT_SUPPORT(x1, X_DTYPE_SUPPORT_LIST, return ACLNN_ERR_PARAM_INVALID); | ||
数据类型校验可以用list来判断,避免过多逻辑符号 ![]() ![]() | |||
| 117 | + OP_CHECK_DTYPE_NOT_SUPPORT(x2, X_DTYPE_SUPPORT_LIST, return ACLNN_ERR_PARAM_INVALID); | ||
| 118 | + OP_CHECK_DTYPE_NOT_SUPPORT(output, OUT_DTYPE_SUPPORT_LIST, return ACLNN_ERR_PARAM_INVALID); | ||
| 119 | + // FP4 要求 x1/x2 同时为 FLOAT4_E2M1(双向拦截,x1=e4m3/x2=fp4 或反之均报错) | ||
| 120 | + if (x1->GetDataType() == op::DataType::DT_FLOAT4_E2M1 || x2->GetDataType() == op::DataType::DT_FLOAT4_E2M1) { | ||
| 121 | + OP_CHECK_DTYPE_NOT_SAME(x1, x2, return ACLNN_ERR_PARAM_INVALID); | ||
| 122 | + } | ||
| 123 | + // x1Scale/x2Scale 为 OPTIONAL,非空时校验 dtype | ||
| 124 | + if (x1Scale != nullptr) { | ||
scale虽然allgathermm是可选,虽然mx量化必选,但是应保持一致性,用可选校验来看待 ![]() ![]() | |||
| 125 | + OP_CHECK_DTYPE_NOT_SUPPORT(x1Scale, SCALE_DTYPE_SUPPORT_LIST, return ACLNN_ERR_PARAM_INVALID); | ||
| 126 | + } | ||
| 127 | + if (x2Scale != nullptr) { | ||
| 128 | + OP_CHECK_DTYPE_NOT_SUPPORT(x2Scale, SCALE_DTYPE_SUPPORT_LIST, return ACLNN_ERR_PARAM_INVALID); | ||
| 129 | + } | ||
| 130 | + // bias 不为空时校验 FLOAT | ||
| 131 | + if (bias != nullptr) { | ||
| 132 | + OP_CHECK_DTYPE_NOT_SUPPORT(bias, BIAS_DTYPE_SUPPORT_LIST, return ACLNN_ERR_PARAM_INVALID); | ||
| 133 | + } | ||
| 134 | + return ACLNN_SUCCESS; | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +// 通用维度数校验:tensor 维度数须等于 expectedDimNum(调用方保证 tensor 非空) | ||
| 138 | +aclnnStatus CheckTensorDimNum(const aclTensor *tensor, const char *paramName, int64_t expectedDimNum) | ||
| 139 | +{ | ||
| 140 | + if (tensor->GetViewShape().GetDimNum() != expectedDimNum) { | ||
| 141 | + OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON( | ||
| 142 | + "aclnnAllGatherQuantMatmulV3", paramName, | ||
| 143 | + (std::to_string(tensor->GetViewShape().GetDimNum()) + "D").c_str(), | ||
| 144 | + ("The shape of " + std::string(paramName) + " must be " + std::to_string(expectedDimNum) + "D.").c_str()); | ||
| 145 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 146 | + } | ||
| 147 | + return ACLNN_SUCCESS; | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | +// 通用 format 校验:仅支持 ND;空指针放行(兼容 OPTIONAL 输入) | ||
| 151 | +aclnnStatus CheckTensorFormatND(const aclTensor *tensor, const char *paramName) | ||
| 152 | +{ | ||
| 153 | + if (tensor != nullptr && tensor->GetStorageFormat() != op::Format::FORMAT_ND) { | ||
| 154 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON("aclnnAllGatherQuantMatmulV3", paramName, | ||
| 155 | + op::ToString(tensor->GetStorageFormat()).GetString(), | ||
| 156 | + "Only ND format is supported"); | ||
| 157 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 158 | + } | ||
| 159 | + return ACLNN_SUCCESS; | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +// CheckFormat: ND 校验(scale 兼容 NCL,同 v2 CheckScale) | ||
| 163 | +aclnnStatus CheckFormat(const aclTensor *context, const aclTensor *x1, const aclTensor *x2, const aclTensor *bias, | ||
| 164 | + const aclTensor *x1Scale, const aclTensor *x2Scale, const aclTensor *output) | ||
| 165 | +{ | ||
| 166 | + aclnnStatus ret = CheckTensorFormatND(context, "context"); | ||
| 167 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 168 | + ret = CheckTensorFormatND(x1, "x1"); | ||
| 169 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 170 | + ret = CheckTensorFormatND(x2, "x2"); | ||
| 171 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 172 | + ret = CheckTensorFormatND(output, "output"); | ||
| 173 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 174 | + ret = CheckTensorFormatND(bias, "bias"); | ||
| 175 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 176 | + if (x1Scale != nullptr && x1Scale->GetStorageFormat() != op::Format::FORMAT_ND && | ||
| 177 | + x1Scale->GetStorageFormat() != op::Format::FORMAT_NCL) { | ||
| 178 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON("aclnnAllGatherQuantMatmulV3", "x1Scale", | ||
| 179 | + op::ToString(x1Scale->GetStorageFormat()).GetString(), | ||
| 180 | + "Only ND/NCL format is supported"); | ||
| 181 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 182 | + } | ||
| 183 | + if (x2Scale != nullptr && x2Scale->GetStorageFormat() != op::Format::FORMAT_ND && | ||
| 184 | + x2Scale->GetStorageFormat() != op::Format::FORMAT_NCL) { | ||
| 185 | + OP_LOGE_FOR_INVALID_FORMATS_WITH_REASON("aclnnAllGatherQuantMatmulV3", "x2Scale", | ||
能用错误的内置宏则用,不得已再用loge ![]() ![]() | |||
| 186 | + op::ToString(x2Scale->GetStorageFormat()).GetString(), | ||
| 187 | + "Only ND/NCL format is supported"); | ||
| 188 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 189 | + } | ||
| 190 | + return ACLNN_SUCCESS; | ||
| 191 | +} | ||
| 192 | + | ||
| 193 | +// 校验 MX scale shape: [dim0, Ceil(K/64), 2];scale 为 OPTIONAL,空指针直接放行 | ||
| 194 | +aclnnStatus CheckScaleShape(const aclTensor *scale, const char *paramName, int64_t dim0, int64_t scaleKDim) | ||
| 195 | +{ | ||
| 196 | + if (scale == nullptr) { | ||
| 197 | + return ACLNN_SUCCESS; | ||
| 198 | + } | ||
| 199 | + aclnnStatus ret = CheckTensorDimNum(scale, paramName, SCALE_DIMS); | ||
| 200 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 201 | + if (scale->GetViewShape().GetDim(0) != dim0 || scale->GetViewShape().GetDim(1) != scaleKDim || | ||
| 202 | + scale->GetViewShape().GetDim(2) != SCALE_LAST_DIM) { | ||
| 203 | + OP_LOGE_FOR_INVALID_SHAPE("aclnnAllGatherQuantMatmulV3", paramName, | ||
| 204 | + op::ToString(scale->GetViewShape()).GetString(), | ||
| 205 | + ("[" + std::to_string(dim0) + ", " + std::to_string(scaleKDim) + ", " + | ||
| 206 | + std::to_string(SCALE_LAST_DIM) + "]") | ||
| 207 | + .c_str()); | ||
| 208 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 209 | + } | ||
| 210 | + return ACLNN_SUCCESS; | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +// CheckShape: scale dim(0) 校验(gather_out/amax_out 不使能,不校验) | ||
| 214 | +aclnnStatus CheckShape(const aclTensor *x1, const aclTensor *x2, const aclTensor *x1Scale, const aclTensor *x2Scale, | ||
| 215 | + const aclTensor *output) | ||
| 216 | +{ | ||
| 217 | + aclnnStatus ret = CheckTensorDimNum(x1, "x1", TWO_DIMS); | ||
| 218 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 219 | + ret = CheckTensorDimNum(x2, "x2", TWO_DIMS); | ||
| 220 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 221 | + ret = CheckTensorDimNum(output, "output", TWO_DIMS); | ||
| 222 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 223 | + // x1: [M, K]; x2: [N, K] | ||
| 224 | + int64_t mVal = x1->GetViewShape().GetDim(0); | ||
| 225 | + int64_t kX1 = x1->GetViewShape().GetDim(1); | ||
| 226 | + int64_t nVal = x2->GetViewShape().GetDim(0); | ||
| 227 | + int64_t kX2 = x2->GetViewShape().GetDim(1); | ||
| 228 | + if (kX1 != kX2) { | ||
| 229 | + OP_LOGE_FOR_INVALID_SHAPES_WITH_REASON("aclnnAllGatherQuantMatmulV3", "x1, x2", | ||
| 230 | + (std::string(op::ToString(x1->GetViewShape()).GetString()) + ", " + | ||
| 231 | + op::ToString(x2->GetViewShape()).GetString()) | ||
| 232 | + .c_str(), | ||
| 233 | + "K mismatch, x2 must be [N, K] layout."); | ||
| 234 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 235 | + } | ||
| 236 | + if (output->GetViewShape().GetDim(1) != nVal) { | ||
| 237 | + OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON("aclnnAllGatherQuantMatmulV3", "output", | ||
| 238 | + op::ToString(output->GetViewShape()).GetString(), | ||
| 239 | + "output.N must be equal to x2.N."); | ||
| 240 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 241 | + } | ||
| 242 | + // scale: x1Scale [M, Ceil(K/64), 2]; x2Scale [N, Ceil(K/64), 2] | ||
| 243 | + int64_t scaleKDim = (kX1 + MX_SCALE_BLOCK - 1) / MX_SCALE_BLOCK; | ||
| 244 | + ret = CheckScaleShape(x1Scale, "x1Scale", mVal, scaleKDim); | ||
| 245 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 246 | + ret = CheckScaleShape(x2Scale, "x2Scale", nVal, scaleKDim); | ||
| 247 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 248 | + return ACLNN_SUCCESS; | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | +// CheckAttrs: 仅校验 REQUIRED 属性(group、hccl_buffer_size);OPTIONAL 属性(comm_mode 等)不在此拦截 | ||
| 252 | +aclnnStatus CheckAttrs(const char *group, int64_t hcclBufferSize) | ||
| 253 | +{ | ||
| 254 | + if (group == nullptr) { | ||
| 255 | + OP_LOGE_WITH_INVALID_INPUT("aclnnAllGatherQuantMatmulV3", "group"); | ||
| 256 | + return ACLNN_ERR_PARAM_NULLPTR; | ||
| 257 | + } | ||
| 258 | + // group 名长度须在 [1, 128):空串与超长(含未 \0 结尾)均拦截 | ||
| 259 | + size_t groupLen = strnlen(group, HCCL_GROUP_NAME_LENGTH_MAX); // 长度 >= 128 时返回 128 | ||
| 260 | + if (groupLen == 0 || groupLen >= HCCL_GROUP_NAME_LENGTH_MAX) { | ||
| 261 | + OP_LOGE_FOR_INVALID_VALUE("aclnnAllGatherQuantMatmulV3", "group length", std::to_string(groupLen).c_str(), | ||
| 262 | + ("in range [1, " + std::to_string(HCCL_GROUP_NAME_LENGTH_MAX) + ")").c_str()); | ||
| 263 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 264 | + } | ||
| 265 | + if (hcclBufferSize <= 0) { | ||
| 266 | + OP_LOGE_WITH_INVALID_ATTR("aclnnAllGatherQuantMatmulV3", "hccl_buffer_size", | ||
| 267 | + std::to_string(hcclBufferSize).c_str(), "positive integer"); | ||
| 268 | + return ACLNN_ERR_PARAM_INVALID; | ||
| 269 | + } | ||
| 270 | + return ACLNN_SUCCESS; | ||
| 271 | +} | ||
| 272 | + | ||
| 273 | +} // namespace | ||
| 274 | + | ||
| 275 | +extern "C" void __attribute__((weak)) NnopbaseSetHcclServerType(void *executor, NnopbaseHcclServerType sType); | ||
| 276 | + | ||
| 277 | +extern "C" aclnnStatus aclnnAllGatherQuantMatmulV3GetWorkspaceSize( | ||
| 278 | + const aclTensor *context, const aclTensor *x1, const aclTensor *x2, const aclTensor *biasOptional, | ||
| 279 | + const aclTensor *x1ScaleOptional, const aclTensor *x2ScaleOptional, const char *group, int64_t rankSize, | ||
| 280 | + int64_t hcclBufferSize, int64_t groupSize, const char *commMode, const aclTensor *output, | ||
| 281 | + const aclTensor *gatherOut, uint64_t *workspaceSize, aclOpExecutor **executor) | ||
| 282 | +{ | ||
| 283 | + OP_LOGD("aclnnAllGatherQuantMatmulV3GetWorkspaceSize start"); | ||
注意校验顺序先做空校验 ![]() ![]() | |||
| 284 | + | ||
| 285 | + // 校验顺序:null -> dtype -> format -> attrs -> shape | ||
| 286 | + if (!CheckNullParams(context, x1, x2, output, workspaceSize, executor)) { | ||
| 287 | + return ACLNN_ERR_PARAM_NULLPTR; | ||
| 288 | + } | ||
| 289 | + aclnnStatus ret = CheckDtype(x1, x2, biasOptional, x1ScaleOptional, x2ScaleOptional, output); | ||
| 290 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 291 | + ret = CheckFormat(context, x1, x2, biasOptional, x1ScaleOptional, x2ScaleOptional, output); | ||
| 292 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 293 | + ret = CheckAttrs(group, hcclBufferSize); | ||
| 294 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 295 | + | ||
| 296 | + OP_LOGD("X1 is %s.", x1->ToString().GetString()); | ||
| 297 | + OP_LOGD("X2 is %s.", x2->ToString().GetString()); | ||
| 298 | + | ||
| 299 | + constexpr bool kIsTransA = false; | ||
| 300 | + constexpr bool kIsTransB = true; | ||
| 301 | + auto transX2 = x2; | ||
| 302 | + auto transX2Scale = x2ScaleOptional; | ||
| 303 | + if (Ops::Transformer::IsTransposeLastTwoDims(x2)) { | ||
| 304 | + OP_LOGI("x2 is a transposed [K,N] view, transpose back to [N,K]."); | ||
| 305 | + transX2 = TransX2Tensor(x2); | ||
| 306 | + if (transX2 == nullptr) { | ||
| 307 | + return ACLNN_ERR_INNER_NULLPTR; | ||
| 308 | + } | ||
| 309 | + } | ||
| 310 | + if ((x2ScaleOptional != nullptr) && MC2Aclnn::IsNeedScaleTrans(x2ScaleOptional)) { | ||
| 311 | + transX2Scale = TransX2Tensor(x2ScaleOptional); | ||
| 312 | + if (transX2Scale == nullptr) { | ||
| 313 | + return ACLNN_ERR_INNER_NULLPTR; | ||
| 314 | + } | ||
| 315 | + OP_LOGI("x2Scale after trans: dim0=%ld dim1=%ld dim2=%ld", transX2Scale->GetViewShape().GetDim(0), | ||
加一些维测日志 ![]() ![]() | |||
| 316 | + transX2Scale->GetViewShape().GetDim(1), transX2Scale->GetViewShape().GetDim(2)); | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + ret = CheckShape(x1, transX2, x1ScaleOptional, transX2Scale, output); | ||
| 320 | + CHECK_RET(ret == ACLNN_SUCCESS, ret); | ||
| 321 | + | ||
| 322 | + uint64_t outDtype = static_cast<uint64_t>(output->GetDataType()); | ||
| 323 | + OP_LOGD("outDtype value is: %lu.", outDtype); | ||
| 324 | + | ||
| 325 | + // gather_out 本次交付不使能(def 为 REQUIRED,torch 侧传 {0} 空占位 tensor),aclnn 原样透传 inner, | ||
| 326 | + // aclnn/tiling 不做处理;amax_out 为 OPTIONAL,inner 固定传 nullptr | ||
| 327 | + ret = aclnnInnerAllGatherMatmulV3GetWorkspaceSize( | ||
| 328 | + context, x1, transX2, biasOptional, x1ScaleOptional, transX2Scale, const_cast<char *>(group), hcclBufferSize, | ||
| 329 | + kIsTransA, kIsTransB, rankSize, groupSize, static_cast<int64_t>(outDtype), const_cast<char *>(commMode), output, | ||
| 330 | + gatherOut, nullptr, workspaceSize, executor); | ||
| 331 | + | ||
| 332 | + OP_LOGD("aclnnInnerAllGatherMatmulV3GetWorkspaceSize ret = %d.", ret); | ||
| 333 | + if (ret != ACLNN_SUCCESS) { | ||
| 334 | + OP_LOGE(ACLNN_ERR_INNER, "aclnnInnerAllGatherMatmulV3GetWorkspaceSize failed, ret=%d", ret); | ||
| 335 | + } | ||
| 336 | + | ||
| 337 | + OP_LOGD("aclnnAllGatherQuantMatmulV3GetWorkspaceSize end: workspaceSize=%lu", *workspaceSize); | ||
| 338 | + return ret; | ||
| 339 | +} | ||
| 340 | + | ||
| 341 | +extern "C" aclnnStatus aclnnAllGatherQuantMatmulV3(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, | ||
| 342 | + aclrtStream stream) | ||
| 343 | +{ | ||
| 344 | + OP_LOGD("aclnnAllGatherQuantMatmulV3 start"); | ||
| 345 | + | ||
| 346 | + if (executor == nullptr) { | ||
| 347 | + OP_LOGE(ACLNN_ERR_INNER_NULLPTR, "aclnnAllGatherQuantMatmulV3: executor is null."); | ||
| 348 | + return ACLNN_ERR_INNER_NULLPTR; | ||
| 349 | + } | ||
| 350 | + if (NnopbaseSetHcclServerType != nullptr) { | ||
| 351 | + NnopbaseSetHcclServerType(executor, NnopbaseHcclServerType::NNOPBASE_HCCL_SERVER_TYPE_MTE); | ||
| 352 | + } | ||
| 353 | + aclnnStatus ret = aclnnInnerAllGatherMatmulV3(workspace, workspaceSize, executor, stream); | ||
| 354 | + if (ret != ACLNN_SUCCESS) { | ||
| 355 | + OP_LOGE(ACLNN_ERR_INNER, "aclnnInnerAllGatherMatmulV3 failed, ret=%d", ret); | ||
| 356 | + return ACLNN_ERR_INNER; | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + OP_LOGD("aclnnAllGatherQuantMatmulV3 end"); | ||
| 360 | + return ACLNN_SUCCESS; | ||
| 361 | +} | ||
| @@ -0,0 +1,48 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +if (BUILD_OPEN_PROJECT) | ||
| 12 | + # Core OpDef registration | ||
| 13 | + target_sources(op_host_aclnnInner PRIVATE | ||
| 14 | + all_gather_matmul_v3_def.cpp | ||
| 15 | + ) | ||
| 16 | + | ||
| 17 | + add_modules_sources_with_soc( | ||
| 18 | + OP_API_INDEPENDENT ON | ||
| 19 | + OP_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../op_api | ||
| 20 | + OP_MC2_ENABLE ON | ||
| 21 | + OPTYPE all_gather_matmul_v3 all_gather_matmul_v3 ACLNNTYPE aclnn aclnn_inner) | ||
| 22 | + set(SUB_MC2_COMPILE TRUE PARENT_SCOPE) | ||
| 23 | + set(MC2_OPT ON PARENT_SCOPE) | ||
| 24 | + set(all_gather_matmul_v3_depends mc2/common mc2/3rd PARENT_SCOPE) | ||
| 25 | + set(all_gather_matmul_v3_apt_depends mc2/common mc2/3rd PARENT_SCOPE) | ||
| 26 | + file(MAKE_DIRECTORY ${CMAKE_SOURCE_DIR}/third_party/ops-tensor/include/tensor_api/impl/c_api | ||
| 27 | + ${CMAKE_SOURCE_DIR}/third_party/ops-tensor/include/tensor_api/include/c_api) | ||
| 28 | + | ||
| 29 | + set(CONDITION_UNIT ${ASCEND_COMPUTE_UNIT}) | ||
| 30 | + if("${CONDITION_UNIT}" STREQUAL "ascend950") | ||
| 31 | + add_ops_compile_options( | ||
| 32 | + OP_NAME AllGatherMatmulV3 | ||
| 33 | + COMPUTE_UNIT Ascend950PR_9599 | ||
| 34 | + OPTIONS --cce-auto-sync=off | ||
| 35 | + -mllvm | ||
| 36 | + -cce-aicore-dcci-before-kernel-end=false | ||
| 37 | + -I${CMAKE_SOURCE_DIR}/mc2/common/op_kernel | ||
| 38 | + -I${CMAKE_SOURCE_DIR}/mc2/common/op_kernel/apace/tests/st/.third_party/ops-tensor/include | ||
| 39 | + ) | ||
| 40 | + endif() | ||
| 41 | + target_include_directories(op_host_aclnnInner PRIVATE | ||
| 42 | + ${CMAKE_SOURCE_DIR}/mc2/common/op_kernel | ||
| 43 | + ${CMAKE_SOURCE_DIR}/mc2 | ||
| 44 | + ) | ||
| 45 | +else() | ||
| 46 | + add_mc2_modules_sources(OPTYPE all_gather_matmul_v3 all_gather_matmul_v3 ACLNNTYPE aclnn aclnn_inner) | ||
| 47 | + set(SUB_MC2_COMPILE TRUE PARENT_SCOPE) | ||
| 48 | +endif() | ||
| @@ -0,0 +1,103 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file all_gather_matmul_v3_def.cpp | ||
| 13 | + * \brief OpDef definition for AllGatherMatmulV3 (MX-quant FP8 only, apace UDMA path) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <register/op_def_registry.h> | ||
| 17 | + | ||
| 18 | +namespace ops { | ||
| 19 | +class AllGatherMatmulV3 : public OpDef { | ||
| 20 | +public: | ||
| 21 | + explicit AllGatherMatmulV3(const char *name) | ||
| 22 | + : OpDef(name) | ||
| 23 | + { | ||
| 24 | + this->Input("context") | ||
| 25 | + .ParamType(REQUIRED) | ||
| 26 | + .DataTypeList({ge::DT_INT32}) | ||
| 27 | + .FormatList({ge::FORMAT_ND}) | ||
| 28 | + .AutoContiguous(); | ||
| 29 | + this->Input("x1") | ||
| 30 | + .ParamType(REQUIRED) | ||
| 31 | + .DataType({ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E5M2, | ||
| 32 | + ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E5M2, | ||
| 33 | + ge::DT_FLOAT4_E2M1, ge::DT_FLOAT4_E2M1}) | ||
| 34 | + .FormatList({ge::FORMAT_ND}) | ||
| 35 | + .AutoContiguous(); | ||
| 36 | + this->Input("x2") | ||
| 37 | + .ParamType(REQUIRED) | ||
| 38 | + .DataType({ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E5M2, | ||
| 39 | + ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E4M3FN, | ||
| 40 | + ge::DT_FLOAT4_E2M1, ge::DT_FLOAT4_E2M1}) | ||
| 41 | + .FormatList({ge::FORMAT_ND}) | ||
| 42 | + .IgnoreContiguous(); | ||
| 43 | + this->Input("bias") | ||
| 44 | + .ParamType(OPTIONAL) | ||
| 45 | + .DataType({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, | ||
| 46 | + ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT}) | ||
| 47 | + .FormatList({ge::FORMAT_ND}) | ||
| 48 | + .AutoContiguous(); | ||
| 49 | + this->Input("x1_scale") | ||
| 50 | + .ParamType(OPTIONAL) | ||
| 51 | + .DataType({ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, | ||
| 52 | + ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, | ||
| 53 | + ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0}) | ||
| 54 | + .FormatList({ge::FORMAT_ND}) | ||
| 55 | + .AutoContiguous(); | ||
| 56 | + this->Input("x2_scale") | ||
| 57 | + .ParamType(OPTIONAL) | ||
| 58 | + .DataType({ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, | ||
| 59 | + ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0, | ||
| 60 | + ge::DT_FLOAT8_E8M0, ge::DT_FLOAT8_E8M0}) | ||
| 61 | + .FormatList({ge::FORMAT_ND}); | ||
| 62 | + this->Output("y") | ||
| 63 | + .ParamType(REQUIRED) | ||
| 64 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_FLOAT16, | ||
| 65 | + ge::DT_BF16, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_FLOAT16}) | ||
| 66 | + .FormatList({ge::FORMAT_ND}); | ||
| 67 | + this->Output("gather_out") | ||
应与v2保持一致,gatherout为必选 ![]() ![]() | |||
| 68 | + .ParamType(REQUIRED) | ||
| 69 | + .DataType({ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E5M2, | ||
| 70 | + ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E4M3FN, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E5M2, | ||
| 71 | + ge::DT_FLOAT4_E2M1, ge::DT_FLOAT4_E2M1}) | ||
| 72 | + .FormatList({ge::FORMAT_ND}); | ||
| 73 | + this->Output("amax_out") | ||
| 74 | + .ParamType(OPTIONAL) | ||
| 75 | + .DataType({ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT, | ||
| 76 | + ge::DT_FLOAT, ge::DT_FLOAT, ge::DT_FLOAT}) | ||
| 77 | + .FormatList({ge::FORMAT_ND}); | ||
| 78 | + this->Attr("group").AttrType(REQUIRED).String(); | ||
| 79 | + this->Attr("hccl_buffer_size").AttrType(REQUIRED).Int(); | ||
| 80 | + this->Attr("is_trans_a").AttrType(OPTIONAL).Bool(false); | ||
| 81 | + this->Attr("is_trans_b").AttrType(OPTIONAL).Bool(false); | ||
| 82 | + this->Attr("rank_size").AttrType(OPTIONAL).Int(0); | ||
| 83 | + this->Attr("group_size").AttrType(OPTIONAL).Int(0); | ||
| 84 | + this->Attr("y_dtype").AttrType(OPTIONAL).Int(static_cast<int64_t>(ge::DT_UNDEFINED)); | ||
| 85 | + this->Attr("comm_mode").AttrType(OPTIONAL).String("ai_cpu"); | ||
默认是ai-cpu不是urma ![]() ![]() | |||
| 86 | + | ||
| 87 | + OpAICoreConfig aicoreConfig_950; | ||
| 88 | + aicoreConfig_950.DynamicCompileStaticFlag(true) | ||
| 89 | + .DynamicFormatFlag(true) | ||
| 90 | + .DynamicRankSupportFlag(true) | ||
| 91 | + .DynamicShapeSupportFlag(true) | ||
| 92 | + .NeedCheckSupportFlag(false) | ||
| 93 | + .PrecisionReduceFlag(true) | ||
| 94 | + .ExtendCfgInfo("aclnnSupport.value", "support_aclnn") | ||
| 95 | + .ExtendCfgInfo("jitCompile.flag", "static_false") // 动态shape,复用二进制,后续图支持后修改 | ||
| 96 | + .ExtendCfgInfo("multiKernelSupportDynamicGraph.value", "multi_kernel") | ||
| 97 | + .ExtendCfgInfo("opFile.value", "all_gather_matmul_v3_apt"); | ||
| 98 | + this->AICore().AddConfig("ascend950", aicoreConfig_950); | ||
| 99 | + } | ||
| 100 | +}; | ||
| 101 | + | ||
| 102 | +OP_ADD(AllGatherMatmulV3); | ||
| 103 | +} // namespace ops | ||
| @@ -0,0 +1,268 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file all_gather_matmul_v3_infershape.cpp | ||
| 13 | + * \brief InferShape for AllGatherMatmulV3 | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <register/op_impl_registry.h> | ||
| 17 | + | ||
| 18 | +#include "common/utils/op_mc2.h" | ||
| 19 | +#include "mc2_log.h" | ||
| 20 | +#include "op_host/mc2_common_infershape.h" | ||
| 21 | +#include "util/math_util.h" | ||
| 22 | + | ||
| 23 | +namespace ops { | ||
| 24 | + | ||
| 25 | +using Ops::Base::CeilDiv; | ||
| 26 | + | ||
| 27 | +namespace { | ||
| 28 | + | ||
| 29 | +constexpr size_t INDEX_IN_X1 = 1; | ||
| 30 | +constexpr size_t INDEX_IN_X2 = 2; | ||
| 31 | +constexpr size_t INDEX_IN_X1_SCALE = 4; | ||
| 32 | +constexpr size_t INDEX_IN_X2_SCALE = 5; | ||
| 33 | +constexpr size_t INDEX_OUT_Y = 0; | ||
| 34 | +constexpr size_t INDEX_OUT_GATHER_OUT = 1; | ||
| 35 | +constexpr size_t INDEX_ATTR_IS_TRANS_B = 3; | ||
| 36 | +constexpr size_t INDEX_ATTR_RANK_SIZE = 4; | ||
| 37 | +constexpr size_t INDEX_ATTR_Y_DTYPE = 6; | ||
| 38 | + | ||
| 39 | +constexpr int64_t MX_SCALE_BLOCK_SIZE = 64; | ||
| 40 | +constexpr int64_t SCALE_LAST_DIM = 2; | ||
| 41 | +constexpr int64_t DIM_MINUS_ONE = -1; | ||
| 42 | +constexpr int64_t K_MIN_VAL = 256; | ||
| 43 | +constexpr int64_t K_MAX_VAL = 65535; | ||
| 44 | +constexpr size_t SUPPORT_DIM_SIZE = 2; | ||
| 45 | + | ||
| 46 | +// scale 各维度可能为动态未知(-1),仅对已知维度做等值校验 | ||
| 47 | +bool IsDimMismatch(uint64_t actual, int64_t expected) | ||
| 48 | +{ | ||
| 49 | + return actual != static_cast<uint64_t>(DIM_MINUS_ONE) && actual != static_cast<uint64_t>(expected); | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +// rank_size 未设置(<=0)时拦截 | ||
| 53 | +ge::graphStatus ResolveRankSize(const gert::InferShapeContext *context, int64_t &rankSize) | ||
| 54 | +{ | ||
| 55 | + const auto nodeName = context->GetNodeName(); | ||
| 56 | + const auto attrs = context->GetAttrs(); | ||
| 57 | + const int64_t *rankSizeAttr = attrs->GetAttrPointer<int64_t>(INDEX_ATTR_RANK_SIZE); | ||
| 58 | + OPS_CHECK(rankSizeAttr == nullptr, OP_LOGE_WITH_INVALID_INPUT(nodeName, "rank_size"), return ge::GRAPH_FAILED); | ||
| 59 | + rankSize = *rankSizeAttr; | ||
| 60 | + OPS_CHECK(rankSize <= 0, OP_LOGE(nodeName, "rank_size attr must be set, got %ld", rankSize), | ||
| 61 | + return ge::GRAPH_FAILED); | ||
| 62 | + return ge::GRAPH_SUCCESS; | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +ge::graphStatus CheckMatrixInputShapes(const gert::InferShapeContext *context) | ||
| 66 | +{ | ||
| 67 | + const auto x1Shape = context->GetInputShape(INDEX_IN_X1); | ||
| 68 | + const auto x2Shape = context->GetInputShape(INDEX_IN_X2); | ||
| 69 | + OPS_CHECK_NULL_WITH_CONTEXT(context, x1Shape); | ||
| 70 | + OPS_CHECK_NULL_WITH_CONTEXT(context, x2Shape); | ||
| 71 | + if (x1Shape->GetDimNum() != SUPPORT_DIM_SIZE) { | ||
| 72 | + OP_LOGE_FOR_INVALID_SHAPEDIM(context->GetNodeName(), "x1", (std::to_string(x1Shape->GetDimNum()) + "D").c_str(), | ||
| 73 | + "2D"); | ||
| 74 | + return ge::GRAPH_FAILED; | ||
| 75 | + } | ||
| 76 | + if (x2Shape->GetDimNum() != SUPPORT_DIM_SIZE) { | ||
| 77 | + OP_LOGE_FOR_INVALID_SHAPEDIM(context->GetNodeName(), "x2", (std::to_string(x2Shape->GetDimNum()) + "D").c_str(), | ||
| 78 | + "2D"); | ||
| 79 | + return ge::GRAPH_FAILED; | ||
| 80 | + } | ||
| 81 | + return ge::GRAPH_SUCCESS; | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +ge::graphStatus CheckMatrixDtypes(const gert::InferShapeContext *context) | ||
| 85 | +{ | ||
| 86 | + const auto nodeName = context->GetNodeName(); | ||
| 87 | + auto x1Dtype = context->GetInputDesc(INDEX_IN_X1)->GetDataType(); | ||
| 88 | + auto x2Dtype = context->GetInputDesc(INDEX_IN_X2)->GetDataType(); | ||
| 89 | + if ((x1Dtype != ge::DT_FLOAT8_E4M3FN && x1Dtype != ge::DT_FLOAT8_E5M2 && x1Dtype != ge::DT_FLOAT4_E2M1) || | ||
| 90 | + (x2Dtype != ge::DT_FLOAT8_E4M3FN && x2Dtype != ge::DT_FLOAT8_E5M2 && x2Dtype != ge::DT_FLOAT4_E2M1)) { | ||
| 91 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON( | ||
| 92 | + nodeName, "x1, x2", | ||
| 93 | + (std::to_string(static_cast<int>(x1Dtype)) + ", " + std::to_string(static_cast<int>(x2Dtype))).c_str(), | ||
| 94 | + "only FP8_E4M3FN/FP8_E5M2/FP4_E2M1 supported"); | ||
| 95 | + return ge::GRAPH_FAILED; | ||
| 96 | + } | ||
| 97 | + if ((x1Dtype == ge::DT_FLOAT4_E2M1) != (x2Dtype == ge::DT_FLOAT4_E2M1)) { | ||
| 98 | + OP_LOGE_FOR_INVALID_DTYPES_WITH_REASON( | ||
| 99 | + nodeName, "x1, x2", | ||
| 100 | + (std::to_string(static_cast<int>(x1Dtype)) + ", " + std::to_string(static_cast<int>(x2Dtype))).c_str(), | ||
| 101 | + "FP4 requires both x1 and x2 to be FP4_E2M1"); | ||
| 102 | + return ge::GRAPH_FAILED; | ||
| 103 | + } | ||
| 104 | + return ge::GRAPH_SUCCESS; | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +ge::graphStatus CheckKDimMatch(const gert::InferShapeContext *context, int64_t kX1, int64_t kX2) | ||
| 108 | +{ | ||
| 109 | + OPS_CHECK(kX1 != kX2, | ||
| 110 | + OP_LOGE_FOR_INVALID_VALUES_WITH_REASON(context->GetNodeName(), "x1.K, x2.K", | ||
| 111 | + (std::to_string(kX1) + ", " + std::to_string(kX2)).c_str(), | ||
| 112 | + "The values of x1.K and x2.K must be the same"), | ||
| 113 | + return ge::GRAPH_FAILED); | ||
| 114 | + return ge::GRAPH_SUCCESS; | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +ge::graphStatus CheckKConstraints(const gert::InferShapeContext *context, int64_t k) | ||
| 118 | +{ | ||
| 119 | + const auto nodeName = context->GetNodeName(); | ||
| 120 | + OPS_CHECK( | ||
| 121 | + k < K_MIN_VAL || k >= K_MAX_VAL, | ||
| 122 | + OP_LOGE_FOR_INVALID_VALUE( | ||
| 123 | + nodeName, "K", std::to_string(k).c_str(), | ||
| 124 | + (std::string("in range [") + std::to_string(K_MIN_VAL) + ", " + std::to_string(K_MAX_VAL) + ")").c_str()), | ||
| 125 | + return ge::GRAPH_FAILED); | ||
| 126 | + | ||
| 127 | + // fp4 要求 K 为偶数 | ||
| 128 | + auto x1Dtype = context->GetInputDesc(INDEX_IN_X1)->GetDataType(); | ||
| 129 | + if (x1Dtype == ge::DT_FLOAT4_E2M1) { | ||
| 130 | + OPS_CHECK(k % 2 != 0, | ||
| 131 | + OP_LOGE_FOR_INVALID_VALUE(nodeName, "K", std::to_string(k).c_str(), "must be even in mxfp4 scene"), | ||
| 132 | + return ge::GRAPH_FAILED); | ||
| 133 | + } | ||
| 134 | + return ge::GRAPH_SUCCESS; | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +ge::graphStatus CheckOneScaleShape(const gert::InferShapeContext *context, const gert::Shape *scaleShape, | ||
| 138 | + const char *paramName, int64_t dim0, int64_t expectedScaleK) | ||
| 139 | +{ | ||
| 140 | + const auto nodeName = context->GetNodeName(); | ||
| 141 | + OPS_CHECK(IsDimMismatch(scaleShape->GetDim(0U), dim0) || IsDimMismatch(scaleShape->GetDim(1U), expectedScaleK) || | ||
| 142 | + IsDimMismatch(scaleShape->GetDim(2U), SCALE_LAST_DIM), | ||
| 143 | + OP_LOGE_FOR_INVALID_SHAPE( | ||
| 144 | + nodeName, paramName, | ||
| 145 | + (std::string("[") + std::to_string(scaleShape->GetDim(0U)) + "," + | ||
| 146 | + std::to_string(scaleShape->GetDim(1U)) + "," + std::to_string(scaleShape->GetDim(2U)) + "]") | ||
| 147 | + .c_str(), | ||
| 148 | + (std::string("[") + std::to_string(dim0) + "," + std::to_string(expectedScaleK) + "," + | ||
| 149 | + std::to_string(SCALE_LAST_DIM) + "]") | ||
| 150 | + .c_str()), | ||
| 151 | + return ge::GRAPH_FAILED); | ||
| 152 | + return ge::GRAPH_SUCCESS; | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +// x1_scale: [M, Ceil(K/64), 2]; x2_scale: [N, Ceil(K/64), 2] | ||
| 156 | +ge::graphStatus CheckScaleShapes(const gert::InferShapeContext *context, int64_t m, int64_t n, int64_t k) | ||
| 157 | +{ | ||
| 158 | + auto x1ScaleShape = context->GetOptionalInputShape(INDEX_IN_X1_SCALE); | ||
| 159 | + auto x2ScaleShape = context->GetOptionalInputShape(INDEX_IN_X2_SCALE); | ||
| 160 | + if (x1ScaleShape == nullptr || x2ScaleShape == nullptr) { | ||
| 161 | + return ge::GRAPH_SUCCESS; | ||
| 162 | + } | ||
| 163 | + int64_t expectedScaleK = CeilDiv(k, MX_SCALE_BLOCK_SIZE); | ||
| 164 | + if (CheckOneScaleShape(context, x1ScaleShape, "x1_scale", m, expectedScaleK) != ge::GRAPH_SUCCESS) { | ||
| 165 | + return ge::GRAPH_FAILED; | ||
| 166 | + } | ||
| 167 | + if (CheckOneScaleShape(context, x2ScaleShape, "x2_scale", n, expectedScaleK) != ge::GRAPH_SUCCESS) { | ||
| 168 | + return ge::GRAPH_FAILED; | ||
| 169 | + } | ||
| 170 | + return ge::GRAPH_SUCCESS; | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +ge::graphStatus DeriveOutputShapes(gert::InferShapeContext *context, int64_t m, int64_t k, int64_t n, int64_t worldSize) | ||
| 174 | +{ | ||
| 175 | + // y = [world_size * M_per_rank, N] | ||
| 176 | + auto outShape = context->GetOutputShape(INDEX_OUT_Y); | ||
| 177 | + OPS_CHECK_NULL_WITH_CONTEXT(context, outShape); | ||
| 178 | + outShape->SetDimNum(SUPPORT_DIM_SIZE); | ||
| 179 | + if (m != DIM_MINUS_ONE && n != DIM_MINUS_ONE) { | ||
| 180 | + outShape->SetDim(0U, m * worldSize); | ||
| 181 | + outShape->SetDim(1U, n); | ||
| 182 | + } else { | ||
| 183 | + outShape->SetDim(0U, DIM_MINUS_ONE); | ||
| 184 | + outShape->SetDim(1U, DIM_MINUS_ONE); | ||
| 185 | + } | ||
| 186 | + | ||
| 187 | + // gather_out = [world_size * M_per_rank, K] (REQUIRED) | ||
| 188 | + auto gatherOutShape = context->GetOutputShape(INDEX_OUT_GATHER_OUT); | ||
| 189 | + OPS_CHECK_NULL_WITH_CONTEXT(context, gatherOutShape); | ||
| 190 | + gatherOutShape->SetDimNum(SUPPORT_DIM_SIZE); | ||
| 191 | + if (m != DIM_MINUS_ONE && k != DIM_MINUS_ONE) { | ||
| 192 | + gatherOutShape->SetDim(0U, m * worldSize); | ||
| 193 | + gatherOutShape->SetDim(1U, k); | ||
| 194 | + } else { | ||
| 195 | + gatherOutShape->SetDim(0U, DIM_MINUS_ONE); | ||
| 196 | + gatherOutShape->SetDim(1U, DIM_MINUS_ONE); | ||
| 197 | + } | ||
| 198 | + return ge::GRAPH_SUCCESS; | ||
| 199 | +} | ||
| 200 | + | ||
| 201 | +} // namespace | ||
| 202 | + | ||
| 203 | +ge::graphStatus AllGatherMatmulV3InferShape(gert::InferShapeContext *context) | ||
| 204 | +{ | ||
| 205 | + const auto nodeName = context->GetNodeName(); | ||
| 206 | + OP_LOGD(nodeName, "InferShape start"); | ||
| 207 | + | ||
| 208 | + OP_LOGE_IF(CheckMatrixInputShapes(context) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 209 | + "check matrix input shapes failed."); | ||
| 210 | + OP_LOGE_IF(CheckMatrixDtypes(context) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 211 | + "check matrix dtypes failed."); | ||
| 212 | + | ||
| 213 | + // 提取维度:x1 [M, K];x2 在 is_trans_b=true 时为 [N, K] | ||
| 214 | + const auto x1Shape = context->GetInputShape(INDEX_IN_X1); | ||
| 215 | + const auto x2Shape = context->GetInputShape(INDEX_IN_X2); | ||
| 216 | + int64_t m = x1Shape->GetDim(0U); | ||
| 217 | + int64_t k = x1Shape->GetDim(1U); | ||
| 218 | + const bool *isTransX2 = context->GetAttrs()->GetAttrPointer<bool>(INDEX_ATTR_IS_TRANS_B); | ||
| 219 | + const bool transX2 = ((isTransX2 != nullptr) && (*isTransX2)); | ||
| 220 | + int64_t n = transX2 ? x2Shape->GetDim(0U) : x2Shape->GetDim(1U); | ||
| 221 | + int64_t kX2 = transX2 ? x2Shape->GetDim(1U) : x2Shape->GetDim(0U); | ||
| 222 | + | ||
| 223 | + // rank_size: 必须由外界显式传入(<=0 时 ResolveRankSize 拦截报错) | ||
| 224 | + int64_t worldSize = 0; | ||
| 225 | + OP_LOGE_IF(ResolveRankSize(context, worldSize) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 226 | + "resolve rank_size failed."); | ||
| 227 | + | ||
| 228 | + OP_LOGD(nodeName, "InferShape: x1[%ld,%ld] x2 K=%ld N=%ld rankSize=%ld", m, k, kX2, n, worldSize); | ||
| 229 | + | ||
| 230 | + OP_LOGE_IF(CheckKDimMatch(context, k, kX2) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 231 | + "check K dim match failed."); | ||
| 232 | + // 静态 shape 才做取值约束,动态 shape(-1) 留待 tiling 校验 | ||
| 233 | + if (m != DIM_MINUS_ONE && k != DIM_MINUS_ONE && n != DIM_MINUS_ONE) { | ||
| 234 | + OP_LOGE_IF(CheckKConstraints(context, k) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 235 | + "check K constraints failed."); | ||
| 236 | + OP_LOGE_IF(CheckScaleShapes(context, m, n, k) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 237 | + "check scale shapes failed."); | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + OP_LOGE_IF(DeriveOutputShapes(context, m, k, n, worldSize) != ge::GRAPH_SUCCESS, ge::GRAPH_FAILED, nodeName, | ||
| 241 | + "derive output shapes failed."); | ||
| 242 | + | ||
| 243 | + OP_LOGD(nodeName, "InferShape success: M_per_rank=%ld K=%ld N=%ld world_size=%ld", m, k, n, worldSize); | ||
| 244 | + return ge::GRAPH_SUCCESS; | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | +// y dtype 由 y_dtype attr 决定(BF16/FP16),gather_out 与 x1 同 dtype | ||
| 248 | +ge::graphStatus AllGatherMatmulV3InferDataType(gert::InferDataTypeContext *context) | ||
| 249 | +{ | ||
| 250 | + const auto nodeName = context->GetNodeName(); | ||
| 251 | + | ||
| 252 | + auto yDtypePtr = context->GetAttrs()->GetAttrPointer<int64_t>(INDEX_ATTR_Y_DTYPE); | ||
| 253 | + ge::DataType yDtype = (yDtypePtr != nullptr) ? static_cast<ge::DataType>(*yDtypePtr) : ge::DT_UNDEFINED; | ||
| 254 | + OPS_CHECK( | ||
| 255 | + yDtype != ge::DT_BF16 && yDtype != ge::DT_FLOAT16, | ||
| 256 | + OP_LOGE_FOR_INVALID_DTYPE(nodeName, "y_dtype", std::to_string(static_cast<int>(yDtype)).c_str(), "BF16/FP16"), | ||
| 257 | + return ge::GRAPH_FAILED); | ||
| 258 | + | ||
| 259 | + context->SetOutputDataType(INDEX_OUT_Y, yDtype); | ||
| 260 | + context->SetOutputDataType(INDEX_OUT_GATHER_OUT, context->GetInputDataType(INDEX_IN_X1)); | ||
| 261 | + return ge::GRAPH_SUCCESS; | ||
| 262 | +} | ||
| 263 | + | ||
| 264 | +IMPL_OP_INFERSHAPE(AllGatherMatmulV3) | ||
| 265 | + .InferShape(AllGatherMatmulV3InferShape) | ||
| 266 | + .InferDataType(AllGatherMatmulV3InferDataType); | ||
| 267 | + | ||
| 268 | +} // namespace ops | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file all_gather_matmul_v3_apt.cpp | ||
| 13 | + * \brief Kernel entry for AllGatherMatmulV3 (MX-quant FP8, apace UDMA path) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <kernel_operator.h> | ||
| 17 | +#include "all_gather_matmul_v3_tiling_key.h" | ||
| 18 | +#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_tiling_data.h" | ||
| 19 | +#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_impl.h" | ||
| 20 | + | ||
| 21 | +using namespace AscendC; | ||
| 22 | +using namespace Apace; | ||
| 23 | + | ||
| 24 | +template <uint32_t QUANTMODE> | ||
| 25 | +__global__ __aicore__ void all_gather_matmul_v3(GM_ADDR context, GM_ADDR x1, GM_ADDR x2, GM_ADDR bias, GM_ADDR x1_scale, | ||
| 26 | + GM_ADDR x2_scale, GM_ADDR y, GM_ADDR gather_out, GM_ADDR amax_out, | ||
| 27 | + GM_ADDR workspaceGM, GM_ADDR tilingGM) | ||
| 28 | +{ | ||
| 29 | + (void)gather_out; | ||
无用地址用void包裹 ![]() ![]() | |||
| 30 | + (void)amax_out; | ||
| 31 | + (void)workspaceGM; | ||
| 32 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIC_1_1); | ||
| 33 | + | ||
| 34 | + REGISTER_TILING_DEFAULT(AllGatherMxMatmulUrmaTilingData); | ||
| 35 | + GET_TILING_DATA_WITH_STRUCT(AllGatherMxMatmulUrmaTilingData, tilingData, tilingGM); | ||
| 36 | + | ||
| 37 | + __gm__ CommContext *hcommCtx = reinterpret_cast<__gm__ CommContext *>(context); | ||
| 38 | + | ||
| 39 | + using Impl = AllGatherMxMatmulUrmaImpl<DTYPE_X1, DTYPE_X2, DTYPE_Y>; | ||
不要用写死值,用具体数据类型传递 ![]() ![]() | |||
| 40 | + | ||
| 41 | + Impl impl; | ||
| 42 | + impl.Init(hcommCtx, x1, x1_scale, x2, x2_scale, y, bias, &tilingData); | ||
| 43 | + impl.Process(); | ||
| 44 | +} | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#ifndef ALL_GATHER_MATMUL_APACE_TILING_KEY_H | ||
| 12 | +#define ALL_GATHER_MATMUL_APACE_TILING_KEY_H | ||
| 13 | + | ||
| 14 | +#include <ascendc/host_api/tiling/template_argument.h> | ||
| 15 | + | ||
| 16 | +#define NON_QUANT_MODE 0 | ||
| 17 | +#define MX_QUANT_MODE 6 | ||
新增一个非量化参数 ![]() ![]() | |||
| 18 | + | ||
| 19 | +ASCENDC_TPL_ARGS_DECL(AllGatherMatmulV3, | ||
| 20 | + ASCENDC_TPL_UINT_DECL(QUANTMODE, ASCENDC_TPL_4_BW, ASCENDC_TPL_UI_LIST, NON_QUANT_MODE, | ||
| 21 | + MX_QUANT_MODE), ); | ||
| 22 | + | ||
| 23 | +ASCENDC_TPL_SEL(ASCENDC_TPL_ARGS_SEL(ASCENDC_TPL_UINT_SEL(QUANTMODE, ASCENDC_TPL_UI_LIST, MX_QUANT_MODE))); | ||
| 24 | + | ||
| 25 | +#endif | ||
| @@ -0,0 +1,16 @@ | |||
| 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 | +file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 13 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 14 | + add_subdirectory(${SUB_DIR}) | ||
| 15 | + endif() | ||
| 16 | +endforeach() | ||
| @@ -0,0 +1,16 @@ | |||
| 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 | +file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 13 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 14 | + add_subdirectory(${SUB_DIR}) | ||
| 15 | + endif() | ||
| 16 | +endforeach() | ||
| @@ -0,0 +1,13 @@ | |||
| 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 | +if(UT_TEST_ALL OR OP_API_UT) | ||
| 12 | + add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 13 | +endif() | ||
| @@ -0,0 +1,122 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <gtest/gtest.h> | ||
| 12 | +#include "test_all_gather_matmul_v3_api_ut_param.h" | ||
| 13 | +#include "op_api_ut_common/tensor_desc.h" | ||
| 14 | +#include "op_api_ut_common/op_api_ut.h" | ||
| 15 | +#include "opdev/platform.h" | ||
| 16 | + | ||
| 17 | +using namespace op; | ||
| 18 | +using namespace std; | ||
| 19 | + | ||
| 20 | +extern "C" aclnnStatus aclnnAllGatherQuantMatmulV3GetWorkspaceSize( | ||
| 21 | + const aclTensor *context, const aclTensor *x1, const aclTensor *x2, const aclTensor *biasOptional, | ||
| 22 | + const aclTensor *x1ScaleOptional, const aclTensor *x2ScaleOptional, const char *group, int64_t rankSize, | ||
| 23 | + int64_t hcclBufferSize, int64_t groupSize, const char *commMode, const aclTensor *output, | ||
| 24 | + const aclTensor *gatherOut, uint64_t *workspaceSize, aclOpExecutor **executor); | ||
| 25 | +extern "C" aclnnStatus aclnnAllGatherQuantMatmulV3(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, | ||
| 26 | + aclrtStream stream); | ||
| 27 | + | ||
| 28 | +namespace AllGatherMatmulV3UT { | ||
| 29 | + | ||
| 30 | +class TestAclnnAllGatherMatmulV3 : public testing::TestWithParam<AllGatherMatmulV3ApiUtParam> { | ||
| 31 | +protected: | ||
| 32 | + static void SetUpTestCase() | ||
| 33 | + { | ||
| 34 | + op::SetPlatformNpuArch(NpuArch::DAV_3510); | ||
| 35 | + cout << "TestAclnnAllGatherMatmulV3 SetUp" << endl; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + static void TearDownTestCase() | ||
| 39 | + { | ||
| 40 | + op::SetPlatformSocVersion(op::SocVersion::ASCEND910B); | ||
| 41 | + cout << "TestAclnnAllGatherMatmulV3 TearDown" << endl; | ||
| 42 | + } | ||
| 43 | +}; | ||
| 44 | + | ||
| 45 | +TEST_P(TestAclnnAllGatherMatmulV3, param) | ||
| 46 | +{ | ||
| 47 | + auto param = GetParam(); | ||
| 48 | + std::cout << "[TEST_CASE] " << param.case_name << std::endl; | ||
| 49 | + | ||
| 50 | + aclTensor *context = param.context.GetViewDims().empty() ? nullptr : param.context.ToAclTypeRawPtr(); | ||
| 51 | + aclTensor *x1 = param.x1.GetViewDims().empty() ? nullptr : param.x1.ToAclTypeRawPtr(); | ||
| 52 | + aclTensor *x2 = param.x2.GetViewDims().empty() ? nullptr : param.x2.ToAclTypeRawPtr(); | ||
| 53 | + aclTensor *bias = param.bias.GetViewDims().empty() ? nullptr : param.bias.ToAclTypeRawPtr(); | ||
| 54 | + aclTensor *x1Scale = param.x1Scale.GetViewDims().empty() ? nullptr : param.x1Scale.ToAclTypeRawPtr(); | ||
| 55 | + aclTensor *x2Scale = param.x2Scale.GetViewDims().empty() ? nullptr : param.x2Scale.ToAclTypeRawPtr(); | ||
| 56 | + aclTensor *output = param.output.GetViewDims().empty() ? nullptr : param.output.ToAclTypeRawPtr(); | ||
| 57 | + aclTensor *gatherOut = param.gatherOut.GetViewDims().empty() ? nullptr : param.gatherOut.ToAclTypeRawPtr(); | ||
| 58 | + | ||
| 59 | + auto ut = OP_API_UT(aclnnAllGatherQuantMatmulV3, | ||
| 60 | + INPUT(context, x1, x2, bias, x1Scale, x2Scale, param.group.c_str(), param.rankSize, | ||
| 61 | + param.hcclBufferSize, param.groupSize, param.commMode.c_str()), | ||
| 62 | + OUTPUT(output, gatherOut)); | ||
| 63 | + uint64_t workspaceSize = 0; | ||
| 64 | + aclOpExecutor *executor = nullptr; | ||
| 65 | + aclnnStatus aclRet = ut.TestGetWorkspaceSizeWithNNopbaseInner(&workspaceSize, executor); | ||
| 66 | + if (param.expectResult == ACLNN_SUCCESS) { | ||
| 67 | + EXPECT_NE(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 68 | + } else { | ||
| 69 | + EXPECT_EQ(aclRet, param.expectResult); | ||
| 70 | + } | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +TEST_F(TestAclnnAllGatherMatmulV3, SecondPhaseNullExecutorTest) | ||
| 74 | +{ | ||
| 75 | + aclnnStatus aclRet = aclnnAllGatherQuantMatmulV3(nullptr, 0, nullptr, nullptr); | ||
| 76 | + EXPECT_EQ(aclRet, ACLNN_ERR_INNER_NULLPTR); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +TEST_F(TestAclnnAllGatherMatmulV3, NullGroupTest) | ||
| 80 | +{ | ||
| 81 | + TensorDesc contextDesc = TensorDesc({100}, ACL_INT32, ACL_FORMAT_ND); | ||
| 82 | + TensorDesc x1Desc = TensorDesc({2048, 4096}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND); | ||
| 83 | + TensorDesc x2Desc = TensorDesc({2560, 4096}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND); | ||
| 84 | + TensorDesc x1ScaleDesc = TensorDesc({2048, 64, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND); | ||
| 85 | + TensorDesc x2ScaleDesc = TensorDesc({2560, 64, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND); | ||
| 86 | + TensorDesc outputDesc = TensorDesc({8192, 2560}, ACL_BF16, ACL_FORMAT_ND); | ||
| 87 | + TensorDesc gatherOutDesc = TensorDesc({8192, 4096}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND); | ||
| 88 | + auto ut = OP_API_UT(aclnnAllGatherQuantMatmulV3, | ||
| 89 | + INPUT(contextDesc, x1Desc, x2Desc, nullptr, x1ScaleDesc, x2ScaleDesc, (const char *)nullptr, 4, | ||
| 90 | + 200, 4295032864L, "urma"), | ||
| 91 | + OUTPUT(outputDesc, gatherOutDesc)); | ||
| 92 | + uint64_t workspaceSize = 0; | ||
| 93 | + aclOpExecutor *executor = nullptr; | ||
| 94 | + aclnnStatus aclRet = ut.TestGetWorkspaceSizeWithNNopbaseInner(&workspaceSize, executor); | ||
| 95 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +TEST_F(TestAclnnAllGatherMatmulV3, EmptyGroupTest) | ||
| 99 | +{ | ||
| 100 | + TensorDesc contextDesc = TensorDesc({100}, ACL_INT32, ACL_FORMAT_ND); | ||
| 101 | + TensorDesc x1Desc = TensorDesc({2048, 4096}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND); | ||
| 102 | + TensorDesc x2Desc = TensorDesc({2560, 4096}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND); | ||
| 103 | + TensorDesc x1ScaleDesc = TensorDesc({2048, 64, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND); | ||
| 104 | + TensorDesc x2ScaleDesc = TensorDesc({2560, 64, 2}, ACL_FLOAT8_E8M0, ACL_FORMAT_ND); | ||
| 105 | + TensorDesc outputDesc = TensorDesc({8192, 2560}, ACL_BF16, ACL_FORMAT_ND); | ||
| 106 | + TensorDesc gatherOutDesc = TensorDesc({8192, 4096}, ACL_FLOAT8_E4M3FN, ACL_FORMAT_ND); | ||
| 107 | + auto ut = OP_API_UT( | ||
| 108 | + aclnnAllGatherQuantMatmulV3, | ||
| 109 | + INPUT(contextDesc, x1Desc, x2Desc, nullptr, x1ScaleDesc, x2ScaleDesc, "", 4, 200, 4295032864L, "urma"), | ||
| 110 | + OUTPUT(outputDesc, gatherOutDesc)); | ||
| 111 | + uint64_t workspaceSize = 0; | ||
| 112 | + aclOpExecutor *executor = nullptr; | ||
| 113 | + aclnnStatus aclRet = ut.TestGetWorkspaceSizeWithNNopbaseInner(&workspaceSize, executor); | ||
| 114 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +INSTANTIATE_TEST_SUITE_P( | ||
| 118 | + AllGatherMatmulV3, TestAclnnAllGatherMatmulV3, | ||
| 119 | + testing::ValuesIn(GetCasesFromCsv<AllGatherMatmulV3ApiUtParam>(ReplaceFileExtension2Csv(__FILE__))), | ||
| 120 | + PrintCaseInfoString<AllGatherMatmulV3ApiUtParam>); | ||
| 121 | + | ||
| 122 | +} // namespace AllGatherMatmulV3UT | ||
| @@ -0,0 +1,46 @@ | |||
| 1 | +case_name,expect_result,context_shape,context_dtype,context_format,x1_shape,x1_dtype,x1_format,x2_shape,x2_dtype,x2_format,bias_shape,bias_dtype,bias_format,x1_scale_shape,x1_scale_dtype,x1_scale_format,x2_scale_shape,x2_scale_dtype,x2_scale_format,output_shape,output_dtype,output_format,gather_out_shape,gather_out_dtype,gather_out_format,group,rank_size,hccl_buffer_size,group_size,comm_mode,x2_stride,x2_storage_shape | ||
| 2 | +test_aclnn_all_gather_matmul_v3_e4m3_e4m3_bf16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 3 | +test_aclnn_all_gather_matmul_v3_e4m3_e4m3_fp16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 4 | +test_aclnn_all_gather_matmul_v3_e5m2_e5m2_bf16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E5M2,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E5M2,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 5 | +test_aclnn_all_gather_matmul_v3_e5m2_e5m2_fp16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E5M2,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT8_E5M2,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 6 | +test_aclnn_all_gather_matmul_v3_e4m3_e5m2_bf16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E5M2,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 7 | +test_aclnn_all_gather_matmul_v3_e5m2_e4m3_fp16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT8_E5M2,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 8 | +test_aclnn_all_gather_matmul_v3_fp4_fp4_bf16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT4_E2M1,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT4_E2M1,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 9 | +test_aclnn_all_gather_matmul_v3_fp4_fp4_fp16_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT4_E2M1,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT4_E2M1,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 10 | +test_aclnn_all_gather_matmul_v3_e4m3_e4m3_bf16_no_bias_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 11 | +test_aclnn_all_gather_matmul_v3_e4m3_e4m3_bf16_m4096_n6144_true,SUCCESS,100,INT32,ND,4096 4096,FLOAT8_E4M3FN,ND,6144 4096,FLOAT8_E4M3FN,ND,6144,FLOAT,ND,4096 64 2,FLOAT8_E8M0,ND,6144 64 2,FLOAT8_E8M0,ND,16384 6144,BF16,ND,16384 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 12 | +test_aclnn_all_gather_matmul_v3_e4m3_e4m3_bf16_m8192_true,SUCCESS,100,INT32,ND,8192 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,8192 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,32768 2560,BF16,ND,32768 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 13 | +test_aclnn_all_gather_matmul_v3_e4m3_e4m3_bf16_m2061_true,SUCCESS,100,INT32,ND,2061 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2061 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8244 2560,BF16,ND,8244 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 14 | +test_aclnn_all_gather_matmul_v3_invalid_x1_dtype_false,PARAM_INVALID,100,INT32,ND,2048 4096,INT8,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,INT8,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 15 | +test_aclnn_all_gather_matmul_v3_invalid_x2_dtype_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 16 | +test_aclnn_all_gather_matmul_v3_fp4_mismatch_x1_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT4_E2M1,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 17 | +test_aclnn_all_gather_matmul_v3_fp4_mismatch_x2_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT4_E2M1,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 18 | +test_aclnn_all_gather_matmul_v3_invalid_output_dtype_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,INT8,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 19 | +test_aclnn_all_gather_matmul_v3_x1_1d_false,PARAM_INVALID,100,INT32,ND,4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,16384 0,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 20 | +test_aclnn_all_gather_matmul_v3_k_mismatch_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4032,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 63 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 21 | +test_aclnn_all_gather_matmul_v3_k_not_divisible_64_false,PARAM_INVALID,100,INT32,ND,2048 4033,FLOAT8_E4M3FN,ND,2560 4033,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 63 2,FLOAT8_E8M0,ND,2560 63 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4033,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 22 | +test_aclnn_all_gather_matmul_v3_x1_scale_wrong_shape_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,1024 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 23 | +test_aclnn_all_gather_matmul_v3_x2_scale_wrong_shape_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,1280 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 24 | +test_aclnn_all_gather_matmul_v3_output_n_mismatch_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 1280,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 25 | +test_aclnn_all_gather_matmul_v3_group_length_127_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is,4,200,4295032864,urma,, | ||
| 26 | +test_aclnn_all_gather_matmul_v3_null_context,PARAM_NULLPTR,,,,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 27 | +test_aclnn_all_gather_matmul_v3_null_x1,PARAM_NULLPTR,100,INT32,ND,,,,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 28 | +test_aclnn_all_gather_matmul_v3_null_x2,PARAM_NULLPTR,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,,,,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 29 | +test_aclnn_all_gather_matmul_v3_null_output,PARAM_NULLPTR,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,,,,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 30 | +test_aclnn_all_gather_matmul_v3_invalid_x1_scale_dtype,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 31 | +test_aclnn_all_gather_matmul_v3_invalid_x2_scale_dtype,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 32 | +test_aclnn_all_gather_matmul_v3_invalid_bias_dtype,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT16,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 33 | +test_aclnn_all_gather_matmul_v3_x1_format_nz,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,FRACTAL_NZ,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 34 | +test_aclnn_all_gather_matmul_v3_group_length_128_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_,4,200,4295032864,urma,, | ||
| 35 | +test_aclnn_all_gather_matmul_v3_group_length_129_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a_very_long_groupname_this_is_a,4,200,4295032864,urma,, | ||
| 36 | +test_aclnn_all_gather_matmul_v3_trans_x2_view_true,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,4096 2560,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,1 4096,2560 4096 | ||
| 37 | +test_aclnn_all_gather_matmul_v3_context_format_nz,PARAM_INVALID,100,INT32,FRACTAL_NZ,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 38 | +test_aclnn_all_gather_matmul_v3_x2_format_nz,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,FRACTAL_NZ,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 39 | +test_aclnn_all_gather_matmul_v3_output_format_nz,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,FRACTAL_NZ,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 40 | +test_aclnn_all_gather_matmul_v3_bias_format_nz,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,FRACTAL_NZ,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 41 | +test_aclnn_all_gather_matmul_v3_x1_scale_format_nz,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,FRACTAL_NZ,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 42 | +test_aclnn_all_gather_matmul_v3_x2_scale_format_nz,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,FRACTAL_NZ,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 43 | +test_aclnn_all_gather_matmul_v3_output_1d_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 44 | +test_aclnn_all_gather_matmul_v3_x1_scale_2d_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 45 | +test_aclnn_all_gather_matmul_v3_x2_scale_2d_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,all_gather_matmul_v3_test_group,4,200,4295032864,urma,, | ||
| 46 | +test_aclnn_all_gather_matmul_v3_hccl_buffer_size_zero_false,PARAM_INVALID,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,,,,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,4,0,4295032864,urma,, | ||
| @@ -0,0 +1,76 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#ifndef ALL_GATHER_MATMUL_V3_API_UT_PARAM_H | ||
| 12 | +#define ALL_GATHER_MATMUL_V3_API_UT_PARAM_H | ||
| 13 | + | ||
| 14 | +#include <sstream> | ||
| 15 | +#include <vector> | ||
| 16 | +#include <cstdlib> | ||
| 17 | +#include "op_api_csv_case_loader.h" | ||
| 18 | +#include "op_api_ut_common/array_desc.h" | ||
| 19 | + | ||
| 20 | +namespace AllGatherMatmulV3UT { | ||
| 21 | + | ||
| 22 | +struct AllGatherMatmulV3ApiUtParam { | ||
| 23 | + std::string case_name; | ||
| 24 | + TensorDesc context; | ||
| 25 | + TensorDesc x1; | ||
| 26 | + TensorDesc x2; | ||
| 27 | + TensorDesc bias; | ||
| 28 | + TensorDesc x1Scale; | ||
| 29 | + TensorDesc x2Scale; | ||
| 30 | + TensorDesc output; | ||
| 31 | + TensorDesc gatherOut; | ||
| 32 | + std::string group; | ||
| 33 | + int64_t rankSize; | ||
| 34 | + int64_t hcclBufferSize; | ||
| 35 | + int64_t groupSize; | ||
| 36 | + std::string commMode; | ||
| 37 | + aclnnStatus expectResult; | ||
| 38 | + | ||
| 39 | + explicit AllGatherMatmulV3ApiUtParam(const csv_map &csvMap) | ||
| 40 | + { | ||
| 41 | + this->case_name = ReadMap(csvMap, "case_name"); | ||
| 42 | + this->context = GetTensorACL(csvMap, "context_shape", "context_dtype", "context_format"); | ||
| 43 | + this->x1 = GetTensorACL(csvMap, "x1_shape", "x1_dtype", "x1_format"); | ||
| 44 | + this->x2 = GetTensorACL(csvMap, "x2_shape", "x2_dtype", "x2_format"); | ||
| 45 | + { | ||
| 46 | + // 非连续转置 x2:view 为 [K, N],storage 为 [N, K],用于覆盖 aclnn 层 TransX2Tensor | ||
| 47 | + std::string x2StrideStr = ReadMap(csvMap, "x2_stride"); | ||
| 48 | + if (!x2StrideStr.empty()) { | ||
| 49 | + aclDataType dtype = ReadMap(ACL_DTYPE, ReadMap(csvMap, "x2_dtype"), ACL_DT_UNDEFINED); | ||
| 50 | + aclFormat format = ReadMap(ACL_FORMAT, ReadMap(csvMap, "x2_format"), ACL_FORMAT_UNDEFINED); | ||
| 51 | + this->x2 = TensorDesc(GetShapeArr(ReadMap(csvMap, "x2_shape")), dtype, format, GetShapeArr(x2StrideStr), | ||
| 52 | + 0, GetShapeArr(ReadMap(csvMap, "x2_storage_shape"))); | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + this->bias = GetTensorACL(csvMap, "bias_shape", "bias_dtype", "bias_format"); | ||
| 56 | + this->x1Scale = GetTensorACL(csvMap, "x1_scale_shape", "x1_scale_dtype", "x1_scale_format"); | ||
| 57 | + this->x2Scale = GetTensorACL(csvMap, "x2_scale_shape", "x2_scale_dtype", "x2_scale_format"); | ||
| 58 | + this->output = GetTensorACL(csvMap, "output_shape", "output_dtype", "output_format"); | ||
| 59 | + this->gatherOut = GetTensorACL(csvMap, "gather_out_shape", "gather_out_dtype", "gather_out_format"); | ||
| 60 | + this->group = ReadMap(csvMap, "group", "group"); | ||
| 61 | + this->rankSize = stoll(ReadMap(csvMap, "rank_size", "4")); | ||
| 62 | + this->hcclBufferSize = stoll(ReadMap(csvMap, "hccl_buffer_size", "200")); | ||
| 63 | + this->groupSize = stoll(ReadMap(csvMap, "group_size", "4295032864")); | ||
| 64 | + this->commMode = ReadMap(csvMap, "comm_mode", "urma"); | ||
| 65 | + this->expectResult = GetAclnnRet(csvMap, "expect_result"); | ||
| 66 | + } | ||
| 67 | +}; | ||
| 68 | + | ||
| 69 | +inline std::ostream &operator<<(std::ostream &os, const AllGatherMatmulV3ApiUtParam ¶m) | ||
| 70 | +{ | ||
| 71 | + return os << param.case_name; | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +} // namespace AllGatherMatmulV3UT | ||
| 75 | + | ||
| 76 | +#endif // ALL_GATHER_MATMUL_V3_API_UT_PARAM_H | ||
| @@ -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 | +if(UT_TEST_ALL OR OP_HOST_UT) | ||
| 12 | + if(UT_INFERSHAPE_FLAG) | ||
| 13 | + add_modules_ut_sources(UT_NAME ${OP_INFERSHAPE_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 14 | + endif() | ||
| 15 | +endif() | ||
| 16 | + | ||
| 17 | +file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 18 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 19 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 20 | + add_subdirectory(${SUB_DIR}) | ||
| 21 | + endif() | ||
| 22 | +endforeach() | ||
| @@ -0,0 +1,84 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#ifndef ALL_GATHER_MATMUL_V3_HOST_UT_PARAM_H | ||
| 12 | +#define ALL_GATHER_MATMUL_V3_HOST_UT_PARAM_H | ||
| 13 | + | ||
| 14 | +#include <sstream> | ||
| 15 | +#include "op_host_csv_case_loader.h" | ||
| 16 | + | ||
| 17 | +namespace AllGatherMatmulV3UT { | ||
| 18 | + | ||
| 19 | +struct AllGatherMatmulV3HostUtParamBase { | ||
| 20 | + std::string case_name; | ||
| 21 | + ge::graphStatus expectResult; | ||
| 22 | + std::string group; | ||
| 23 | + int64_t hcclBufferSize; | ||
| 24 | + bool isTransA; | ||
| 25 | + bool isTransB; | ||
| 26 | + int64_t rankSize; | ||
| 27 | + int64_t groupSize; | ||
| 28 | + int64_t yDtypeAttr; | ||
| 29 | + std::string commMode; | ||
| 30 | + uint64_t rankNum; | ||
| 31 | + | ||
| 32 | + explicit AllGatherMatmulV3HostUtParamBase(const csv_map &csvMap) | ||
| 33 | + { | ||
| 34 | + this->case_name = ReadMap(csvMap, "case_name"); | ||
| 35 | + this->expectResult = Str2StatusGE(ReadMap(csvMap, "expectResult")); | ||
| 36 | + this->group = ReadMap(csvMap, "group", "group"); | ||
| 37 | + this->hcclBufferSize = stoll(ReadMap(csvMap, "hccl_buffer_size", "200")); | ||
| 38 | + this->isTransA = StrToBoolIgnoreCase(ReadMap(csvMap, "is_trans_a", "false")); | ||
| 39 | + this->isTransB = StrToBoolIgnoreCase(ReadMap(csvMap, "is_trans_b", "true")); | ||
| 40 | + this->rankSize = stoll(ReadMap(csvMap, "rank_size", "4")); | ||
| 41 | + this->groupSize = stoll(ReadMap(csvMap, "group_size", "4295032864")); | ||
| 42 | + this->yDtypeAttr = stoll(ReadMap(csvMap, "y_dtype_attr", "27")); | ||
| 43 | + this->commMode = ReadMap(csvMap, "comm_mode", "urma"); | ||
| 44 | + this->rankNum = static_cast<uint64_t>(stoull(ReadMap(csvMap, "rank_num", "4"))); | ||
| 45 | + } | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +inline std::ostream &operator<<(std::ostream &os, const AllGatherMatmulV3HostUtParamBase ¶m) | ||
| 49 | +{ | ||
| 50 | + return os << param.case_name; | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +struct AllGatherMatmulV3TilingUtParam : public AllGatherMatmulV3HostUtParamBase { | ||
| 54 | + gert::TilingContextPara::TensorDescription context = TD_DEFAULT; | ||
| 55 | + gert::TilingContextPara::TensorDescription x1 = TD_DEFAULT; | ||
| 56 | + gert::TilingContextPara::TensorDescription x2 = TD_DEFAULT; | ||
| 57 | + gert::TilingContextPara::TensorDescription bias = TD_DEFAULT; | ||
| 58 | + gert::TilingContextPara::TensorDescription x1Scale = TD_DEFAULT; | ||
| 59 | + gert::TilingContextPara::TensorDescription x2Scale = TD_DEFAULT; | ||
| 60 | + gert::TilingContextPara::TensorDescription y = TD_DEFAULT; | ||
| 61 | + gert::TilingContextPara::TensorDescription gatherOut = TD_DEFAULT; | ||
| 62 | + std::string soc; | ||
| 63 | + uint64_t expectTilingKey; | ||
| 64 | + | ||
| 65 | + explicit AllGatherMatmulV3TilingUtParam(const csv_map &csvMap) | ||
| 66 | + : AllGatherMatmulV3HostUtParamBase(csvMap) | ||
| 67 | + { | ||
| 68 | + GetTensorGE(csvMap, "context_shape", "context_dtype", "context_format", this->context); | ||
| 69 | + GetTensorGE(csvMap, "x1_shape", "x1_dtype", "x1_format", this->x1); | ||
| 70 | + GetTensorGE(csvMap, "x2_shape", "x2_dtype", "x2_format", this->x2); | ||
| 71 | + GetTensorGE(csvMap, "bias_shape", "bias_dtype", "bias_format", this->bias); | ||
| 72 | + GetTensorGE(csvMap, "x1_scale_shape", "x1_scale_dtype", "x1_scale_format", this->x1Scale); | ||
| 73 | + GetTensorGE(csvMap, "x2_scale_shape", "x2_scale_dtype", "x2_scale_format", this->x2Scale); | ||
| 74 | + GetTensorGE(csvMap, "y_shape", "y_dtype", "y_format", this->y); | ||
| 75 | + GetTensorGE(csvMap, "gather_out_shape", "gather_out_dtype", "gather_out_format", this->gatherOut); | ||
| 76 | + this->soc = ReadMap(csvMap, "soc_version", "3510"); | ||
| 77 | + std::string tilingKeyStr = ReadMap(csvMap, "expectTilingKey"); | ||
| 78 | + this->expectTilingKey = tilingKeyStr.empty() ? UINT64_MAX : stoull(tilingKeyStr); | ||
| 79 | + } | ||
| 80 | +}; | ||
| 81 | + | ||
| 82 | +} // namespace AllGatherMatmulV3UT | ||
| 83 | + | ||
| 84 | +#endif // ALL_GATHER_MATMUL_V3_HOST_UT_PARAM_H | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +if(UT_TEST_ALL OR OP_HOST_UT) | ||
| 12 | + add_modules_ut_sources(UT_NAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 13 | +endif() | ||
| @@ -0,0 +1,74 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file test_all_gather_matmul_v3_tiling.cpp | ||
| 13 | + * \brief host侧tiling ut | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <gtest/gtest.h> | ||
| 17 | +#include "../all_gather_matmul_v3_host_ut_param.h" | ||
| 18 | +#include "mc2_tiling_case_executor.h" | ||
| 19 | + | ||
| 20 | +namespace AllGatherMatmulV3UT { | ||
| 21 | + | ||
| 22 | +static const std::string OP_NAME = "AllGatherMatmulV3"; | ||
| 23 | + | ||
| 24 | +static struct AllGatherMatmulV3CompileInfo { | ||
| 25 | +} compileInfo; | ||
| 26 | + | ||
| 27 | +class AllGatherMatmulV3Arch35TilingTest : public testing::TestWithParam<AllGatherMatmulV3TilingUtParam> { | ||
| 28 | +protected: | ||
| 29 | + static void SetUpTestCase() | ||
| 30 | + { | ||
| 31 | + setenv("HCCL_BUFFSIZE", "300", 1); | ||
| 32 | + std::cout << "AllGatherMatmulV3Arch35TilingTest SetUp." << std::endl; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + static void TearDownTestCase() | ||
| 36 | + { | ||
| 37 | + unsetenv("HCCL_BUFFSIZE"); | ||
| 38 | + std::cout << "AllGatherMatmulV3Arch35TilingTest TearDown." << std::endl; | ||
| 39 | + } | ||
| 40 | +}; | ||
| 41 | + | ||
| 42 | +TEST_P(AllGatherMatmulV3Arch35TilingTest, param) | ||
| 43 | +{ | ||
| 44 | + auto param = GetParam(); | ||
| 45 | + std::cout << "[TEST_CASE] " << param.case_name << std::endl; | ||
| 46 | + | ||
| 47 | + std::vector<gert::TilingContextPara::TensorDescription> inputTensorDesc_( | ||
| 48 | + {param.context, param.x1, param.x2, param.bias, param.x1Scale, param.x2Scale}); | ||
| 49 | + | ||
| 50 | + std::vector<gert::TilingContextPara::TensorDescription> outputTensorDesc_({param.y, param.gatherOut}); | ||
| 51 | + | ||
| 52 | + std::vector<gert::TilingContextPara::OpAttr> attrs_( | ||
| 53 | + {{"group", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.group)}, | ||
| 54 | + {"hccl_buffer_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.hcclBufferSize)}, | ||
| 55 | + {"is_trans_a", Ops::Transformer::AnyValue::CreateFrom<bool>(param.isTransA)}, | ||
| 56 | + {"is_trans_b", Ops::Transformer::AnyValue::CreateFrom<bool>(param.isTransB)}, | ||
| 57 | + {"rank_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.rankSize)}, | ||
| 58 | + {"group_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.groupSize)}, | ||
| 59 | + {"y_dtype", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.yDtypeAttr)}, | ||
| 60 | + {"comm_mode", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.commMode)}}); | ||
| 61 | + | ||
| 62 | + gert::TilingContextPara tilingContextPara(OP_NAME, inputTensorDesc_, outputTensorDesc_, attrs_, &compileInfo, | ||
| 63 | + param.soc, 64, 262144, 8192); | ||
| 64 | + Mc2Hcom::MockValues hcomTopologyMockValues{{"rankNum", param.rankNum}}; | ||
| 65 | + Mc2ExecuteTestCase(tilingContextPara, hcomTopologyMockValues, param.expectResult, param.expectTilingKey, "", {}, | ||
| 66 | + MC2_TILING_DATA_RESERVED_LEN); | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +INSTANTIATE_TEST_SUITE_P( | ||
| 70 | + AllGatherMatmulV3TilingUT, AllGatherMatmulV3Arch35TilingTest, | ||
| 71 | + testing::ValuesIn(GetCasesFromCsv<AllGatherMatmulV3TilingUtParam>(ReplaceFileExtension2Csv(__FILE__))), | ||
| 72 | + PrintCaseInfoString<AllGatherMatmulV3TilingUtParam>); | ||
| 73 | + | ||
| 74 | +} // namespace AllGatherMatmulV3UT | ||
| @@ -0,0 +1,44 @@ | |||
| 1 | +case_name,expectResult,context_shape,context_dtype,context_format,x1_shape,x1_dtype,x1_format,x2_shape,x2_dtype,x2_format,bias_shape,bias_dtype,bias_format,x1_scale_shape,x1_scale_dtype,x1_scale_format,x2_scale_shape,x2_scale_dtype,x2_scale_format,y_shape,y_dtype,y_format,gather_out_shape,gather_out_dtype,gather_out_format,group,hccl_buffer_size,is_trans_a,is_trans_b,rank_size,group_size,y_dtype_attr,comm_mode,rank_num,soc_version,expectTilingKey | ||
| 2 | +all_gather_matmul_v3_case_e4m3_bf16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 3 | +all_gather_matmul_v3_case_e4m3_fp16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,1,urma,4,3510, | ||
| 4 | +all_gather_matmul_v3_case_e5m2_bf16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E5M2,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E5M2,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 5 | +all_gather_matmul_v3_case_e5m2_fp16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E5M2,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT8_E5M2,ND,group,209715200,false,true,4,4295032864,1,urma,4,3510, | ||
| 6 | +all_gather_matmul_v3_case_e4m3_e5m2_bf16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E5M2,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 7 | +all_gather_matmul_v3_case_e5m2_e4m3_fp16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT8_E5M2,ND,group,209715200,false,true,4,4295032864,1,urma,4,3510, | ||
| 8 | +all_gather_matmul_v3_case_fp4_bf16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT4_E2M1,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT4_E2M1,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 9 | +all_gather_matmul_v3_case_fp4_fp16_rank4,SUCCESS,100,INT32,ND,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT4_E2M1,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,FLOAT16,ND,8192 4096,FLOAT4_E2M1,ND,group,209715200,false,true,4,4295032864,1,urma,4,3510, | ||
| 10 | +all_gather_matmul_v3_case_e4m3_bf16_rank2,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,4096 2560,BF16,ND,4096 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,2,4295032864,27,urma,2,3510, | ||
| 11 | +all_gather_matmul_v3_case_e4m3_bf16_rank8,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,16384 2560,BF16,ND,16384 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,8,4295032864,27,urma,8,3510, | ||
| 12 | +all_gather_matmul_v3_case_e4m3_bf16_rank16,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,32768 2560,BF16,ND,32768 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,16,4295032864,27,urma,16,3510, | ||
| 13 | +all_gather_matmul_v3_case_e4m3_fp16_rank4_m2061,SUCCESS,100,INT32,ND,2061 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2061 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8244 2560,FLOAT16,ND,8244 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,1,urma,4,3510, | ||
| 14 | +all_gather_matmul_v3_case_e4m3_bf16_rank4_n6144,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,6144 4096,FLOAT8_E4M3FN,ND,6144,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,6144 64 2,FLOAT8_E8M0,ND,8192 6144,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 15 | +all_gather_matmul_v3_case_e4m3_fp16_rank4_m8192,SUCCESS,100,INT32,ND,8192 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,8192 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,32768 2560,FLOAT16,ND,32768 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,1,urma,4,3510, | ||
| 16 | +all_gather_matmul_v3_case_e4m3_bf16_rank4_m3072,SUCCESS,100,INT32,ND,3072 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,3072 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,12288 2560,BF16,ND,12288 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 17 | +all_gather_matmul_v3_case_group_size_zero_infer,SUCCESS,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,0,27,urma,4,3510, | ||
| 18 | +all_gather_matmul_v3_abuse_case_invalid_x1_dtype,FAILED,100,INT32,ND,2048 4096,INT8,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,INT8,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 19 | +all_gather_matmul_v3_abuse_case_invalid_x2_dtype,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 20 | +all_gather_matmul_v3_abuse_case_fp4_mismatch_x1,FAILED,100,INT32,ND,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT4_E2M1,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 21 | +all_gather_matmul_v3_abuse_case_fp4_mismatch_x2,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT4_E2M1,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 22 | +all_gather_matmul_v3_abuse_case_invalid_y_dtype,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,INT8,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,2,urma,4,3510, | ||
| 23 | +all_gather_matmul_v3_abuse_case_invalid_x1_scale_dtype,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 24 | +all_gather_matmul_v3_abuse_case_invalid_x2_scale_dtype,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 25 | +all_gather_matmul_v3_abuse_case_invalid_bias_dtype,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT16,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 26 | +all_gather_matmul_v3_abuse_case_x1_1d,FAILED,100,INT32,ND,4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,16384 0,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 27 | +all_gather_matmul_v3_abuse_case_x2_3d,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2 2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 28 | +all_gather_matmul_v3_abuse_case_y_3d,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,2 4096 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 29 | +all_gather_matmul_v3_abuse_case_k_mismatch,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4032,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 63 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 30 | +all_gather_matmul_v3_abuse_case_k_not_divisible_64,FAILED,100,INT32,ND,2048 4033,FLOAT8_E4M3FN,ND,2560 4033,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 63 2,FLOAT8_E8M0,ND,2560 63 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4033,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 31 | +all_gather_matmul_v3_abuse_case_k_exceeds_max,FAILED,100,INT32,ND,2048 65536,FLOAT8_E4M3FN,ND,2560 65536,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 1024 2,FLOAT8_E8M0,ND,2560 1024 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 65536,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 32 | +all_gather_matmul_v3_abuse_case_invalid_rank_size,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,6144 2560,BF16,ND,6144 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,3,4295032864,27,urma,3,3510, | ||
| 33 | +all_gather_matmul_v3_abuse_case_is_trans_b_false,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,false,4,4295032864,27,urma,4,3510, | ||
| 34 | +all_gather_matmul_v3_abuse_case_comm_mode_ai_cpu,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,ai_cpu,4,3510, | ||
| 35 | +all_gather_matmul_v3_abuse_case_x1_scale_wrong_shape,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,1024 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 36 | +all_gather_matmul_v3_abuse_case_x2_scale_wrong_shape,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,1280 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 37 | +all_gather_matmul_v3_abuse_case_y_shape_mismatch,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,4096 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 38 | +all_gather_matmul_v3_abuse_case_x1_format_nz,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,FRACTAL_NZ,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 39 | +all_gather_matmul_v3_abuse_case_x1_scale_2d,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 40 | +all_gather_matmul_v3_abuse_case_bias_wrong_shape,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,1280,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 41 | +all_gather_matmul_v3_abuse_case_m_zero,FAILED,100,INT32,ND,0 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,0 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,0 2560,BF16,ND,0 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 42 | +all_gather_matmul_v3_abuse_case_k_zero,FAILED,100,INT32,ND,2048 0,FLOAT8_E4M3FN,ND,2560 0,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 0 2,FLOAT8_E8M0,ND,2560 0 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 0,FLOAT8_E4M3FN,ND,group,209715200,false,true,4,4295032864,27,urma,4,3510, | ||
| 43 | +all_gather_matmul_v3_abuse_case_rank_size_zero,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,209715200,false,true,0,4295032864,27,urma,4,3510, | ||
| 44 | +all_gather_matmul_v3_abuse_case_hccl_buffer_too_small,FAILED,100,INT32,ND,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2560,FLOAT,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,8192 2560,BF16,ND,8192 4096,FLOAT8_E4M3FN,ND,group,33554432,false,true,4,4295032864,27,urma,4,3510, | ||
| @@ -0,0 +1,82 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file test_all_gather_matmul_v3_dtype_infershape.cpp | ||
| 13 | + * \brief inferdtype ut | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <gtest/gtest.h> | ||
| 17 | +#include "test_all_gather_matmul_v3_host_ut_param.h" | ||
| 18 | +#include "infer_datatype_context_faker.h" | ||
| 19 | +#include "base/registry/op_impl_space_registry_v2.h" | ||
| 20 | + | ||
| 21 | +namespace AllGatherMatmulV3UT { | ||
| 22 | + | ||
| 23 | +class AllGatherMatmulV3InferDataTypeTest : public testing::TestWithParam<AllGatherMatmulV3InferDataTypeUtParam> { | ||
| 24 | +protected: | ||
| 25 | + static void SetUpTestCase() | ||
| 26 | + { | ||
| 27 | + std::cout << "AllGatherMatmulV3InferDataTypeTest SetUp" << std::endl; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + static void TearDownTestCase() | ||
| 31 | + { | ||
| 32 | + std::cout << "AllGatherMatmulV3InferDataTypeTest TearDown" << std::endl; | ||
| 33 | + } | ||
| 34 | +}; | ||
| 35 | + | ||
| 36 | +TEST_P(AllGatherMatmulV3InferDataTypeTest, param) | ||
UT增加更多异常用例 ![]() ![]() | |||
| 37 | +{ | ||
| 38 | + auto param = GetParam(); | ||
| 39 | + std::cout << "[TEST_CASE] " << param.case_name << std::endl; | ||
| 40 | + | ||
| 41 | + // def 输入顺序: context(0) x1(1) x2(2) bias(3) x1_scale(4) x2_scale(5),仅放入已实例化的输入 | ||
| 42 | + ge::DataType contextDtype = ge::DT_INT32; | ||
| 43 | + std::vector<void *> inputDataTypes; | ||
| 44 | + inputDataTypes.emplace_back(&contextDtype); | ||
| 45 | + inputDataTypes.emplace_back(¶m.x1); | ||
| 46 | + inputDataTypes.emplace_back(¶m.x2); | ||
| 47 | + inputDataTypes.emplace_back(¶m.x1Scale); | ||
| 48 | + inputDataTypes.emplace_back(¶m.x2Scale); | ||
| 49 | + | ||
| 50 | + auto contextHolder = | ||
| 51 | + gert::InferDataTypeContextFaker() | ||
| 52 | + .SetOpType("AllGatherMatmulV3") | ||
| 53 | + .IrInstanceNum(param.inputInstance, param.outputInstance) | ||
| 54 | + .InputDataTypes(inputDataTypes) | ||
| 55 | + .NodeOutputTd(0, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 56 | + .NodeOutputTd(1, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 57 | + .NodeAttrs({{"group", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.group)}, | ||
| 58 | + {"hccl_buffer_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.hcclBufferSize)}, | ||
| 59 | + {"is_trans_a", Ops::Transformer::AnyValue::CreateFrom<bool>(param.isTransA)}, | ||
| 60 | + {"is_trans_b", Ops::Transformer::AnyValue::CreateFrom<bool>(param.isTransB)}, | ||
| 61 | + {"rank_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.rankSize)}, | ||
| 62 | + {"group_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.groupSize)}, | ||
| 63 | + {"y_dtype", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.yDtypeAttr)}, | ||
| 64 | + {"comm_mode", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.commMode)}}) | ||
| 65 | + .Build(); | ||
| 66 | + | ||
| 67 | + auto spaceRegistry = gert::DefaultOpImplSpaceRegistryV2::GetInstance().GetSpaceRegistry(); | ||
| 68 | + auto inferDtypeFunc = spaceRegistry->GetOpImpl("AllGatherMatmulV3")->infer_datatype; | ||
| 69 | + ASSERT_EQ(inferDtypeFunc(contextHolder.GetContext<gert::InferDataTypeContext>()), param.expectResult); | ||
| 70 | + if (param.expectResult == ge::GRAPH_SUCCESS) { | ||
| 71 | + EXPECT_EQ(contextHolder.GetContext<gert::InferDataTypeContext>()->GetOutputDataType(0), param.expectYDtype); | ||
| 72 | + EXPECT_EQ(contextHolder.GetContext<gert::InferDataTypeContext>()->GetOutputDataType(1), | ||
| 73 | + param.expectGatherOutDtype); | ||
| 74 | + } | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +INSTANTIATE_TEST_SUITE_P( | ||
| 78 | + AllGatherMatmulV3InferDataTypeUT, AllGatherMatmulV3InferDataTypeTest, | ||
| 79 | + testing::ValuesIn(GetCasesFromCsv<AllGatherMatmulV3InferDataTypeUtParam>(ReplaceFileExtension2Csv(__FILE__))), | ||
| 80 | + PrintCaseInfoString<AllGatherMatmulV3InferDataTypeUtParam>); | ||
| 81 | + | ||
| 82 | +} // namespace AllGatherMatmulV3UT | ||
| @@ -0,0 +1,8 @@ | |||
| 1 | +case_name,expectResult,x1_dtype,x2_dtype,x1_scale_dtype,x2_scale_dtype,y_dtype_attr,expect_y_dtype,expect_gather_out_dtype | ||
| 2 | +e4m3_e4m3_bf16,SUCCESS,FLOAT8_E4M3FN,FLOAT8_E4M3FN,FLOAT8_E8M0,FLOAT8_E8M0,27,BF16,FLOAT8_E4M3FN | ||
| 3 | +e4m3_e4m3_fp16,SUCCESS,FLOAT8_E4M3FN,FLOAT8_E4M3FN,FLOAT8_E8M0,FLOAT8_E8M0,1,FLOAT16,FLOAT8_E4M3FN | ||
| 4 | +e4m3_e5m2_bf16,SUCCESS,FLOAT8_E4M3FN,FLOAT8_E5M2,FLOAT8_E8M0,FLOAT8_E8M0,27,BF16,FLOAT8_E4M3FN | ||
| 5 | +e5m2_e4m3_fp16,SUCCESS,FLOAT8_E5M2,FLOAT8_E4M3FN,FLOAT8_E8M0,FLOAT8_E8M0,1,FLOAT16,FLOAT8_E5M2 | ||
| 6 | +fp4_fp4_bf16,SUCCESS,FLOAT4_E2M1,FLOAT4_E2M1,FLOAT8_E8M0,FLOAT8_E8M0,27,BF16,FLOAT4_E2M1 | ||
| 7 | +invalid_y_dtype_int32,FAILED,FLOAT8_E4M3FN,FLOAT8_E4M3FN,FLOAT8_E8M0,FLOAT8_E8M0,3,, | ||
| 8 | +invalid_y_dtype_undefined,FAILED,FLOAT8_E4M3FN,FLOAT8_E4M3FN,FLOAT8_E8M0,FLOAT8_E8M0,28,, | ||
| @@ -0,0 +1,89 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#ifndef TEST_ALL_GATHER_MATMUL_V3_HOST_UT_PARAM_H | ||
| 12 | +#define TEST_ALL_GATHER_MATMUL_V3_HOST_UT_PARAM_H | ||
| 13 | + | ||
| 14 | +#include <sstream> | ||
| 15 | +#include "all_gather_matmul_v3_host_ut_param.h" | ||
| 16 | + | ||
| 17 | +namespace AllGatherMatmulV3UT { | ||
| 18 | + | ||
| 19 | +struct AllGatherMatmulV3InferShapeUtParam : public AllGatherMatmulV3HostUtParamBase { | ||
| 20 | + gert::InfershapeContextPara::TensorDescription context = ID_DEFAULT; | ||
| 21 | + gert::InfershapeContextPara::TensorDescription x1 = ID_DEFAULT; | ||
| 22 | + gert::InfershapeContextPara::TensorDescription x2 = ID_DEFAULT; | ||
| 23 | + gert::InfershapeContextPara::TensorDescription bias = ID_DEFAULT; | ||
| 24 | + gert::InfershapeContextPara::TensorDescription x1Scale = ID_DEFAULT; | ||
| 25 | + gert::InfershapeContextPara::TensorDescription x2Scale = ID_DEFAULT; | ||
| 26 | + gert::InfershapeContextPara::TensorDescription y = ID_DEFAULT; | ||
| 27 | + gert::InfershapeContextPara::TensorDescription gatherOut = ID_DEFAULT; | ||
| 28 | + std::vector<uint32_t> inputInstance; | ||
| 29 | + std::vector<uint32_t> outputInstance; | ||
| 30 | + std::vector<std::vector<int64_t>> expectOutputShape; | ||
| 31 | + | ||
| 32 | + explicit AllGatherMatmulV3InferShapeUtParam(const csv_map &csvMap) | ||
| 33 | + : AllGatherMatmulV3HostUtParamBase(csvMap) | ||
| 34 | + { | ||
| 35 | + // def 输入顺序: context(0) x1(1) x2(2) bias(3) x1_scale(4) x2_scale(5),context 恒实例化 | ||
| 36 | + this->context = gert::InfershapeContextPara::TensorDescription(gert::StorageShape({100}, {100}), ge::DT_INT32, | ||
| 37 | + ge::FORMAT_ND); | ||
| 38 | + this->inputInstance.emplace_back(1); | ||
| 39 | + this->inputInstance.emplace_back(GetTensorGE(csvMap, "x1_shape", "x1_dtype", "x1_format", this->x1)); | ||
| 40 | + this->inputInstance.emplace_back(GetTensorGE(csvMap, "x2_shape", "x2_dtype", "x2_format", this->x2)); | ||
| 41 | + this->inputInstance.emplace_back(GetTensorGE(csvMap, "bias_shape", "bias_dtype", "bias_format", this->bias)); | ||
| 42 | + this->inputInstance.emplace_back( | ||
| 43 | + GetTensorGE(csvMap, "x1_scale_shape", "x1_scale_dtype", "x1_scale_format", this->x1Scale)); | ||
| 44 | + this->inputInstance.emplace_back( | ||
| 45 | + GetTensorGE(csvMap, "x2_scale_shape", "x2_scale_dtype", "x2_scale_format", this->x2Scale)); | ||
| 46 | + this->y = gert::InfershapeContextPara::TensorDescription({}, Str2DTypeGE(ReadMap(csvMap, "y_dtype", "BF16")), | ||
| 47 | + ge::FORMAT_ND); | ||
| 48 | + this->gatherOut = gert::InfershapeContextPara::TensorDescription( | ||
| 49 | + {}, Str2DTypeGE(ReadMap(csvMap, "gather_out_dtype", "FLOAT8_E4M3FN")), ge::FORMAT_ND); | ||
| 50 | + // def 输出顺序: y(0) gather_out(1) amax_out(2),amax_out 未实现不实例化 | ||
| 51 | + this->outputInstance = {1, 1, 0}; | ||
| 52 | + if (this->expectResult == ge::GRAPH_SUCCESS) { | ||
| 53 | + this->expectOutputShape.emplace_back(GetShapeArr(ReadMap(csvMap, "expect_y_shape"))); | ||
| 54 | + this->expectOutputShape.emplace_back(GetShapeArr(ReadMap(csvMap, "expect_gather_out_shape"))); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | +}; | ||
| 58 | + | ||
| 59 | +struct AllGatherMatmulV3InferDataTypeUtParam : public AllGatherMatmulV3HostUtParamBase { | ||
| 60 | + ge::DataType x1 = ge::DT_UNDEFINED; | ||
| 61 | + ge::DataType x2 = ge::DT_UNDEFINED; | ||
| 62 | + ge::DataType x1Scale = ge::DT_UNDEFINED; | ||
| 63 | + ge::DataType x2Scale = ge::DT_UNDEFINED; | ||
| 64 | + std::vector<uint32_t> inputInstance; | ||
| 65 | + std::vector<uint32_t> outputInstance; | ||
| 66 | + ge::DataType expectYDtype = ge::DT_UNDEFINED; | ||
| 67 | + ge::DataType expectGatherOutDtype = ge::DT_UNDEFINED; | ||
| 68 | + | ||
| 69 | + explicit AllGatherMatmulV3InferDataTypeUtParam(const csv_map &csvMap) | ||
| 70 | + : AllGatherMatmulV3HostUtParamBase(csvMap) | ||
| 71 | + { | ||
| 72 | + GetDataTypeGE(csvMap, "x1_dtype", this->x1); | ||
| 73 | + GetDataTypeGE(csvMap, "x2_dtype", this->x2); | ||
| 74 | + GetDataTypeGE(csvMap, "x1_scale_dtype", this->x1Scale); | ||
| 75 | + GetDataTypeGE(csvMap, "x2_scale_dtype", this->x2Scale); | ||
| 76 | + // def 输入顺序: context(0) x1(1) x2(2) bias(3) x1_scale(4) x2_scale(5),bias 不实例化 | ||
| 77 | + this->inputInstance = {1, 1, 1, 0, 1, 1}; | ||
| 78 | + // def 输出顺序: y(0) gather_out(1) amax_out(2),amax_out 未实现不实例化 | ||
| 79 | + this->outputInstance = {1, 1, 0}; | ||
| 80 | + if (this->expectResult == ge::GRAPH_SUCCESS) { | ||
| 81 | + this->expectYDtype = Str2DTypeGE(ReadMap(csvMap, "expect_y_dtype")); | ||
| 82 | + this->expectGatherOutDtype = Str2DTypeGE(ReadMap(csvMap, "expect_gather_out_dtype")); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | +}; | ||
| 86 | + | ||
| 87 | +} // namespace AllGatherMatmulV3UT | ||
| 88 | + | ||
| 89 | +#endif // TEST_ALL_GATHER_MATMUL_V3_HOST_UT_PARAM_H | ||
| @@ -0,0 +1,76 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +/*! | ||
| 12 | + * \file test_all_gather_matmul_v3_shape_infershape.cpp | ||
| 13 | + * \brief infershape ut | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | +#include <gtest/gtest.h> | ||
| 17 | +#include "test_all_gather_matmul_v3_host_ut_param.h" | ||
| 18 | +#include "mc2_infer_shape_case_executor.h" | ||
| 19 | + | ||
| 20 | +namespace AllGatherMatmulV3UT { | ||
| 21 | + | ||
| 22 | +class AllGatherMatmulV3InferShapeTest : public testing::TestWithParam<AllGatherMatmulV3InferShapeUtParam> { | ||
| 23 | +protected: | ||
| 24 | + static void SetUpTestCase() | ||
| 25 | + { | ||
| 26 | + std::cout << "AllGatherMatmulV3InferShapeTest SetUp" << std::endl; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + static void TearDownTestCase() | ||
| 30 | + { | ||
| 31 | + std::cout << "AllGatherMatmulV3InferShapeTest TearDown" << std::endl; | ||
| 32 | + } | ||
| 33 | +}; | ||
| 34 | + | ||
| 35 | +TEST_P(AllGatherMatmulV3InferShapeTest, param) | ||
| 36 | +{ | ||
| 37 | + auto param = GetParam(); | ||
| 38 | + std::cout << "[TEST_CASE] " << param.case_name << std::endl; | ||
| 39 | + | ||
| 40 | + // def 输入顺序: context(0) x1(1) x2(2) bias(3) x1_scale(4) x2_scale(5),仅放入已实例化的输入 | ||
| 41 | + std::vector<gert::InfershapeContextPara::TensorDescription> inputTensorDesc; | ||
| 42 | + inputTensorDesc.emplace_back(param.context); | ||
| 43 | + if (param.inputInstance[1] == 1) | ||
| 44 | + inputTensorDesc.emplace_back(param.x1); | ||
| 45 | + if (param.inputInstance[2] == 1) | ||
| 46 | + inputTensorDesc.emplace_back(param.x2); | ||
| 47 | + if (param.inputInstance[3] == 1) | ||
| 48 | + inputTensorDesc.emplace_back(param.bias); | ||
| 49 | + if (param.inputInstance[4] == 1) | ||
| 50 | + inputTensorDesc.emplace_back(param.x1Scale); | ||
| 51 | + if (param.inputInstance[5] == 1) | ||
| 52 | + inputTensorDesc.emplace_back(param.x2Scale); | ||
| 53 | + std::vector<gert::InfershapeContextPara::TensorDescription> outputTensorDesc({param.y, param.gatherOut}); | ||
| 54 | + | ||
| 55 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 56 | + "AllGatherMatmulV3", inputTensorDesc, outputTensorDesc, | ||
| 57 | + {{"group", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.group)}, | ||
| 58 | + {"hccl_buffer_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.hcclBufferSize)}, | ||
| 59 | + {"is_trans_a", Ops::Transformer::AnyValue::CreateFrom<bool>(param.isTransA)}, | ||
| 60 | + {"is_trans_b", Ops::Transformer::AnyValue::CreateFrom<bool>(param.isTransB)}, | ||
| 61 | + {"rank_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.rankSize)}, | ||
| 62 | + {"group_size", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.groupSize)}, | ||
| 63 | + {"y_dtype", Ops::Transformer::AnyValue::CreateFrom<int64_t>(param.yDtypeAttr)}, | ||
| 64 | + {"comm_mode", Ops::Transformer::AnyValue::CreateFrom<std::string>(param.commMode)}}, | ||
| 65 | + param.inputInstance, param.outputInstance); | ||
| 66 | + Mc2Hcom::MockValues hcomTopologyMockValues{{"rankNum", param.rankNum}}; | ||
| 67 | + | ||
| 68 | + Mc2ExecuteTestCase(infershapeContextPara, hcomTopologyMockValues, param.expectResult, param.expectOutputShape); | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +INSTANTIATE_TEST_SUITE_P( | ||
| 72 | + AllGatherMatmulV3InferShapeUT, AllGatherMatmulV3InferShapeTest, | ||
| 73 | + testing::ValuesIn(GetCasesFromCsv<AllGatherMatmulV3InferShapeUtParam>(ReplaceFileExtension2Csv(__FILE__))), | ||
| 74 | + PrintCaseInfoString<AllGatherMatmulV3InferShapeUtParam>); | ||
| 75 | + | ||
| 76 | +} // namespace AllGatherMatmulV3UT | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +case_name,expectResult,x1_shape,x1_dtype,x1_format,x2_shape,x2_dtype,x2_format,x1_scale_shape,x1_scale_dtype,x1_scale_format,x2_scale_shape,x2_scale_dtype,x2_scale_format,y_dtype,gather_out_dtype,rank_size,is_trans_b,expect_y_shape,expect_gather_out_shape | ||
| 2 | +basic_2d_e4m3_rank4,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,8192 2560,8192 4096 | ||
| 3 | +basic_2d_e4m3_rank2,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,2,true,4096 2560,4096 4096 | ||
| 4 | +basic_2d_e4m3_rank8,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,8,true,16384 2560,16384 4096 | ||
| 5 | +basic_2d_e4m3_rank16,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,16,true,32768 2560,32768 4096 | ||
| 6 | +basic_2d_e5m2_rank4,SUCCESS,2048 4096,FLOAT8_E5M2,ND,2560 4096,FLOAT8_E5M2,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,FLOAT16,FLOAT8_E5M2,4,true,8192 2560,8192 4096 | ||
| 7 | +basic_2d_fp4_rank4,SUCCESS,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT4_E2M1,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT4_E2M1,4,true,8192 2560,8192 4096 | ||
| 8 | +basic_2d_mixed_e4m3_e5m2_rank4,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E5M2,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,8192 2560,8192 4096 | ||
| 9 | +dynamic_m,SUCCESS,-1 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,-1 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,-1 -1,-1 -1 | ||
| 10 | +dynamic_k,SUCCESS,2048 -1,FLOAT8_E4M3FN,ND,2560 -1,FLOAT8_E4M3FN,ND,2048 -1 2,FLOAT8_E8M0,ND,2560 -1 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,8192 2560,-1 -1 | ||
| 11 | +dynamic_n,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,-1 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,-1 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,-1 -1,8192 4096 | ||
| 12 | +invalid_x1_dtype,FAILED,2048 4096,FLOAT,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT,4,true,, | ||
| 13 | +invalid_x2_dtype,FAILED,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,INT8,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,, | ||
| 14 | +fp4_mismatch,FAILED,2048 4096,FLOAT4_E2M1,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT4_E2M1,4,true,, | ||
| 15 | +k_mismatch,FAILED,2048 4096,FLOAT8_E4M3FN,ND,2560 4032,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 63 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,, | ||
| 16 | +k_not_divisible_64,FAILED,2048 4033,FLOAT8_E4M3FN,ND,2560 4033,FLOAT8_E4M3FN,ND,2048 63 2,FLOAT8_E8M0,ND,2560 63 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,, | ||
| 17 | +x1_one_dim,FAILED,4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,, | ||
| 18 | +x2_one_dim,FAILED,2048 4096,FLOAT8_E4M3FN,ND,4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,, | ||
| 19 | +x1_scale_wrong_shape,FAILED,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,1024 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,8192 2560,8192 4096 | ||
| 20 | +x2_scale_wrong_shape,FAILED,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,1280 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,8192 2560,8192 4096 | ||
| 21 | +x1_scale_wrong_dim_count,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,2560 4096,FLOAT8_E4M3FN,ND,2048 64,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,true,8192 2560,8192 4096 | ||
| 22 | +trans_b_false,SUCCESS,2048 4096,FLOAT8_E4M3FN,ND,4096 2560,FLOAT8_E4M3FN,ND,2048 64 2,FLOAT8_E8M0,ND,2560 64 2,FLOAT8_E8M0,ND,BF16,FLOAT8_E4M3FN,4,false,8192 2560,8192 4096 | ||
| @@ -0,0 +1,12 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | +__all__ = ["all_gather_quant_matmul"] | ||
| 11 | + | ||
| 12 | +from .all_gather_quant_matmul import all_gather_quant_matmul | ||
| @@ -0,0 +1,332 @@ | |||
| 1 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 10 | +import logging | ||
| 11 | +from typing import Optional, List, Tuple | ||
| 12 | + | ||
| 13 | +import torch | ||
| 14 | +from torch.library import impl | ||
| 15 | +from torch_npu.utils._error_code import ErrCode, ops_error | ||
| 16 | +from cann_ops_transformer.op_builder import OpBuilder, get_as_library | ||
| 17 | +from ..common import CommChannelBuilderManager | ||
| 18 | + | ||
| 19 | +_logger = logging.getLogger(__name__) | ||
| 20 | + | ||
| 21 | +_ACL_DTYPE_TO_TORCH_DTYPE = { | ||
| 22 | + 5: torch.float16, | ||
| 23 | + 6: torch.float32, | ||
| 24 | + 15: torch.bfloat16, | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +class _AllGatherQuantMatmulOpBuilder(OpBuilder): | ||
| 29 | + def __init__(self): | ||
| 30 | + super(_AllGatherQuantMatmulOpBuilder, self).__init__( | ||
| 31 | + "npu_all_gather_quant_matmul", category="mc2" | ||
| 32 | + ) | ||
| 33 | + | ||
| 34 | + def sources(self): | ||
| 35 | + return ["csrc/mc2/all_gather_quant_matmul.cpp"] | ||
| 36 | + | ||
| 37 | + def schema(self) -> str: | ||
| 38 | + return ( | ||
| 39 | + "npu_all_gather_quant_matmul(Tensor context, Tensor x1, Tensor x2, " | ||
| 40 | + "int hccl_buffer_size, str group_name, int rank_size, *, " | ||
| 41 | + "Tensor? bias=None, Tensor? x1_scale=None, Tensor? x2_scale=None, " | ||
| 42 | + "int[] group_sizes=[], " | ||
| 43 | + "int? x1_dtype=None, int? x2_dtype=None, " | ||
| 44 | + "int? x1_scale_dtype=None, int? x2_scale_dtype=None, " | ||
| 45 | + 'int? y_dtype=None, str comm_mode="ai_cpu"' | ||
| 46 | + ") -> (Tensor, Tensor, Tensor)" | ||
| 47 | + ) | ||
| 48 | + | ||
| 49 | + def register_meta(self): | ||
| 50 | + @impl(get_as_library(), self.name, "Meta") | ||
| 51 | + def npu_all_gather_quant_matmul_meta( | ||
| 52 | + context, | ||
| 53 | + x1, | ||
| 54 | + x2, | ||
| 55 | + hccl_buffer_size, | ||
| 56 | + group_name, | ||
| 57 | + rank_size, | ||
| 58 | + bias=None, | ||
| 59 | + x1_scale=None, | ||
| 60 | + x2_scale=None, | ||
| 61 | + group_sizes=None, | ||
| 62 | + x1_dtype=None, | ||
| 63 | + x2_dtype=None, | ||
| 64 | + x1_scale_dtype=None, | ||
| 65 | + x2_scale_dtype=None, | ||
| 66 | + y_dtype=None, | ||
| 67 | + comm_mode="ai_cpu", | ||
| 68 | + ): | ||
| 69 | + if rank_size <= 0: | ||
| 70 | + raise ValueError( | ||
| 71 | + f"rank_size should be greater than 0, {ops_error(ErrCode.VALUE)}." | ||
| 72 | + ) | ||
| 73 | + if x1.dim() != 2: | ||
| 74 | + raise ValueError( | ||
| 75 | + f"x1 should be 2D, but got {x1.dim()}D, {ops_error(ErrCode.VALUE)}." | ||
| 76 | + ) | ||
| 77 | + if x2.dim() != 2: | ||
| 78 | + raise ValueError( | ||
| 79 | + f"x2 should be 2D, but got {x2.dim()}D, {ops_error(ErrCode.VALUE)}." | ||
| 80 | + ) | ||
| 81 | + m_per_rank = x1.size(0) | ||
| 82 | + k = x1.size(1) | ||
| 83 | + n = x2.size(1) | ||
| 84 | + out_dtype = torch.bfloat16 | ||
| 85 | + if y_dtype is not None: | ||
| 86 | + out_dtype = _ACL_DTYPE_TO_TORCH_DTYPE.get(y_dtype, out_dtype) | ||
| 87 | + y = x1.new_empty(tuple([m_per_rank * rank_size, n]), dtype=out_dtype) | ||
| 88 | + gather_out = x1.new_empty( | ||
| 89 | + tuple([m_per_rank * rank_size, k]), dtype=x1.dtype | ||
| 90 | + ) | ||
| 91 | + amax_out = x1.new_empty(tuple([0]), dtype=torch.float32) | ||
| 92 | + return (y, gather_out, amax_out) | ||
| 93 | + | ||
| 94 | + | ||
| 95 | +_all_gather_quant_matmul_op_builder = _AllGatherQuantMatmulOpBuilder() | ||
| 96 | +_op_module = _all_gather_quant_matmul_op_builder.load() | ||
| 97 | + | ||
| 98 | + | ||
| 99 | +@impl(get_as_library(), _all_gather_quant_matmul_op_builder.name, "PrivateUse1") | ||
| 100 | +def _npu_all_gather_quant_matmul( | ||
| 101 | + context, | ||
| 102 | + x1, | ||
| 103 | + x2, | ||
| 104 | + hccl_buffer_size, | ||
| 105 | + group_name, | ||
| 106 | + rank_size, | ||
| 107 | + bias=None, | ||
| 108 | + x1_scale=None, | ||
| 109 | + x2_scale=None, | ||
| 110 | + group_sizes=None, | ||
| 111 | + x1_dtype=None, | ||
| 112 | + x2_dtype=None, | ||
| 113 | + x1_scale_dtype=None, | ||
| 114 | + x2_scale_dtype=None, | ||
| 115 | + y_dtype=None, | ||
| 116 | + comm_mode="ai_cpu", | ||
| 117 | +): | ||
| 118 | + result = _op_module.npu_all_gather_quant_matmul( | ||
| 119 | + context, | ||
| 120 | + x1, | ||
| 121 | + x2, | ||
| 122 | + hccl_buffer_size, | ||
| 123 | + group_name, | ||
| 124 | + rank_size, | ||
| 125 | + bias, | ||
| 126 | + x1_scale, | ||
| 127 | + x2_scale, | ||
| 128 | + group_sizes if group_sizes is not None else [], | ||
| 129 | + x1_dtype, | ||
| 130 | + x2_dtype, | ||
| 131 | + x1_scale_dtype, | ||
| 132 | + x2_scale_dtype, | ||
| 133 | + y_dtype, | ||
| 134 | + comm_mode, | ||
| 135 | + ) | ||
| 136 | + return result | ||
| 137 | + | ||
| 138 | + | ||
| 139 | +def _check_params( | ||
| 140 | + x1, | ||
| 141 | + x2, | ||
| 142 | + x1_scale, | ||
| 143 | + x2_scale, | ||
| 144 | + x1_dtype, | ||
| 145 | + x2_dtype, | ||
| 146 | + x1_scale_dtype, | ||
| 147 | + x2_scale_dtype, | ||
| 148 | + comm_mode, | ||
| 149 | +): | ||
| 150 | + """Validate input parameters.""" | ||
| 151 | + if comm_mode != "urma": | ||
| 152 | + raise ValueError( | ||
| 153 | + f"comm_mode only supports 'urma', but got '{comm_mode}'. " | ||
| 154 | + f"Please pass comm_mode='urma' explicitly." | ||
| 155 | + ) | ||
| 156 | + fp4_dtype_enums = (296,) | ||
torch侧拦截用torch check ![]() ![]() | |||
| 157 | + if x1.dtype == torch.uint8 and x1_dtype not in fp4_dtype_enums: | ||
| 158 | + raise ValueError( | ||
| 159 | + f"x1 is uint8 tensor (likely fp4 packed) but x1_dtype={x1_dtype} " | ||
| 160 | + f"is not a valid fp4 enum. Please pass x1_dtype=296 (fp4_e2m1)." | ||
| 161 | + ) | ||
| 162 | + if x2.dtype == torch.uint8 and x2_dtype not in fp4_dtype_enums: | ||
| 163 | + raise ValueError( | ||
| 164 | + f"x2 is uint8 tensor (likely fp4 packed) but x2_dtype={x2_dtype} " | ||
| 165 | + f"is not a valid fp4 enum. Please pass x2_dtype=296 (fp4_e2m1)." | ||
| 166 | + ) | ||
| 167 | + fp8_e8m0_dtype_enum = 293 | ||
| 168 | + if ( | ||
| 169 | + x1_scale is not None | ||
| 170 | + and x1_scale.dtype == torch.uint8 | ||
| 171 | + and x1_scale_dtype != fp8_e8m0_dtype_enum | ||
| 172 | + ): | ||
| 173 | + raise ValueError( | ||
| 174 | + f"x1_scale is uint8 tensor (fp8_e8m0 stored as uint8) but " | ||
| 175 | + f"x1_scale_dtype={x1_scale_dtype} is not 293 (fp8_e8m0). " | ||
| 176 | + f"Please pass x1_scale_dtype=293." | ||
| 177 | + ) | ||
| 178 | + if ( | ||
| 179 | + x2_scale is not None | ||
| 180 | + and x2_scale.dtype == torch.uint8 | ||
| 181 | + and x2_scale_dtype != fp8_e8m0_dtype_enum | ||
| 182 | + ): | ||
| 183 | + raise ValueError( | ||
| 184 | + f"x2_scale is uint8 tensor (fp8_e8m0 stored as uint8) but " | ||
| 185 | + f"x2_scale_dtype={x2_scale_dtype} is not 293 (fp8_e8m0). " | ||
| 186 | + f"Please pass x2_scale_dtype=293." | ||
| 187 | + ) | ||
| 188 | + | ||
| 189 | + | ||
| 190 | +def _prepare_comm_context(group): | ||
| 191 | + """Create communication context, return context/buffer/rank info.""" | ||
| 192 | + rank_id = torch.distributed.get_rank(group) | ||
| 193 | + rank_size = torch.distributed.get_world_size(group) | ||
| 194 | + if rank_size <= 0: | ||
| 195 | + rank_size = torch.distributed.get_rank_size() | ||
| 196 | + group_name = group._get_backend(torch.device("npu")).get_hccl_comm_name(rank_id) | ||
| 197 | + channel_builder = CommChannelBuilderManager(group_name) | ||
| 198 | + ctx_tag = group_name + "all_gather_matmul" | ||
| 199 | + context = channel_builder.create_context(ctx_tag) | ||
| 200 | + hccl_buffer_size = channel_builder.get_hccl_buffer_size() | ||
| 201 | + return context, hccl_buffer_size, rank_id, rank_size, group_name | ||
| 202 | + | ||
| 203 | + | ||
| 204 | +def _check_hccl_buffer(x1, x1_scale, rank_size, hccl_buffer_size): | ||
| 205 | + """Check comm data + 2MB reserved <= hccl_buffer_size.""" | ||
| 206 | + hccl_buffer_reserved_bytes = 2 * 1024 * 1024 | ||
| 207 | + m_per_rank = x1.size(0) | ||
| 208 | + k = x1.size(1) | ||
| 209 | + x1_data_bytes = rank_size * m_per_rank * k * x1.element_size() | ||
| 210 | + scale_k_groups = (k + 63) // 64 | ||
| 211 | + x1_scale_bytes = 0 | ||
| 212 | + if x1_scale is not None: | ||
| 213 | + x1_scale_bytes = ( | ||
| 214 | + rank_size * m_per_rank * scale_k_groups * 2 * x1_scale.element_size() | ||
| 215 | + ) | ||
| 216 | + comm_data_bytes = x1_data_bytes + x1_scale_bytes | ||
| 217 | + need_bytes = comm_data_bytes + hccl_buffer_reserved_bytes | ||
| 218 | + _logger.info( | ||
| 219 | + "hccl_buffer_size=%s bytes (%.2f MB), comm_data_bytes=%s bytes (%.2f MB) " | ||
| 220 | + "= data %s + scale %s, need (with 2MB reserved)=%s", | ||
| 221 | + hccl_buffer_size, | ||
| 222 | + hccl_buffer_size / 1024 / 1024, | ||
| 223 | + comm_data_bytes, | ||
| 224 | + comm_data_bytes / 1024 / 1024, | ||
| 225 | + x1_data_bytes, | ||
| 226 | + x1_scale_bytes, | ||
| 227 | + need_bytes, | ||
| 228 | + ) | ||
| 229 | + if need_bytes > hccl_buffer_size: | ||
| 230 | + raise ValueError( | ||
| 231 | + f"Communication data size + 2MB reserved ({need_bytes} bytes = " | ||
| 232 | + f"data {x1_data_bytes} + scale {x1_scale_bytes} + reserved " | ||
| 233 | + f"{hccl_buffer_reserved_bytes}) exceeds hccl_buffer_size " | ||
| 234 | + f"({hccl_buffer_size} bytes = {hccl_buffer_size / 1024 / 1024:.2f} MB). " | ||
| 235 | + f"Please increase HCCL_BUFFSIZE environment variable." | ||
| 236 | + ) | ||
| 237 | + | ||
| 238 | + | ||
| 239 | +def all_gather_quant_matmul( | ||
超大函数进行拆分 ![]() ![]() | |||
| 240 | + x1: torch.Tensor, | ||
| 241 | + x2: torch.Tensor, | ||
| 242 | + group, | ||
| 243 | + *, | ||
| 244 | + bias: Optional[torch.Tensor] = None, | ||
| 245 | + x1_scale: Optional[torch.Tensor] = None, | ||
| 246 | + x2_scale: Optional[torch.Tensor] = None, | ||
| 247 | + group_sizes: Optional[List[int]] = None, | ||
| 248 | + x1_dtype: Optional[int] = None, | ||
| 249 | + x2_dtype: Optional[int] = None, | ||
| 250 | + x1_scale_dtype: Optional[int] = None, | ||
| 251 | + x2_scale_dtype: Optional[int] = None, | ||
| 252 | + y_dtype: Optional[int] = None, | ||
| 253 | + comm_mode: Optional[str] = "ai_cpu", | ||
| 254 | +) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: | ||
| 255 | + """AllGather + MX quantized Matmul fused computation (apace UDMA path). | ||
| 256 | + | ||
| 257 | + Each rank gathers A from all ranks, then multiplies with its local B: | ||
| 258 | + ``y = AllGather(x1) @ x2^T``. | ||
| 259 | + | ||
| 260 | + Args: | ||
| 261 | + x1 (Tensor): Left matrix (per-rank A), shape ``(M_per_rank, K)``, dtype | ||
| 262 | + float8_e4m3fn/float8_e5m2/float4_e2m1fn_x2. | ||
| 263 | + x2 (Tensor): Right matrix (transposed B), shape ``(N, K)``, dtype | ||
| 264 | + float8_e4m3fn/float8_e5m2/float4_e2m1fn_x2. FP4 requires x1 and x2 | ||
| 265 | + both FP4. | ||
| 266 | + group (ProcessGroup): torch.distributed process group for AllGather | ||
| 267 | + communication. | ||
| 268 | + bias (Tensor, optional): Bias added after matmul, shape ``(N,)``, dtype float32. | ||
| 269 | + x1_scale (Tensor, optional): MX scale for x1, shape ``(M_per_rank, Ceil(K/64), 2)``, | ||
| 270 | + dtype float8_e8m0fnu. Required in MX scene. | ||
| 271 | + x2_scale (Tensor, optional): MX scale for x2, shape ``(N, Ceil(K/64), 2)``, dtype | ||
| 272 | + float8_e8m0fnu. Required in MX scene. | ||
| 273 | + group_sizes (List[int], optional): Quantization group sizes, MX only | ||
| 274 | + supports ``[1, 1, 32]``. None means auto-inferred from scale shapes. | ||
| 275 | + x1_dtype (int, optional): x1 dtype enum for bitcast, None means use tensor dtype. | ||
| 276 | + x2_dtype (int, optional): x2 dtype enum for bitcast, None means use tensor dtype. | ||
| 277 | + x1_scale_dtype (int, optional): x1_scale dtype enum for bitcast, None means use tensor dtype. | ||
| 278 | + x2_scale_dtype (int, optional): x2_scale dtype enum for bitcast, None means use tensor dtype. | ||
| 279 | + y_dtype (int, optional): Output dtype enum, None means default bfloat16. | ||
| 280 | + Only bfloat16/float16 are supported. | ||
| 281 | + comm_mode (str, optional): Communication engine. Only ``"urma"`` is supported; | ||
| 282 | + the default ``"ai_cpu"`` is rejected, so pass ``"urma"`` explicitly. | ||
| 283 | + | ||
| 284 | + Returns: | ||
| 285 | + Tuple[Tensor, Tensor, Tensor]: (y, gather_out, amax_out) where y has | ||
| 286 | + shape ``(M_per_rank * rank_size, N)``, gather_out and amax_out are | ||
| 287 | + empty tensor (not implemented yet). Users typically use | ||
| 288 | + ``y, _, _ = all_gather_quant_matmul(...)`` to ignore the latter two. | ||
| 289 | + """ | ||
| 290 | + if group_sizes is None: | ||
| 291 | + group_sizes = [] | ||
| 292 | + _check_params( | ||
| 293 | + x1, | ||
| 294 | + x2, | ||
| 295 | + x1_scale, | ||
| 296 | + x2_scale, | ||
| 297 | + x1_dtype, | ||
| 298 | + x2_dtype, | ||
| 299 | + x1_scale_dtype, | ||
| 300 | + x2_scale_dtype, | ||
| 301 | + comm_mode, | ||
| 302 | + ) | ||
| 303 | + context, hccl_buffer_size, rank_id, rank_size, group_name = _prepare_comm_context( | ||
| 304 | + group | ||
| 305 | + ) | ||
| 306 | + _check_hccl_buffer(x1, x1_scale, rank_size, hccl_buffer_size) | ||
| 307 | + _logger.info( | ||
| 308 | + "rank=%s, rank_size=%s, comm_mode=%s, calling npu_all_gather_quant_matmul ...", | ||
| 309 | + rank_id, | ||
| 310 | + rank_size, | ||
| 311 | + comm_mode, | ||
| 312 | + ) | ||
| 313 | + result = torch.ops.cann_ops_transformer.npu_all_gather_quant_matmul( | ||
| 314 | + context, | ||
| 315 | + x1, | ||
| 316 | + x2, | ||
| 317 | + hccl_buffer_size, | ||
| 318 | + group_name, | ||
| 319 | + rank_size, | ||
| 320 | + bias=bias, | ||
| 321 | + x1_scale=x1_scale, | ||
| 322 | + x2_scale=x2_scale, | ||
| 323 | + group_sizes=group_sizes, | ||
| 324 | + x1_dtype=x1_dtype, | ||
| 325 | + x2_dtype=x2_dtype, | ||
| 326 | + x1_scale_dtype=x1_scale_dtype, | ||
| 327 | + x2_scale_dtype=x2_scale_dtype, | ||
| 328 | + y_dtype=y_dtype, | ||
| 329 | + comm_mode=comm_mode, | ||
| 330 | + ) | ||
| 331 | + _logger.info("rank=%s, npu_all_gather_quant_matmul returned", rank_id) | ||
| 332 | + return result | ||
| @@ -0,0 +1,127 @@ | |||
| 1 | +// ----------------------------------------------------------------------------------------------------------- | ||
| 2 | +// Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +// This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +// CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +// Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +// INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +// See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +// ----------------------------------------------------------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +#include <set> | ||
| 12 | +#include <torch/extension.h> | ||
| 13 | +#include <cstring> | ||
| 14 | +#include "aclnn_common.h" | ||
| 15 | + | ||
| 16 | +namespace op_api { | ||
| 17 | +using npu_utils = at_npu::native::NpuUtils; | ||
| 18 | +const int DIM_TWO = 2; | ||
| 19 | +static const int64_t GROUP_MAX = 65535; | ||
| 20 | +static const size_t GROUP_DIM = 3; | ||
| 21 | +static const size_t OFFSET_32_BITS = 32; | ||
| 22 | +static const size_t OFFSET_16_BITS = 16; | ||
| 23 | +const std::set<int> SUPPORT_RANK_SIZE_LIST{2, 4, 8, 16}; | ||
| 24 | + | ||
| 25 | +int64_t CheckAndGetGroupSizeAg(at::IntArrayRef groupSizeList) | ||
| 26 | +{ | ||
| 27 | + int64_t groups = 0; | ||
| 28 | + if (groupSizeList.empty()) { | ||
| 29 | + return groups; | ||
| 30 | + } | ||
| 31 | + size_t groupDim = groupSizeList.size(); | ||
| 32 | + TORCH_CHECK(groupDim == GROUP_DIM, "group_sizes only support input with three elements, but got ", groupDim); | ||
| 33 | + | ||
| 34 | + int64_t groupM = static_cast<int64_t>(groupSizeList[0]); | ||
| 35 | + int64_t groupN = static_cast<int64_t>(groupSizeList[1]); | ||
| 36 | + int64_t groupK = static_cast<int64_t>(groupSizeList[2]); | ||
| 37 | + | ||
| 38 | + bool invalid_group_param = ((groupM <= GROUP_MAX && groupM >= 0) && (groupN <= GROUP_MAX && groupN >= 0) && | ||
| 39 | + (groupK <= GROUP_MAX && groupK >= 0)); | ||
| 40 | + TORCH_CHECK(invalid_group_param, "group param value must conform to range [0, 65535]"); | ||
| 41 | + | ||
| 42 | + groups = static_cast<int64_t>((static_cast<uint64_t>(groupM) << OFFSET_32_BITS) + | ||
| 43 | + (static_cast<uint64_t>(groupN) << OFFSET_16_BITS) + static_cast<uint64_t>(groupK)); | ||
| 44 | + return groups; | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +std::tuple<at::Tensor, at::Tensor, at::Tensor> NpuAllGatherQuantMatmul( | ||
| 48 | + const at::Tensor &context, const at::Tensor &x1, const at::Tensor &x2, int64_t hcclBufferSize, std::string group, | ||
| 49 | + int64_t rankSize, const c10::optional<at::Tensor> &biasOptional, const c10::optional<at::Tensor> &x1ScaleOptional, | ||
| 50 | + const c10::optional<at::Tensor> &x2ScaleOptional, c10::IntArrayRef groupSizes, c10::optional<int64_t> x1Dtype, | ||
| 51 | + c10::optional<int64_t> x2Dtype, c10::optional<int64_t> x1ScaleDtype, c10::optional<int64_t> x2ScaleDtype, | ||
| 52 | + c10::optional<int64_t> yDtype, std::string commMode) | ||
| 53 | +{ | ||
| 54 | + TORCH_CHECK(x1.dim() == DIM_TWO, | ||
| 55 | + "The x1 input of allgatherquantmatmul is required to be 2D, but the actual x1 input is ", x1.dim(), | ||
| 56 | + "D."); | ||
| 57 | + TORCH_CHECK(x2.dim() == DIM_TWO, | ||
| 58 | + "The x2 input of allgatherquantmatmul is required to be 2D, but the actual x2 input is ", x2.dim(), | ||
| 59 | + "D."); | ||
| 60 | + // x2 为 .t() 转置 view: viewShape [K,N],物理存储 [N,K]; | ||
| 61 | + // aclnn 层 IsTransposeLastTwoDims+TransX2Tensor 会翻回 [N,K],K 维交叉校验在 aclnn CheckShape 做 | ||
| 62 | + TORCH_CHECK(SUPPORT_RANK_SIZE_LIST.find(rankSize) != SUPPORT_RANK_SIZE_LIST.end(), | ||
| 63 | + "The rank_size should be in [2, 4, 8, 16], but the actual value is ", rankSize, "."); | ||
| 64 | + | ||
| 65 | + auto x1Size = x1.sizes(); | ||
| 66 | + auto x2Size = x2.sizes(); | ||
| 67 | + int64_t mPerRank = x1Size[0]; | ||
| 68 | + int64_t n = x2Size[1]; // x2 传 .t() view [K, N],dim1=N | ||
| 69 | + | ||
| 70 | + at::ScalarType outScalarType = at::kBFloat16; | ||
| 71 | + if (yDtype.has_value()) { | ||
| 72 | + aclDataType outAclDtype = GetAclDataType(yDtype.value()); | ||
| 73 | + // V3 仅支持 bf16/fp16 输出,其余枚举前置拦截(之前非三者之一会静默 fallback 到 bf16 放行) | ||
| 74 | + TORCH_CHECK(outAclDtype == ACL_FLOAT16 || outAclDtype == ACL_BF16, | ||
| 75 | + "y_dtype only supports fp16(5)/bf16(15), but got invalid enum value ", yDtype.value(), "."); | ||
| 76 | + outScalarType = (outAclDtype == ACL_FLOAT16) ? at::kHalf : at::kBFloat16; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + at::Tensor y = at::empty({mPerRank * rankSize, n}, x1.options().dtype(outScalarType)); | ||
| 80 | + | ||
| 81 | + std::string commModeStr = std::string(commMode); | ||
| 82 | + char *commModePtr = const_cast<char *>(commModeStr.c_str()); | ||
| 83 | + | ||
| 84 | + std::string groupStr = std::string(group); | ||
| 85 | + char *groupPtr = const_cast<char *>(groupStr.c_str()); | ||
| 86 | + | ||
| 87 | + aclDataType x1AclDtype = | ||
| 88 | + x1Dtype.has_value() ? GetAclDataType(x1Dtype.value()) : ConvertToAclDataType(x1.scalar_type()); | ||
| 89 | + aclDataType x2AclDtype = | ||
| 90 | + x2Dtype.has_value() ? GetAclDataType(x2Dtype.value()) : ConvertToAclDataType(x2.scalar_type()); | ||
| 91 | + | ||
| 92 | + // gather_out / amax_out 当前不使能, | ||
| 93 | + // torch 侧传 {0} 空占位 tensor 经 aclnn 透传 inner(aclnn/tiling/kernel 均不处理),并原样返回给 torch。 | ||
| 94 | + at::Tensor gatherOut = at::empty({0}, x1.options().dtype(x1.scalar_type())); | ||
| 95 | + at::Tensor amaxOut = at::empty({0}, x1.options().dtype(at::kFloat)); | ||
| 96 | + | ||
| 97 | + const at::Tensor &x1ScaleReal = x1ScaleOptional.value_or(at::Tensor()); | ||
| 98 | + const at::Tensor &x2ScaleReal = x2ScaleOptional.value_or(at::Tensor()); | ||
| 99 | + aclDataType x1ScaleAclDtype = | ||
| 100 | + x1ScaleDtype.has_value() ? | ||
| 101 | + GetAclDataType(x1ScaleDtype.value()) : | ||
| 102 | + (x1ScaleReal.defined() ? ConvertToAclDataType(x1ScaleReal.scalar_type()) : ACL_DT_UNDEFINED); | ||
| 103 | + aclDataType x2ScaleAclDtype = | ||
| 104 | + x2ScaleDtype.has_value() ? | ||
| 105 | + GetAclDataType(x2ScaleDtype.value()) : | ||
| 106 | + (x2ScaleReal.defined() ? ConvertToAclDataType(x2ScaleReal.scalar_type()) : ACL_DT_UNDEFINED); | ||
| 107 | + | ||
| 108 | + TensorWrapper x1Wrapper = {x1, x1AclDtype}; | ||
fp8等非torch原生数据类型用wrapper包裹 ![]() ![]() | |||
| 109 | + TensorWrapper x2Wrapper = {x2, x2AclDtype}; | ||
| 110 | + TensorWrapper x1ScaleWrapper = {x1ScaleReal, x1ScaleAclDtype}; | ||
| 111 | + TensorWrapper x2ScaleWrapper = {x2ScaleReal, x2ScaleAclDtype}; | ||
| 112 | + TensorWrapper gatherOutWrapper = {gatherOut, x1AclDtype}; | ||
| 113 | + | ||
| 114 | + int64_t groupSize = CheckAndGetGroupSizeAg(groupSizes); | ||
| 115 | + | ||
| 116 | + ACLNN_CMD(aclnnAllGatherQuantMatmulV3, context, x1Wrapper, x2Wrapper, biasOptional, x1ScaleWrapper, x2ScaleWrapper, | ||
| 117 | + groupPtr, rankSize, hcclBufferSize, groupSize, commModePtr, y, gatherOutWrapper); | ||
| 118 | + | ||
| 119 | + return std::make_tuple(y, gatherOut, amaxOut); | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) | ||
| 123 | +{ | ||
| 124 | + m.def("npu_all_gather_quant_matmul", &NpuAllGatherQuantMatmul, "npu_all_gather_quant_matmul"); | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +} // namespace op_api | ||
Rmc2/common/op_kernel/apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_udma_impl.h→mc2/common/op_kernel/apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_impl.h+29-21
| @@ -9,7 +9,7 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | /*! | 11 | /*! |
| 12 | - * \file all_gather_mx_matmul_udma_impl.h | 12 | + * \file all_gather_mx_matmul_urma_impl.h |
| 13 | * \brief AllGatherQuantMatmul 算子实现,基于 FragmentTensor + 通算解耦(UDMA 通信) | 13 | * \brief AllGatherQuantMatmul 算子实现,基于 FragmentTensor + 通算解耦(UDMA 通信) |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| @@ -17,7 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | #include "kernel_basic_intf.h" | 18 | #include "kernel_basic_intf.h" |
| 19 | #include "kernel_tiling/kernel_tiling.h" | 19 | #include "kernel_tiling/kernel_tiling.h" |
| 20 | -#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_udma_tiling_data.h" | 20 | +#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_tiling_data.h" |
| 21 | #include "apace/kernel/matmul/quant_batch_matmul/all_gather_qbmm_mx_kernel.h" | 21 | #include "apace/kernel/matmul/quant_batch_matmul/all_gather_qbmm_mx_kernel.h" |
| 22 | #include "adv_api/hcomm/hcomm.h" | 22 | #include "adv_api/hcomm/hcomm.h" |
| 23 | #include "apace/core/aiv_comm/collective_comm_context.h" | 23 | #include "apace/core/aiv_comm/collective_comm_context.h" |
| @@ -37,11 +37,12 @@ using LayoutC = AscendC::Te::NDExtLayoutPtn; | |||
| 37 | using ProblemShape = AscendC::Te::Shape<int64_t, int64_t, int64_t, int64_t>; | 37 | using ProblemShape = AscendC::Te::Shape<int64_t, int64_t, int64_t, int64_t>; |
| 38 | 38 | ||
| 39 | template <typename AType, typename BType, typename CType> | 39 | template <typename AType, typename BType, typename CType> |
| 40 | -class AllGatherMxMatmulUdmaImpl { | 40 | +class AllGatherMxMatmulUrmaImpl { |
| 41 | public: | 41 | public: |
| 42 | - __aicore__ inline AllGatherMxMatmulUdmaImpl() {} | 42 | + __aicore__ inline AllGatherMxMatmulUrmaImpl() {} |
| 43 | __aicore__ inline void Init(__gm__ CommContext *hcommCtx, GM_ADDR aGM, GM_ADDR aScaleGM, GM_ADDR bGM, | 43 | __aicore__ inline void Init(__gm__ CommContext *hcommCtx, GM_ADDR aGM, GM_ADDR aScaleGM, GM_ADDR bGM, |
| 44 | - GM_ADDR bScaleGM, GM_ADDR cGM, const AllGatherMxMatmulUdmaTilingData *tilingData); | 44 | + GM_ADDR bScaleGM, GM_ADDR cGM, GM_ADDR biasGM, |
| 45 | + const AllGatherMxMatmulUrmaTilingData *tilingData); | ||
| 45 | __aicore__ inline void Process(); | 46 | __aicore__ inline void Process(); |
| 46 | 47 | ||
| 47 | using QuantMatmulKernelImpl = AllGatherQbmmMxKernel<AType, BType, CType>; | 48 | using QuantMatmulKernelImpl = AllGatherQbmmMxKernel<AType, BType, CType>; |
| @@ -52,7 +53,7 @@ public: | |||
| 52 | QuantMatmulKernelImpl quantMatmulKernelImpl_; | 53 | QuantMatmulKernelImpl quantMatmulKernelImpl_; |
| 53 | 54 | ||
| 54 | private: | 55 | private: |
| 55 | - __aicore__ inline void InitBaseParams(const AllGatherMxMatmulUdmaTilingData *td); | 56 | + __aicore__ inline void InitBaseParams(const AllGatherMxMatmulUrmaTilingData *td); |
| 56 | 57 | ||
| 57 | __aicore__ inline void AllGatherProcess(); | 58 | __aicore__ inline void AllGatherProcess(); |
| 58 | __aicore__ inline void MatmulProcess(); | 59 | __aicore__ inline void MatmulProcess(); |
| @@ -83,6 +84,7 @@ private: | |||
| 83 | GM_ADDR bGM_{}; | 84 | GM_ADDR bGM_{}; |
| 84 | GM_ADDR bScaleGM_{}; | 85 | GM_ADDR bScaleGM_{}; |
| 85 | GM_ADDR cGM_{}; | 86 | GM_ADDR cGM_{}; |
| 87 | + GM_ADDR biasGM_{}; | ||
| 86 | 88 | ||
| 87 | uint32_t rankId_{}; | 89 | uint32_t rankId_{}; |
| 88 | uint32_t rankSize_{}; | 90 | uint32_t rankSize_{}; |
| @@ -104,13 +106,13 @@ private: | |||
| 104 | uint64_t dataRegionBytes_{}; | 106 | uint64_t dataRegionBytes_{}; |
| 105 | uint64_t scaleRegionBytes_{}; | 107 | uint64_t scaleRegionBytes_{}; |
| 106 | 108 | ||
| 107 | - const AllGatherMxMatmulUdmaTilingData *tilingData_{}; | 109 | + const AllGatherMxMatmulUrmaTilingData *tilingData_{}; |
| 108 | }; | 110 | }; |
| 109 | 111 | ||
| 110 | template <typename AType, typename BType, typename CType> | 112 | template <typename AType, typename BType, typename CType> |
| 111 | -__aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::Init( | 113 | +__aicore__ inline void AllGatherMxMatmulUrmaImpl<AType, BType, CType>::Init( |
| 112 | __gm__ CommContext *hcommCtx, GM_ADDR aGM, GM_ADDR aScaleGM, GM_ADDR bGM, GM_ADDR bScaleGM, GM_ADDR cGM, | 114 | __gm__ CommContext *hcommCtx, GM_ADDR aGM, GM_ADDR aScaleGM, GM_ADDR bGM, GM_ADDR bScaleGM, GM_ADDR cGM, |
| 113 | - const AllGatherMxMatmulUdmaTilingData *tilingData) | 115 | + GM_ADDR biasGM, const AllGatherMxMatmulUrmaTilingData *tilingData) |
| 114 | { | 116 | { |
| 115 | tilingData_ = tilingData; | 117 | tilingData_ = tilingData; |
| 116 | hcommCtx_ = hcommCtx; | 118 | hcommCtx_ = hcommCtx; |
| @@ -119,6 +121,7 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::Init( | |||
| 119 | bGM_ = bGM; | 121 | bGM_ = bGM; |
| 120 | bScaleGM_ = bScaleGM; | 122 | bScaleGM_ = bScaleGM; |
| 121 | cGM_ = cGM; | 123 | cGM_ = cGM; |
| 124 | + biasGM_ = biasGM; | ||
| 122 | 125 | ||
| 123 | InitBaseParams(tilingData); | 126 | InitBaseParams(tilingData); |
| 124 | 127 | ||
| @@ -149,7 +152,8 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::Init( | |||
| 149 | commTilingData_.splitAxisTileCnt = tileCnt_; // head 段 tile 数量 | 152 | commTilingData_.splitAxisTileCnt = tileCnt_; // head 段 tile 数量 |
| 150 | commTilingData_.splitAxisTailSize = tailM_; // tail 行数 | 153 | commTilingData_.splitAxisTailSize = tailM_; // tail 行数 |
| 151 | commTilingData_.splitAxisTailCnt = tailCnt_; | 154 | commTilingData_.splitAxisTailCnt = tailCnt_; |
| 152 | - commTilingData_.nonSplitAxisSize = k_; // 非切分轴k | 155 | + // 通信按 Dtype 元素个数计:FP4(fp4x2) 每元素 2 个逻辑值,故按字节行宽折算 |
| 156 | + commTilingData_.nonSplitAxisSize = dataBytesPerMRow_ / sizeof(AType); // 非切分轴k | ||
| 153 | 157 | ||
| 154 | commTilingScale_.splitAxisTileSize = tileM_; | 158 | commTilingScale_.splitAxisTileSize = tileM_; |
| 155 | commTilingScale_.splitAxisTileCnt = tileCnt_; | 159 | commTilingScale_.splitAxisTileCnt = tileCnt_; |
| @@ -164,8 +168,8 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::Init( | |||
| 164 | } | 168 | } |
| 165 | 169 | ||
| 166 | template <typename AType, typename BType, typename CType> | 170 | template <typename AType, typename BType, typename CType> |
| 167 | -__aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::InitBaseParams( | 171 | +__aicore__ inline void AllGatherMxMatmulUrmaImpl<AType, BType, CType>::InitBaseParams( |
| 168 | - const AllGatherMxMatmulUdmaTilingData *td) | 172 | + const AllGatherMxMatmulUrmaTilingData *td) |
| 169 | { | 173 | { |
| 170 | const auto &ct = td->commTile; | 174 | const auto &ct = td->commTile; |
| 171 | tileCnt_ = static_cast<uint32_t>(ct.splitAxisTileCnt); | 175 | tileCnt_ = static_cast<uint32_t>(ct.splitAxisTileCnt); |
| @@ -180,14 +184,16 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::InitBaseP | |||
| 180 | headRows_ = static_cast<uint64_t>(tileCnt_) * tileM_; | 184 | headRows_ = static_cast<uint64_t>(tileCnt_) * tileM_; |
| 181 | 185 | ||
| 182 | scaleKGroups_ = Blaze::Gemm::CeilDiv(static_cast<uint64_t>(k_), Blaze::Gemm::MXFP_DIVISOR_SIZE); | 186 | scaleKGroups_ = Blaze::Gemm::CeilDiv(static_cast<uint64_t>(k_), Blaze::Gemm::MXFP_DIVISOR_SIZE); |
| 183 | - dataBytesPerMRow_ = static_cast<uint64_t>(k_) * sizeof(AType); | 187 | + // FP4 (fp4x2) 1 字节装 2 个元素:每行字节数 = k/2;FP8 等 = k * sizeof(AType) |
| 188 | + dataBytesPerMRow_ = | ||
| 189 | + Blaze::Gemm::IsFp4<AType>() ? (static_cast<uint64_t>(k_) >> 1) : static_cast<uint64_t>(k_) * sizeof(AType); | ||
| 184 | scaleBytesPerMRow_ = | 190 | scaleBytesPerMRow_ = |
| 185 | scaleKGroups_ * static_cast<uint64_t>(Blaze::Gemm::MXFP_MULTI_BASE_SIZE) * sizeof(AscendC::fp8_e8m0_t); | 191 | scaleKGroups_ * static_cast<uint64_t>(Blaze::Gemm::MXFP_MULTI_BASE_SIZE) * sizeof(AscendC::fp8_e8m0_t); |
| 186 | cBytesPerM_ = static_cast<uint64_t>(n_) * sizeof(CType); | 192 | cBytesPerM_ = static_cast<uint64_t>(n_) * sizeof(CType); |
| 187 | } | 193 | } |
| 188 | 194 | ||
| 189 | template <typename AType, typename BType, typename CType> | 195 | template <typename AType, typename BType, typename CType> |
| 190 | -__aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::Process() | 196 | +__aicore__ inline void AllGatherMxMatmulUrmaImpl<AType, BType, CType>::Process() |
| 191 | { | 197 | { |
| 192 | if ASCEND_IS_AIV { | 198 | if ASCEND_IS_AIV { |
| 193 | AllGatherProcess(); | 199 | AllGatherProcess(); |
| @@ -198,7 +204,7 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::Process() | |||
| 198 | } | 204 | } |
| 199 | 205 | ||
| 200 | template <typename AType, typename BType, typename CType> | 206 | template <typename AType, typename BType, typename CType> |
| 201 | -__aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::MatmulProcess() | 207 | +__aicore__ inline void AllGatherMxMatmulUrmaImpl<AType, BType, CType>::MatmulProcess() |
| 202 | { | 208 | { |
| 203 | KernelParams params; | 209 | KernelParams params; |
| 204 | params.mmTile = &tilingData_->mmTile; | 210 | params.mmTile = &tilingData_->mmTile; |
| @@ -222,6 +228,8 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::MatmulPro | |||
| 222 | params.bGM = bGM_; | 228 | params.bGM = bGM_; |
| 223 | params.bScaleGM = bScaleGM_; | 229 | params.bScaleGM = bScaleGM_; |
| 224 | params.cGM = cGM_; | 230 | params.cGM = cGM_; |
| 231 | + params.biasGM = biasGM_; | ||
| 232 | + params.isBias = (tilingData_->isBias != 0); | ||
| 225 | params.winDataBase = GetWinDataRegionBase(); | 233 | params.winDataBase = GetWinDataRegionBase(); |
| 226 | params.winScaleBase = GetWinScaleRegionBase(); | 234 | params.winScaleBase = GetWinScaleRegionBase(); |
| 227 | params.dataBytesPerMRow = dataBytesPerMRow_; | 235 | params.dataBytesPerMRow = dataBytesPerMRow_; |
| @@ -231,19 +239,19 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::MatmulPro | |||
| 231 | } | 239 | } |
| 232 | 240 | ||
| 233 | template <typename AType, typename BType, typename CType> | 241 | template <typename AType, typename BType, typename CType> |
| 234 | -__aicore__ inline GM_ADDR AllGatherMxMatmulUdmaImpl<AType, BType, CType>::GetWinDataRegionBase() | 242 | +__aicore__ inline GM_ADDR AllGatherMxMatmulUrmaImpl<AType, BType, CType>::GetWinDataRegionBase() |
| 235 | { | 243 | { |
| 236 | return reinterpret_cast<GM_ADDR>(udmaCtx_->commBufferAddrs[rankId_]); | 244 | return reinterpret_cast<GM_ADDR>(udmaCtx_->commBufferAddrs[rankId_]); |
| 237 | } | 245 | } |
| 238 | 246 | ||
| 239 | template <typename AType, typename BType, typename CType> | 247 | template <typename AType, typename BType, typename CType> |
| 240 | -__aicore__ inline GM_ADDR AllGatherMxMatmulUdmaImpl<AType, BType, CType>::GetWinScaleRegionBase() | 248 | +__aicore__ inline GM_ADDR AllGatherMxMatmulUrmaImpl<AType, BType, CType>::GetWinScaleRegionBase() |
| 241 | { | 249 | { |
| 242 | return GetWinDataRegionBase() + dataRegionBytes_; | 250 | return GetWinDataRegionBase() + dataRegionBytes_; |
| 243 | } | 251 | } |
| 244 | 252 | ||
| 245 | template <typename AType, typename BType, typename CType> | 253 | template <typename AType, typename BType, typename CType> |
| 246 | -__aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::AllGatherProcess() | 254 | +__aicore__ inline void AllGatherMxMatmulUrmaImpl<AType, BType, CType>::AllGatherProcess() |
| 247 | { | 255 | { |
| 248 | // 预触发 dependTileIdx=0:自身数据始终就绪,AIC 可直接消费。 | 256 | // 预触发 dependTileIdx=0:自身数据始终就绪,AIC 可直接消费。 |
| 249 | CrossCoreSetFlag<0x2, PIPE_MTE3>(0); | 257 | CrossCoreSetFlag<0x2, PIPE_MTE3>(0); |
| @@ -271,10 +279,10 @@ __aicore__ inline void AllGatherMxMatmulUdmaImpl<AType, BType, CType>::AllGather | |||
| 271 | 279 | ||
| 272 | __global__ __aicore__ void AllGatherQuantMatmulKernel(__gm__ Apace::AivComm::CommContext *hcommCtx, GM_ADDR aGM, | 280 | __global__ __aicore__ void AllGatherQuantMatmulKernel(__gm__ Apace::AivComm::CommContext *hcommCtx, GM_ADDR aGM, |
| 273 | GM_ADDR aScaleGM, GM_ADDR bGM, GM_ADDR bScaleGM, GM_ADDR cGM, | 281 | GM_ADDR aScaleGM, GM_ADDR bGM, GM_ADDR bScaleGM, GM_ADDR cGM, |
| 274 | - AllGatherMxMatmulUdmaTilingData tilingData) | 282 | + GM_ADDR biasGM, AllGatherMxMatmulUrmaTilingData tilingData) |
| 275 | { | 283 | { |
| 276 | KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIC_1_1); | 284 | KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_MIX_AIC_1_1); |
| 277 | - Apace::AllGatherMxMatmulUdmaImpl<fp8_e4m3fn_t, fp8_e4m3fn_t, bfloat16_t> impl; | 285 | + Apace::AllGatherMxMatmulUrmaImpl<fp8_e4m3fn_t, fp8_e4m3fn_t, bfloat16_t> impl; |
| 278 | - impl.Init(hcommCtx, aGM, aScaleGM, bGM, bScaleGM, cGM, &tilingData); | 286 | + impl.Init(hcommCtx, aGM, aScaleGM, bGM, bScaleGM, cGM, biasGM, &tilingData); |
| 279 | impl.Process(); | 287 | impl.Process(); |
| 280 | } | 288 | } |
Rmc2/common/op_kernel/apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_udma_tiling_data.h→mc2/common/op_kernel/apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_tiling_data.h+3-2
| @@ -9,7 +9,7 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | /*! | 11 | /*! |
| 12 | - * \file all_gather_mx_matmul_udma_tiling_data.h | 12 | + * \file all_gather_mx_matmul_urma_tiling_data.h |
| 13 | * \brief Tiling data for AllGather + QuantMatmul fusion kernel (prefill variant) | 13 | * \brief Tiling data for AllGather + QuantMatmul fusion kernel (prefill variant) |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| @@ -33,8 +33,9 @@ struct CommContext { | |||
| 33 | using Apace::AivComm::CommContext; | 33 | using Apace::AivComm::CommContext; |
| 34 | 34 | ||
| 35 | #pragma pack(push, 8) | 35 | #pragma pack(push, 8) |
| 36 | -struct alignas(8) AllGatherMxMatmulUdmaTilingData { | 36 | +struct alignas(8) AllGatherMxMatmulUrmaTilingData { |
| 37 | QuantMatmulTilingData mmTile; | 37 | QuantMatmulTilingData mmTile; |
| 38 | CommTilingData commTile; | 38 | CommTilingData commTile; |
| 39 | + uint8_t isBias{0}; | ||
| 39 | }; | 40 | }; |
| 40 | #pragma pack(pop) | 41 | #pragma pack(pop) |
| @@ -133,6 +133,8 @@ public: | |||
| 133 | GM_ADDR bGM{nullptr}; | 133 | GM_ADDR bGM{nullptr}; |
| 134 | GM_ADDR bScaleGM{nullptr}; | 134 | GM_ADDR bScaleGM{nullptr}; |
| 135 | GM_ADDR cGM{nullptr}; | 135 | GM_ADDR cGM{nullptr}; |
| 136 | + GM_ADDR biasGM{nullptr}; | ||
| 137 | + bool isBias{false}; | ||
| 136 | 138 | ||
| 137 | // Win buffer base addresses (computed by communication layer) | 139 | // Win buffer base addresses (computed by communication layer) |
| 138 | GM_ADDR winDataBase{nullptr}; | 140 | GM_ADDR winDataBase{nullptr}; |
| @@ -189,6 +191,7 @@ private: | |||
| 189 | __gm__ BType *bGmAddr_{nullptr}; | 191 | __gm__ BType *bGmAddr_{nullptr}; |
| 190 | __gm__ AscendC::fp8_e8m0_t *scaleBGmAddr_{nullptr}; | 192 | __gm__ AscendC::fp8_e8m0_t *scaleBGmAddr_{nullptr}; |
| 191 | __gm__ CType *cGmAddr_{nullptr}; | 193 | __gm__ CType *cGmAddr_{nullptr}; |
| 194 | + __gm__ float *biasGmAddr_{nullptr}; | ||
| 192 | 195 | ||
| 193 | // ---- FragmentTensor state ---- | 196 | // ---- FragmentTensor state ---- |
| 194 | FragTensorA headFragA_{}; | 197 | FragTensorA headFragA_{}; |
| @@ -201,10 +204,10 @@ private: | |||
| 201 | FragScaleA tailFragScaleA_{}; | 204 | FragScaleA tailFragScaleA_{}; |
| 202 | FragTensorC tailFragC_{}; | 205 | FragTensorC tailFragC_{}; |
| 203 | 206 | ||
| 204 | - // ---- Address bookkeeping ---- | 207 | + static constexpr uint32_t MAX_RANK_SIZE = 16U; // 与 tiling rank_size 上限一致 |
| 205 | - GM_ADDR cFragAddrs_[8]{}; | 208 | + GM_ADDR cFragAddrs_[MAX_RANK_SIZE]{}; |
| 206 | - GM_ADDR winDataRankBase_[8]{}; | 209 | + GM_ADDR winDataRankBase_[MAX_RANK_SIZE]{}; |
| 207 | - GM_ADDR winScaleRankBase_[8]{}; | 210 | + GM_ADDR winScaleRankBase_[MAX_RANK_SIZE]{}; |
| 208 | 211 | ||
| 209 | static constexpr uint32_t MAX_FRAG = Apace::Basic::MAX_FRAGMENT_COUNT; | 212 | static constexpr uint32_t MAX_FRAG = Apace::Basic::MAX_FRAGMENT_COUNT; |
| 210 | GM_ADDR headAddrListA_[MAX_FRAG]{}; | 213 | GM_ADDR headAddrListA_[MAX_FRAG]{}; |
| @@ -241,6 +244,7 @@ __aicore__ inline void AllGatherQbmmMxKernel<AType, BType, CType>::Init(const Pa | |||
| 241 | cGmAddr_ = reinterpret_cast<__gm__ CType *>(params.cGM); | 244 | cGmAddr_ = reinterpret_cast<__gm__ CType *>(params.cGM); |
| 242 | scaleAGmAddr_ = reinterpret_cast<__gm__ AscendC::fp8_e8m0_t *>(params.aScaleGM); | 245 | scaleAGmAddr_ = reinterpret_cast<__gm__ AscendC::fp8_e8m0_t *>(params.aScaleGM); |
| 243 | scaleBGmAddr_ = reinterpret_cast<__gm__ AscendC::fp8_e8m0_t *>(params.bScaleGM); | 246 | scaleBGmAddr_ = reinterpret_cast<__gm__ AscendC::fp8_e8m0_t *>(params.bScaleGM); |
| 247 | + biasGmAddr_ = reinterpret_cast<__gm__ float *>(params.biasGM); | ||
| 244 | } | 248 | } |
| 245 | 249 | ||
| 246 | template <typename AType, typename BType, typename CType> | 250 | template <typename AType, typename BType, typename CType> |
| @@ -308,7 +312,7 @@ __aicore__ inline void AllGatherQbmmMxKernel<AType, BType, CType>::Run(const Par | |||
| 308 | ProblemShape problemShape{totalLogicalM, Ni, Ki, 1}; | 312 | ProblemShape problemShape{totalLogicalM, Ni, Ki, 1}; |
| 309 | BlockScheduler sch(problemShape, schParams); | 313 | BlockScheduler sch(problemShape, schParams); |
| 310 | BlockMmadFragC mmadFrag; | 314 | BlockMmadFragC mmadFrag; |
| 311 | - mmadFrag.Init(problemShape, l0TileShape, fragL1, false, mmT.dbL0c > 1); | 315 | + mmadFrag.Init(problemShape, l0TileShape, fragL1, params.isBias, mmT.dbL0c > 1); |
| 312 | 316 | ||
| 313 | // 延迟构建 fragment tensor(head 先建,main/tail 在 Process 中按需建) | 317 | // 延迟构建 fragment tensor(head 先建,main/tail 在 Process 中按需建) |
| 314 | BuildFragmentTensors(params); | 318 | BuildFragmentTensors(params); |
| @@ -336,8 +340,9 @@ __aicore__ inline void AllGatherQbmmMxKernel<AType, BType, CType>::Process(const | |||
| 336 | auto gmB = Te::MakeTensor(Te::MakeMemPtr<Te::Location::GM>(bGmAddr_), MakeLayoutB{}(Ki, Ni)); | 340 | auto gmB = Te::MakeTensor(Te::MakeMemPtr<Te::Location::GM>(bGmAddr_), MakeLayoutB{}(Ki, Ni)); |
| 337 | auto gmScaleB = Te::MakeTensor(Te::MakeMemPtr<Te::Location::GM>(scaleBGmAddr_), MakeLayoutScaleB{}(scaleKLen, Ni)); | 341 | auto gmScaleB = Te::MakeTensor(Te::MakeMemPtr<Te::Location::GM>(scaleBGmAddr_), MakeLayoutScaleB{}(scaleKLen, Ni)); |
| 338 | __gm__ float *biasNull = nullptr; | 342 | __gm__ float *biasNull = nullptr; |
| 343 | + __gm__ float *biasPtr = params.isBias ? biasGmAddr_ : biasNull; | ||
| 339 | auto gmBias = | 344 | auto gmBias = |
| 340 | - Te::MakeTensor(Te::MakeMemPtr<Te::Location::GM>(biasNull), Te::MakeFrameLayout<Te::NDExtLayoutPtn>(1L, Ni)); | 345 | + Te::MakeTensor(Te::MakeMemPtr<Te::Location::GM>(biasPtr), Te::MakeFrameLayout<Te::NDExtLayoutPtn>(1L, Ni)); |
| 341 | 346 | ||
| 342 | const auto &mTailTile = mmT.mTailTile; | 347 | const auto &mTailTile = mmT.mTailTile; |
| 343 | const auto &nTailTile = mmT.nTailTile; | 348 | const auto &nTailTile = mmT.nTailTile; |
| @@ -31,7 +31,7 @@ from statistics import median | |||
| 31 | _DEFAULT_PROF = os.path.join( | 31 | _DEFAULT_PROF = os.path.join( |
| 32 | os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "prof" | 32 | os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "prof" |
| 33 | ) | 33 | ) |
| 34 | -KERNEL_SUBSTR = "all_gather_quant_matmul" | 34 | +KERNEL_SUBSTR = "AllGatherQuantMatmulUbmemKernel" |
| 35 | GROUP_THRESHOLD_S = 5 | 35 | GROUP_THRESHOLD_S = 5 |
| 36 | OUTLIER_FACTOR = 1.2 | 36 | OUTLIER_FACTOR = 1.2 |
| 37 | WARMUP_SKIP = 3 # 删除前 N 轮数据(冷启动 + 预热) | 37 | WARMUP_SKIP = 3 # 删除前 N 轮数据(冷启动 + 预热) |
| @@ -33,8 +33,8 @@ | |||
| 33 | #include "apace/utils/apace_constant.h" | 33 | #include "apace/utils/apace_constant.h" |
| 34 | #include "apace/utils/apace_common_utils.h" | 34 | #include "apace/utils/apace_common_utils.h" |
| 35 | #include "apace/tiling/quant_matmul_tiling_swat.h" | 35 | #include "apace/tiling/quant_matmul_tiling_swat.h" |
| 36 | -#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_udma_tiling_data.h" | 36 | +#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_tiling_data.h" |
| 37 | -#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_udma_impl.h" | 37 | +#include "apace/kernel/fusions/all_gather_quant_matmul/all_gather_mx_matmul_urma_impl.h" |
| 38 | #include "apace/core/aiv_comm/collective_comm_context.h" | 38 | #include "apace/core/aiv_comm/collective_comm_context.h" |
| 39 | #include "apace/utils/comm_channel_builder.h" | 39 | #include "apace/utils/comm_channel_builder.h" |
| 40 | #include "../../../utils/root_info_exchanger.h" | 40 | #include "../../../utils/root_info_exchanger.h" |
| @@ -93,10 +93,10 @@ void ParseArgs(int argc, char *argv[], int *m, int *k, int *n, int *rankNum, std | |||
| 93 | 93 | ||
| 94 | int LaunchKernel(uint32_t usedCoreNum, aclrtStream stream, CommContext *devContext, GM_ADDR deviceA, | 94 | int LaunchKernel(uint32_t usedCoreNum, aclrtStream stream, CommContext *devContext, GM_ADDR deviceA, |
| 95 | GM_ADDR deviceScaleA, GM_ADDR deviceB, GM_ADDR deviceScaleB, GM_ADDR deviceOutput, | 95 | GM_ADDR deviceScaleA, GM_ADDR deviceB, GM_ADDR deviceScaleB, GM_ADDR deviceOutput, |
| 96 | - AllGatherMxMatmulUdmaTilingData &tilingData) | 96 | + AllGatherMxMatmulUrmaTilingData &tilingData) |
| 97 | { | 97 | { |
| 98 | AllGatherQuantMatmulKernel<<<usedCoreNum, nullptr, stream>>>(devContext, deviceA, deviceScaleA, deviceB, | 98 | AllGatherQuantMatmulKernel<<<usedCoreNum, nullptr, stream>>>(devContext, deviceA, deviceScaleA, deviceB, |
| 99 | - deviceScaleB, deviceOutput, tilingData); | 99 | + deviceScaleB, deviceOutput, nullptr, tilingData); |
| 100 | return 0; | 100 | return 0; |
| 101 | } | 101 | } |
| 102 | 102 | ||
| @@ -105,7 +105,7 @@ int RunAllGatherQuantMatmul(int rankNum, int rankId, int m, int k, int n, const | |||
| 105 | const char *ipport = "tcp://127.0.0.1:8998"; | 105 | const char *ipport = "tcp://127.0.0.1:8998"; |
| 106 | INFO_LOG("rankNum=%d, rankId=%d", rankNum, rankId); | 106 | INFO_LOG("rankNum=%d, rankId=%d", rankNum, rankId); |
| 107 | 107 | ||
| 108 | - AllGatherMxMatmulUdmaTilingData tilingData; | 108 | + AllGatherMxMatmulUrmaTilingData tilingData; |
| 109 | 109 | ||
| 110 | uint32_t tileM = TILE_M; | 110 | uint32_t tileM = TILE_M; |
| 111 | if (m < static_cast<int>(tileM)) { | 111 | if (m < static_cast<int>(tileM)) { |
| @@ -31,7 +31,7 @@ from statistics import median | |||
| 31 | _DEFAULT_PROF = os.path.join( | 31 | _DEFAULT_PROF = os.path.join( |
| 32 | os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "prof" | 32 | os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "prof" |
| 33 | ) | 33 | ) |
| 34 | -KERNEL_SUBSTR = "quant_matmul_reduce_scatter" | 34 | +KERNEL_SUBSTR = "QuantMatmulReduceScatterUbmemKernel" |
| 35 | GROUP_THRESHOLD_S = 5 | 35 | GROUP_THRESHOLD_S = 5 |
| 36 | OUTLIER_FACTOR = 1.2 | 36 | OUTLIER_FACTOR = 1.2 |
| 37 | WARMUP_SKIP = 3 # 删除前 N 轮数据(冷启动 + 预热) | 37 | WARMUP_SKIP = 3 # 删除前 N 轮数据(冷启动 + 预热) |


延用V2转置逻辑,统一一些