The SynetPermute class is a C++ wrapper of tensor dimension permutation. More...
#include <SimdSynet.hpp>
Public Member Functions | |
| SynetPermute () | |
| virtual | ~SynetPermute () |
| SIMD_INLINE void | Init (const Shape &shape, const Shape &order, SimdTensorDataType type) |
| SIMD_INLINE bool | Enable () const |
| SIMD_INLINE size_t | InternalBufferSize () const |
| SIMD_INLINE void | Forward (const uint8_t *src, uint8_t *dst) |
| SIMD_INLINE void | Clear () |
Detailed Description
The SynetPermute class is a C++ wrapper of tensor dimension permutation.
The class wraps C API functions SimdSynetPermuteInit, SimdSynetPermuteInternalBufferSize and SimdSynetPermuteForward. It reorders tensor dimensions. If input shape is shape[0..count-1], then output dimension i has size shape[order[i]]:
dstShape[i] = srcShape[order[i]].
Supported dimension count is from 2 to 5. Dimensions with size 1 can be skipped by the implementation, but the requested permutation must change at least two non-unit dimensions. Supported tensor types are FP32, INT32, INT8, UINT8, BF16 and FP16. Call Init() before Forward(). Use Enable() to check that a context was created. The context is released by Clear() or by the destructor.
Using example:
#include "Simd/SimdSynet.hpp"
int main()
{
const size_t n = 4, m = 8;
std::vector<float> src(n * m), dst(n * m);
for (size_t i = 0; i < src.size(); ++i)
src[i] = float(i);
Simd::Shape shape = Simd::Shape({ n, m });
Simd::Shape order = Simd::Shape({ 1, 0 });
Simd::SynetPermute permute;
permute.Init(shape, order, SimdTensorData32f);
if (permute.Enable())
permute.Forward((const uint8_t*)src.data(), (uint8_t*)dst.data());
return 0;
}
Constructor & Destructor Documentation
◆ SynetPermute()
| SynetPermute | ( | ) |
Creates a new empty SynetPermute class.
◆ ~SynetPermute()
|
virtual |
SynetPermute class destructor. Releases internal context.
Member Function Documentation
◆ Init()
| SIMD_INLINE void Init | ( | const Shape & | shape, |
| const Shape & | order, | ||
| SimdTensorDataType | type | ||
| ) |
Initializes (or re-initializes) a tensor permutation context.
Creates an internal context with using of function SimdSynetPermuteInit. The context is recreated only if input tensor shape or output dimension order were changed.
- Note
- This function is a C++ wrapper for function SimdSynetPermuteInit.
- Parameters
-
[in] shape - a shape of input tensor. Dimension count must be from 2 to 5. [in] order - an output dimension order. The size must be equal to shape size and contain a permutation of dimension indices. [in] type - an input and output tensor data type.
◆ Enable()
| SIMD_INLINE bool Enable | ( | ) | const |
Checks that the internal permutation context was created.
- Returns
- true if the context exists and Forward() can be called.
◆ InternalBufferSize()
| SIMD_INLINE size_t InternalBufferSize | ( | ) | const |
Gets the size in bytes of internal storage used by the permutation context.
- Note
- This function is a C++ wrapper for function SimdSynetPermuteInternalBufferSize.
- Returns
- size of internal buffer in bytes used inside permutation algorithm.
◆ Forward()
| SIMD_INLINE void Forward | ( | const uint8_t * | src, |
| uint8_t * | dst | ||
| ) |
Performs tensor dimension permutation.
The function reorders dimensions of src according to the order stored in the context created by Init() and writes the result to dst.
- Note
- This function is a C++ wrapper for function SimdSynetPermuteForward.
- Parameters
-
[in] src - a pointer to the input tensor bytes. [out] dst - a pointer to the output tensor bytes.
◆ Clear()
| SIMD_INLINE void Clear | ( | ) |
Releases internal context and clears stored tensor parameters.