SetValue
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
√ |
|
√ |
|
√ |
|
√ |
Function Usage
Sets a value in the LocalTensor.
This API is supported only when the TPosition of the LocalTensor is VECIN, VECCALC, or VECOUT.
Prototype
1 2 | template <typename T1> __aicore__ inline __inout_pipe__(S) void SetValue(const uint32_t index, const T1 value) const |
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
index |
Input |
LocalTensor index. The unit is element. |
value |
Input |
Value to be set. |
Returns
None
Restrictions
Do not use SetValue to assign values to the LocalTensor frequently. Otherwise, the performance deteriorates. If a large number of values need to be assigned, select basic APIs for data padding or high-level APIs for data padding (Pad and Broadcast) based on the actual situation. If incremental sequences need to be generated, select Arange.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // srcLen = 256, num = 100, M=50 // Example 1 for (int32_t i = 0; i < srcLen; ++i) { inputLocal.SetValue(i, num); // Assign num to the ith position in inputLocal. } // The result of example 1 is as follows: // Data (inputLocal): [100 100 100... 100] // srcLen = 256, num = 99, M=50 // Example 2 for (int32_t i = 0; i < srcLen; ++i) { inputLocal(i) = num; // Assign num to the ith position in inputLocal. } // The result of example 2 is as follows: // Data (inputLocal): [99 99 99... 99] |