Mul

功能说明

乘法运算,支持张量*张量,张量*标量,标量*张量。

所属头文件链接

/include/operators/math_expression.h

函数原型

template<typename T, typename U>
struct OpMul : BinaryOp<T, U>

template<typename T, typename U>
__host_aicore__ constexpr auto operator*(Expression<T> lhs, Expression<U> rhs)

template<typename T, typename U>
__host_aicore__ constexpr auto operator*(Expression<T> lhs, U &&rhs)

template<typename T, typename U>
__host_aicore__ constexpr auto operator*(T &&lhs, Expression<U> rhs)

参数说明

参数名称 参数类型 输入/输出 数据类型 参数说明 默认值
T 模板参数 输入 NA 乘法左操作数数据类型 NA
U 模板参数 输入 NA 乘法右操作数数据类型 NA
lhs 函数形参 输入 NA 乘法左操作数,当类型是Expression<T>时,是张量,当类型是T时,是标量 NA
rhs 函数形参 输入 NA 乘法右操作数,当类型是Expression<U>时,是张量,当类型是U时,是标量 NA

返回值说明

返回值数据类型 返回值说明
Expression> 返回一个OpMul的表达式

约束说明

不支持广播

使用示例

template <typename InputDtype, typename OutputDtype>
struct Config {
    struct Compute {
        template <template <typename> class Tensor>
        __host_aicore__ constexpr auto Compute() const
        {
            auto in1 = Atvoss::PlaceHolder<1, Tensor<InputDtype>, Atvoss::ParamUsage::IN>();
            auto in2 = Atvoss::PlaceHolder<2, Tensor<InputDtype>, Atvoss::ParamUsage::IN>();
            auto out = Atvoss::PlaceHolder<3, Tensor<OutputDtype>, Atvoss::ParamUsage::OUT>();

            // 🔥🔥🔥 使用示例 🔥🔥🔥
            return (out = in1 * in2);
            // 🔥🔥🔥 使用示例 🔥🔥🔥
        };
    };
};

template <typename InputDtype, typename OutputDtype>
struct Config {
    struct Compute {
        template <template <typename> class Tensor>
        __host_aicore__ constexpr auto Compute() const
        {
            auto in = Atvoss::PlaceHolder<1, Tensor<InputDtype>, Atvoss::ParamUsage::IN>();
            auto scalar = Atvoss::PlaceHolder<2, InputDtype, Atvoss::ParamUsage::IN>();
            auto out = Atvoss::PlaceHolder<3, Tensor<OutputDtype>, Atvoss::ParamUsage::OUT>();

            // 🔥🔥🔥 使用示例 🔥🔥🔥
            return (out = in * scalar);
            // 🔥🔥🔥 使用示例 🔥🔥🔥
        };
    };
};

template <typename InputDtype, typename OutputDtype>
struct Config {
    struct Compute {
        template <template <typename> class Tensor>
        __host_aicore__ constexpr auto Compute() const
        {
            auto in = Atvoss::PlaceHolder<1, Tensor<InputDtype>, Atvoss::ParamUsage::IN>();
            auto scalar = Atvoss::PlaceHolder<2, InputDtype, Atvoss::ParamUsage::IN>();
            auto out = Atvoss::PlaceHolder<3, Tensor<OutputDtype>, Atvoss::ParamUsage::OUT>();

            // 🔥🔥🔥 使用示例 🔥🔥🔥
            return (out = scalar * in);
            // 🔥🔥🔥 使用示例 🔥🔥🔥
        };
    };
};