__clz

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Returns the number of consecutive leading zeros in the binary representation of the input data, starting from the most significant bit.

Prototype

1
int __clz(int x)
1
int __clz(long long x)
1
int __clz(long x)

Parameters

Table 1 Parameters

Parameter

Input/Output

Description

x

Input

Source operand.

Returns

The number of consecutive leading zeros in the binary representation of the input data, starting from the most significant bit.

Restrictions

For SIMT programming, this API is not supported.

Header File to Be Included

To use this API, the simt_api/device_functions.h header file must be included.

Examples

For SIMD and SIMT programming:
1
2
3
4
5
__simt_vf__ __launch_bounds__(1024) inline void KernelClz(__gm__ int* dst, __gm__ int* x)
{
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    dst[idx] = __clz(x[idx]);
}
1
2
3
4
5
__simt_vf__ __launch_bounds__(1024) inline void KernelClz(__gm__ int* dst, __gm__ long long* x)
{
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    dst[idx] = __clz(x[idx]);
}