Nrm2

Applicable Products

Hardware Model

Supported or Not

Atlas 200I/500 A2 inference products

Not supported

Atlas inference products

Not supported

Atlas training products

Not supported

Atlas A2 training products / Atlas A2 inference products

Supported

Atlas A3 inference products / Atlas A3 training products

Supported

Function Description

API function

  • asdBlasMakeNrm2Plan: initializes the Nrm2 operator configuration corresponding to the handle.
  • asdBlasSnrm2: computes the Euclidean norm of a real number vector.
  • asdBlasScnrm2: sums the absolute values of all input elements. The input elements are complex numbers.

Formula:

  • asdBlasSnrm2 formula:

    represents the th element in the vector .

    • Example:

      Input x:

      [1, 2, -3, 4]

      After the Snrm2 operator is called, the output result is as follows:

      5.47723
  • asdBlasScnrm2 formula:

    represents the th element in the vector , is a complex element, and .

    • Example:

      Input x:

      [1+2i, 2-2i, -3+3i, 4-3i]

      After the Scnrm2 operator is called, the output result is as follows:

      7.48331

Function Prototype

  • AspbStatus asdBlasMakeNrm2Plan(asdBlasHandle handle)
  • AspbStatus asdBlasSnrm2(asdBlasHandle handle, const int64_t n, aclTensor *x, const int64_t incx, aclTensor *result)
  • AspbStatus asdBlasScnrm2(asdBlasHandle handle, const int64_t n, aclTensor *x, const int64_t incx, aclTensor *result)

Parameter Description

  • asdBlasMakeNrm2Plan

    Parameter

    Input/Output

    Type

    Description

    handle

    Input

    asdBlasHandle

    Handle of the Nrm2 operator.

  • asdBlasSnrm2 & asdBlasScnrm2

    Parameter

    Input/Output

    Type

    Description

    handle

    Input

    asdBlasHandle

    Nrm2 operator handle.

    n

    Input

    const char

    Total number of elements.

    x

    Input

    aclTensor *

    x in the formula, which is a tensor on the device. The data format can be ND, and the shape is [n].

    • For Snrm2, the supported data type is FLOAT32.
    • For Scnrm2, the supported data type is COMPLEX64.

    incx

    Input

    const int64_t

    Memory address increment between the consecutive elements (currently, the offset is 1).

    result

    Output

    aclTensor *

    result in the formula, which is a tensor on the device. The supported data type is FLOAT32. It contains only one element. The data format supports ND, and the shape is [1].

Return Value Description

For details about the return values, see Return Value.

Constraints

  • asdBlasMakeNrm2Plan: none.
  • asdBlasSnrm2
    • The input element count n currently supports the range [1, 6.71e+06].
    • The input shape of the operator is [n], and the output shape is [1].
    • The operator does not support the calculation for three or more dimensions.
  • asdBlasScnrm2
    • The input element count n currently supports the range [1, 6.71e+06].
    • The input shape of the operator is [n], and the output shape is [1].
    • The operator does not support the calculation for three or more dimensions.

Calling Example

For details about the operator calling example, see Nrm2.