v?add
Perform element-wise addition of vectors. The sum is also a vector.
Interface Definition
C interface:
void vsadd(const int len, const float* src1, const float* src2, float* dst);
void vdadd(const int len, const double* src1, const double* src2, double* dst);
void vcadd(const int len, const float complex *src1, const float complex *src2, float complex *dst);
void vzadd(const int len, const double complex *src1, const double complex *src2, double complex *dst);
void vhadd(const int len, const __fp16 *src1, const __fp16 *src2, __fp16 *dst);
void vchadd(const int len, const complex_fp16 *src1, const complex_fp16 *src2, complex_fp16 *dst);
Fortran interface:
CALL VSADD(LEN, SRC1, SRC2, DST);
CALL VDADD(LEN, SRC1, SRC2, DST);
CALL VZADD(LEN, SRC1, SRC2, DST);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
len |
Integer |
Number of elements in the input vector. If len ≤ 0, an invalid parameter error is reported and the function returns. |
Input |
src1 |
|
Input vector src1 with length len. If the pointer is null, a null pointer error is reported and the function returns. |
Input |
src2 |
|
Input vector src2 with length len. If the pointer is null, a null pointer error is reported and the function returns. |
Input |
dst |
|
Output vector dst with length len. If the pointer is null, a null pointer error is reported and the function returns. |
Output |
Return Value
- The sum of two numbers is returned for each operation value. The value range is (-INF, +INF).
- For vsadd and vdadd, special output values are listed in the following table.
Input Value 1 (src1)
Input Value 2 (src2)
Output Value (dst)
+inf
-inf
nan
-inf
-inf
-inf
+inf
+inf
+inf
-inf
+inf
nan
nan
nan
nan
- For vcadd and vzadd, special output values are listed in vcadd&vzadd.xlsx.
Dependencies
C: "kvml.h"
Examples
C interface:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | int i, len = 4; float src1[len] = {0.0f, 0.5f, 1.5f, 5.5f}; float src2[len] = {0.3f, 0.7f, 2.5f, 10.0f}; float* dst = (float*)malloc(sizeof(float) * len); if (dst == NULL) { printf("Malloc Failed!\n"); return 0; } vsadd(len, src1, src2, dst); /** * Output dst: * 0.3 1.2 4.0 15.5 * */ |
Fortran interface:
INTEGER :: LEN = 4
REAL(4) SRC1(4)
REAL(4) SRC2(4)
REAL(4) DST(4)
DATA SRC1 /1.2, 2.5, -2.4, 3.6/
DATA SRC2 /8.6, -2.5, -12.4, 32.6/
CALL VSADD(LEN, SRC1, SRC2, DST)
!
! OUTPUT DST
! 9.800000191, 0.000000000, -14.799999237, 36.199996948
!