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

PR1 - Audio - Non silent region detection HOST Tensor #149

Conversation

snehaa8
Copy link

@snehaa8 snehaa8 commented Aug 3, 2023

Includes unittest setup

@r-abishek r-abishek added the enhancement New feature or request label Aug 31, 2023
@r-abishek r-abishek added this to the sow9ms4 milestone Aug 31, 2023

// Set case names
char funcName[1000];
switch (testCase)
Copy link
Owner

Choose a reason for hiding this comment

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

@sampath1117 Things like this have to be rearranged. Cannot have switch case twice. Mods like those for image test suite needed here

Choose a reason for hiding this comment

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

Done


// The SF_INFO struct must be initialized before using it
memset (&sfinfo, 0, sizeof (sfinfo));
if (!(infile = sf_open (temp, SFM_READ, &sfinfo)))
Copy link
Owner

Choose a reason for hiding this comment

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

Same with the strategies we employed to avoid image reads twice

else
missingFuncFlag = 1;

verify_non_silent_region_detection(detectedIndex, detectionLength, testCaseName, noOfAudioFiles, audioNames);
Copy link
Owner

Choose a reason for hiding this comment

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

We cannot add this to the Wall or CPU time @HazarathKumarM @sampath1117. End timer here, and then verify.

Copy link
Owner

Choose a reason for hiding this comment

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

Where are we on this?

Choose a reason for hiding this comment

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

Done


