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

DownMix Node and to_decibels augmentations #32

Open
wants to merge 37 commits into
base: swbs_m2/audio/pr5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ba6ff14
Merging swbs_m2/audio/pr5 into swbs_m3/audio/pr6
swetha097 Mar 14, 2024
e94c53f
Fixing build issues
SundarRajan28 Mar 15, 2024
4495d5c
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 22, 2024
247cf70
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 22, 2024
1a51fee
Add openvx extensions for to_decibels augmentations
SundarRajan28 Mar 22, 2024
e8ff20e
Merge branch 'swbs_m1/audio/pr3' into swbs_m3/audio/pr6
SundarRajan28 Mar 25, 2024
a649fba
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 25, 2024
01aba8a
Fixing issues with src ROI
SundarRajan28 Mar 25, 2024
a25b645
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 25, 2024
68a5d7e
Resolving review comments
SundarRajan28 Mar 25, 2024
ebe8933
Resolving review comments
SundarRajan28 Mar 25, 2024
a446bff
Removing dstROI from to_decibels openvx augmentation
SundarRajan28 Mar 25, 2024
ce4778f
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 25, 2024
070bd82
Resolving review comments
SundarRajan28 Mar 25, 2024
658504f
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 26, 2024
a2c1063
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Mar 26, 2024
b08b602
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Apr 16, 2024
3be53bf
Update changelog
SundarRajan28 Apr 16, 2024
c69afd8
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Apr 17, 2024
58d8c0d
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 Apr 17, 2024
4121a9c
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
swetha097 May 8, 2024
d7db0cb
Merge remote-tracking branch 'upstream/develop' into swbs_m3/audio/pr6
SundarRajan28 May 10, 2024
81c5533
Resolving review comments
SundarRajan28 May 13, 2024
209b83a
Merge remote-tracking branch 'swbs_m2/audio/pr5_layout' into swbs_m3/…
SundarRajan28 May 13, 2024
e0883dd
Resolving review comments
SundarRajan28 May 14, 2024
a849125
Minor changes
SundarRajan28 May 15, 2024
36fdc89
Removing if blocks for CPU device checks
SundarRajan28 May 15, 2024
99eeb10
Merge remote-tracking branch 'upstream/develop' into swbs_m3/audio/pr6
SundarRajan28 May 17, 2024
fefc759
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
fiona-gladwin May 20, 2024
ff3c50f
Add RPP_AUDIO flag for RPP audio API
fiona-gladwin May 20, 2024
3f8d1c8
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
fiona-gladwin May 20, 2024
f1cb901
Merge remote-tracking branch 'upstream/develop' into swbs_m3/audio/pr6
SundarRajan28 May 22, 2024
f601ad9
Merge branch 'develop' into swbs_m3/audio/pr6
SundarRajan28 May 24, 2024
0df3adb
Audio PR - Augmentation support [ Spectrogram ] (#1355)
fiona-gladwin May 28, 2024
b1c7694
Merge branch 'swbs_m2/audio/pr5' into swbs_m3/audio/pr6
SundarRajan28 May 29, 2024
f4dd4e3
Merge remote-tracking branch 'upstream/develop' into swbs_m3/audio/pr6
SundarRajan28 May 29, 2024
832d9ef
Rename map variable
SundarRajan28 May 30, 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
2 changes: 2 additions & 0 deletions amd_openvx_extensions/amd_rpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ list(APPEND SOURCES
source/tensor/Copy.cpp
source/tensor/Crop.cpp
source/tensor/CropMirrorNormalize.cpp
source/tensor/Downmix.cpp
source/tensor/Exposure.cpp
source/tensor/FishEye.cpp
source/tensor/Flip.cpp
Expand All @@ -155,6 +156,7 @@ list(APPEND SOURCES
source/tensor/SequenceRearrange.cpp
source/tensor/Snow.cpp
source/tensor/Spectrogram.cpp
source/tensor/ToDecibels.cpp
source/tensor/Vignette.cpp
source/tensor/WarpAffine.cpp
source/tensor/SequenceRearrange.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ vx_status WarpAffine_Register(vx_context);
vx_status SequenceRearrange_Register(vx_context);
vx_status PreemphasisFilter_Register(vx_context);
vx_status Spectrogram_Register(vx_context);
vx_status Downmix_Register(vx_context);
vx_status ToDecibels_Register(vx_context);

// kernel names
#define VX_KERNEL_RPP_NOPBATCHPD_NAME "org.rpp.NopbatchPD"
Expand Down Expand Up @@ -283,5 +285,7 @@ vx_status Spectrogram_Register(vx_context);
#define VX_KERNEL_RPP_SEQUENCEREARRANGE_NAME "org.rpp.SequenceRearrange"
SundarRajan28 marked this conversation as resolved.
Show resolved Hide resolved
#define VX_KERNEL_RPP_PREEMPHASISFILTER_NAME "org.rpp.PreemphasisFilter"
#define VX_KERNEL_RPP_SPECTROGRAM_NAME "org.rpp.Spectrogram"
#define VX_KERNEL_RPP_DOWNMIX_NAME "org.rpp.Downmix"
#define VX_KERNEL_RPP_TODECIBELS_NAME "org.rpp.ToDecibels"

#endif //_AMDVX_EXT__PUBLISH_KERNELS_H_
4 changes: 3 additions & 1 deletion amd_openvx_extensions/amd_rpp/include/kernels_rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ extern "C"
VX_KERNEL_RPP_VIGNETTE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x72,
VX_KERNEL_RPP_WARPAFFINE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x73,
VX_KERNEL_RPP_PREEMPHASISFILTER = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x74,
VX_KERNEL_RPP_SPECTROGRAM = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x75
VX_KERNEL_RPP_SPECTROGRAM = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x75,
VX_KERNEL_RPP_DOWNMIX = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x76,
VX_KERNEL_RPP_TODECIBELS = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x77
};

#ifdef __cplusplus
Expand Down
23 changes: 23 additions & 0 deletions amd_openvx_extensions/amd_rpp/include/vx_ext_rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,29 @@ extern "C"
*/
SHARED_PUBLIC vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_tensor pDstRoi, vx_array windowFunction, vx_scalar centerWindow, vx_scalar reflectPadding, vx_scalar spectrogramLayout, vx_scalar power, vx_scalar nfft, vx_scalar windowLength, vx_scalar windowStep);

/*! \brief [Graph] Applies downmixing to the input tensor.
* \ingroup group_amd_rpp
* \param [in] graph The handle to the graph.
* \param [in] pSrc The input tensor in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param [out] pDst The output tensor in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param [in] pSrcRoi The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the input.
* \return A node reference <tt>\ref vx_node</tt>. Any possible errors preventing a successful creation should be checked using <tt>\ref vxGetStatus</tt>.
*/
SHARED_PUBLIC vx_node VX_API_CALL vxExtRppDownmix(vx_graph graph, vx_tensor pSrc, vx_tensor pDst, vx_tensor srcRoi);
SundarRajan28 marked this conversation as resolved.
Show resolved Hide resolved

/*! \brief [Graph] Applies to_decibels augmentation to the input tensor.
* \ingroup group_amd_rpp
* \param [in] graph The handle to the graph.
* \param [in] pSrc The input tensor in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param[in] pSrcRoi The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the input.
* \param [out] pDst The output tensor in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param[in] cutOffDB The input scalar in <tt>\ref VX_TYPE_FLOAT32</tt> format containing minimum or cut-off ratio in dB
Copy link
Collaborator

@fiona-gladwin fiona-gladwin Mar 25, 2024

Choose a reason for hiding this comment

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

Is it dims or ROI, please change name accordingly

For both srcDims and dstDims

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also is it of xywh or ltrb format? For audio

Copy link
Collaborator

Choose a reason for hiding this comment

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

Change the supported data types

* \param[in] multiplier The input scalar in <tt>\ref VX_TYPE_FLOAT32</tt> format containing factor by which the logarithm is multiplied
* \param[in] referenceMagnitude The input scalar in <tt>\ref VX_TYPE_FLOAT32</tt> format containing Reference magnitude which if not provided uses maximum value of input as reference
* \return A node reference <tt>\ref vx_node</tt>. Any possible errors preventing a successful creation should be checked using <tt>\ref vxGetStatus</tt>.
*/
SHARED_PUBLIC vx_node VX_API_CALL vxExtRppToDecibels(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_scalar cutOffDB, vx_scalar multiplier, vx_scalar referenceMagnitude);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ vx_status get_kernels_to_publish()
STATUS_ERROR_CHECK(ADD_KERNEL(WarpAffine_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(PreemphasisFilter_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(Spectrogram_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(Downmix_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(ToDecibels_Register));

return status;
}
Expand Down
35 changes: 35 additions & 0 deletions amd_openvx_extensions/amd_rpp/source/kernel_rpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,41 @@ VX_API_ENTRY vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor p
return node;
}

VX_API_ENTRY vx_node VX_API_CALL vxExtRppDownmix(vx_graph graph, vx_tensor pSrc, vx_tensor pDst, vx_tensor pSrcRoi) {
vx_node node = NULL;
vx_context context = vxGetContext((vx_reference)graph);
if (vxGetStatus((vx_reference)context) == VX_SUCCESS) {
vx_uint32 devType = getGraphAffinity(graph);
vx_scalar deviceType = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &devType);
vx_reference params[] = {
(vx_reference)pSrc,
(vx_reference)pDst,
(vx_reference)pSrcRoi,
(vx_reference)deviceType};
node = createNode(graph, VX_KERNEL_RPP_DOWNMIX, params, 4);
}
return node;
}

VX_API_ENTRY vx_node VX_API_CALL vxExtRppToDecibels(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_scalar cutOffDB, vx_scalar multiplier, vx_scalar referenceMagnitude) {
vx_node node = NULL;
vx_context context = vxGetContext((vx_reference)graph);
if (vxGetStatus((vx_reference)context) == VX_SUCCESS) {
vx_uint32 devType = getGraphAffinity(graph);
vx_scalar deviceType = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &devType);
vx_reference params[] = {
(vx_reference)pSrc,
(vx_reference)pSrcRoi,
(vx_reference)pDst,
(vx_reference)cutOffDB,
(vx_reference)multiplier,
(vx_reference)referenceMagnitude,
(vx_reference)deviceType};
node = createNode(graph, VX_KERNEL_RPP_TODECIBELS, params, 7);
}
return node;
}

RpptDataType getRpptDataType(vx_enum vxDataType) {
switch(vxDataType) {
case vx_type_e::VX_TYPE_FLOAT32:
Expand Down
206 changes: 206 additions & 0 deletions amd_openvx_extensions/amd_rpp/source/tensor/Downmix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
/*
Copyright (c) 2024 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 "internal_publishKernels.h"
#include "vx_ext_amd.h"

struct DownmixLocalData {
vxRppHandle *handle;
Rpp32u deviceType;
RppPtr_t pSrc;
RppPtr_t pDst;
vx_int32 *psrcRoi;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please change psrcRoi to pSrcRoi

RpptDescPtr pSrcDesc;
RpptDescPtr pDstDesc;
size_t inputTensorDims[RPP_MAX_TENSOR_DIMS];
size_t outputTensorDims[RPP_MAX_TENSOR_DIMS];
};

static vx_status VX_CALLBACK refreshDownmix(vx_node node, const vx_reference *parameters, vx_uint32 num, DownmixLocalData *data) {
vx_status status = VX_SUCCESS;
void *roi_tensor_ptr_src;
if (data->deviceType == AGO_TARGET_AFFINITY_GPU) {
#if ENABLE_OPENCL || ENABLE_HIP
return VX_ERROR_NOT_IMPLEMENTED;
#endif
SundarRajan28 marked this conversation as resolved.
Show resolved Hide resolved
} else if (data->deviceType == AGO_TARGET_AFFINITY_CPU) {
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[0], VX_TENSOR_BUFFER_HOST, &data->pSrc, sizeof(data->pSrc)));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_BUFFER_HOST, &data->pDst, sizeof(data->pDst)));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[2], VX_TENSOR_BUFFER_HOST, &roi_tensor_ptr_src, sizeof(roi_tensor_ptr_src)));
}
RpptROI *src_roi = reinterpret_cast<RpptROI *>(roi_tensor_ptr_src);
for (int n = 0; n < data->inputTensorDims[0]; n++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Restructure the loop as below so that we have multiplication as part of loop counter

    for (int n = 0, k = 0; n < data->inputTensorDims[0]; n++, k += 2) 
    {
           data->psrcRoi[k] = src_roi[n].xywhROI.roiWidth;
           data->psrcRoi[k + 1] = src_roi[n].xywhROI.roiHeight;
    }

data->psrcRoi[n * 2] = src_roi[n].xywhROI.roiWidth;
data->psrcRoi[n * 2 + 1] = src_roi[n].xywhROI.roiHeight;
}
return status;
}

static vx_status VX_CALLBACK validateDownmix(vx_node node, const vx_reference parameters[], vx_uint32 num, vx_meta_format metas[]) {
vx_status status = VX_SUCCESS;
vx_enum scalar_type;
STATUS_ERROR_CHECK(vxQueryScalar((vx_scalar)parameters[3], VX_SCALAR_TYPE, &scalar_type, sizeof(scalar_type)));
if (scalar_type != VX_TYPE_UINT32)
return ERRMSG(VX_ERROR_INVALID_TYPE, "validate: Paramter: #3 type=%d (must be size)\n", scalar_type);

// Check for input parameters
size_t num_tensor_dims;
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[0], VX_TENSOR_NUMBER_OF_DIMS, &num_tensor_dims, sizeof(num_tensor_dims)));
if (num_tensor_dims < 3) return ERRMSG(VX_ERROR_INVALID_DIMENSION, "validate: Downmix: tensor: #0 dimensions=%lu (must be greater than or equal to 3)\n", num_tensor_dims);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the dims be greater than 3? Modify comments accordingly


// Check for output parameters
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_NUMBER_OF_DIMS, &num_tensor_dims, sizeof(num_tensor_dims)));
if (num_tensor_dims < 3) return ERRMSG(VX_ERROR_INVALID_DIMENSION, "validate: Downmix: tensor: #1 dimensions=%lu (must be greater than or equal to 3)\n", num_tensor_dims);

vx_uint8 tensor_fixed_point_position;
size_t tensor_dims[RPP_MAX_TENSOR_DIMS];
vx_enum tensor_datatype;

STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_DIMS, &tensor_dims, sizeof(tensor_dims)));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_DATA_TYPE, &tensor_datatype, sizeof(tensor_datatype)));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_FIXED_POINT_POSITION, &tensor_fixed_point_position, sizeof(tensor_fixed_point_position)));
STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(metas[1], VX_TENSOR_NUMBER_OF_DIMS, &num_tensor_dims, sizeof(num_tensor_dims)));
STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(metas[1], VX_TENSOR_DIMS, &tensor_dims, sizeof(tensor_dims)));
STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(metas[1], VX_TENSOR_DATA_TYPE, &tensor_datatype, sizeof(tensor_datatype)));
STATUS_ERROR_CHECK(vxSetMetaFormatAttribute(metas[1], VX_TENSOR_FIXED_POINT_POSITION, &tensor_fixed_point_position, sizeof(tensor_fixed_point_position)));
return status;
}

static vx_status VX_CALLBACK processDownmix(vx_node node, const vx_reference *parameters, vx_uint32 num) {
RppStatus rpp_status = RPP_SUCCESS;
vx_status return_status = VX_SUCCESS;
DownmixLocalData *data = NULL;
STATUS_ERROR_CHECK(vxQueryNode(node, VX_NODE_LOCAL_DATA_PTR, &data, sizeof(data)));
if (data->deviceType == AGO_TARGET_AFFINITY_GPU) {
#if ENABLE_OPENCL || ENABLE_HIP
return VX_ERROR_NOT_IMPLEMENTED;
#endif
SundarRajan28 marked this conversation as resolved.
Show resolved Hide resolved
} else if (data->deviceType == AGO_TARGET_AFFINITY_CPU) {
refreshDownmix(node, parameters, num, data);
rpp_status = rppt_down_mixing_host((float *)data->pSrc, data->pSrcDesc, (float *)data->pDst, data->pDstDesc, (Rpp32s *)data->psrcRoi, false, data->handle->rppHandle);
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 this casting to (float *) since it is not needed

return_status = (rpp_status == RPP_SUCCESS) ? VX_SUCCESS : VX_FAILURE;
}
return return_status;
}

static vx_status VX_CALLBACK initializeDownmix(vx_node node, const vx_reference *parameters, vx_uint32 num) {
DownmixLocalData *data = new DownmixLocalData;
memset(data, 0, sizeof(DownmixLocalData));

vx_enum input_tensor_datatype, output_tensor_datatype;
STATUS_ERROR_CHECK(vxCopyScalar((vx_scalar)parameters[3], &data->deviceType, VX_READ_ONLY, VX_MEMORY_TYPE_HOST));

// Querying for input tensor
data->pSrcDesc = new RpptDesc;
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[0], VX_TENSOR_NUMBER_OF_DIMS, &data->pSrcDesc->numDims, sizeof(data->pSrcDesc->numDims)));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[0], VX_TENSOR_DIMS, &data->inputTensorDims, sizeof(vx_size) * data->pSrcDesc->numDims));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[0], VX_TENSOR_DATA_TYPE, &input_tensor_datatype, sizeof(input_tensor_datatype)));
data->pSrcDesc->dataType = getRpptDataType(input_tensor_datatype);
data->pSrcDesc->offsetInBytes = 0;
fillAudioDescriptionPtrFromDims(data->pSrcDesc, data->inputTensorDims);

// Querying for output tensor
data->pDstDesc = new RpptDesc;
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_NUMBER_OF_DIMS, &data->pDstDesc->numDims, sizeof(data->pDstDesc->numDims)));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_DIMS, &data->outputTensorDims, sizeof(vx_size) * data->pDstDesc->numDims));
STATUS_ERROR_CHECK(vxQueryTensor((vx_tensor)parameters[1], VX_TENSOR_DATA_TYPE, &output_tensor_datatype, sizeof(output_tensor_datatype)));
data->pDstDesc->dataType = getRpptDataType(output_tensor_datatype);
data->pDstDesc->offsetInBytes = 0;
fillAudioDescriptionPtrFromDims(data->pDstDesc, data->outputTensorDims);

data->psrcRoi = new vx_int32[data->pSrcDesc->n * 2];

refreshDownmix(node, parameters, num, data);
STATUS_ERROR_CHECK(createRPPHandle(node, &data->handle, data->pSrcDesc->n, data->deviceType));
STATUS_ERROR_CHECK(vxSetNodeAttribute(node, VX_NODE_LOCAL_DATA_PTR, &data, sizeof(data)));
return VX_SUCCESS;
}

static vx_status VX_CALLBACK uninitializeDownmix(vx_node node, const vx_reference *parameters, vx_uint32 num) {
DownmixLocalData *data;
STATUS_ERROR_CHECK(vxQueryNode(node, VX_NODE_LOCAL_DATA_PTR, &data, sizeof(data)));
STATUS_ERROR_CHECK(releaseRPPHandle(node, data->handle, data->deviceType));
delete[] data->psrcRoi;
delete data->pSrcDesc;
delete data->pDstDesc;
delete data;
return VX_SUCCESS;
}

//! \brief The kernel target support callback.
// TODO::currently the node is setting the same affinity as context. This needs to change when we have hybrid modes in the same graph
static vx_status VX_CALLBACK query_target_support(vx_graph graph, vx_node node,
vx_bool use_opencl_1_2, // [input] false: OpenCL driver is 2.0+; true: OpenCL driver is 1.2
vx_uint32 &supported_target_affinity // [output] must be set to AGO_TARGET_AFFINITY_CPU or AGO_TARGET_AFFINITY_GPU or (AGO_TARGET_AFFINITY_CPU | AGO_TARGET_AFFINITY_GPU)
) {
vx_context context = vxGetContext((vx_reference)graph);
AgoTargetAffinityInfo affinity;
vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_AMD_AFFINITY, &affinity, sizeof(affinity));
if (affinity.device_type == AGO_TARGET_AFFINITY_GPU)
supported_target_affinity = AGO_TARGET_AFFINITY_GPU;
else
supported_target_affinity = AGO_TARGET_AFFINITY_CPU;

// hardcode the affinity to CPU for OpenCL backend to avoid VerifyGraph failure since there is no codegen callback for amd_rpp nodes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this comment applicable here, Please check this
@swetha097 Please check in other PR's too


return VX_SUCCESS;
}

vx_status Downmix_Register(vx_context context) {
vx_status status = VX_SUCCESS;
// Add kernel to the context with callbacks
vx_kernel kernel = vxAddUserKernel(context, "org.rpp.Downmix",
VX_KERNEL_RPP_DOWNMIX,
processDownmix,
4,
validateDownmix,
initializeDownmix,
uninitializeDownmix);
ERROR_CHECK_OBJECT(kernel);
AgoTargetAffinityInfo affinity;
vxQueryContext(context, VX_CONTEXT_ATTRIBUTE_AMD_AFFINITY, &affinity, sizeof(affinity));
#if ENABLE_HIP
// enable OpenCL buffer access since the kernel_f callback uses OpenCL buffers instead of host accessible buffers
vx_bool enableBufferAccess = vx_true_e;
if (affinity.device_type == AGO_TARGET_AFFINITY_GPU)
STATUS_ERROR_CHECK(vxSetKernelAttribute(kernel, VX_KERNEL_ATTRIBUTE_AMD_GPU_BUFFER_ACCESS_ENABLE, &enableBufferAccess, sizeof(enableBufferAccess)));
#else
vx_bool enableBufferAccess = vx_false_e;
#endif
amd_kernel_query_target_support_f query_target_support_f = query_target_support;

if (kernel) {
STATUS_ERROR_CHECK(vxSetKernelAttribute(kernel, VX_KERNEL_ATTRIBUTE_AMD_QUERY_TARGET_SUPPORT, &query_target_support_f, sizeof(query_target_support_f)));
PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 0, VX_INPUT, VX_TYPE_TENSOR, VX_PARAMETER_STATE_REQUIRED));
PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 1, VX_OUTPUT, VX_TYPE_TENSOR, VX_PARAMETER_STATE_REQUIRED));
PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 2, VX_INPUT, VX_TYPE_TENSOR, VX_PARAMETER_STATE_REQUIRED));
PARAM_ERROR_CHECK(vxAddParameterToKernel(kernel, 3, VX_INPUT, VX_TYPE_SCALAR, VX_PARAMETER_STATE_REQUIRED));
PARAM_ERROR_CHECK(vxFinalizeKernel(kernel));
}
if (status != VX_SUCCESS) {
exit:
vxRemoveKernel(kernel);
return VX_FAILURE;
}

return status;
}
Loading