Global Average Pool
File:
/src/neuralNetBlocks/pool.hppLines 1174–1229 /**
* @brief Perform global average pool on an input stored in OCM.
*
* A global average pool compresses a tensor by mapping each input channel
* to a single element that is the average of the values in that
* channel. The output is a row vector of sequential data.
*
* For example, a tensor of dimensions `<1, 512, 8, 8>` would be
* compressed to a tensor of dimensions `<1, 1, 1, 512>`.
*
* When the data is flown in, each input channel maps to a single
* qVar_t that is the element-wise sum of each of the tiles
* composing that input channel so that the array of qVar_t's can
* easily be passed to calculateTileSum without having to do
* complicated indexing.
*
* When transferring the data after calculateTileSum to qOutput[],
* there is an outCond that determines the manner in which
* qOutput[] is populated. qOutput[] is populated sequentially
* with the average for each input channel. Since each tile in
* qData[] contains the average for that corresponding input
* channel, we can copy the 0th element of qData[0], the 1st
* element of qData[1], and so on into qOutput[0]. When we get to
* the 65th input channel, we copy the 0th element of qData[64] to
* qOutput[1]. For the 66th channel, we copy the 1st element of
* qData[65] to qOutput[1]. And so on for all of the input
* channels.
*
* Note that when rescaleFactor is used, it *must* include the
* division by the layer size. This provides maximum precision.
*
* @ingroup pooling
* @param ocmIn The input tensor to be globally-average pooled.
* @param ocmOut The output tensor where the global average pool will be stored.
* @param rescaleFactor Scaling factor used for re-quantization.
* @param inputZeroPoint Input zero point used for asymmetric quantization.
* @param outputZeroPoint Output zero point used for asymmetric quantization.
* @param offset Offset in OCM output tensor where global average pool output will be written.
* @tparam OcmInTensorShape The shape of the ocm in.
* @tparam OcmOutTensorShape The shape of the ocm out.
* @tparam T The FixedPoint Library Type.
* @tparam ScaleType Type of scaling factor used for re-quantization.
*/
// clang-format on
template <typename OcmInTensorShape,
typename OcmOutTensorShape,
typename T,
isOcmTensor<OcmInTensorShape> = 0,
isOcmTensor<OcmOutTensorShape> = 0,
typename ScaleType = EmptyType>
INLINE void globalAveragePool(OcmInTensorShape& ocmIn,
OcmOutTensorShape& ocmOut,
const ScaleType& rescaleFactor = EmptyType(),
const std::int32_t inputZeroPoint = 0,
const std::int32_t outputZeroPoint = 0,
const std::int32_t offset = 0) {
Corner Pool
File:
/src/neuralNetBlocks/pool.hppLines 2699–2723 /**
* @brief
* Performs corner pool operations.
*
* Please see the descriptions of individual corner pool functions to understand the limitations of supported
* Image sizes. ( @ref cornerPoolTop, @ref cornerPoolBottom, @ref cornerPoolLeft, @ref cornerPoolRight )
*
* @ingroup pooling
*
* @tparam poolType cornerpool direction as enum
* @tparam DdrInputImageShape The shape of the input DDR tensor
* @tparam DdrOutputImageShape The shape of the output DDR tensor
* @tparam OcmAllocatorType Type of OCM memory allocator
*
* @param[in] ddrInputImage Input DDR tensor
* @param ddrOutputImage Output DDR tensor
* @param ocmMemAlloc OCM memory allocator
*/
template <CornerPoolType poolType,
typename DdrInputImageShape,
typename DdrOutputImageShape,
typename OcmAllocatorType>
void cornerPool(DdrInputImageShape& ddrInputImage,
DdrOutputImageShape& ddrOutputImage,
OcmAllocatorType& ocmMemAlloc) {