diff --git a/ggml/src/ggml-cann/aclnn_ops.cpp b/ggml/src/ggml-cann/aclnn_ops.cpp index a98bd49c37e0cf..211de6c8ab4157 100644 --- a/ggml/src/ggml-cann/aclnn_ops.cpp +++ b/ggml/src/ggml-cann/aclnn_ops.cpp @@ -109,8 +109,11 @@ void ggml_cann_repeat(ggml_backend_cann_context& ctx, ggml_tensor* dst) { * @brief Adds two tensors element-wise and stores the result in a destination * tensor. * - * This function performs the operation: dst = acl_src0 + alpha * acl_src1 - * where alpha is a scalar value. + * This function performs the operation: + * \f[ + * dst = acl\_src0 + alpha \times acl\_src1 + * \f] + * where alpha is a scalar value and defaults to 1.0f. * * @param ctx The context for the CANN backend operations. * @param acl_src0 The first source tensor. @@ -119,7 +122,6 @@ void ggml_cann_repeat(ggml_backend_cann_context& ctx, ggml_tensor* dst) { */ static void aclnn_add(ggml_backend_cann_context& ctx, aclTensor* acl_src0, aclTensor* acl_src1, aclTensor* acl_dst) { - // add: dst = acl_src0 + alpha*acl_src1 aclScalar* alpha = nullptr; float alphaValue = 1.0f; alpha = aclCreateScalar(&alphaValue, aclDataType::ACL_FLOAT); @@ -248,8 +250,11 @@ void ggml_cann_concat(ggml_backend_cann_context& ctx, ggml_tensor* dst) { * @brief Creates a tensor with values starting from `start`, incremented by * `step`, and ending before `stop`. * - * This function performs the operation: [start, stop), out(i+1) = out(i) + - * step. + * This function performs the operation: + * \f[ + * \text {out}_{i+1}=\text {out}_i+\text {step} + * \f] + * the range is [start, stop). * * @param ctx The context for the CANN backend operations. * @param acl_dst The destination tensor where the values will be stored. @@ -893,7 +898,7 @@ void ggml_cann_dup(ggml_backend_cann_context& ctx, ggml_tensor* dst) { ACL_CHECK(aclDestroyTensor(acl_dst)); return; } - // TODO: simplefify + // TODO: simplify if (src->type == GGML_TYPE_F16) { if (dst->type == GGML_TYPE_Q8_0) { aclrtlaunch_ascendc_quantize_f16_q8_0( @@ -1396,6 +1401,10 @@ void ggml_cann_im2col(ggml_backend_cann_context& ctx, ggml_tensor* dst) { * * This function computes the exponential of each element in the source tensor * `acl_src` and stores the result back into the same tensor. + * The operation is defined as: + * \f[ + * \text {acl_src}_i=e^{acl\_src_i} + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_src The tensor on which the exponential function will be applied. @@ -1422,7 +1431,12 @@ static void aclnn_exp(ggml_backend_cann_context& ctx, aclTensor* acl_src) { * * This function multiplies each element of the source tensor `acl_src` by the * scalar `scale` and stores the result in the destination tensor `acl_dst`. If - * `inplace` is true, the operation is performed in-place on `acl_src`. + * `inplace` is true, `acl_dst` will not be used and the operation is performed + * in-place on `acl_src`. + * The operation is defined as: + * \f[ + * \text {acl_dst}_i=\text {acl_src}_i \times \text {scale} + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_src The source tensor whose elements will be multiplied. @@ -1471,6 +1485,10 @@ static void aclnn_muls(ggml_backend_cann_context& ctx, aclTensor* acl_src, * * This function performs an element-wise multiplication of the tensors * `acl_src` and `acl_other` and stores the result in `acl_src`. + * The operation is defined as: + * \f[ + * \text {acl_src}_i=\text {acl_src}_i \times \text {acl_other}_i + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_src The source tensor where the multiplication result will be @@ -1500,6 +1518,10 @@ static void aclnn_inplace_mul(ggml_backend_cann_context& ctx, * * This function performs element-wise multiplication of the tensors `acl_src` * and `acl_other` and stores the result in the destination tensor `acl_dst`. + * The operation is defined as: + * \f[ + * \text {acl_dst}_i=\text {acl_src}_i \times \text {acl_other}_i + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_src The first tensor for element-wise multiplication. @@ -1528,6 +1550,10 @@ static void aclnn_mul(ggml_backend_cann_context& ctx, * * This function computes the cosine of each element in the source tensor `acl_src` * and stores the result in the destination tensor `acl_dst`. + * The operation is defined as: + * \f[ + * \text {acl_dst}_i=\cos \left(\text {acl_src}_i\right) + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_src The source tensor on which the cosine function will be applied. @@ -1554,7 +1580,11 @@ static void aclnn_cos(ggml_backend_cann_context& ctx, aclTensor* acl_src, * * This function computes the sine of each element in the source tensor `acl_src` * and stores the result in the destination tensor `acl_dst`. - * + * The operation is defined as: + * \f[ + * \text {acl_dst}_i=\sin \left(\text {acl_src}_i\right) + * \f] + * @param ctx The context for the CANN backend operations. * @param acl_src The source tensor on which the sine function will be applied. * @param acl_dst The destination tensor where the sine results will be stored. @@ -1721,6 +1751,10 @@ static void aclnn_fill_scalar(ggml_backend_cann_context& ctx, float scalar, * * This function computes the element-wise power of the destination tensor * `acl_dst` raised to the power of the exponent tensor `acl_exp`. + * The operation is defined as: + * \f[ + * \text {acl_dst}_i=acl\_dst_i^{\text {acl_exp}_i} + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_dst The destination tensor, which also serves as the base tensor. @@ -1764,12 +1798,16 @@ static void aclnn_pow_tensor_tensor(ggml_backend_cann_context& ctx, * @param dst The destination tensor object for additional metadata. * * The function performs the following steps: - * 1. Calculates the logarithm floor of the number of heads to determine the base for bias calculation. - * 2. Initializes arrays with arithmetic sequences and fills them with bias values. - * 3. Computes the bias tensor based on the calculated biases and arithmetic sequences. + * 1. Calculates the logarithm floor of the number of heads to determine the + base for bias calculation. + * 2. Initializes arrays with arithmetic sequences and fills them with bias + values. + * 3. Computes the bias tensor based on the calculated biases and arithmetic + sequences. * 4. Reshapes the bias tensor to match the dimensions of the input tensors. * 5. Multiplies the position tensor by the bias tensor. - * 6. Adds the result of the multiplication to the source tensor to produce the final output. + * 6. Adds the result of the multiplication to the source tensor to produce the + final output. */ static void aclnn_alibi(ggml_backend_cann_context& ctx, aclTensor* acl_src, aclTensor* acl_position, aclTensor* acl_dst, @@ -2189,6 +2227,10 @@ static void aclnn_repeat_interleave(ggml_backend_cann_context& ctx, * This function computes the matrix multiplication of the input tensor * `acl_input` and the weight tensor `acl_weight`, and stores the result in the * destination tensor `acl_dst`. + * The operation is defined as: + * \f[ + * \text {acl_dst}=\text {acl_input@acl_weight} + * \f] * * @param ctx The context for the CANN backend operations. * @param acl_input The input tensor for the matrix multiplication.