Add transpose function for 4D tensors and related templates
Context
New transpose OP for export_cpp
Modified files
-
transpose.hpp
new kernel transpose; -
operator.py
, to take in case an export of node Transpose; -
transpose_ND_forward.jinja
and 'transpose_ND_config.jinja' to generate the code.
TODO
-
Unit-Tests : waiting for the feature to compare results between the export, onnx_runtime and aidge from @pineapple
Merge request reports
Activity
To compare result don't use onnx_rt use this https://gitlab.eclipse.org/eclipse/aidge/aidge_core/-/blob/main/aidge_core/export_utils/generate_main.py?ref_type=heads#L67 instead to compare with backend_cpu
Edited by Cyril Moineauassigned to @wboussella
requested review from @cmoineau
- aidge_export_cpp/kernels/transpose.hpp 0 → 100644
12 * dimensions reordered as specified by the permute array. 13 * 14 * @tparam T Data type of the tensor elements (e.g., float, double). 15 * @param[in] inputs Pointer to the input tensor data stored in contiguous memory. 16 * @param[out] outputs Pointer to the pre-allocated memory for the transposed tensor. 17 * Ensure this memory is appropriately sized to hold the transposed data. 18 * @param[in] in_dim1 Size of the first dimension of the input tensor. 19 * @param[in] in_dim2 Size of the second dimension of the input tensor. 20 * @param[in] in_dim3 Size of the third dimension of the input tensor. 21 * @param[in] in_dim4 Size of the fourth dimension of the input tensor. 22 * @param[in] permute Array of four unsigned integers specifying the desired permutation 23 * of dimensions. Each value should be in the range [0, 3], defining 24 * the new order of dimensions for the output tensor. 25 */ 26 template <typename T> 27 void transpose_4D_forward(const T* inputs, changed this line in version 2 of the diff
- aidge_export_cpp/kernels/transpose.hpp 0 → 100644
18 * @param[in] in_dim1 Size of the first dimension of the input tensor. 19 * @param[in] in_dim2 Size of the second dimension of the input tensor. 20 * @param[in] in_dim3 Size of the third dimension of the input tensor. 21 * @param[in] in_dim4 Size of the fourth dimension of the input tensor. 22 * @param[in] permute Array of four unsigned integers specifying the desired permutation 23 * of dimensions. Each value should be in the range [0, 3], defining 24 * the new order of dimensions for the output tensor. 25 */ 26 template <typename T> 27 void transpose_4D_forward(const T* inputs, 28 T* outputs, 29 unsigned int in_dim1, 30 unsigned int in_dim2, 31 unsigned int in_dim3, 32 unsigned int in_dim4, 33 const unsigned int* permute) - Comment on lines +27 to +33
For export pointer should use the keyword
__restrict
changed this line in version 2 of the diff
- aidge_export_cpp/kernels/transpose.hpp 0 → 100644
12 * dimensions reordered as specified by the permute array. 13 * 14 * @tparam T Data type of the tensor elements (e.g., float, double). 15 * @param[in] inputs Pointer to the input tensor data stored in contiguous memory. 16 * @param[out] outputs Pointer to the pre-allocated memory for the transposed tensor. 17 * Ensure this memory is appropriately sized to hold the transposed data. 18 * @param[in] in_dim1 Size of the first dimension of the input tensor. 19 * @param[in] in_dim2 Size of the second dimension of the input tensor. 20 * @param[in] in_dim3 Size of the third dimension of the input tensor. 21 * @param[in] in_dim4 Size of the fourth dimension of the input tensor. 22 * @param[in] permute Array of four unsigned integers specifying the desired permutation 23 * of dimensions. Each value should be in the range [0, 3], defining 24 * the new order of dimensions for the output tensor. 25 */ 26 template <typename T> 27 void transpose_4D_forward(const T* inputs, changed this line in version 2 of the diff
- Resolved by Cyril Moineau
- Resolved by Cyril Moineau
- aidge_export_cpp/kernels/transpose.hpp 0 → 100644
26 template <typename T> 27 void transpose_4D_forward(const T* inputs, 28 T* outputs, 29 unsigned int in_dim1, 30 unsigned int in_dim2, 31 unsigned int in_dim3, 32 unsigned int in_dim4, 33 const unsigned int* permute) 34 { 35 unsigned int in_dims[4] = {in_dim1, in_dim2, in_dim3, in_dim4}; 36 unsigned int out_dims[4]; 37 for (unsigned int i = 0; i < 4; ++i) { 38 out_dims[i] = in_dims[permute[i]]; 39 } 40 41 unsigned int in_strides[4] = { changed this line in version 2 of the diff
- Resolved by Cyril Moineau
- Resolved by Cyril Moineau
- Resolved by Cyril Moineau
295 295 str(ROOT / "kernels" / "activation.hpp"), 296 296 str(ROOT / "kernels" / "rescaling.hpp") 297 297 ] 298 299 @ExportLibCpp.register("Transpose", aidge_core.ImplSpec(aidge_core.IOSpec(aidge_core.dtype.float32))) I did this because the other kernels are also in dtype.float32, but it will be set at any in the next commit
Edited by Wissam Boussellachanged this line in version 2 of the diff
- aidge_export_cpp/kernels/transpose.hpp 0 → 100644
20 * @param[in] in_dim3 Size of the third dimension of the input tensor. 21 * @param[in] in_dim4 Size of the fourth dimension of the input tensor. 22 * @param[in] permute Array of four unsigned integers specifying the desired permutation 23 * of dimensions. Each value should be in the range [0, 3], defining 24 * the new order of dimensions for the output tensor. 25 */ 26 template <typename T> 27 void transpose_4D_forward(const T* inputs, 28 T* outputs, 29 unsigned int in_dim1, 30 unsigned int in_dim2, 31 unsigned int in_dim3, 32 unsigned int in_dim4, 33 const unsigned int* permute) 34 { 35 unsigned int in_dims[4] = {in_dim1, in_dim2, in_dim3, in_dim4}; changed this line in version 2 of the diff
added 1 commit
- ac47d3e6 - keep transpose in nhwc in operator.py, but need to be changed
- Resolved by Cyril Moineau