Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio HIP PR5 - Preemphasis Filter HIP Support #270

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1147bfe
Update CMakeLists.txt
kiritigowda Apr 12, 2024
5e3fc7a
Bump rocm-docs-core[api_reference] from 0.38.1 to 1.0.0 in /docs/sphi…
dependabot[bot] Apr 18, 2024
fe1a3e6
Add Pre emphasis filter HIP implementation
sampath1117 Apr 25, 2024
77e14ef
Minor common-fixes for HIP (#345)
r-abishek May 7, 2024
34f3f6d
Readme Updates: --usecase=rocm (#349)
kiritigowda May 8, 2024
ab52683
RPP Tensor Audio Support - Spectrogram (#312)
r-abishek May 8, 2024
ee0d6fe
Update CHANGELOG.md (#352)
r-abishek May 8, 2024
2decd32
RPP Tensor Audio Support - Slice (#325)
r-abishek May 8, 2024
30ce1d6
RPP Tensor Audio Support - MelFilterBank (#332)
r-abishek May 8, 2024
64ae74f
RPP Tensor Normalize ND on HOST and HIP (#335)
r-abishek May 9, 2024
1a3015c
SWDEV-459739 - Remove the package obsolete setting (#353)
raramakr May 9, 2024
e5865f9
clean up the code
sampath1117 May 9, 2024
c87f98b
Merge remote-tracking branch 'abishek/develop' into sr/pre_emphasis_f…
sampath1117 May 9, 2024
64ca5a3
Address review comments
sampath1117 May 17, 2024
5eeb4b1
Merge remote-tracking branch 'abishek/develop' into sr/pre_emphasis_f…
HazarathKumarM May 30, 2024
708160c
Resolve review comments and modify load and store in HIP kernel
HazarathKumarM Jun 27, 2024
7e4f3f1
Merge remote-tracking branch 'abishek/develop' into sr/pre_emphasis_f…
HazarathKumarM Jun 27, 2024
7e7af14
modified verify_output to have different cutoff for HIP and HOST back…
HazarathKumarM Jun 27, 2024
290449e
cleanup
HazarathKumarM Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions include/rppt_tensor_audio_augmentations.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ RppStatus rppt_to_decibels_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_
*/
RppStatus rppt_pre_emphasis_filter_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, Rpp32s *srcLengthTensor, Rpp32f *coeffTensor, RpptAudioBorderType borderType, rppHandle_t rppHandle);

#ifdef GPU_SUPPORT
/*! \brief Pre Emphasis Filter augmentation on HIP backend
* \details Pre Emphasis Filter augmentation for audio data
* \param [in] srcPtr source tensor in HIP memory
* \param [in] srcDescPtr source tensor descriptor (Restrictions - numDims = 3, offsetInBytes >= 0, dataType = F32)
* \param [out] dstPtr destination tensor in HIP memory
* \param [in] dstDescPtr destination tensor descriptor (Restrictions - numDims = 2, offsetInBytes >= 0, dataType = F32)
* \param [in] srcLengthTensor source audio buffer length (1D tensor in HIP memory, of size batchSize)
* \param [in] coeffTensor preemphasis coefficient (1D tensor in Pinned / HIP memory, of size batchSize)
* \param [in] borderType border value policy
* \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_pre_emphasis_filter_gpu(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, Rpp32s *srcLengthTensor, Rpp32f *coeffTensor, RpptAudioBorderType borderType, rppHandle_t rppHandle);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the description for HIP API too
I have added similar description for ToDecibels HIP API
https://github.com/sampath1117/rpp/blob/sr/to_decibels_hip/include/rppt_tensor_audio_augmentations.h#L83

In recent RPP changes, we are following this approach of adding description for both api's

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#endif // GPU_SUPPORT

/*! \brief Down Mixing augmentation on HOST backend
* \details Down Mixing augmentation for audio data
* \param[in] srcPtr source tensor in HOST memory
Expand Down Expand Up @@ -126,16 +144,12 @@ RppStatus rppt_down_mixing_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_
* \param [in] power exponent of the magnitude of the spectrum
* \param [in] windowLength window size in number of samples
* \param [in] windowStep step between the STFT windows in number of samples
* \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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

*/
RppStatus rppt_spectrogram_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, Rpp32s *srcLengthTensor, bool centerWindows, bool reflectPadding, Rpp32f *windowFunction, Rpp32s nfft, Rpp32s power, Rpp32s windowLength, Rpp32s windowStep, rppHandle_t rppHandle);

/*! \brief Mel filter bank augmentation HOST backend
* \details Mel filter bank augmentation for audio data
* \param[in] srcPtr source tensor in HOST memory
* \param[out] dstPtr srcPtr source tensor in HOST memory
* \param[in] srcDescPtr source tensor descriptor (Restrictions - numDims = 3, offsetInBytes >= 0, dataType = F32, layout - NFT)
* \param[out] dstPtr destination tensor in HOST memory
* \param[in] dstDescPtr destination tensor descriptor (Restrictions - numDims = 3, offsetInBytes >= 0, dataType = F32, layout - NFT)
Expand Down
6 changes: 6 additions & 0 deletions src/modules/hip/hip_tensor_audio_augmentations.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef HIP_TENSOR_AUDIO_AUGMENTATIONS_HPP
#define HIP_TENSOR_AUDIO_AUGMENTATIONS_HPP

#include "kernel/pre_emphasis_filter.hpp"

#endif // HIP_TENSOR_AUDIO_AUGMENTATIONS_HPP
74 changes: 74 additions & 0 deletions src/modules/hip/kernel/pre_emphasis_filter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <hip/hip_runtime.h>
#include "rpp_hip_common.hpp"

__device__ __forceinline__ void pre_emphasis_filter_hip_compute(d_float8 *src1_f8, d_float8 *src2_f8, d_float8 *dst_f8, float4 *coeff_f4)
{
dst_f8->f4[0] = src1_f8->f4[0] - (*coeff_f4 * src2_f8->f4[0]);
dst_f8->f4[1] = src1_f8->f4[1] - (*coeff_f4 * src2_f8->f4[1]);
}

__global__ void pre_emphasis_filter_tensor(float *srcPtr,
uint srcStride,
float *dstPtr,
uint dstStride,
float *coeffTensor,
int *srcLengthTensor,
RpptAudioBorderType borderType)
{
int id_x = (hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x) * 8;
int id_z = hipBlockIdx_z * hipBlockDim_z + hipThreadIdx_z;

if (id_x >= srcLengthTensor[id_z])
return;

uint srcIdx = (id_z * srcStride) + id_x;
uint dstIdx = (id_z * dstStride) + id_x;
float coeff = coeffTensor[id_z];

d_float8 src1_f8, src2_f8, dst_f8;
float4 coeff_f4 = static_cast<float4>(coeff);

rpp_hip_load8_and_unpack_to_float8(srcPtr + srcIdx, &src1_f8);

if(id_x == 0)
{
src2_f8.f1[0] = (borderType == RpptAudioBorderType::CLAMP) ? src1_f8.f1[0] :
(borderType == RpptAudioBorderType::REFLECT) ? src1_f8.f1[1] : 0.0f;
for(int i = 1; i < 8; i++)
src2_f8.f1[i] = src1_f8.f1[i - 1];
}
else
rpp_hip_load8_and_unpack_to_float8(srcPtr + srcIdx - 1, &src2_f8);

pre_emphasis_filter_hip_compute(&src1_f8, &src2_f8, &dst_f8, &coeff_f4);
rpp_hip_pack_float8_and_store8(dstPtr + dstIdx, &dst_f8);
}

RppStatus hip_exec_pre_emphasis_filter_tensor(Rpp32f *srcPtr,
RpptDescPtr srcDescPtr,
Rpp32f *dstPtr,
RpptDescPtr dstDescPtr,
Rpp32f *coeffTensor,
Rpp32s *srcLengthTensor,
RpptAudioBorderType borderType,
rpp::Handle& handle)
{
Rpp32s globalThreads_x = (dstDescPtr->strides.nStride + 7) >> 3;
Rpp32s globalThreads_y = 1;
Rpp32s globalThreads_z = dstDescPtr->n;

hipLaunchKernelGGL(pre_emphasis_filter_tensor,
dim3(ceil((float)globalThreads_x/LOCAL_THREADS_X_1DIM), ceil((float)globalThreads_y/LOCAL_THREADS_Y_1DIM), ceil((float)globalThreads_z/LOCAL_THREADS_Z_1DIM)),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

dim3(LOCAL_THREADS_X_1DIM, LOCAL_THREADS_Y_1DIM, LOCAL_THREADS_Z_1DIM),
0,
handle.GetStream(),
srcPtr,
srcDescPtr->strides.nStride,
dstPtr,
dstDescPtr->strides.nStride,
coeffTensor,
srcLengthTensor,
borderType);

return RPP_SUCCESS;
}
45 changes: 45 additions & 0 deletions src/modules/rppt_tensor_audio_augmentations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ SOFTWARE.
#include "rppt_tensor_audio_augmentations.h"
#include "cpu/host_tensor_audio_augmentations.hpp"

#ifdef HIP_COMPILE
#include "hip/hip_tensor_audio_augmentations.hpp"
#endif // HIP_COMPILE

/******************** non_silent_region_detection ********************/

RppStatus rppt_non_silent_region_detection_host(RppPtr_t srcPtr,
Expand Down Expand Up @@ -271,4 +275,45 @@ RppStatus rppt_resample_host(RppPtr_t srcPtr,
}
}

/********************************************************************************************************************/
/*********************************************** RPP_GPU_SUPPORT = ON ***********************************************/
/********************************************************************************************************************/

#ifdef GPU_SUPPORT

/******************** pre_emphasis_filter ********************/

RppStatus rppt_pre_emphasis_filter_gpu(RppPtr_t srcPtr,
RpptDescPtr srcDescPtr,
RppPtr_t dstPtr,
RpptDescPtr dstDescPtr,
Rpp32s *srcLengthTensor,
Rpp32f *coeffTensor,
RpptAudioBorderType borderType,
rppHandle_t rppHandle)
{
#ifdef HIP_COMPILE

if ((srcDescPtr->dataType == RpptDataType::F32) && (dstDescPtr->dataType == RpptDataType::F32))
{
hip_exec_pre_emphasis_filter_tensor(static_cast<Rpp32f*>(srcPtr),
srcDescPtr,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check numDims = 3 and other such restrictions in the API file for all these PRs

static_cast<Rpp32f*>(dstPtr),
dstDescPtr,
coeffTensor,
srcLengthTensor,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the order of function-specific arguments when compared to the external API.
If it was srcLengthTensor, coeffTensor..., retain the same order here

borderType,
rpp::deref(rppHandle));
}
else
{
return RPP_ERROR_NOT_IMPLEMENTED;
}

return RPP_SUCCESS;
#elif defined(OCL_COMPILE)
return RPP_ERROR_NOT_IMPLEMENTED;
#endif // backend
}

#endif // AUDIO_SUPPORT
25 changes: 24 additions & 1 deletion utilities/test_suite/HIP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ find_package(hip QUIET)
find_package(OpenCV QUIET)
find_package(TurboJpeg QUIET)
find_package(NIFTI QUIET)
find_library(libsnd_LIBS
NAMES sndfile libsndfile
PATHS ${CMAKE_SYSTEM_PREFIX_PATH} ${LIBSND_ROOT_DIR} "/usr/local"
PATH_SUFFIXES lib lib64)

# OpenMP
find_package(OpenMP REQUIRED)
Expand Down Expand Up @@ -111,4 +115,23 @@ if(NIFTI_FOUND AND OpenCV_FOUND)
target_link_libraries(Tensor_voxel_hip ${OpenCV_LIBS} -lturbojpeg -lrpp ${hip_LIBRARIES} pthread ${LINK_LIBRARY_LIST} hip::device ${NIFTI_PACKAGE_PREFIX}NIFTI::${NIFTI_PACKAGE_PREFIX}niftiio)
else()
message("-- ${Yellow}Warning: libniftiio must be installed to install ${PROJECT_NAME}/Tensor_voxel_hip successfully!${ColourReset}")
endif()
endif()

if(NOT libsnd_LIBS)
message("-- ${Yellow}Warning: libsndfile must be installed to install ${PROJECT_NAME}/Tensor_audio_host successfully!${ColourReset}")
else()
message("-- ${Green}${PROJECT_NAME} set to build with rpp and libsndfile ${ColourReset}")
set(COMPILER_FOR_HIP ${ROCM_PATH}/bin/hipcc)
set(CMAKE_CXX_COMPILER ${COMPILER_FOR_HIP})
include_directories(${ROCM_PATH}/include ${ROCM_PATH}/include/rpp /usr/local/include)
link_directories(${ROCM_PATH}/lib /usr/local/lib)
include_directories(${SndFile_INCLUDE_DIRS})
link_directories(${SndFile_LIBRARIES_DIR} /usr/local/lib/)

add_executable(Tensor_audio_hip Tensor_audio_hip.cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++17")
if(NOT APPLE)
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} stdc++fs)
endif()
target_link_libraries(Tensor_audio_hip ${libsnd_LIBS} -lsndfile -lrpp pthread ${LINK_LIBRARY_LIST})
endif()
Loading