void verify_non_silent_region_detection(float *detectedIndex, float *detectionLength, string testCase, int bs, char audioNames[][1000])
{
fstream ref_file;
Copy link
Owner

Choose a reason for hiding this comment

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

camelCase

Choose a reason for hiding this comment

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

Done

void verify_non_silent_region_detection(float *detectedIndex, float *detectionLength, string testCase, int bs, char audioNames[][1000])
{
fstream ref_file;
string ref_path = get_current_dir_name();
Copy link
Owner

Choose a reason for hiding this comment

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

camelCase

Choose a reason for hiding this comment

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

Done

string pattern = "HOST/audio/build";
remove_substring(ref_path, pattern);
ref_path = ref_path + "REFERENCE_OUTPUTS_AUDIO/";
int file_match = 0;
Copy link
Owner

Choose a reason for hiding this comment

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

camelCase

Choose a reason for hiding this comment

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

Done

Rpp32s ref_index, ref_length;
Rpp32s out_index, out_length;
ref_file>>ref_index;
ref_file>>ref_length;
Copy link
Owner

Choose a reason for hiding this comment

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

Spaces before/after operator, and camelCase for variables

Choose a reason for hiding this comment

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

Done

file_match += 1;
ref_file.close();
}
std::cerr<<std::endl<<"Results for Test case: "<<testCase<<std::endl;
Copy link
Owner

Choose a reason for hiding this comment

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

Lets stick to any one standard, to use std::cerr or std::cout for any print statements everywhere

Copy link
Owner

Choose a reason for hiding this comment

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

And spaces before/after operators

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@sampath1117 sampath1117 left a comment

Choose a reason for hiding this comment

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

@snehaa8
Please address review comments

Rpp32u maxSrcLength = *std::max_element(srcLengthTensor, (srcLengthTensor + srcDescPtr->n));
Rpp32f *mmsBuffer = static_cast<Rpp32f *>(calloc(maxSrcLength, sizeof(Rpp32f)));

Rpp32f cutOff = std::pow(10.0f, cutOffDB * 0.1f);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the additional space at L53
Add const specifier for cutOff like const Rpp32f cutoff

Copy link
Author

Choose a reason for hiding this comment

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

Done

{
Rpp32u numThreads = handle.GetNumThreads();
Rpp32u maxSrcLength = *std::max_element(srcLengthTensor, (srcLengthTensor + srcDescPtr->n));
Rpp32f *mmsBuffer = static_cast<Rpp32f *>(calloc(maxSrcLength, sizeof(Rpp32f)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we allocating a single mmsBuffer of size maxSrcLength for entire batch of audio samples?
if yes, this assumption is not correct and won't work as expected

Please change this

Copy link
Author

Choose a reason for hiding this comment

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

Fixed this
allocating a buffer inside batching loop itself was better in terms of perf.

rpp::Handle& handle)
{
Rpp32u numThreads = handle.GetNumThreads();
Rpp32u maxSrcLength = *std::max_element(srcLengthTensor, (srcLengthTensor + srcDescPtr->n));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not very sure if this max calculation is also valid or not
@snehaa8 Have you verified the working of this?

Copy link
Author

Choose a reason for hiding this comment

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

This is valid, but removed it as we allocate mmsBuffer internally.

@snehaa8
Copy link
Author

snehaa8 commented Sep 8, 2023

Pulled in latest audio testsuite changes as done by Hazarath

  1. I am not sure if review comments for testsuite added in this PR have been addressed.

  2. I am still seeing
    Error: libsndfile must be installed to install test_suite/HOST successfully!
    "sudo apt-get install libsndfile1-dev" as usual helped
    Not sure if this is expected

  3. Need to add readme for Audio QA testsuite.

  4. On running
    python3 runAudioTests.py --qa_mode 1 --batch_size 8
    Attaching output file here
    I see passed for NSR which is expected but then I see
    QA mode can only run with a batch size of 1.
    towards end of log file.
    I have shared corresponding log file via slack. @HazarathKumarM

These were my observations so far.

@r-abishek
Copy link
Owner

@HazarathKumarM please address audio test suite related review, and comment on the ones been addressed.
@snehaa8 libsndfile dependency for test suite is in the ReadMe change in this PR - https://github.com/r-abishek/rpp/pull/149/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
@sampath1117 Please review if audio test suite's ReadMe is clear to the user - for current unit/qa/perf test support offered

@@ -187,10 +187,10 @@ int main(int argc, char **argv)

// Get number of images and image Names
vector<string> imageNames, imageNamesSecond, imageNamesPath, imageNamesPathSecond;
search_jpg_files(src, imageNames, imageNamesPath);
search_files_recursive(src, imageNames, imageNamesPath, ".jpg");
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need to touch the non-audio tests in this PR? (Tensor_host.cpp and Tensor_hip.cpp changes)

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have made the recursive file search generic, so that valid extensions are passed as input, so that it can be used for both image and audio

@HazarathKumarM May be you can issue this minor change as seperate PR to abishek fork and this can be merged as part of test suite PR3 itself. Since that PR is currently open, we can may be add this change, so that this change won't show up in audio PR

Choose a reason for hiding this comment

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

We have made changes to use same recursive file search function for both audio and image, so we are passing extensions as input to the function

Copy link
Owner

Choose a reason for hiding this comment

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

If this change has a specific reason why its in the Audio PR, that's okay.
But if there are no dependencies for Tensor_host.cpp and Tensor_hip.cpp, would suggest putting it in the Test suite upgrade 3 PR.

Copy link
Collaborator

@sampath1117 sampath1117 left a comment

Choose a reason for hiding this comment

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

@HazarathKumarM
Please address review comments

Also downmix and 3 sample wav files are also added in this PR. Please remove them
image

.gitignore Outdated
@@ -12,6 +12,8 @@ hip_build/
OUTPUT_IMAGES*
OUTPUT_PERFORMANCE*
QA_RESULTS*
OUTPUT_AUDIO*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why output audio is added?
we are not generating any audio outputs right?

Choose a reason for hiding this comment

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

When we discussed we plan to log the PASS OR FAIL IN an text file right
I am adding that txt file in OUTPUT_AUDIO* folder

Choose a reason for hiding this comment

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

@sampath1117 can you please confirm this

Choose a reason for hiding this comment

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

@r-abishek For image unit tests we are having output folder as OUTPUT_IMAGE_HOST , so for the audio I am using OUTPUT_AUDIO_HOST
is it Okay or we need some different folder name?

Copy link
Owner

Choose a reason for hiding this comment

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

Similar folder name is fine yes, but only if its necessary to store actual outputs in it.
I was thinking PASS/FAIL is part of QA testing logged inside QA_results.txt inside a folder that starts with QA_RESULTS_* and not OUTPUT_*
Pls clarify

.gitignore Outdated
@@ -12,6 +12,8 @@ hip_build/
OUTPUT_IMAGES*
OUTPUT_PERFORMANCE*
QA_RESULTS*
OUTPUT_AUDIO*
QA_AUDIO*
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also need not be added, i feel
we can have one folder QA_RESULTS which can be used for both image and audio

Choose a reason for hiding this comment

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

Done


## Build & Install RPP
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert this spacing change

Choose a reason for hiding this comment

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

Done


#include "kernel/non_silent_region_detection.hpp"

#endif // HOST_TENSOR_AUDIO_AUGMENTATIONS_HPP
Copy link
Collaborator

Choose a reason for hiding this comment

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

@r-abishek
Please let us know if one space is needed for all files in RPP as well
In MIVisionX this convention is followed. I am not sure whether are we following the same in RPP as well

Copy link
Owner

Choose a reason for hiding this comment

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

For #include we still have no-space convention for RPP which is fine for now. Can do a global change PR if needed.

``` python
python runAudioTests.py --case_start 0 --case_end 0 --test_type 0 --qa_mode 1 --batch_size 8
```
- Unit test mode - Unit tests allowing users to pass a path to a folder containing audio files, to execute the desired functionality and variant once, report RPP execution wall time, save and view output
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the save and view output, since for audio, there is no output that is gonna be generated

Choose a reason for hiding this comment

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

Done

exit()

# Check if the folder is the root folder or exists, and remove the specified subfolders
def validate_and_remove_folders(path, folder):
Copy link
Collaborator

Choose a reason for hiding this comment

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

For python also we have some common functions which can be used across test suites
May be we can have this common code in a file called commons.py and use it across?

Not necessarily now, but better we do it this way
@r-abishek kindly request you to share your thoughts on this

Copy link
Owner

Choose a reason for hiding this comment

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

Agreed, keep similar names for the cpp and python common headers. Use the word test_suite or say testSuiteCommon.py
Please add this one to your running test suite list of tasks.

# Get a list of log files based on a flag for preserving output
def get_log_file_list(preserveOutput):
return [
"../../OUTPUT_AUDIO_PERFORMANCE_LOGS_HOST_" + timestamp + "/Tensor_host_audio_raw_performance_log.txt",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets rename the file as OUTPUT_PERFORMANCE_AUDIO_XX, so that we need to add new formats in .gitignore for audio alone

Choose a reason for hiding this comment

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

Done

qaMode = args.qa_mode
preserveOutput = args.preserve_output
batchSize = args.batch_size
bitDepth = 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a comment to this stating
"bitdepth is fixed to 2 since only bitdepth 2 (F32) only supported for audio"

Choose a reason for hiding this comment

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

Done

if qaMode:
outFilePath = os.path.join(os.path.dirname(cwd), 'QA_AUDIO_RESULTS_HOST_' + timestamp)
else:
outFilePath = os.path.join(os.path.dirname(cwd), 'OUTPUT_AUDIO_HOST_' + timestamp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the usage of this OUTPUT_AUDIO_HOST

Choose a reason for hiding this comment

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

discussed about this change and decided to have the folder name as OUTPUT_AUDIO_HOST for now

numRuns = 1
elif(testType == 1):
if "--num_runs" not in sys.argv:
numRuns = 100#default numRuns for running performance tests
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add space after 100

Choose a reason for hiding this comment

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

Done

@snehaa8
Copy link
Author

snehaa8 commented Sep 12, 2023

Confirmed NSR QA tests is unaffected after testsuite update.


}


Copy link
Owner

Choose a reason for hiding this comment

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

Please go over the code quickly and remove any double line spaces. Also from L263-L278, lets compact by removing too many empty lines - similar elsewhere

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done
Somehow it is not showing in github UI though

return (value * value);
}

Rpp32f getMax(Rpp32f *values, Rpp32s srcLength)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you change this to use std::max_element(values, values + srcLength)? And remove this, please check output.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done
Verified with QA tests and it passes

{
Rpp32f *srcPtrTemp = srcPtr + batchCount * srcDescPtr->strides.nStride;
Rpp32s srcLength = srcLengthTensor[batchCount];
Rpp32f *mmsBuffer = static_cast<Rpp32f *>(calloc(srcLength, sizeof(Rpp32f)));
Copy link
Owner

Choose a reason for hiding this comment

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

Please add a comment here stating why specifically srcLength could be a wide range, and its hard to statically initialize or pre-initialize during handle creation. You can even give a range

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done
Again somehow this change is not being shown in github ui

// Set numDims, offset, n/c/h/w values for src/dst
srcDescPtr->numDims = 4;
srcDescPtr->offsetInBytes = 0;
srcDescPtr->n = batchSize;
Copy link
Owner

Choose a reason for hiding this comment

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

Can't we use set_descriptor_dims_and_strides() like in Tensor_host.cpp?
Also, don't we have calls to these below?

// Set src/dst layout types in tensor descriptors
set_descriptor_layout(srcDescPtr, dstDescPtr, layoutType, pln1OutTypeCase, outputFormatToggle);
// Set src/dst data types in tensor descriptors
set_descriptor_data_type(inputBitDepth, funcName, srcDescPtr, dstDescPtr);

Copy link
Collaborator

Choose a reason for hiding this comment

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

For audio there is no input layout
So we are not able to use the functions defined for image in audio

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add few more helpers to modularize the code

missingFuncFlag = 1;

if (testType == 0)
verify_non_silent_region_detection(detectedIndex, detectionLength, testCaseName, batchSize, audioNames, dst);
Copy link
Owner

Choose a reason for hiding this comment

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

The verify_non_silent_region_detection() can't be included inside the time taken to run the function. @sampath1117 this Audio test suite file needs some cleanup, before external PR. Please check.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it ok if i declare some static buffers for begin and length outside the switch case and have a branch statement in the end of switch case calling two different verify functions based on the case?

Please let me know your thoughts

Copy link
Collaborator

Choose a reason for hiding this comment

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

Added a comment stating it won't run in performance tests

@r-abishek r-abishek changed the base branch from master to ar/audio_support_1_non_silent_region September 27, 2023 15:19
@r-abishek r-abishek merged commit 87b0138 into r-abishek:ar/audio_support_1_non_silent_region Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants