Skip to content

Commit

Permalink
RPP Rain augmentation - HOST and HIP implementation (#463)
Browse files Browse the repository at this point in the history
* Add Intial u8 implementation for Rain

* Add I8 implementation and Changes based on the Review comments

* Initial HIP implementation
Add F32 and F16 Tensor Implementation

* Add test case for Rain in HIP test suite
code cleanup

* minor code cleanup

* Modified func names and removed unnecessary code

* Resolve Review comments

* replaced pinned memory with HIP memory for Rain Layer computation

* Modified RGB Rain Mask to planar Rain Mask in HIP

* Address review comments

* Add Rain compute function

* Add version changes and Resolve review comments

* fix build warnings

* Fix the outputs of f16 toggle variants

* Revert Rain width changes

* Fix pln3 outputs for u8 and i8 bitdepths

* Resolve review comments

* Modified load and store routines for planar cases

* Resolve review comments

* Modify docs image

* Fix versioning

* Updates to 1.9.10 including rain feature

---------

Co-authored-by: HazarathKumarM <[email protected]>
Co-authored-by: Kiriti Gowda <[email protected]>
Co-authored-by: Srihari-mcw <[email protected]>
  • Loading branch information
4 people authored Jan 15, 2025
1 parent 4395c69 commit d2fdd62
Show file tree
Hide file tree
Showing 15 changed files with 1,816 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Full documentation for RPP is available at [https://rocm.docs.amd.com/projects/r

* RPP Tensor Gaussian Filter support on HOST
* RPP Fog augmentation on HOST and HIP
* RPP Rain augmentation on HOST and HIP
* RPP Warp Perspective on HOST and HIP
* RPP Threshold on HOST and HIP

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions include/rppt_tensor_effects_augmentations.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,60 @@ RppStatus rppt_glitch_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dst
RppStatus rppt_glitch_gpu(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, RpptChannelOffsets *rgbOffsets, RpptROIPtr roiTensorPtrSrc, RpptRoiType roiType, rppHandle_t rppHandle);
#endif // GPU_SUPPORT

/*! \brief Rain augmentation on HOST backend for a NCHW/NHWC layout tensor
* \details The rain augmentation simulates a rain effect for a batch of RGB (3-channel) / greyscale (1-channel) images with an NHWC/NCHW tensor layout.<br>
* <b> NOTE: This augmentation gives a more realistic Rain output when all images in a batch are of similar / same sizes </b> <br>
* - srcPtr depth ranges - Rpp8u (0 to 255), Rpp16f (0 to 1), Rpp32f (0 to 1), Rpp8s (-128 to 127).
* - dstPtr depth ranges - Will be the same depth as srcPtr.
* \image html img640x480.png Sample Input
* \image html effects_augmentations_rain_img640x480.png Sample Output
* \param [in] srcPtr source tensor in HOST memory
* \param [in] srcDescPtr source tensor descriptor (Restrictions - numDims = 4, offsetInBytes >= 0, dataType = U8/F16/F32/I8, layout = NCHW/NHWC, c = 1/3)
* \param [out] dstPtr destination tensor in HOST memory
* \param [in] dstDescPtr destination tensor descriptor (Restrictions - numDims = 4, offsetInBytes >= 0, dataType = U8/F16/F32/I8, layout = NCHW/NHWC, c = same as that of srcDescPtr)
* \param [in] rainPercentage The percentage of the rain effect to be applied (0 <= rainPercentage <= 100)
* \param [in] rainWidth Width of the rain drops in pixels. To be tuned by user depending on size of the image.
* \param [in] rainHeight Height of the rain drops in pixels. To be tuned by user depending on size of the image.
* \param [in] slantAngle Slant angle of the rain drops (positive value for right slant, negative for left slant). A single Rpp32s/f representing the slant of raindrops in degrees.
* Values range from [-90, 90], where -90 represents extreme left slant, 0 is vertical, and 90 is extreme right slant.
* \param [in] alpha An array of alpha blending values to be used for blending the rainLayer and the input image for each image in the batch (0 ≤ alpha ≤ 1 for each image in the batch).
* \param [in] roiTensorPtrSrc ROI data for each image in source tensor (2D tensor of size batchSize * 4, in either format - XYWH(xy.x, xy.y, roiWidth, roiHeight) or LTRB(lt.x, lt.y, rb.x, rb.y))
* \param [in] roiType ROI type used (RpptRoiType::XYWH or RpptRoiType::LTRB)
* \param [in] rppHandle RPP HOST handle created with <tt>\ref rppCreateWithBatchSize()</tt>
* \return A <tt> \ref RppStatus</tt> enumeration.
* \retval RPP_SUCCESS Successful completion.
* \retval RPP_ERROR* Unsuccessful completion.
*/
RppStatus rppt_rain_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, Rpp32f rainPercentage, Rpp32u rainWidth, Rpp32u rainHeight, Rpp32f slantAngle, Rpp32f *alpha, RpptROIPtr roiTensorPtrSrc, RpptRoiType roiType, rppHandle_t rppHandle);

#ifdef GPU_SUPPORT
/*! \brief Rain augmentation on HIP backend for a NCHW/NHWC layout tensor
* \details The rain augmentation simulates a rain effect for a batch of RGB (3-channel) / greyscale (1-channel) images with an NHWC/NCHW tensor layout.<br>
* <b> NOTE: This augmentation gives a more realistic Rain output when all images in a batch are of similar / same sizes </b> <br>
* - srcPtr depth ranges - Rpp8u (0 to 255), Rpp16f (0 to 1), Rpp32f (0 to 1), Rpp8s (-128 to 127).
* - dstPtr depth ranges - Will be the same depth as srcPtr.
* \image html img640x480.png Sample Input
* \image html effects_augmentations_rain_img640x480.png Sample Output
* \param [in] srcPtr source tensor in HIP memory
* \param [in] srcDescPtr source tensor descriptor (Restrictions - numDims = 4, offsetInBytes >= 0, dataType = U8/F16/F32/I8, layout = NCHW/NHWC, c = 1/3)
* \param [out] dstPtr destination tensor in HIP memory
* \param [in] dstDescPtr destination tensor descriptor (Restrictions - numDims = 4, offsetInBytes >= 0, dataType = U8/F16/F32/I8, layout = NCHW/NHWC, c = same as that of srcDescPtr)
* \param [in] rainPercentage The percentage of the rain effect to be applied (0 <= rainPercentage <= 100)
* \param [in] rainWidth Width of the rain drops in pixels. To be tuned by user depending on size of the image.
* \param [in] rainHeight Height of the rain drops in pixels. To be tuned by user depending on size of the image.
* \param [in] slantAngle Slant angle of the rain drops (positive value for right slant, negative for left slant). A single Rpp32s/f representing the slant of raindrops in degrees.
* Values range from [-90, 90], where -90 represents extreme left slant, 0 is vertical, and 90 is extreme right slant.
* \param [in] alpha An array of alpha blending values in pinned / HIP memory is used for blending the rainLayer and the input image for each image in the batch (0 ≤ alpha ≤ 1 for each image in the batch).
* \param [in] roiTensorPtrSrc ROI data for each image in source tensor (2D tensor of size batchSize * 4, in either format - XYWH(xy.x, xy.y, roiWidth, roiHeight) or LTRB(lt.x, lt.y, rb.x, rb.y))
* \param [in] roiType ROI type used (RpptRoiType::XYWH or RpptRoiType::LTRB)
* \param [in] rppHandle RPP HIP handle created with <tt>\ref rppCreateWithStreamAndBatchSize()</tt>
* \return A <tt> \ref RppStatus</tt> enumeration.
* \retval RPP_SUCCESS Successful completion.
* \retval RPP_ERROR* Unsuccessful completion.
*/
RppStatus rppt_rain_gpu(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, Rpp32f rainPercentage, Rpp32u rainWidth, Rpp32u rainHeight, Rpp32f slantAngle, Rpp32f *alpha, RpptROIPtr roiTensorPtrSrc, RpptRoiType roiType, rppHandle_t rppHandle);
#endif // GPU_SUPPORT

/*! \brief Pixelate augmentation on HOST backend for a NCHW/NHWC layout tensor
* \details The pixelate augmentation performs a pixelate transformation for a batch of RGB(3 channel) / greyscale(1 channel) images with an NHWC/NCHW tensor layout.<br>
* - srcPtr depth ranges - Rpp8u (0 to 255), Rpp16f (0 to 1), Rpp32f (0 to 1), Rpp8s (-128 to 127).
Expand Down
25 changes: 25 additions & 0 deletions src/include/cpu/rpp_cpu_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6630,6 +6630,31 @@ inline void compute_transpose4x8_avx(__m256 *pSrc, __m128 *pDst)
pDst[7] = _mm256_extractf128_ps(pSrc[3], 1); /* extract [P08|P16|P24|P32] */
}

