Exemplo n.º 1
0
void example_explore_parameters(vx_context context, vx_kernel kernel)
{
    vx_uint32 p, numParams = 0;
    vx_graph graph = vxCreateGraph(context);
    vx_node node = vxCreateGenericNode(graph, kernel);
    vxQueryKernel(kernel, VX_KERNEL_PARAMETERS, &numParams, sizeof(numParams));
    for (p = 0; p < numParams; p++)
    {
        //! [Getting the ref]
        vx_parameter param = vxGetParameterByIndex(node, p);
        vx_reference ref;
        vxQueryParameter(param, VX_PARAMETER_REF, &ref, sizeof(ref));
        //! [Getting the ref]
        if (ref)
        {
            //! [Getting the type]
            vx_enum type;
            vxQueryParameter(param, VX_PARAMETER_TYPE, &type, sizeof(type));
            /* cast the ref to the correct vx_<type>. Atomics are now vx_scalar */
            //! [Getting the type]
        }
        vxReleaseParameter(&param);
    }
    vxReleaseNode(&node);
    vxReleaseGraph(&graph);
}
Exemplo n.º 2
0
 //**************************************************************************
 // EXPORTED FUNCTIONS
 //**************************************************************************
 static void Initialize(JNIEnv *env, jobject obj, jlong g, jlong k)
 {
     vx_graph graph = (vx_graph)g;
     vx_kernel kernel = (vx_kernel)k;
     vx_node n = vxCreateGenericNode(graph, kernel);
     SetHandle(env, obj, NodeClass, parentName, g);
     SetHandle(env, obj, NodeClass, handleName, (jlong)n);
 }
