Skip to content

Commit

Permalink
Subpixel layout support for RGB/BGR to greyscale (ROCm#113)
Browse files Browse the repository at this point in the history
* Mods to handle RGB and BGR subpixel layouts

* Test suite mods to handle RGB/BGR subpixel layouts in color to greyscale conversions

* Rename files from rgb_to_greyscale to color_to_greyscale
  • Loading branch information
r-abishek authored Jul 13, 2022
1 parent ca3bd97 commit 64dd326
Show file tree
Hide file tree
Showing 21 changed files with 440 additions and 371 deletions.
7 changes: 6 additions & 1 deletion include/rppdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,14 @@ typedef enum
{
LTRB,
XYWH

} RpptRoiType;

typedef enum
{
RGBtype,
BGRtype
} RpptSubpixelLayout;

typedef enum
{
NEAREST_NEIGHBOR = 0,
Expand Down
9 changes: 5 additions & 4 deletions include/rppt_tensor_data_exchange_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,22 @@ RppStatus rppt_swap_channels_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPt
RppStatus rppt_swap_channels_gpu(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, rppHandle_t rppHandle);
#endif // GPU_SUPPORT

/******************** rgb_to_greyscale ********************/
/******************** color_to_greyscale ********************/

// RGB to greyscale operation for a NCHW/NHWC layout tensor
// Color to greyscale operation for a RGB/BGR NCHW/NHWC layout tensor

// *param[in] srcPtr source tensor memory
// *param[in] srcDescPtr source tensor descriptor
// *param[out] dstPtr destination tensor memory
// *param[in] dstDescPtr destination tensor descriptor
// *param[in] srcSubpixelLayout A RpptSubpixelLayout type enum to specify source subpixel layout (RGBtype or BGRtype)
// *returns a RppStatus enumeration.
// *retval RPP_SUCCESS : succesful completion
// *retval RPP_ERROR : Error

RppStatus rppt_rgb_to_greyscale_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, rppHandle_t rppHandle);
RppStatus rppt_color_to_greyscale_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, RpptSubpixelLayout srcSubpixelLayout, rppHandle_t rppHandle);
#ifdef GPU_SUPPORT
RppStatus rppt_rgb_to_greyscale_gpu(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, rppHandle_t rppHandle);
RppStatus rppt_color_to_greyscale_gpu(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, RpptSubpixelLayout srcSubpixelLayout, rppHandle_t rppHandle);
#endif // GPU_SUPPORT

#ifdef __cplusplus
Expand Down
24 changes: 12 additions & 12 deletions src/include/cpu/rpp_cpu_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2146,28 +2146,28 @@ inline RppStatus custom_convolve_image_host(T* srcPtr, RppiSize srcSize, U* dstP

// Compute Functions for RPP Tensor API

inline void compute_rgb_48_to_greyscale_16_host(__m256 *p, __m256 *pWeightsRGB)
inline void compute_color_48_to_greyscale_16_host(__m256 *p, __m256 *pChannelWeights)
{
p[0] = _mm256_fmadd_ps(p[0], pWeightsRGB[0], _mm256_fmadd_ps(p[2], pWeightsRGB[1], _mm256_mul_ps(p[4], pWeightsRGB[2])));
p[1] = _mm256_fmadd_ps(p[1], pWeightsRGB[0], _mm256_fmadd_ps(p[3], pWeightsRGB[1], _mm256_mul_ps(p[5], pWeightsRGB[2])));
p[0] = _mm256_fmadd_ps(p[0], pChannelWeights[0], _mm256_fmadd_ps(p[2], pChannelWeights[1], _mm256_mul_ps(p[4], pChannelWeights[2])));
p[1] = _mm256_fmadd_ps(p[1], pChannelWeights[0], _mm256_fmadd_ps(p[3], pChannelWeights[1], _mm256_mul_ps(p[5], pChannelWeights[2])));
}

inline void compute_rgb_48_to_greyscale_16_host(__m128 *p, __m128 *pWeightsRGB)
inline void compute_color_48_to_greyscale_16_host(__m128 *p, __m128 *pChannelWeights)
{
p[0] = _mm_fmadd_ps(p[0], pWeightsRGB[0], _mm_fmadd_ps(p[4], pWeightsRGB[1], _mm_mul_ps(p[8], pWeightsRGB[2])));
p[1] = _mm_fmadd_ps(p[1], pWeightsRGB[0], _mm_fmadd_ps(p[5], pWeightsRGB[1], _mm_mul_ps(p[9], pWeightsRGB[2])));
p[2] = _mm_fmadd_ps(p[2], pWeightsRGB[0], _mm_fmadd_ps(p[6], pWeightsRGB[1], _mm_mul_ps(p[10], pWeightsRGB[2])));
p[3] = _mm_fmadd_ps(p[3], pWeightsRGB[0], _mm_fmadd_ps(p[7], pWeightsRGB[1], _mm_mul_ps(p[11], pWeightsRGB[2])));
p[0] = _mm_fmadd_ps(p[0], pChannelWeights[0], _mm_fmadd_ps(p[4], pChannelWeights[1], _mm_mul_ps(p[8], pChannelWeights[2])));
p[1] = _mm_fmadd_ps(p[1], pChannelWeights[0], _mm_fmadd_ps(p[5], pChannelWeights[1], _mm_mul_ps(p[9], pChannelWeights[2])));
p[2] = _mm_fmadd_ps(p[2], pChannelWeights[0], _mm_fmadd_ps(p[6], pChannelWeights[1], _mm_mul_ps(p[10], pChannelWeights[2])));
p[3] = _mm_fmadd_ps(p[3], pChannelWeights[0], _mm_fmadd_ps(p[7], pChannelWeights[1], _mm_mul_ps(p[11], pChannelWeights[2])));
}

inline void compute_rgb_24_to_greyscale_8_host(__m256 *p, __m256 *pWeightsRGB)
inline void compute_color_24_to_greyscale_8_host(__m256 *p, __m256 *pChannelWeights)
{
p[0] = _mm256_fmadd_ps(p[0], pWeightsRGB[0], _mm256_fmadd_ps(p[1], pWeightsRGB[1], _mm256_mul_ps(p[2], pWeightsRGB[2])));
p[0] = _mm256_fmadd_ps(p[0], pChannelWeights[0], _mm256_fmadd_ps(p[1], pChannelWeights[1], _mm256_mul_ps(p[2], pChannelWeights[2])));
}

inline void compute_rgb_12_to_greyscale_4_host(__m128 *p, __m128 *pWeightsRGB)
inline void compute_color_12_to_greyscale_4_host(__m128 *p, __m128 *pChannelWeights)
{
p[0] = _mm_fmadd_ps(p[0], pWeightsRGB[0], _mm_fmadd_ps(p[1], pWeightsRGB[1], _mm_mul_ps(p[2], pWeightsRGB[2])));
p[0] = _mm_fmadd_ps(p[0], pChannelWeights[0], _mm_fmadd_ps(p[1], pChannelWeights[1], _mm_mul_ps(p[2], pChannelWeights[2])));
}

inline void compute_contrast_48_host(__m256 *p, __m256 *pContrastParams)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cpu/host_tensor_data_exchange_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ THE SOFTWARE.

#include "kernel/copy.hpp"
#include "kernel/swap_channels.hpp"
#include "kernel/rgb_to_greyscale.hpp"
#include "kernel/color_to_greyscale.hpp"

#endif // HOST_TENSOR_DATA_EXCHANGEE_OPERATIONS_HPP
Loading

0 comments on commit 64dd326

Please sign in to comment.