Skip to content

Commit ef676b0

Browse files
committed
add comment for aclnn_ops.cpp
1 parent a5e0e2c commit ef676b0

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

ggml/src/ggml-cann/aclnn_ops.cpp

+54-12
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ void ggml_cann_repeat(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
109109
* @brief Adds two tensors element-wise and stores the result in a destination
110110
* tensor.
111111
*
112-
* This function performs the operation: dst = acl_src0 + alpha * acl_src1
113-
* where alpha is a scalar value.
112+
* This function performs the operation:
113+
* \f[
114+
* dst = acl\_src0 + alpha \times acl\_src1
115+
* \f]
116+
* where alpha is a scalar value and defaults to 1.0f.
114117
*
115118
* @param ctx The context for the CANN backend operations.
116119
* @param acl_src0 The first source tensor.
@@ -119,7 +122,6 @@ void ggml_cann_repeat(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
119122
*/
120123
static void aclnn_add(ggml_backend_cann_context& ctx, aclTensor* acl_src0,
121124
aclTensor* acl_src1, aclTensor* acl_dst) {
122-
// add: dst = acl_src0 + alpha*acl_src1
123125
aclScalar* alpha = nullptr;
124126
float alphaValue = 1.0f;
125127
alpha = aclCreateScalar(&alphaValue, aclDataType::ACL_FLOAT);
@@ -248,8 +250,11 @@ void ggml_cann_concat(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
248250
* @brief Creates a tensor with values starting from `start`, incremented by
249251
* `step`, and ending before `stop`.
250252
*
251-
* This function performs the operation: [start, stop), out(i+1) = out(i) +
252-
* step.
253+
* This function performs the operation:
254+
* \f[
255+
* \text {out}_{i+1}=\text {out}_i+\text {step}
256+
* \f]
257+
* the range is [start, stop).
253258
*
254259
* @param ctx The context for the CANN backend operations.
255260
* @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) {
893898
ACL_CHECK(aclDestroyTensor(acl_dst));
894899
return;
895900
}
896-
// TODO: simplefify
901+
// TODO: simplify
897902
if (src->type == GGML_TYPE_F16) {
898903
if (dst->type == GGML_TYPE_Q8_0) {
899904
aclrtlaunch_ascendc_quantize_f16_q8_0(
@@ -1396,6 +1401,10 @@ void ggml_cann_im2col(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
13961401
*
13971402
* This function computes the exponential of each element in the source tensor
13981403
* `acl_src` and stores the result back into the same tensor.
1404+
* The operation is defined as:
1405+
* \f[
1406+
* \text {acl_src}_i=e^{acl\_src_i}
1407+
* \f]
13991408
*
14001409
* @param ctx The context for the CANN backend operations.
14011410
* @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) {
14221431
*
14231432
* This function multiplies each element of the source tensor `acl_src` by the
14241433
* scalar `scale` and stores the result in the destination tensor `acl_dst`. If
1425-
* `inplace` is true, the operation is performed in-place on `acl_src`.
1434+
* `inplace` is true, `acl_dst` will not be used and the operation is performed
1435+
* in-place on `acl_src`.
1436+
* The operation is defined as:
1437+
* \f[
1438+
* \text {acl_dst}_i=\text {acl_src}_i \times \text {scale}
1439+
* \f]
14261440
*
14271441
* @param ctx The context for the CANN backend operations.
14281442
* @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,
14711485
*
14721486
* This function performs an element-wise multiplication of the tensors
14731487
* `acl_src` and `acl_other` and stores the result in `acl_src`.
1488+
* The operation is defined as:
1489+
* \f[
1490+
* \text {acl_src}_i=\text {acl_src}_i \times \text {acl_other}_i
1491+
* \f]
14741492
*
14751493
* @param ctx The context for the CANN backend operations.
14761494
* @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,
15001518
*
15011519
* This function performs element-wise multiplication of the tensors `acl_src`
15021520
* and `acl_other` and stores the result in the destination tensor `acl_dst`.
1521+
* The operation is defined as:
1522+
* \f[
1523+
* \text {acl_dst}_i=\text {acl_src}_i \times \text {acl_other}_i
1524+
* \f]
15031525
*
15041526
* @param ctx The context for the CANN backend operations.
15051527
* @param acl_src The first tensor for element-wise multiplication.
@@ -1528,6 +1550,10 @@ static void aclnn_mul(ggml_backend_cann_context& ctx,
15281550
*
15291551
* This function computes the cosine of each element in the source tensor `acl_src`
15301552
* and stores the result in the destination tensor `acl_dst`.
1553+
* The operation is defined as:
1554+
* \f[
1555+
* \text {acl_dst}_i=\cos \left(\text {acl_src}_i\right)
1556+
* \f]
15311557
*
15321558
* @param ctx The context for the CANN backend operations.
15331559
* @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,
15541580
*
15551581
* This function computes the sine of each element in the source tensor `acl_src`
15561582
* and stores the result in the destination tensor `acl_dst`.
1557-
*
1583+
* The operation is defined as:
1584+
* \f[
1585+
* \text {acl_dst}_i=\sin \left(\text {acl_src}_i\right)
1586+
* \f]
1587+
15581588
* @param ctx The context for the CANN backend operations.
15591589
* @param acl_src The source tensor on which the sine function will be applied.
15601590
* @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,
17211751
*
17221752
* This function computes the element-wise power of the destination tensor
17231753
* `acl_dst` raised to the power of the exponent tensor `acl_exp`.
1754+
* The operation is defined as:
1755+
* \f[
1756+
* \text {acl_dst}_i=acl\_dst_i^{\text {acl_exp}_i}
1757+
* \f]
17241758
*
17251759
* @param ctx The context for the CANN backend operations.
17261760
* @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,
17641798
* @param dst The destination tensor object for additional metadata.
17651799
*
17661800
* The function performs the following steps:
1767-
* 1. Calculates the logarithm floor of the number of heads to determine the base for bias calculation.
1768-
* 2. Initializes arrays with arithmetic sequences and fills them with bias values.
1769-
* 3. Computes the bias tensor based on the calculated biases and arithmetic sequences.
1801+
* 1. Calculates the logarithm floor of the number of heads to determine the
1802+
base for bias calculation.
1803+
* 2. Initializes arrays with arithmetic sequences and fills them with bias
1804+
values.
1805+
* 3. Computes the bias tensor based on the calculated biases and arithmetic
1806+
sequences.
17701807
* 4. Reshapes the bias tensor to match the dimensions of the input tensors.
17711808
* 5. Multiplies the position tensor by the bias tensor.
1772-
* 6. Adds the result of the multiplication to the source tensor to produce the final output.
1809+
* 6. Adds the result of the multiplication to the source tensor to produce the
1810+
final output.
17731811
*/
17741812
static void aclnn_alibi(ggml_backend_cann_context& ctx, aclTensor* acl_src,
17751813
aclTensor* acl_position, aclTensor* acl_dst,
@@ -2189,6 +2227,10 @@ static void aclnn_repeat_interleave(ggml_backend_cann_context& ctx,
21892227
* This function computes the matrix multiplication of the input tensor
21902228
* `acl_input` and the weight tensor `acl_weight`, and stores the result in the
21912229
* destination tensor `acl_dst`.
2230+
* The operation is defined as:
2231+
* \f[
2232+
* \text {acl_dst}=\text {acl_input@acl_weight}
2233+
* \f]
21922234
*
21932235
* @param ctx The context for the CANN backend operations.
21942236
* @param acl_input The input tensor for the matrix multiplication.

0 commit comments

Comments
 (0)