TIOVX User Guide
node_code.py
1 #
2 # Copyright (c) 2017 Texas Instruments Incorporated
3 #
4 # All rights reserved not granted herein.
5 #
6 # Limited License.
7 #
8 # Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
9 # license under copyrights and patents it now or hereafter owns or controls to make,
10 # have made, use, import, offer to sell and sell ("Utilize") this software subject to the
11 # terms herein. With respect to the foregoing patent license, such license is granted
12 # solely to the extent that any such patent is necessary to Utilize the software alone.
13 # The patent license shall not apply to any combinations which include this software,
14 # other than combinations with devices manufactured by or for TI ("TI Devices").
15 # No hardware patent is licensed hereunder.
16 #
17 # Redistributions must preserve existing copyright notices and reproduce this license
18 # (including the above copyright notice and the disclaimer and (if applicable) source
19 # code license limitations below) in the documentation and/or other materials provided
20 # with the distribution
21 #
22 # Redistribution and use in binary form, without modification, are permitted provided
23 # that the following conditions are met:
24 #
25 # No reverse engineering, decompilation, or disassembly of this software is
26 # permitted with respect to any software provided in binary form.
27 #
28 # any redistribution and use are licensed by TI for use only with TI Devices.
29 #
30 # Nothing shall obligate TI to provide you with source code for the software
31 # licensed and provided to you in object code.
32 #
33 # If software source code is provided to you, modification and redistribution of the
34 # source code are permitted provided that the following conditions are met:
35 #
36 # any redistribution and use of the source code, including any resulting derivative
37 # works, are licensed by TI for use only with TI Devices.
38 #
39 # any redistribution and use of any object code compiled from the source code
40 # and any resulting derivative works, are licensed by TI for use only with TI Devices.
41 #
42 # Neither the name of Texas Instruments Incorporated nor the names of its suppliers
43 #
44 # may be used to endorse or promote products derived from this software without
45 # specific prior written permission.
46 #
47 # DISCLAIMER.
48 #
49 # THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS
50 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 # IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
56 # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
57 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
58 # OF THE POSSIBILITY OF SUCH DAMAGE.
59 #
60 #
61 
62 from . import *
63 
64 class NodeCode (ReferenceCode) :
65  def __init__(self, ref) :
66  ReferenceCode.__init__(self, ref)
67 
68  def declare_var(self, code_gen) :
69  code_gen.write_line('vx_node %s;' % self.ref.name)
70 
71  def define_create(self, code_gen) :
72  code_gen.write_line("static vx_node usecase_node_create_%s (" % self.ref.name)
73  num_params = len(self.ref.ref)
74 
75  end_char = ","
76  if num_params == 0 :
77  end_char = ""
78  code_gen.write_line(" vx_graph graph %s" % (end_char))
79 
80  i=0
81  for ref in self.ref.ref :
82  end_char = ","
83  if i == (num_params-1) :
84  end_char = ""
85  if ref.type != Type.NULL :
86  if ((i == (num_params-2)) and (self.ref.ref[num_params-1].type == Type.NULL)) or \
87  ((i == (num_params-3)) and (self.ref.ref[num_params-2].type == Type.NULL) and \
88  (self.ref.ref[num_params-1].type == Type.NULL)):
89  end_char = ""
90 
91  code_gen.write_line(" %s %s_%d %s" % (Type.get_vx_name(ref.type), ref.type.name.lower(), i, end_char))
92  i = i+1
93  code_gen.write_line(" )")
94 
95  code_gen.write_open_brace()
96  code_gen.write_line("vx_node node = NULL;")
97  code_gen.write_line("vx_reference params[] =")
98  code_gen.write_open_brace()
99  i=0
100  for ref in self.ref.ref :
101  end_char = ","
102  if i == (num_params-1) :
103  end_char = ""
104  if ref.type != Type.NULL :
105  code_gen.write_line(" (vx_reference)%s_%d %s" % (ref.type.name.lower(), i, end_char))
106  else :
107  code_gen.write_line(" NULL %s" % (end_char))
108  i = i+1
109  code_gen.write_close_brace(";")
110 
111  code_gen.write_open_brace()
112  code_gen.write_line("vx_kernel kernel = vxGetKernelByName(vxGetContext((vx_reference)graph), \"%s\");" % self.ref.kernel)
113  code_gen.write_newline()
114  code_gen.write_line("if (vxGetStatus((vx_reference)kernel)==VX_SUCCESS)");
115  code_gen.write_open_brace();
116  code_gen.write_line("node = tivxCreateNodeByKernelRef(graph, kernel, params, %d);" % (num_params))
117  code_gen.write_close_brace()
118  code_gen.write_line("vxReleaseKernel(&kernel);")
119  code_gen.write_close_brace()
120  code_gen.write_newline()
121  code_gen.write_line("return node;")
122  code_gen.write_close_brace()
123  code_gen.write_newline()
124 
125  def call_create(self, code_gen) :
126  num_params = len(self.ref.ref)
127 
128  code_gen.write_if_status();
129  code_gen.write_open_brace();
130  code_gen.write_line("usecase->%s = usecase_node_create_%s (" % (self.ref.name, self.ref.name))
131  end_char = ","
132  if num_params == 0 :
133  end_char = ""
134  code_gen.write_line(" graph %s" % (end_char))
135  i=0
136  for ref in self.ref.ref :
137  end_char = ","
138  if i == (num_params-1) :
139  end_char = ""
140  if ((i == (num_params-2)) and (self.ref.ref[num_params-1].type == Type.NULL)) or \
141  ((i == (num_params-3)) and (self.ref.ref[num_params-2].type == Type.NULL) and \
142  (self.ref.ref[num_params-1].type == Type.NULL)):
143  end_char = ""
144  if ref.type != Type.NULL :
145  code_gen.write_line(" usecase->%s %s" % (ref.name, end_char))
146  i = i+1
147  code_gen.write_line(" );")
148  self.set_ref_name(code_gen)
149  code_gen.write_if_status();
150  code_gen.write_open_brace();
151  code_gen.write_line("status = vxSetNodeTarget(usecase->%s, VX_TARGET_STRING, %s);" % (self.ref.name, Target.get_vx_enum_name(self.ref.target)))
152  code_gen.write_close_brace();
153  code_gen.write_close_brace();
154 
155  def call_delete(self, code_gen) :
156  num_params = len(self.ref.ref)
157 
158  code_gen.write_if_status();
159  code_gen.write_open_brace();
160  code_gen.write_line("status = vxReleaseNode( &usecase->%s );" % (self.ref.name))
161  code_gen.write_close_brace();
def __init__(self, image_in1, matrix_in2, interp3, image_out4, name="default", target=Target.DEFAULT)
Constructor used to create this object.
Definition: node.py:1718