From d05f7fa48aa737733cc9dcf9edf915a038f86f87 Mon Sep 17 00:00:00 2001 From: LakshmiKumar23 Date: Mon, 19 Oct 2020 07:24:13 -0700 Subject: [PATCH 1/5] vxRetainRef line 371 fix --- amd_openvx/openvx/ago/ago_util.cpp | 6 ++++++ amd_openvx/openvx/api/vx_api.cpp | 2 ++ 2 files changed, 8 insertions(+) diff --git a/amd_openvx/openvx/ago/ago_util.cpp b/amd_openvx/openvx/ago/ago_util.cpp index f0921a1a09..759431a8af 100644 --- a/amd_openvx/openvx/ago/ago_util.cpp +++ b/amd_openvx/openvx/ago/ago_util.cpp @@ -1951,6 +1951,7 @@ AgoData * agoCreateDataFromDescription(AgoContext * acontext, AgoGraph * agraph, agoResetReference(&data->ref, data->ref.type, acontext, data->isVirtual ? &agraph->ref : NULL); if (isForExternalUse) { data->ref.external_count = 1; + acontext->num_active_references++; } else { data->ref.internal_count = 1; @@ -2728,6 +2729,7 @@ void agoRetainData(AgoGraph * graph, AgoData * data, bool isForExternalUse) { if (isForExternalUse) { data->ref.external_count++; + data->ref.context->num_active_references++; } else { data->ref.internal_count++; @@ -2773,6 +2775,8 @@ int agoReleaseData(AgoData * data, bool isForExternalUse) if (data->ref.internal_count > 0) data->ref.internal_count--; } + if(data->ref.external_count == 0 && isForExternalUse) + graph->ref.context->num_active_references--; if (data->ref.external_count == 0 && data->ref.internal_count == 0) { // clear child link in it's paren link if (data->parent) { @@ -2813,6 +2817,8 @@ int agoReleaseData(AgoData * data, bool isForExternalUse) data->ref.internal_count--; } } + if(data->ref.external_count == 0 && isForExternalUse) + context->num_active_references--; if (data->ref.external_count == 0 && data->ref.internal_count == 0) { // clear child link in it's paren link if (data->parent) { diff --git a/amd_openvx/openvx/api/vx_api.cpp b/amd_openvx/openvx/api/vx_api.cpp index c8bb21c945..3d08ccf488 100644 --- a/amd_openvx/openvx/api/vx_api.cpp +++ b/amd_openvx/openvx/api/vx_api.cpp @@ -2057,6 +2057,7 @@ VX_API_ENTRY vx_image VX_API_CALL vxCreateImageFromChannel(vx_image img, vx_enum } if (subImage) { subImage->ref.external_count++; + subImage->ref.context->num_active_references++; } return (vx_image)subImage; } @@ -8598,6 +8599,7 @@ VX_API_ENTRY vx_reference VX_API_CALL vxGetObjectArrayItem(vx_object_array arr, // convert the index from 0..-(N-1) to 0..N-1 if (index < data->u.objarr.numitems) { item = data->children[index]; + agoRetainData((AgoGraph *)data->ref.scope, item, true); } } return (vx_reference)item; From dcc4a23cddc3317180f07b561807c7fd226dea3f Mon Sep 17 00:00:00 2001 From: LakshmiKumar23 Date: Thu, 22 Oct 2020 09:16:23 -0700 Subject: [PATCH 2/5] vxSetReferenceName fix --- amd_openvx/openvx/ago/ago_internal.h | 1 + amd_openvx/openvx/api/vx_api.cpp | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/amd_openvx/openvx/ago/ago_internal.h b/amd_openvx/openvx/ago/ago_internal.h index dbfbe579b1..89d39149ed 100644 --- a/amd_openvx/openvx/ago/ago_internal.h +++ b/amd_openvx/openvx/ago/ago_internal.h @@ -628,6 +628,7 @@ struct AgoNodeList { }; struct AgoGraph { AgoReference ref; + std::string name; AgoGraph * next; CRITICAL_SECTION cs; HANDLE hThread, hSemToThread, hSemFromThread; diff --git a/amd_openvx/openvx/api/vx_api.cpp b/amd_openvx/openvx/api/vx_api.cpp index 3d08ccf488..73b693335c 100644 --- a/amd_openvx/openvx/api/vx_api.cpp +++ b/amd_openvx/openvx/api/vx_api.cpp @@ -4157,10 +4157,20 @@ VX_API_ENTRY vx_status VX_API_CALL vxQueryReference(vx_reference ref, vx_enum at break; case VX_REFERENCE_NAME: if (size == sizeof(vx_char*)) { - AgoData * data = (AgoData *)ref; - //strncpy((char *)ptr, data->name.c_str(), size); - *(vx_char**)ptr = &data->name[0]; - status = VX_SUCCESS; + if(ref->type == VX_TYPE_GRAPH) + { + AgoGraph * graph = (AgoGraph *)ref; + //strncpy((char *)ptr, data->name.c_str(), size); + *(vx_char**)ptr = &graph->name[0]; + status = VX_SUCCESS; + } + else + { + AgoData * data = (AgoData *)ref; + //strncpy((char *)ptr, data->name.c_str(), size); + *(vx_char**)ptr = &data->name[0]; + status = VX_SUCCESS; + } } break; default: @@ -4298,7 +4308,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxSetReferenceName(vx_reference ref, const vx vx_status status = VX_ERROR_INVALID_REFERENCE; if (agoIsValidReference(ref) && ((ref->type >= VX_TYPE_DELAY && ref->type <= VX_TYPE_REMAP) || (ref->type == VX_TYPE_TENSOR) || - (ref->type >= VX_TYPE_VENDOR_OBJECT_START && ref->type <= VX_TYPE_VENDOR_OBJECT_END) || (ref->type == VX_TYPE_GRAPH))) + (ref->type >= VX_TYPE_VENDOR_OBJECT_START && ref->type <= VX_TYPE_VENDOR_OBJECT_END))) { AgoData * data = (AgoData *)ref; //printf("%s %s %lu\n", data->name.c_str(), name, strlen(name)); @@ -4314,6 +4324,12 @@ VX_API_ENTRY vx_status VX_API_CALL vxSetReferenceName(vx_reference ref, const vx status = VX_SUCCESS; } + else if(agoIsValidReference(ref) && (ref->type == VX_TYPE_GRAPH)) + { + AgoGraph * graph = (AgoGraph *)ref; + graph->name = name; + status = VX_SUCCESS; + } return status; } From 429eae1a7daea23866bdb49f63d64db1198d813e Mon Sep 17 00:00:00 2001 From: LakshmiKumar23 Date: Fri, 23 Oct 2020 07:06:30 -0700 Subject: [PATCH 3/5] pyramid fixes --- amd_openvx/openvx/ago/ago_util.cpp | 6 +++--- amd_openvx/openvx/api/vx_api.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/amd_openvx/openvx/ago/ago_util.cpp b/amd_openvx/openvx/ago/ago_util.cpp index 759431a8af..b9b77b811d 100644 --- a/amd_openvx/openvx/ago/ago_util.cpp +++ b/amd_openvx/openvx/ago/ago_util.cpp @@ -2729,7 +2729,7 @@ void agoRetainData(AgoGraph * graph, AgoData * data, bool isForExternalUse) { if (isForExternalUse) { data->ref.external_count++; - data->ref.context->num_active_references++; + //data->ref.context->num_active_references++; } else { data->ref.internal_count++; @@ -2775,7 +2775,7 @@ int agoReleaseData(AgoData * data, bool isForExternalUse) if (data->ref.internal_count > 0) data->ref.internal_count--; } - if(data->ref.external_count == 0 && isForExternalUse) + if(data->ref.external_count >= 0 && isForExternalUse && data->ref.internal_count >= 0) graph->ref.context->num_active_references--; if (data->ref.external_count == 0 && data->ref.internal_count == 0) { // clear child link in it's paren link @@ -2817,7 +2817,7 @@ int agoReleaseData(AgoData * data, bool isForExternalUse) data->ref.internal_count--; } } - if(data->ref.external_count == 0 && isForExternalUse) + if(data->ref.external_count >= 0 && isForExternalUse && data->ref.internal_count >= 0) context->num_active_references--; if (data->ref.external_count == 0 && data->ref.internal_count == 0) { // clear child link in it's paren link diff --git a/amd_openvx/openvx/api/vx_api.cpp b/amd_openvx/openvx/api/vx_api.cpp index 73b693335c..0dc31d8b87 100644 --- a/amd_openvx/openvx/api/vx_api.cpp +++ b/amd_openvx/openvx/api/vx_api.cpp @@ -4276,6 +4276,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxRetainReference(vx_reference ref) vx_status status = VX_ERROR_INVALID_REFERENCE; if (agoIsValidReference(ref)) { ref->external_count++; + ref->context->num_active_references++; status = VX_SUCCESS; } return status; @@ -6995,6 +6996,7 @@ VX_API_ENTRY vx_image VX_API_CALL vxGetPyramidLevel(vx_pyramid pyr, vx_uint32 in if (agoIsValidData(data, VX_TYPE_PYRAMID) && (index < data->u.pyr.levels) && !data->isNotFullyConfigured) { img = data->children[index]; agoRetainData((AgoGraph *)data->ref.scope, img, true); + data->ref.context->num_active_references++; } return (vx_image)img; } @@ -8616,6 +8618,7 @@ VX_API_ENTRY vx_reference VX_API_CALL vxGetObjectArrayItem(vx_object_array arr, if (index < data->u.objarr.numitems) { item = data->children[index]; agoRetainData((AgoGraph *)data->ref.scope, item, true); + data->ref.context->num_active_references++; } } return (vx_reference)item; From 7d6a5077bca59208d3e9c52fa447b888ce1a666f Mon Sep 17 00:00:00 2001 From: LakshmiKumar23 Date: Mon, 26 Oct 2020 03:49:36 -0700 Subject: [PATCH 4/5] smoke test fixes for dangling references --- amd_openvx/openvx/ago/ago_interface.cpp | 5 ++++- amd_openvx/openvx/api/vx_api.cpp | 7 ++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/amd_openvx/openvx/ago/ago_interface.cpp b/amd_openvx/openvx/ago/ago_interface.cpp index 179eea1936..1fc27de64f 100644 --- a/amd_openvx/openvx/ago/ago_interface.cpp +++ b/amd_openvx/openvx/ago/ago_interface.cpp @@ -96,6 +96,8 @@ int agoReleaseContext(AgoContext * acontext) vx_reference ref = (vx_reference)acontext; ref->external_count = ref->external_count- 1; + if(ref->external_count >= 0) + acontext->num_active_references--; if(&ref->external_count == 0) { EnterCriticalSection(&acontext->cs); @@ -163,9 +165,10 @@ int agoReleaseGraph(AgoGraph * agraph) int status = 0; agraph->ref.external_count--; + if(agraph->ref.external_count >= 0) + agraph->ref.context->num_active_references--; if (agraph->ref.external_count == 0) { EnterCriticalSection(&agraph->cs); - agraph->ref.context->num_active_references--; // stop graph thread if (agraph->hThread) { agraph->threadThreadTerminationState = 1; diff --git a/amd_openvx/openvx/api/vx_api.cpp b/amd_openvx/openvx/api/vx_api.cpp index 0dc31d8b87..750dfe0b59 100644 --- a/amd_openvx/openvx/api/vx_api.cpp +++ b/amd_openvx/openvx/api/vx_api.cpp @@ -2331,8 +2331,6 @@ VX_API_ENTRY vx_kernel VX_API_CALL vxAddKernel(vx_context context, kernel->importing_module_index_plus1 = context->importing_module_index_plus1; kernel->user_kernel = vx_false_e; agoAddKernel(&context->kernelList, kernel); - // update reference count - kernel->ref.context->num_active_references++; } } return kernel; @@ -2392,8 +2390,6 @@ VX_API_ENTRY vx_kernel VX_API_CALL vxAddUserKernel(vx_context context, kernel->importing_module_index_plus1 = context->importing_module_index_plus1; kernel->user_kernel = vx_true_e; agoAddKernel(&context->kernelList, kernel); - // update reference count - kernel->ref.context->num_active_references++; } } return kernel; @@ -4276,7 +4272,8 @@ VX_API_ENTRY vx_status VX_API_CALL vxRetainReference(vx_reference ref) vx_status status = VX_ERROR_INVALID_REFERENCE; if (agoIsValidReference(ref)) { ref->external_count++; - ref->context->num_active_references++; + if (ref->type != VX_TYPE_KERNEL && ref->type != VX_TYPE_NODE && ref->type != VX_TYPE_PARAMETER) + ref->context->num_active_references++; status = VX_SUCCESS; } return status; From 856339883a58a82445edb25f6b17da38b1c4292e Mon Sep 17 00:00:00 2001 From: LakshmiKumar23 Date: Tue, 27 Oct 2020 23:58:34 -0700 Subject: [PATCH 5/5] resolves all dangling reference issues --- amd_openvx/openvx/api/vx_api.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/amd_openvx/openvx/api/vx_api.cpp b/amd_openvx/openvx/api/vx_api.cpp index 750dfe0b59..17d16a0452 100644 --- a/amd_openvx/openvx/api/vx_api.cpp +++ b/amd_openvx/openvx/api/vx_api.cpp @@ -3642,6 +3642,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxQueryParameter(vx_parameter param, vx_enum // TBD: handle optimized buffers and kernels if (ref) { ref->external_count++; + ref->context->num_active_references++; } status = VX_SUCCESS; }