This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PROCESSOR-SDK-DRA8X-TDA4X: Custom kernel requires array of tensors as input

Part Number: PROCESSOR-SDK-DRA8X-TDA4X


Hello,

I am using python script to generate a custom kernel that requires array of tensor as input.

I could not find any way of declaring it in the python script. So which data object should be used for this purpose ? Or it should be handled in the application itself ?

Regards,

Dipti

  • Hello, 

    As per my previous query : My application requires array of tensors as input .

    I was not able to find any specific enum to include Array of tensors in my python script.

    Hence I took reference from AVP example provided which passes array of input tensors to the TIDL node and the output is also array of tensors.Here the node creation function had changes to accept array of  tensors as input and output. I tried doing the changes in my auto generated code on the same lines, and I am facing a run time error :

    VX_ZONE_ERROR : [tivxCreateNodeByKernelName 136]: Call to vxGetKernelByName failed; kernel may not be registered
    VX_ZONE_ERROR : [vxSetReferenceName 558] : vxSetReferenceName : Invalid reference.

    1) The python script I used is as follows:

    from tiovx import *

    code = KernelExportCode("tensor_array", "c66x", "CUSTOM_KERNEL_PATH")

    kernel = Kernel("TEST_TENSOR")

    kernel.setParameter(Type.TENSOR, Direction.INPUT, ParamState.REQUIRED, "TENSOR_ARR")
    kernel.setParameter(Type.USER_DATA_OBJECT, Direction.OUTPUT, ParamState.REQUIRED, "OUTPUT")

    kernel.setTarget(Target.DSP1)
    kernel.setTarget(Target.DSP2)

    code.export(kernel)

    2) Changes I made in the node API call in auto-generated file : host/tivx_tensor_array_node_api.c : 

        
    VX_API_ENTRY vx_node VX_API_CALL tivxTestTensorNode(vx_graph graph,
                                          vx_tensor            tensor_arr,
                                          vx_user_data_object  output)
    {
         vx_reference prms[TIVX_KERNEL_TEST_TENSOR_MAX_PARAMS];
         vx_int32 i;
         vx_int32 num_params = 10;
         for(i = 0; i < 9; i++){
          prms[i] = (vx_reference)tensor_arr[i];
         }
         prms[9] = (vx_reference)output;
        vx_node node = tivxCreateNodeByKernelName(graph,
                                                TIVX_KERNEL_TEST_TENSOR_NAME,
                                                prms,
                                                num_params);

        
        printf("kernel name: %s,num_params : %d\n",TIVX_KERNEL_TEST_TENSOR_NAME,num_params);
        return node;
    }
    3) Added the logic for multiple tensors in auto-generated code for target : c66/vx_test_tensor_target.c : In process call
    for(i = 0; i < 9; i++) 
            {
            tensor_arr_desc = (tivx_obj_desc_tensor_t *)obj_desc[i];
            tensor_arr_target_ptr[i] = tivxMemShared2TargetPtr(&tensor_arr_desc->mem_ptr);
            tivxMemBufferMap(tensor_arr_target_ptr, tensor_arr_desc->mem_size, VX_MEMORY_TYPE_HOST, VX_WRITE_ONLY);
            }
    4) Modified 
    TIVX_KERNEL_TEST_TENSOR_MAX_PARAMS in the header file : include/tivx_kernel_test_tensor.h
    5) Also modified the validate function in host/vx_test_tensor_host.c to accept and query array of tensors.
    Let me know if this is a right way of implementing or there is something I am missing out .
  • Hello Dipti,

    With regards to your method of taking an input array of tensors to your new node, you have two different options:

    1. You can follow the template of the TIDL node and take your input tensor number as an argument of the registration function as you are doing.

    2. You can use the OpenVX object called an "object array" as the input type for your tensor array.  This object is described in more detail below.  This data type allows you to create an array of any OpenVX-defined data object.

    https://www.khronos.org/registry/OpenVX/specs/1.1/html/db/d9f/group__group__object__array.html  

    So to answer your question, yes, your methodology is an acceptable way of going about creating the input array of tensors to your new node.

    A couple notes on the implementation of this per your second post:

    On #2, the updated API should include the array in the definition as per below:

    VX_API_ENTRY vx_node VX_API_CALL tivxTestTensorNode(vx_graph graph,
                                          vx_tensor            tensor_arr[],
                                          vx_user_data_object  output)
    Additionally, on #2, are you always expecting that 9 input tensors will be provided to the node?  If not, you will need to ensure that you are accepting as an argument the number of tensors into the API so that this can be registered properly.  Please refer to the tivxTIDLNode definition in tiovx/kernels_j7/tidl/host/tivx_tidl_node_api.c for these details.
    Regards,
    Lucas
  • Hi Lucas,

    1) As per your suggestion, I made the changes required in API . 

    I still get the following error : 

    VX_ZONE_ERROR : [tivxCreateNodeByKernelName 136]: Call to vxGetKernelByName failed; kernel may not be registered
    VX_ZONE_ERROR : [vxSetReferenceName 558] : vxSetReferenceName : Invalid reference.
    For just experimental purpose I have taken 9 tensors.
    Are you suggesting that just not having number of tensors as argument to node will create issues while registration?
    I will give it a try and get back to you.
    2) I have looked in to the object array option that you suggested , I am not clear about the following thing mentioned in the document :
    The exemplar object that defines the type of object in the ObjectArray. Only exemplar type of vx_imagevx_array and vx_pyramid are allowed.
    It says that the objects allowed are only these three.
    Can you clarify about the same.
    Thanks,
    Dipti
    Thanks,
    Dipti
  • Hello Dipti,

    I have a few questions and suggestions for your two points below:

    1) Have you made any changes in the kernel host side registration to account for the 9 tensors?  After adding the host side kernel using the vxAddUserKernel API, there is an API called vxAddParameterToKernel that allows one to register parameters with the kernel.  If you used the PyTIOVX script from above, the auto-generated code would only use a single tensor input parameter.  Given your modifications to allow 9 tensors, this would need to be modified in this location as well.  Please refer to tiovx/kernels_j7/tidl/host/vx_tidl_host.c for how this is done with the TIDL node.

    2) As you said, the standard specification limits this to the types you mentioned.  This is not strictly enforced in the TIOVX framework, but given the spec recommendation and the fact that this has not been fully tested in the TIOVX framework, I would recommend that you use the method of registering tensors similar to the TIDL node as you are doing.  Apologies for the misleading information.

    Regards,

    Lucas

  • Hello Lucas,

    I agree to the first point, I had missed that change. That will surely solve my issue. Thanks for providing references.

    As you mentioned in point 2 , object array might not be a tried and tested solution for now.

    I will follow TIDL example.

    Thanks,

    Dipti

  • Hello Dipti,

    Please feel free to comment on this thread if you have further issues with this.

    Regards,

    Lucas