Exemplo n.º 3
0
vx_node vx_create_specific_sobel(vx_context context, vx_graph graph, vx_bool easy)
{
    vx_node n = 0;
    if (easy == vx_false_e) {
        //! [firstmethod]
        vx_kernel kernel = vxGetKernelByEnum(context, VX_KERNEL_SOBEL_3x3);
        vx_node node = vxCreateGenericNode(graph, kernel);
        //! [firstmethod]
#if defined(EXPERIMENTAL_USE_TARGET)
        vx_target target = vxGetTargetByName(context, "gpu");
        vxAssignNodeAffinity(node, target);
#endif
#if defined(EXPERIMENTAL_USE_VARIANTS)
        //! [variant:firstmethod]
        vxChooseKernelVariant(node, "faster");
        //! [variant:firstmethod]
#endif
        n = node;
    } else {
#if defined(EXPERIMENTAL_USE_VARIANTS)
        //! [variant:second]
#if defined(EXPERIMENTAL_USE_TARGET)
        vx_kernel kernel = vxGetKernelByName(context, "cpu:org.khronos.openvx.sobel3x3:faster");
#else
        vx_kernel kernel = vxGetKernelByName(context, "org.khronos.openvx.sobel3x3:faster");
#endif
        vx_node node = vxCreateGenericNode(graph, kernel);
        //! [variant:second]
#else   /*defined(EXPERIMENTAL_USE_VARIANTS)*/
        //! [secondmethod]
        vx_kernel kernel = vxGetKernelByName(context, "org.khronos.openvx.sobel3x3");
        vx_node node = vxCreateGenericNode(graph, kernel);
        //! [secondmethod]
#endif
        n = node;
    }
    return n;
}
Exemplo n.º 4
0
//! [node]
vx_node vxXYZNode(vx_graph graph, vx_image input, vx_uint32 value, vx_image output, vx_array temp)
{
    vx_uint32 i;
    vx_node node = 0;
    vx_context context = vxGetContext((vx_reference)graph);
    vx_status status = vxLoadKernels(context, "xyz");
    if (status == VX_SUCCESS)
    {
        //! [xyz node]
        vx_kernel kernel = vxGetKernelByName(context, VX_KERNEL_NAME_KHR_XYZ);
        if (kernel)
        {
            node = vxCreateGenericNode(graph, kernel);
            if (vxGetStatus((vx_reference)node) == VX_SUCCESS)
            {
                vx_status statuses[4];
                vx_scalar scalar = vxCreateScalar(context, VX_TYPE_INT32, &value);
                statuses[0] = vxSetParameterByIndex(node, 0, (vx_reference)input);
                statuses[1] = vxSetParameterByIndex(node, 1, (vx_reference)scalar);
                statuses[2] = vxSetParameterByIndex(node, 2, (vx_reference)output);
                statuses[3] = vxSetParameterByIndex(node, 3, (vx_reference)temp);
                vxReleaseScalar(&scalar);
                for (i = 0; i < dimof(statuses); i++)
                {
                    if (statuses[i] != VX_SUCCESS)
                    {
                        status = VX_ERROR_INVALID_PARAMETERS;
                        vxReleaseNode(&node);
                        vxReleaseKernel(&kernel);
                        node = 0;
                        kernel = 0;
                        break;
                    }
                }
            }
            else
            {
                vxReleaseKernel(&kernel);
            }
        }
        else
        {
            vxUnloadKernels(context, "xyz");
        }
        //! [xyz node]
    }
    return node;
}
Exemplo n.º 5
0
////////
// The node creation interface for the "app.userkernels.tensor_cos" kernel.
// This user kernel example expects parameters in the following order:
//   parameter #0  --  input tensor  of format VX_TYPE_INT16
//   parameter #1  --  output tensor of format VX_TYPE_INT16
//
// TODO STEP 01:********
//   1. Use vxGetKernelByEnum API to get a kernel object from USER_KERNEL_TENSOR_COS.
//      Note that you need to use vxGetContext API to get the context from a graph object.
//   2. Use vxCreateGenericNode API to create a node from the kernel object.
//   3. Use vxSetParameterByIndex API to set node arguments.
//   4. Release the kernel object that are not needed any more.
//   5. Use ERROR_CHECK_OBJECT and ERROR_CHECK_STATUS macros for error detection.
vx_node userTensorCosNode( vx_graph graph,
                           vx_tensor input,
                           vx_tensor output )
{
    vx_context context = vxGetContext( ( vx_reference ) graph );
    vx_kernel kernel   = vxGetKernelByEnum( context, USER_KERNEL_TENSOR_COS );
    ERROR_CHECK_OBJECT( kernel );
    vx_node node       = vxCreateGenericNode( graph, kernel );
    ERROR_CHECK_OBJECT( node );

//    ERROR_CHECK_STATUS( vxSetParameterByIndex( node, 0, ( vx_reference ) /* Fill in parameter */ ) );
//    ERROR_CHECK_STATUS( vxSetParameterByIndex( node, 1, ( vx_reference ) /* Fill in parameter */ ) );

    ERROR_CHECK_STATUS( vxReleaseKernel( &kernel ) );

    return node;
}
Exemplo n.º 6
0
vx_node vxCreateNodeByStructure(vx_graph graph,
                                vx_enum kernelenum,
                                vx_reference params[],
                                vx_uint32 num)
{
    vx_status status = VX_SUCCESS;
    vx_node node = 0;
    vx_context context = vxGetContext((vx_reference)graph);
    vx_kernel kernel = vxGetKernelByEnum(context, kernelenum);
    if (kernel)
    {
        node = vxCreateGenericNode(graph, kernel);
        if (node)
        {
            vx_uint32 p = 0;
            for (p = 0; p < num; p++)
            {
                status = vxSetParameterByIndex(node,
                                               p,
                                               params[p]);
                if (status != VX_SUCCESS)
                {
                    vxAddLogEntry((vx_reference)graph, status, "Kernel %d Parameter %u is invalid.\n", kernelenum, p);
                    vxReleaseNode(&node);
                    node = 0;
                    break;
                }
            }
        }
        else
        {
            vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_PARAMETERS, "Failed to create node with kernel enum %d\n", kernelenum);
            status = VX_ERROR_NO_MEMORY;
        }
        vxReleaseKernel(&kernel);
    }
    else
    {
        vxAddLogEntry((vx_reference)graph, VX_ERROR_INVALID_PARAMETERS, "failed to retrieve kernel enum %d\n", kernelenum);
        status = VX_ERROR_NOT_SUPPORTED;
    }
    return node;
}
Exemplo n.º 7
0
static VALUE Node_init(int argc, VALUE *args, VALUE self)
{
    vx_graph graph = 0;
    vx_kernel kernel = 0;
    Check_Type(self, T_DATA);

    if (argc <= 1)
        rb_raise(rb_eArgError, "Not enough arguments");

    graph = (vx_graph)DATA_PTR(args[0]);

    if (argc == 2) // Kernel
    {
        Check_Type(args[1], T_DATA);
        kernel = (vx_kernel)DATA_PTR(args[1]);
        DATA_PTR(self) = (void *)vxCreateGenericNode(graph, kernel);
    }
    else if (argc == 3) // graph, [string|enum], array of hashes
    {
        vx_node node = 0;
        VALUE kern = args[1];
        VALUE array = args[2];
        long param = 0;

        if (TYPE(kern) == T_STRING)
            kernel = vxGetKernelByName(context, RSTRING_PTR(kern));
        else if (TYPE(kern) == T_FIXNUM)
            kernel = vxGetKernelByEnum(context, FIX2INT(kern));
        else if (TYPE(kern) == T_DATA) // a OpenVX::Kernel
            kernel = (vx_kernel)DATA_PTR(kern);
        else
            rb_raise(rb_eTypeError, "kernel must be a string, fixnum, or OpenVX::Kernel");

        if (kernel == 0)
            rb_raise(rb_eNameError, "kernel could not be found in OpenVX");

        Check_Type(array, T_ARRAY);

        node = vxCreateGenericNode(graph, kernel);
        if (node == 0)
            rb_raise(rb_eTypeError, "node could not be created!");

        REXT_PRINT("Array of parameters has len = %ld\n", RARRAY_LEN(array));
        for (param = 0; param < RARRAY_LEN(array) ; param++)
        {
            VALUE ref,hash;
            vx_reference ref2 = 0;
            vx_status status = 0;
            const char *name = NULL;

            hash = rb_ary_entry(array, param);
            Check_Type(hash, T_HASH);
            ref = rb_hash_aref(hash, ID2SYM(rb_intern("ref")));
            name = rb_obj_classname(ref);
            REXT_PRINT("ref class = %s\n", name);
            Check_Type(ref, T_DATA);
            ref2 = (vx_reference)DATA_PTR(ref);
            status = vxSetParameterByIndex(node, param, ref2);
            REXT_PRINT("status = %d\n", status);

        }
        DATA_PTR(self) = (void *)node;
    }
    else
    {
        rb_raise(rb_eArgError, "incorrect number of arguments");
    }
    return Qnil;
}