Skip to content
Snippets Groups Projects

Add Resize operator

Merged Houssem ROUIS requested to merge enhance_resize into dev
Files
8
/********************************************************************************
* Copyright (c) 2025 CEA-List
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
#ifndef AIDGE_CUDA_DATA_INTERPOLATION_H_
#define AIDGE_CUDA_DATA_INTERPOLATION_H_
#include "aidge/data/Interpolation.hpp"
namespace Aidge {
namespace InterpolationCUDA {
/**
* @brief Computes the approximate input coordinates corresponding to given output coordinates,
* according to the specified coordinate transformation mode.
*
* This function performs an "untransform" step for spatial interpolation, mapping output-space
* integer coordinates (`coordOut`) back into approximate input-space floating-point coordinates
* (`coordInApprox`) based on the transformation strategy provided.
*
* @param coordOut Pointer to the output coordinates (integer values).
* @param inputDims Pointer to the dimensions of the input tensor.
* @param outputDims Pointer to the dimensions of the output tensor.
* @param coordTransfoMode The coordinate transformation mode (e.g., AlignCorners, HalfPixel, etc.).
* @param roi Pointer to region of interest values, used only for TFCropAndResize mode;
* expected to be of size 2 * rank.
* @param coordInApprox Pointer to the output array where the approximate input coordinates will be stored.
* @param rank The dimensionality of the spatial domain (e.g., 2 for 2D, 3 for 3D).
*/
__device__ void untransformCoordinates(
const int* coordOut,
const int* inputDims,
const int* outputDims,
Aidge::Interpolation::CoordinateTransformation coordTransfoMode,
const float* roi,
float* coordInApprox,
int rank);
/**
* @brief Retrieves neighboring input tensor values around a set of continuous coordinates for interpolation.
*
* This function gathers neighboring values from a multidimensional tensor for use in interpolation,
* depending on the interpolation mode (e.g., linear or cubic), scaling, padding strategy, and
* anti-aliasing settings. The gathered values and their coordinates are stored in output buffers.
*
* @tparam T The data type of the input and output tensor values.
* @param tensorValues Pointer to the input tensor values (flattened array).
* @param tensorDims Pointer to the dimensions of the input tensor.
* @param coords Pointer to the floating-point coordinates in the input space.
* @param scales Pointer to scaling factors per dimension.
* @param rank The number of spatial dimensions in the tensor.
* @param mode Interpolation mode (e.g., Linear, Cubic).
* @param paddingMode Padding mode used for out-of-bound accesses (e.g., Zero, Edge).
* @param antialiasing Whether antialiasing is enabled (affects kernel footprint).
* @param outValues Pointer to the buffer where retrieved neighbor values will be stored.
* @param outCoords Pointer to the buffer where the corresponding coordinates of neighbors will be stored.
* Output shape is [maxNeighbours x rank].
* @param outCount Pointer to a single integer where the number of valid neighbors will be written.
* @param maxNeighbours Maximum number of neighbors to retrieve (capacity of the output buffers).
*/
template <typename T>
__device__ void retrieveNeighboursKernel(
const T* tensorValues,
const int* tensorDims,
float* coords,
const float* scales,
int rank,
Aidge::Interpolation::Mode mode,
Aidge::PadBorderType paddingMode,
bool antialiasing,
T* outValues,
int* outCoords,
int* outCount,
int maxNeighbours
);
/**
* @brief Performs N-dimensional linear interpolation given neighbor points and their values.
*
* This function computes a weighted average of neighbor values based on linear interpolation
* weights derived from their distance to a target coordinate. It optionally applies antialiasing
* scaling to the distances. The weights are normalized to ensure smooth interpolation.
*
* @tparam T The data type of the input and output values.
* @param coordToInterpolate Pointer to the floating-point coordinate to interpolate at (length = rank).
* @param scales Pointer to scale factors per dimension.
* @param pointsCoords Pointer to neighbor coordinates (flattened array of size coordsNbr × rank).
* @param pointValues Pointer to values corresponding to neighbor coordinates.
* @param coordsNbr Number of neighboring points used in the interpolation.
* @param rank Number of spatial dimensions.
* @param antialiasing Whether to apply antialiasing by scaling coordinate deltas.
* @return T The interpolated value at the target coordinate.
*/
template <typename T>
__device__ T interpolateLinear(
const float* coordToInterpolate,
const float* scales,
const int* pointsCoords,
const T* pointValues,
int coordsNbr,
int rank,
bool antialiasing
);
/**
* @brief Performs N-dimensional cubic interpolation given neighbor points and their values.
*
* This function computes a weighted average of neighbor values based on cubic interpolation weights,
* optionally applying antialiasing and excluding neighbors outside input dimensions.
* Static dimensions (with size 1 and scale 1) are ignored in the weight calculation.
*
* @tparam T The data type of the input and output values.
* @param coordToInterpolate Pointer to the floating-point coordinate to interpolate at (length = rank).
* @param scales Pointer to scale factors per dimension.
* @param pointsCoords Pointer to neighbor coordinates (flattened array of size coordsNbr × rank).
* @param pointValues Pointer to values corresponding to neighbor coordinates.
* @param coordsNbr Number of neighboring points used in the interpolation.
* @param rank Number of spatial dimensions.
* @param inputDims Pointer to input tensor dimensions.
* @param a Cubic interpolation parameter (often -0.75 for Catmull-Rom).
* @param antialiasing Whether to apply antialiasing in weight calculation.
* @param excludeOutside Whether to exclude neighbors outside input dimensions.
* @return T The interpolated value at the target coordinate.
*/
template <typename T>
__device__ T interpolateCubic(
float* coordToInterpolate,
const float* scales,
int* pointsCoords,
T* pointValues,
int coordsNbr,
int rank,
const int* inputDims,
float a,
bool antialiasing,
bool excludeOutside
);
/**
* @brief Dispatches to the appropriate interpolation method (linear or cubic) based on the mode.
*
* This function selects the interpolation method and computes the interpolated value
* at the given coordinate using either cubic or linear interpolation. Returns zero
* for unsupported interpolation modes.
*
* @tparam T The data type of the input and output values.
* @param coordToInterpolate Pointer to the floating-point coordinate to interpolate at (length = rank).
* @param scales Pointer to scale factors per dimension.
* @param pointsCoords Pointer to neighbor coordinates (flattened array of size coordsNbr × rank).
* @param pointValues Pointer to values corresponding to neighbor coordinates.
* @param coordsNbr Number of neighboring points used in the interpolation.
* @param rank Number of spatial dimensions.
* @param mode Interpolation mode (Linear or Cubic).
* @param cubicCoeffA Cubic interpolation coefficient (used only for cubic mode).
* @param antialiasing Whether to apply antialiasing in interpolation.
* @param excludeOutside Whether to exclude neighbors outside input dimensions (only cubic mode).
* @param inputDims Pointer to input tensor dimensions.
* @return T The interpolated value at the target coordinate.
*/
template <typename T>
__device__ T interpolate(float* coordToInterpolate,
const float* scales,
int* pointsCoords,
T* pointValues,
int coordsNbr,
int rank,
Aidge::Interpolation::Mode mode,
float cubicCoeffA,
bool antialiasing,
bool excludeOutside,
const int* inputDims);
} // namespace InterpolationCUDA
} // namespace Aidge
#endif /*AIDGE_CUDA_DATA_INTERPOLATION_H_*/
\ No newline at end of file
Loading