normf
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Obtains the square root of the sum of squares of the first n elements in the input data a (a[0]2 + a[1]2 + ... + a[n-1]2).

Prototype
1 | inline float normf(int n, float* a) |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
n |
Input |
Source operand. Number of consecutive elements for computation in the input data a. |
a |
Input |
Source operand. Unified Buffer, Global Memory, or stack address. |
Returns
Square root of a[0]2 + a[1]2 + ... + a[n-1]2.
- If the square root of a[0]2 + a[1]2 + ... + a[n-1]2 exceeds the maximum range of float, the return value is inf.
- If any or more of a[0], a[1], ..., and a[n-1] are ±inf, the return value is inf.
- If any or more of a[0], a[1], ..., and a[n-1] are nan and not ±inf, the return value is nan.
- If n is less than 1, the absolute value of a[0] is returned.
Restrictions
- The length of the input data a must be greater than or equal to that of the parameter n.
- If n is too large, the API performance cannot be guaranteed.
- For SIMT programming, this API is not supported.
Header File to Be Included
To use this API, the simt_api/math_functions.h header file must be included.
1 | #include "simt_api/math_functions.h" |
Examples
For SIMD and SIMT programming:
In SIMD and SIMT programming, the address space qualifier must be explicitly used to indicate the address space. __gm__ indicates the Global Memory memory space, and __ubuf__ indicates the Unified Buffer memory space. No address space qualifier is required for the stack space.
1 2 3 4 5 | __simt_vf__ __launch_bounds__(1024) inline void KernelNorm(__gm__ float* dst, __gm__ int* n, __gm__ float* a) { int idx = threadIdx.x + blockIdx.x * blockDim.x; dst[idx] = normf(n[idx], a); } |
Parent topic: Mathematical Functions