vec_ln
Description
Computes the natural logarithm element-wise: 

Prototype
vec_ln(mask, dst, src, repeat_times, dst_rep_stride, src_rep_stride)
Parameters
For details, see Parameters.
dst and src must have the same data type.
Returns
None
Applicability
Restrictions
- The src values must be positive. If negatives or zeros are used, an unknown result may be generated.
- For the
Atlas 200/300/500 Inference Product , the compute result using this API with float16 input in the range (0, 5/3) fails to meet the dual-0.1% error limit (the error ratio is within 0.1% and the relative error is within 0.1%). If the accuracy requirement is high, the vec_ln_high_preci API is preferred. - For other restrictions, see Restrictions.
Example
This example applies to a small amount of data that can be moved at a time, helping you understand the API functions. For more complex samples with a large amount of data, see Example.
from tbe import tik
tik_instance = tik.Tik()
# Define the tensors.
src_gm = tik_instance.Tensor("float16", (128,), tik.scope_gm, "src_gm")
src_ub = tik_instance.Tensor("float16", (128,), name="src_ub", scope=tik.scope_ubuf)
dst_ub = tik_instance.Tensor("float16", (128,), name="dst_ub", scope=tik.scope_ubuf)
dst_gm = tik_instance.Tensor("float16", (128,), tik.scope_gm, "dst_gm")
# Move the user input from the Global Memory to the Unified Buffer.
tik_instance.data_move(src_ub, src_gm, 0, 1, 8, 0, 0)
tik_instance.vec_ln(128, dst_ub, src_ub, 1, 8, 8)
# Move the compute result from the Unified Buffer to the destination Global Memory.
tik_instance.data_move(dst_gm, dst_ub, 0, 1, 8, 0, 0)
tik_instance.BuildCCE(kernel_name="vec_ln", inputs=[src_gm], outputs=[dst_gm])
Result example:
Input: [1, 2, 3, 4, ......, 128] Output: [0, 0.6931, 1.0986, 1.3863, ......, 4.8520]
Parent topic: Single Source (Gather Mode)