inline void compute_rain_48_host(__m256 *p1, __m256 *p2, __m256 &pMul)
{
p1[0] = _mm256_fmadd_ps(_mm256_sub_ps(p2[0], p1[0]), pMul, p1[0]); // alpha-blending adjustment
p1[1] = _mm256_fmadd_ps(_mm256_sub_ps(p2[1], p1[1]), pMul, p1[1]); // alpha-blending adjustment
p1[2] = _mm256_fmadd_ps(_mm256_sub_ps(p2[0], p1[2]), pMul, p1[2]); // alpha-blending adjustment
p1[3] = _mm256_fmadd_ps(_mm256_sub_ps(p2[1], p1[3]), pMul, p1[3]); // alpha-blending adjustment
p1[4] = _mm256_fmadd_ps(_mm256_sub_ps(p2[0], p1[4]), pMul, p1[4]); // alpha-blending adjustment
p1[5] = _mm256_fmadd_ps(_mm256_sub_ps(p2[1], p1[5]), pMul, p1[5]); // alpha-blending adjustment
}

inline void compute_rain_32_host(__m256 *p1, __m256 *p2, __m256 &pMul)
{
p1[0] = _mm256_fmadd_ps(_mm256_sub_ps(p2[0], p1[0]), pMul, p1[0]); // alpha-blending adjustment
p1[1] = _mm256_fmadd_ps(_mm256_sub_ps(p2[1], p1[1]), pMul, p1[1]); // alpha-blending adjustment
p1[2] = _mm256_fmadd_ps(_mm256_sub_ps(p2[2], p1[2]), pMul, p1[2]); // alpha-blending adjustment
p1[3] = _mm256_fmadd_ps(_mm256_sub_ps(p2[3], p1[3]), pMul, p1[3]); // alpha-blending adjustment
}

inline void compute_rain_24_host(__m256 *p1, __m256 p2, __m256 &pMul)
{
p1[0] = _mm256_fmadd_ps(_mm256_sub_ps(p2, p1[0]), pMul, p1[0]); // alpha-blending adjustment
p1[1] = _mm256_fmadd_ps(_mm256_sub_ps(p2, p1[1]), pMul, p1[1]); // alpha-blending adjustment
p1[2] = _mm256_fmadd_ps(_mm256_sub_ps(p2, p1[2]), pMul, p1[2]); // alpha-blending adjustment
}

// Compute hanning window
inline RPP_HOST_DEVICE void hann_window(Rpp32f *output, Rpp32s windowSize)
{
Expand Down
1 change: 1 addition & 0 deletions src/modules/cpu/host_tensor_effects_augmentations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ SOFTWARE.
#include "kernel/resize.hpp" //pixelate dependency
#include "kernel/erase.hpp"
#include "kernel/fog.hpp"
#include "kernel/rain.hpp"

#endif // HOST_TENSOR_EFFECTS_AUGMENTATIONS_HPP
Loading

0 comments on commit d2fdd62

Please sign in to comment.