reshape
File:
/src/neuralNetBlocks/pool.hppLines 537–618 /**
* @brief
* Perform reshape from the input shape to the output shape.
* Currently, we support 3 shape layouts (C, H, W), (C, 1, H*W), and (1, 1, C*H*W).
* The implementation:
* 1. Uses a Row Iterator to flow in data:
* 2. Computes the input x, y, z locations for each core
* 3. Computes the input location in contiguous memory
* 4. Computes the output x, y, z for each core
* 5. Using the pitched width of the output tensor, computes the output location.
* 6. rau::store valid data values.
* @ingroup pooling
* The following reshapes are supported and tested:
* \verbatim
*
* +---------------+
* | | +-------+
* | | +-----+ |
* | | +----------> | | |
* | | | | +
* +---------------+ +-----+
* 2D Tensor Shape 3D Tensor Shape
* (C, 1, H * W) (C, H, W)
*
*
*
* +--------+ +---------------+
* | | |
* +------+ | | |
* | | | +----------> | |
* | | + | |
* +------+ +---------------+
* 3D Tensor Shape 2D Tensor Shape
* (C, H, W) (C, 1, H * W)
*
*
*
* +--------+
* +-------+ |
* +-------------+ +----------> | | |
* 1D Tensor Shape | | +
* (C * H * W) +-------+
* 3D Tensor Shape
* (C, H, W)
* +------------+
* |
* +-----------+ | +-----------> +-----------------+
* | | | 1D Tensor Shape
* | | + (C * H * W)
* +-----------+
* 3D Tensor Shape
* (C, H, W)
* \endverbatim
* @param[in] ocmIn The Ocm Input
* @param ocmOut The Ocm output
*
* @tparam OcmInTensorShape The shape of the input ocm tensor
* @tparam OcmOutTensorShape The shape of the output ocm tensor
* @tparam numRowFlowsPerInputWidth The number of flows in width if the row iterator is used for fetching
* @tparam numRowFlowsPerOutputWidth The number of flows in width if the row iterator is used for writing
* @tparam useDefaultImplementation Whether or not we use the implementation of reshape that uses a row
* iterator to fetch or a row iterator to write. We determine if we use a rau
* load and a row iterator write strategy or a row iterator fetch and
* rau store strategy depending on the total
* number of flows we would need to properly remap the data in OCM.
* We pick whichever strategy leads to less overall flows to improve
* performance. This implementation choses the row iterator fetch and rau
* store strategy
*/
template <
typename OcmInTensorShape,
typename OcmOutTensorShape,
typename OcmAllocatorType,
std::int32_t numRowFlowsPerInputWidth =
roundUpToNearestMultiple(OcmInTensorShape::NUM_COLS, core_array::numArrayCores) / core_array::numArrayCores,
std::int32_t numRowFlowsPerOutputWidth =
roundUpToNearestMultiple(OcmOutTensorShape::NUM_COLS, core_array::numArrayCores) / core_array::numArrayCores,
bool useDefaultImplementation =
(OcmInTensorShape::NUM_CHN * OcmInTensorShape::NUM_ROWS * numRowFlowsPerInputWidth) <
(OcmOutTensorShape::NUM_CHN * OcmOutTensorShape::NUM_ROWS * numRowFlowsPerOutputWidth),
std::enable_if_t<useDefaultImplementation, std::int32_t> = 0>
INLINE void reshape(OcmInTensorShape& ocmIn, OcmOutTensorShape& ocmOut, OcmAllocatorType& ocmMemAlloc) {
Resize
General tensor resize (chimera::image::resize) is documented in Image Resize, including nearest neighbors, DDR → DDR, and multicore variants.
where
File:
/src/tensorOps.hppLines 27–56 /**
* @brief This function fetches elements of an input tensor of shape TensorShape from a ROI of shape
* RoIShape using the fetchTilesInRoi function in the EPU cores.
* It takes a lambda function which selects a set of values and returns a list of addresses
* of the selected values. If the ROI is 1d then the output shape is 1D and nDim is 1.
* Currently only ROI of 1D has been implemented and tested. The code should work for 2D, 3D and 4D
* RoI shape, but the address computation for greater than 1D has not been fully implemented.
* @tparam T is either FixedPoint or int32/int16/int8/uint32/uint16/uint8
* @tparam TensorShape of the input tensor shape
* @tparam RoIShape is the shape of the RoI of interest
* @tparam nDims is the number of dimensions of the RoI Shape
* @tparam lambda is the type of the function used to select the values
* @param t is the input tensor,
* @param colMap is the output tensor of addresses of the selected elements
* @param is batch position of the RoIShape
* @param is the channel position of the RoIShape
* @param is the row position of the RoIShape
* @param is the col position of the RoIShape
* @param isTrueFn is the lambda function used to select the values
* @return is a qVar specifying the number of addresses selected. All the values in the tile have
* the same value
*/
template <typename T, typename TensorShape, typename RoIShape, typename OutputShape, typename Lambda>
qVar_t<std::int32_t> where(TensorShape& t,
OutputShape& colMap,
std::int16_t batchOffset,
std::int16_t channelOffset,
std::int16_t rowOffset,
std::int16_t colOffset,
Lambda isTrueFn) {