-
Notifications
You must be signed in to change notification settings - Fork 3
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
PR2 - Audio - To decibels HOST Tensor #150
Changes from all commits
dcd9833
ed1e425
8e05043
23ba5a5
337ccc1
d1b5b41
c413836
527ed18
7753fda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,25 @@ extern "C" { | |
*/ | ||
RppStatus rppt_non_silent_region_detection_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, Rpp32s *srcLengthTensor, Rpp32f *detectedIndexTensor, Rpp32f *detectionLengthTensor, Rpp32f cutOffDB, Rpp32s windowLength, Rpp32f referencePower, Rpp32s resetInterval, rppHandle_t rppHandle); | ||
|
||
/*! \brief To Decibels augmentation HOST | ||
* \details To Decibels augmentation that converts magnitude values to decibel values | ||
* \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] srcDims source tensor size (tensor of batchSize * 2 values) | ||
* \param[in] cutOffDB minimum or cut-off ratio in dB | ||
* \param[in] multiplier factor by which the logarithm is multiplied | ||
* \param[in] referenceMagnitude Reference magnitude if not provided maximum value of input used as reference | ||
* \param[in] rppHandle HIP-handle for "_gpu" variants and Host-handle for "_host" variants | ||
* \return <tt> RppStatus enum</tt>. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs to be before enum. Pls check non silent region and replicate |
||
* \returns RPP_SUCCESS <tt>\ref RppStatus</tt> on successful completion. | ||
* Else return RPP_ERROR | ||
* \ingroup group_tensor_audio | ||
*/ | ||
|
||
RppStatus rppt_to_decibels_host(RppPtr_t srcPtr, RpptDescPtr srcDescPtr, RppPtr_t dstPtr, RpptDescPtr dstDescPtr, RpptImagePatchPtr srcDims, Rpp32f cutOffDB, Rpp32f multiplier, Rpp32f referenceMagnitude, rppHandle_t rppHandle); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
Copyright (c) 2019 - 2023 Advanced Micro Devices, Inc. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
*/ | ||
|
||
#include "rppdefs.h" | ||
#include <omp.h> | ||
|
||
RppStatus to_decibels_host_tensor(Rpp32f *srcPtr, | ||
RpptDescPtr srcDescPtr, | ||
Rpp32f *dstPtr, | ||
RpptDescPtr dstDescPtr, | ||
RpptImagePatchPtr srcDims, | ||
Rpp32f cutOffDB, | ||
Rpp32f multiplier, | ||
Rpp32f referenceMagnitude, | ||
rpp::Handle& handle) | ||
{ | ||
Rpp32u numThreads = handle.GetNumThreads(); | ||
|
||
// Calculate the intermediate values needed for DB conversion | ||
Rpp32f minRatio = std::pow(10, cutOffDB / multiplier); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If user gives multiplier as 0, is there a check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure added this check |
||
if(minRatio == 0.0f) | ||
minRatio = std::nextafter(0.0f, 1.0f); | ||
|
||
const Rpp32f log10Factor = 0.3010299956639812; //1 / std::log(10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize as #define in rpp_cpu_common There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initializing that as #define even at the start of this file lead to output mismatches, thus left it as such There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @snehaa8 Then instead of #define, lets just move the const Rpp32f as-is to rpp_cpu_common |
||
multiplier *= log10Factor; | ||
|
||
omp_set_dynamic(0); | ||
#pragma omp parallel for num_threads(numThreads) | ||
for(int batchCount = 0; batchCount < srcDescPtr->n; batchCount++) | ||
{ | ||
Rpp32f *srcPtrCurrent = srcPtr + batchCount * srcDescPtr->strides.nStride; | ||
Rpp32f *dstPtrCurrent = dstPtr + batchCount * dstDescPtr->strides.nStride; | ||
|
||
Rpp32u height = srcDims[batchCount].height; | ||
Rpp32u width = srcDims[batchCount].width; | ||
Rpp32f refMag = referenceMagnitude; | ||
|
||
// Compute maximum value in the input buffer | ||
if(!referenceMagnitude) | ||
{ | ||
refMag = -std::numeric_limits<Rpp32f>::max(); | ||
Rpp32f *srcPtrTemp = srcPtrCurrent; | ||
if(width == 1) | ||
refMag = std::max(refMag, *(std::max_element(srcPtrTemp, srcPtrTemp + height))); | ||
else | ||
{ | ||
for(int i = 0; i < height; i++) | ||
{ | ||
refMag = std::max(refMag, *(std::max_element(srcPtrTemp, srcPtrTemp + width))); | ||
srcPtrTemp += srcDescPtr->strides.hStride; | ||
} | ||
} | ||
} | ||
|
||
// Avoid division by zero | ||
if(!refMag) | ||
refMag = 1.0f; | ||
|
||
Rpp32f invReferenceMagnitude = 1.f / refMag; | ||
// Interpret as 1D array | ||
if(width == 1) | ||
{ | ||
for(Rpp32s vectorLoopCount = 0; vectorLoopCount < height; vectorLoopCount++) | ||
*dstPtrCurrent++ = multiplier * std::log2(std::max(minRatio, (*srcPtrCurrent++) * invReferenceMagnitude)); | ||
} | ||
else | ||
{ | ||
Rpp32f *srcPtrRow, *dstPtrRow; | ||
srcPtrRow = srcPtrCurrent; | ||
dstPtrRow = dstPtrCurrent; | ||
for(int i = 0; i < height; i++) | ||
{ | ||
Rpp32f *srcPtrTemp, *dstPtrTemp; | ||
srcPtrTemp = srcPtrRow; | ||
dstPtrTemp = dstPtrRow; | ||
Rpp32s vectorLoopCount = 0; | ||
for(; vectorLoopCount < width; vectorLoopCount++) | ||
*dstPtrTemp++ = multiplier * std::log2(std::max(minRatio, (*srcPtrTemp++) * invReferenceMagnitude)); | ||
|
||
srcPtrRow += srcDescPtr->strides.hStride; | ||
dstPtrRow += dstDescPtr->strides.hStride; | ||
} | ||
} | ||
} | ||
|
||
return RPP_SUCCESS; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,28 @@ int main(int argc, char **argv) | |
|
||
break; | ||
} | ||
case 1: | ||
{ | ||
testCaseName = "to_decibels"; | ||
Rpp32f cutOffDB = std::log(1e-20); | ||
Rpp32f multiplier = std::log(10); | ||
Rpp32f referenceMagnitude = 1.0f; | ||
|
||
for (int i = 0; i < batchSize; i++) | ||
{ | ||
srcDims[i].height = dstDims[i].height = srcLengthTensor[i]; | ||
srcDims[i].width = dstDims[i].width = 1; | ||
} | ||
|
||
startWallTime = omp_get_wtime(); | ||
startCpuTime = clock(); | ||
if (inputBitDepth == 2) | ||
rppt_to_decibels_host(inputf32, srcDescPtr, outputf32, dstDescPtr, srcDims, cutOffDB, multiplier, referenceMagnitude, handle); | ||
else | ||
missingFuncFlag = 1; | ||
|
||
break; | ||
} | ||
default: | ||
{ | ||
missingFuncFlag = 1; | ||
|
@@ -173,6 +195,29 @@ int main(int argc, char **argv) | |
maxWallTime = std::max(maxWallTime, wallTime); | ||
minWallTime = std::min(minWallTime, wallTime); | ||
avgWallTime += wallTime; | ||
|
||
// QA mode - verify outputs with golden outputs. Below code doesn’t run for performance tests | ||
if (testType == 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did we increase to 8 reference outputs for to_decibels? QA has always been 3, non_silent_region has 3 too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @snehaa8 Could you remove those reference outputs not needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done removed extra ones, it was 8 initially and Sampath made this change in NSR at a later point. |
||
{ | ||
/* Run only if testCase is not 0 | ||
For testCase 0 verify_non_silent_region_detection function is used for QA testing */ | ||
if (testCase != 0) | ||
verify_output(outputf32, dstDescPtr, dstDims, testCaseName, audioNames, dst); | ||
|
||
/* Dump the outputs to csv files for debugging | ||
Runs only if | ||
1. DEBUG_MODE is enabled | ||
2. Current iteration is 1st iteration | ||
3. Test case is not 0 */ | ||
if (DEBUG_MODE && iterCount == 0 && testCase != 0) | ||
{ | ||
std::ofstream refFile; | ||
refFile.open(func + ".csv"); | ||
for (int i = 0; i < oBufferSize; i++) | ||
refFile << *(outputf32 + i) << "\n"; | ||
refFile.close(); | ||
} | ||
} | ||
} | ||
} | ||
rppDestroyHost(handle); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets specify HOST as per the new doxygen style