From 1c5561ba9483ee89e860237faf66613c097c4149 Mon Sep 17 00:00:00 2001 From: Pierre Aubert Date: Sat, 16 Jan 2021 23:40:47 +0100 Subject: [PATCH] Add function to reshuffle tensor in vector mode --- TESTS/CMakeLists.txt | 1 + src/PTensor.h | 2 +- src/reshuffle_tensor.h | 26 ++++++++++++ src/reshuffle_tensor_impl.h | 83 +++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/reshuffle_tensor.h create mode 100644 src/reshuffle_tensor_impl.h diff --git a/TESTS/CMakeLists.txt b/TESTS/CMakeLists.txt index cc0db5e..c0fc256 100644 --- a/TESTS/CMakeLists.txt +++ b/TESTS/CMakeLists.txt @@ -6,4 +6,5 @@ add_subdirectory(TEST_TENSOR_SIZE) add_subdirectory(TEST_TENSOR_MESSAGE) add_subdirectory(TEST_TENSOR_FILE) add_subdirectory(TEST_TENSOR_COPY_POINTER) +add_subdirectory(TEST_TENSOR_RESHUFFLE) diff --git a/src/PTensor.h b/src/PTensor.h index 45e2c46..1cd9276 100644 --- a/src/PTensor.h +++ b/src/PTensor.h @@ -10,7 +10,7 @@ #include #include "data_all.h" #include "template_alloc.h" - +#include "reshuffle_tensor.h" ///@brief Deal with general tensor, allocation and other stuff template diff --git a/src/reshuffle_tensor.h b/src/reshuffle_tensor.h new file mode 100644 index 0000000..aee6529 --- /dev/null +++ b/src/reshuffle_tensor.h @@ -0,0 +1,26 @@ +/*************************************** + Auteur : Pierre Aubert + Mail : aubertp7@gmail.com + Licence : CeCILL-C +****************************************/ + +#ifndef __RESHUFFLE_TENSOR_H__ +#define __RESHUFFLE_TENSOR_H__ + +#include + +template +void reshuffle_row_toVecNeighbour(T * rowVecNeighbour, size_t paddingVec, const T * rowScalNeighbour, size_t nbCol, size_t vectorSize); + +template +void reshuffle_row_toScalNeighbour(T * rowScalNeighbour, const T * rowVecNeighbour, size_t paddingVec, size_t nbCol, size_t vectorSize); + +template +void reshuffle_tensor_toVecNeighbour(T * tensorVecNeighbour, size_t paddingVec, const T * tensorScalNeighbour, size_t paddingScal, size_t nbRow, size_t nbCol, size_t vectorSize); + +template +void reshuffle_tensor_toScalNeighbour(T * tensorScalNeighbour, size_t paddingScal, const T * tensorVecNeighbour, size_t paddingVec, size_t nbRow, size_t nbCol, size_t vectorSize); + +#include "reshuffle_tensor_impl.h" + +#endif diff --git a/src/reshuffle_tensor_impl.h b/src/reshuffle_tensor_impl.h new file mode 100644 index 0000000..7f19bd8 --- /dev/null +++ b/src/reshuffle_tensor_impl.h @@ -0,0 +1,83 @@ +/*************************************** + Auteur : Pierre Aubert + Mail : aubertp7@gmail.com + Licence : CeCILL-C +****************************************/ + +#ifndef __RESHUFFLE_TENSOR_IMPL_H__ +#define __RESHUFFLE_TENSOR_IMPL_H__ + +#include "reshuffle_tensor.h" + +///Convert a row of a tensor with neigbhour in the given register size +/** @param[out] rowVecNeighbour : pointer to the reordered row + * @param paddingVec : padding of the vectorial row + * @param rowScalNeighbour : pointer to the row to be reoganised + * @param nbCol : number of column of the row + * @param vectorSize : number of element in the vectorial register (to make vectorial register usable as element) +*/ +template +void reshuffle_row_toVecNeighbour(T * rowVecNeighbour, size_t paddingVec, const T * rowScalNeighbour, size_t nbCol, size_t vectorSize){ + size_t rowSizeVec(nbCol + paddingVec); + for(size_t i(0lu); i < nbCol; ++i){ + T value(rowScalNeighbour[i]); + size_t shift(i*vectorSize / rowSizeVec); + size_t vecIndex((i*vectorSize + shift) % rowSizeVec); + rowVecNeighbour[vecIndex] = value; + } +} + +///Convert a row of a reshuffled tensor with neigbhour back with scalar neigbhours +/** @param[out] rowScalNeighbour : pointer to the reordered row + * @param rowVecNeighbour : pointer to the row to be reoganised + * @param paddingVec : padding of the vectorial row + * @param nbCol : number of column of the row + * @param vectorSize : number of element in the vectorial register (to make vectorial register usable as element) +*/ +template +void reshuffle_row_toScalNeighbour(T * rowScalNeighbour, const T * rowVecNeighbour, size_t paddingVec, size_t nbCol, size_t vectorSize){ + size_t rowSizeVec(nbCol + paddingVec); + for(size_t i(0lu); i < nbCol; ++i){ + size_t shift(i*vectorSize / rowSizeVec); + size_t vecIndex((i*vectorSize + shift) % rowSizeVec); + T value(rowVecNeighbour[vecIndex]); + rowScalNeighbour[i] = value; + } +} + +///Convert a tensor with scalar neigbhours (sa a classical tensor) in tensor with vectorial neigbhours with the given register size +/** @param[out] tensorVecNeighbour : pointer to the reordered tensor + * @param paddingVec : padding of the vectorial tensor + * @param tensorScalNeighbour : pointer to the row to be reoganised + * @param paddingScal : padding of the scalar tensor + * @param nbRow : number of rows of the tensor + * @param nbCol : number of column of the tensor + * @param vectorSize : number of element in the vectorial register (to make vectorial register usable as element) +*/ +template +void reshuffle_tensor_toVecNeighbour(T * tensorVecNeighbour, size_t paddingVec, const T * tensorScalNeighbour, size_t paddingScal, size_t nbRow, size_t nbCol, size_t vectorSize){ + size_t rowSizeScal(nbCol + paddingScal), rowSizeVec(nbCol + paddingVec); + for(size_t i(0lu); i < nbRow; ++i){ + reshuffle_row_toVecNeighbour(tensorVecNeighbour + i*rowSizeVec, paddingVec, tensorScalNeighbour + i*rowSizeScal, nbCol, vectorSize); + } +} + +///Convert a reshuffled tensor with neigbhour back with scalar neigbhours +/** @param[out] tensorScalNeighbour : pointer to the reordered tensor + * @param paddingScal : padding of the scalar tensor + * @param tensorVecNeighbour : pointer to the tensor to be reoganised + * @param paddingVec : padding of the vectorial tensor + * @param nbRow : number of rows of the tensor + * @param nbCol : number of column of the tensor + * @param vectorSize : number of element in the vectorial register (to make vectorial register usable as element) +*/ +template +void reshuffle_tensor_toScalNeighbour(T * tensorScalNeighbour, size_t paddingScal, const T * tensorVecNeighbour, size_t paddingVec, size_t nbRow, size_t nbCol, size_t vectorSize){ + size_t rowSizeScal(nbCol + paddingScal), rowSizeVec(nbCol + paddingVec); + for(size_t i(0lu); i < nbRow; ++i){ + reshuffle_row_toScalNeighbour(tensorScalNeighbour + i*rowSizeScal, tensorVecNeighbour + i*rowSizeVec, paddingVec, nbCol, vectorSize); + } +} + +#endif + -- GitLab