Mask Operations

The mask operation APIs are used to manually configure the normal mode and counter mode outside the vector computation API and set the mask in the corresponding mode.

What Are the Normal Mode and Counter Mode?

The normal mode is the default mode. You can configure the number of iterations. The configuration mode described in Common Parameters is the normal mode. To simplify operations, the counter mode is provided. You do not need to perceive the number of iterations or process non-aligned tail blocks. Instead, the data to be computed can be directly copied in. The actual number of iterations is automatically inferred by the Vector Unit.

  • The counter mode is more convenient because it does not need to compute the tail blocks. However, it does not support the mask operations in a single iteration.
  • The normal mode supports the mask operations in a single iteration. However, the normal mode is not as convenient as the counter mode, because you need to pay attention to the number of iterations and compute the tail blocks.

By default, the normal mode is used in the high-dimensional sharding computation API, and the counter mode is used in the API for computing the first n data shards of a tensor.

In Which Scenarios Do I Need to Manually Set the Normal Mode or Counter Mode?

Since the normal mode or counter mode has been used in the high-dimensional sharding computation API or the API for computing the first n data shards of a tensor, why do you need to manually configure the mode?

  • Counter mode
    • For contiguous computation, if the data volume is the same, you can use the counter mode and set the data volume to be computed. You do not need to set the data volume repeatedly in the API, which improves the performance.
    • When the high-dimensional sharding computation API is used with the counter mode, the interval computation is added to the computation of the first n data shards of the tensor. The dataBlockStride and repeatStride parameters are supported.
  • Normal mode

    For non-contiguous computation with the mask parameter (controlling the number of elements involved in the computation in a single iteration), if the mask parameters are the same, you can use the normal mode and set the mask parameters. You do not need to set the mask parameters repeatedly in the API, which saves the repeated setting process in the API and improves the performance.

How Do I Manually Set the Normal Mode?

The process of setting and using the normal mode is as follows:

  1. Call the SetMaskNorm API to set the normal mode.
  2. Call the SetVectorMask API to set the mask. In normal mode, the mask parameter is used to control the number of elements involved in computation in a single iteration.
  3. Call the high-dimensional tensor sharding computation API.
    • The isSetMask template parameter must be set to false, indicating that the mask is set outside the vector computation API. The input parameter mask of the API is set to MASK_PLACEHOLDER, which is used as a placeholder and has no actual meaning.
    • In normal mode, set repeatTimes, dataBlockStride, and repeatStride as required.
  4. Call the ResetMask API to restore the value of mask to the default value.

How Do I Manually Set the Counter Mode?

  1. Call the SetMaskCount API to set the counter mode.
  2. Call the SetVectorMask API to set the mask. In counter mode, the mask parameter indicates the number of elements involved in the entire vector computation.
  3. Call the vector computation APIs.
    • API for high-dimensional tensor sharding computation:
      • The isSetMask template parameter must be set to false, indicating that the mask is set outside the vector computation API. The input parameter mask of the API is set to MASK_PLACEHOLDER, which is used as a placeholder and has no actual meaning.
      • Set the dataBlockStride and repeatStride parameters as required. Set repeatTimes to a fixed value (recommended: 1, indicating this value does not take effect).
    • API for computing the first n data shards of a tensor (Currently, only some of these APIs support the isSetMask template parameter.): The isSetMask template parameter must be set to false, indicating that the mask is set outside the vector computation API. The input parameter calCount of the API does not take effect, and you are advised to set it to 1.
  4. In counter mode, you need to call SetMaskNorm to restore the mask mode to the normal mode after the vector computation is complete.
  5. Call the ResetMask API to restore the value of mask to the default value.