-
Notifications
You must be signed in to change notification settings - Fork 35
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
RPP Tensor Audio Support - To Decibels #258
Changes from 72 commits
6627464
dcd9833
3720c8f
ed1e425
f7f51c8
676de7c
46b8fb5
11fb3ab
8e05043
79d9e6f
5719db9
4aad4d6
abf15d8
71ef2f5
adad92b
8e01e0e
69fba3e
a7b1b22
441bfac
c8803c2
e7169fe
11b4709
d64bc7b
23ba5a5
337ccc1
d1b5b41
223de61
512a79f
6a18957
c413836
2247696
527ed18
87b0138
8e2975d
b9f8c12
b22bf93
4a5c357
2c8a78b
f07786a
54cfa29
c8bd726
92f8ed7
c4d8f3d
1db1425
1d3e7ce
13995ad
e85f581
296ed72
0aec6e1
3140717
fe4ef51
0713890
e98a4e8
a1f7366
749a552
3f5aec6
1b466bc
38119f3
b98bb99
3795f37
58e1ff5
64c52cd
6b2add5
7753fda
072cc1e
d205055
f9c66a6
ce13b82
a90e280
8227726
783ee98
2be82b1
1875d85
132eaa6
9322cd0
b650f02
f3d0a7d
1135cbc
40f2cc9
5aa53cb
8dc04bb
331f160
4ec92c6
b7cf24f
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 |
---|---|---|
@@ -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); | ||
if(minRatio == 0.0f) | ||
minRatio = std::nextafter(0.0f, 1.0f); | ||
|
||
const Rpp32f log10Factor = 0.3010299956639812; //1 / std::log(10); | ||
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; | ||
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. please combine the above statement in this line : if inv = refMag? 1./ref : 1; |
||
// Interpret as 1D array | ||
if(width == 1) | ||
{ | ||
for(Rpp32s vectorLoopCount = 0; vectorLoopCount < height; vectorLoopCount++) | ||
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. are we planning to optimize this in AVX 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. Hi Rajy, So we are forced to go back to Raw c code to make it match with reference outputs |
||
*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; | ||
} |
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.
is there a case where width is 1?
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.
To decibels kernel can take both 1D and 2D inputs
width = 1 is considered 1D input, all other values of width is considered 2D inputs