#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# ----------------------------------------------------------------------------
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
# CANN Open Software License Agreement Version 2.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ----------------------------------------------------------------------------
__golden__ = {
"kernel": {
"matmul_all_reduce": "matmul_all_reduce_golden"
}
}
import numpy as np
import torch
def matmul_all_reduce_golden(
x1,
x2,
bias=None,
x3=None,
antiquant_scale=None,
antiquant_offset=None,
dequant_scale=None,
pertoken_scale=None,
comm_quant_scale_1=None,
comm_quant_scale_2=None,
group=None,
reduce_op: str = "sum",
is_trans_a: bool = False,
is_trans_b: bool = False,
comm_turn: int = 0,
antiquant_group_size: int = 0,
group_size: int = 0,
y_dtype: int = 0,
comm_quant_mode: int = 0,
**kwargs
):
if is_trans_b:
x2 = x2.t()
output = torch.matmul(x1, x2)
if bias is not None:
output = torch.add(output, bias)
return output