202 def __init__(self, module="ext1", core="c66", env_var='VISION_APPS_PATH', include_subpath="TI", include_filename="") :
205 if type(module)
is Module :
206 self.
module = module.value
208 print(
"WARNING: module argument should use the Module class to avoid potential name clashes")
209 self.
module = module.lower()
210 if include_filename :
214 if type(core)
is Core :
215 self.
core = core.value
216 elif type(core)
is str :
217 print(
"WARNING: core argument should use the Core class to avoid potential name clashes")
220 sys.exit(
"core argument has invalid type.")
225 if module == Module.TEST_KERNELS:
226 self.
idirs_path =
"$(HOST_ROOT)/conformance_tests/kernels" 231 print(
"ERROR: You must define %s environment variable as the root of the kernel workarea." % self.
env_var);
232 sys.exit(
"Try typing “export CUSTOM_APPLICATION_PATH=<path to where you want the output kernels generated>” in your terminal window and try again.");
234 if self.
env_var ==
'CUSTOM_KERNEL_PATH':
239 def getDataColor(self, ref) :
242 def outputData(self, data) :
243 self.
file.write(
' %s [color=%s, style=filled]\n' % (data.name_lower, self.
getDataColor(data)))
245 def outputDataList(self, kernel) :
246 self.
file.write(
'\n')
247 self.
file.write(
' /* DATA OBJECTS */\n')
248 for ref
in kernel.params :
250 self.
file.write(
'\n')
252 def getTargetColor(self, target) :
253 if target == Target.DSP1 :
255 if target == Target.DSP2 :
256 return "darkturquoise" 257 if target == Target.EVE1 :
259 if target == Target.EVE2 :
261 if target == Target.EVE3 :
263 if target == Target.EVE4 :
265 if target == Target.A15_0 :
267 if target == Target.MCU2_0 :
269 if target == Target.MCU2_1 :
271 if target == Target.IPU2 :
272 return "MediumOrchid" 275 def outputNode(self, kernel) :
277 self.
file.write(
' %s [label=\"%s\", color=%s, style=filled]\n' % (kernel.name_lower, kernel.name_lower, self.
getTargetColor(kernel.targets[0])) )
279 self.
file.write(
' %s [label=\"%s\", color=%s, style=filled]\n' % (kernel.name_lower, kernel.name_lower, self.
getTargetColor(
"white")) )
281 def outputNodeList(self, kernel) :
282 self.
file.write(
'\n')
283 self.
file.write(
' /* NODE OBJECTS */\n')
285 self.
file.write(
'\n')
287 def outputNodeConnection(self, kernel) :
289 for prm
in kernel.params :
290 if prm.direction == Direction.INPUT :
291 self.
file.write(
' %s -> %s [taillabel=%d, labeldistance=3]\n' % (prm.name_lower, kernel.name_lower, idx))
293 self.
file.write(
' %s -> %s [headlabel=%d, labeldistance=3]\n' % (kernel.name_lower, prm.name_lower, idx))
296 def outputNodeConnectionList(self, kernel) :
297 self.
file.write(
'\n')
298 self.
file.write(
' /* NODE CONNECTIONS */\n')
300 self.
file.write(
'\n')
305 print (
'Generating image from OpenVX kernel ...')
307 self.
filename = kernel.name_lower +
"_img.txt" 312 self.
file.write(
'digraph %s {\n' % kernel.name_lower)
313 self.
file.write(
'\n')
314 self.
file.write(
' label = \"%s\"\n' % kernel.name_lower)
318 self.
file.write(
'\n')
319 self.
file.write(
'}\n')
325 print(
'Executing dot tool command ... [' + command_str +
']')
326 subprocess.call(command_args)
327 print (
'Generating image from OpenVX context ... DONE !!!')
328 except FileNotFoundError:
329 print(
'ERROR: \'dot\' tool not found. Make sure \'graphviz\' is installed and \'dot\' command is added to system PATH !!!')
330 print(
'ERROR: Cannot generate .jpg file !!!')
333 def setCompanyDirectory(self, company) :
336 def setTopHeaderName(self, header) :
339 def setModuleDirectory(self, module) :
340 if type(module)
is Module :
341 self.
module = module.value
342 elif type(core)
is str :
346 def setCoreDirectory(self, core) :
347 if type(core)
is Core :
348 self.
core = core.value
349 elif type(core)
is str :
352 sys.exit(
"core argument has invalid type.")
354 def create_all_directories(self):
357 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
367 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
374 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
394 def create_directory(self, directory):
400 def generate_h_file_code(self):
403 self.
h_code.write_ifndef_define(
"_" + self.
kernel.enum_str_prefix + self.
kernel.name_upper +
"_")
404 self.
h_code.write_extern_c_top()
405 self.
h_code.write_newline();
406 for prm
in self.
kernel.params :
407 self.
h_code.write_line(
"#define %s%s_%s_IDX (%dU)" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper, prm.index))
408 self.
h_code.write_newline();
409 self.
h_code.write_line(
"#define %s%s_MAX_PARAMS (%dU)" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper, len(self.
kernel.params)))
410 self.
h_code.write_newline();
411 self.
h_code.write_extern_c_bottom()
412 self.
h_code.write_newline()
413 self.
h_code.write_endif(
"_" + self.
kernel.enum_str_prefix + self.
kernel.name_upper +
"_")
416 def generate_host_c_add_func_code(self):
417 self.
host_c_code.write_line(
"vx_status tivxAddKernel%s(vx_context context)" % (self.
kernel.name_camel))
424 self.
host_c_code.write_line(
"status = vxAllocateUserKernelId(context, &kernel_id);")
425 self.
host_c_code.write_line(
"if(status != (vx_status)VX_SUCCESS)")
427 self.
host_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"Unable to allocate user kernel ID\\n\");")
432 self.
host_c_code.write_line(
"kernel = vxAddUserKernel(");
438 self.
host_c_code.write_line(
" tivxAddKernel%sValidate," % (self.
kernel.name_camel) )
439 self.
host_c_code.write_line(
" tivxAddKernel%sInitialize," % (self.
kernel.name_camel) )
442 self.
host_c_code.write_line(
"status = vxGetStatus((vx_reference)kernel);")
448 for prm
in self.
kernel.params :
449 if prm != self.
kernel.params[0] :
452 self.
host_c_code.write_line(
"status = vxAddParameterToKernel(kernel,")
454 self.
host_c_code.write_line(
" (vx_enum)%s," % (Direction.get_vx_enum_name(prm.direction)) )
455 if Type.is_scalar_type(prm.type) :
456 self.
host_c_code.write_line(
" (vx_enum)VX_TYPE_SCALAR,")
458 self.
host_c_code.write_line(
" (vx_enum)%s," % (Type.get_vx_enum_name(prm.type)) )
459 self.
host_c_code.write_line(
" (vx_enum)%s" % (ParamState.get_vx_enum_name(prm.state)) )
466 self.
host_c_code.write_comment_line(
"add supported target's")
467 for target
in self.
kernel.targets :
468 self.
host_c_code.write_line(
"tivxAddKernelTarget(kernel, %s);" % (Target.get_vx_enum_name(target)))
473 self.
host_c_code.write_line(
"status = vxFinalizeKernel(kernel);")
476 self.
host_c_code.write_line(
"if (status != (vx_status)VX_SUCCESS)")
478 self.
host_c_code.write_line(
"vxReleaseKernel(&kernel);")
493 def generate_host_c_remove_func_code(self):
494 self.
host_c_code.write_line(
"vx_status tivxRemoveKernel%s(vx_context context)" % (self.
kernel.name_camel))
497 self.
host_c_code.write_line(
"vx_kernel kernel = vx_%s_kernel;" % self.
kernel.name_lower)
499 self.
host_c_code.write_line(
"status = vxRemoveKernel(kernel);")
506 def verify_parameter_relationship_items(self, relationship_list, prm, attribute, name) :
507 for rel
in relationship_list :
508 if prm
in rel.prm_list :
509 if attribute
in rel.attribute_list :
512 for local_name
in rel.attribute_list :
513 if local_name.name == name :
515 if attribute == ImageAttribute.FORMAT :
517 elif attribute == UserDataObjectAttribute.NAME :
519 elif attribute == UserDataObjectAttribute.SIZE :
521 elif attribute == ArrayAttribute.ITEMSIZE :
523 elif attribute == ArrayAttribute.ITEMTYPE :
525 elif attribute == PyramidAttribute.FORMAT :
527 elif attribute == MatrixAttribute.TYPE :
529 elif attribute == LutAttribute.TYPE :
534 def convert_string_to_array_type(self, print_type):
535 if print_type.startswith(
'VX_TYPE_') :
536 string_length = len(print_type)
537 substring = print_type[8:string_length]
539 if t.name == substring :
544 def check_array_type(self, print_type):
546 return Type.is_array_type(array_type)
548 def generate_host_c_validate_func_code(self):
549 self.
host_c_code.write_line(
"static vx_status VX_CALLBACK tivxAddKernel%sValidate(vx_node node," % self.
kernel.name_camel)
550 self.
host_c_code.write_line(
" const vx_reference parameters[ ],")
552 self.
host_c_code.write_line(
" vx_meta_format metas[])")
556 self.
host_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
558 for prm
in self.
kernel.params :
561 attr = Attribute.from_type(prm.type)
562 if Type.is_scalar_type(prm.type) :
563 self.
host_c_code.write_line(
"vx_scalar %s = NULL;" % prm.name_lower)
564 self.
host_c_code.write_line(
"vx_enum %s_scalar_type;" % (prm.name_lower))
566 self.
host_c_code.write_line(
"%s %s = NULL;" % (Type.get_vx_name(prm.type), prm.name_lower))
567 for name, member
in attr.__members__.items() :
569 if member == UserDataObjectAttribute.NAME :
570 self.
host_c_code.write_line(
"%s %s_%s[VX_MAX_REFERENCE_NAME];" % (member.value[1], prm.name_lower, member.value[0]))
572 self.
host_c_code.write_line(
"%s %s_%s;" % (member.value[1], prm.name_lower, member.value[0]))
576 self.
host_c_code.write_line(
"if ( (num != %s%s_MAX_PARAMS)" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper) )
577 for prm
in self.
kernel.params :
578 if prm.state
is ParamState.REQUIRED :
579 self.
host_c_code.write_line(
" || (NULL == parameters[%s%s_%s_IDX])" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper))
582 self.
host_c_code.write_line(
"status = (vx_status)VX_ERROR_INVALID_PARAMETERS;")
583 self.
host_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"One or more REQUIRED parameters are set to NULL\\n\");")
588 self.
host_c_code.write_line(
"if ((vx_status)VX_SUCCESS == status)")
592 for prm
in self.
kernel.params :
593 if Type.is_scalar_type(prm.type) :
594 self.
host_c_code.write_line(
"%s = (%s)parameters[%s%s_%s_IDX];" %
595 (prm.name_lower, Type.get_vx_name(Type.SCALAR), self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper) )
597 self.
host_c_code.write_line(
"%s = (%s)parameters[%s%s_%s_IDX];" %
598 (prm.name_lower, Type.get_vx_name(prm.type), self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper) )
603 self.
host_c_code.write_line(
"/* PARAMETER ATTRIBUTE FETCH */")
610 self.
host_c_code.write_line(
"if ((vx_status)VX_SUCCESS == status)")
612 for prm
in self.
kernel.params :
613 if prm.state
is ParamState.OPTIONAL :
614 self.
host_c_code.write_line(
"if (NULL != %s)" % prm.name_lower)
617 attr = Attribute.from_type(prm.type)
618 if Type.is_scalar_type(prm.type) :
619 self.
host_c_code.write_line(
"tivxCheckStatus(&status, vxQueryScalar(%s, (vx_enum)VX_SCALAR_TYPE, &%s_scalar_type, sizeof(%s_scalar_type)));" % (prm.name_lower, prm.name_lower, prm.name_lower))
621 for name, member
in attr.__members__.items() :
623 if prm.type == Type.RAW_IMAGE :
624 self.
host_c_code.write_line(
"tivxCheckStatus(&status, tivxQuery%s(%s, (vx_enum)TIVX_%s_%s, &%s_%s, sizeof(%s_%s)));" % (toCamelCase(prm.type.name), prm.name_lower, prm.type.name, name, prm.name_lower, member.value[0], prm.name_lower, member.value[0]))
625 elif prm.type == Type.LUT:
626 self.
host_c_code.write_line(
"tivxCheckStatus(&status, vxQueryLUT(%s, (vx_enum)VX_%s_%s, &%s_%s, sizeof(%s_%s)));" % (prm.name_lower, prm.type.name, name, prm.name_lower, member.value[0], prm.name_lower, member.value[0]))
628 self.
host_c_code.write_line(
"tivxCheckStatus(&status, vxQuery%s(%s, (vx_enum)VX_%s_%s, &%s_%s, sizeof(%s_%s)));" % (toCamelCase(prm.type.name), prm.name_lower, prm.type.name, name, prm.name_lower, member.value[0], prm.name_lower, member.value[0]))
630 if prm.state
is ParamState.OPTIONAL :
632 if prm
is not self.
kernel.params[-1] :
637 self.
host_c_code.write_line(
"/* PARAMETER CHECKING */")
641 self.
host_c_code.write_line(
"if ((vx_status)VX_SUCCESS == status)")
643 for prm
in self.
kernel.params :
644 if Type.IMAGE == prm.type
or Type.PYRAMID == prm.type
or Type.ARRAY == prm.type
or Type.MATRIX == prm.type
or Type.LUT == prm.type
or Type.USER_DATA_OBJECT == prm.type
or Type.is_scalar_type(prm.type)
is True :
645 if prm.state
is ParamState.OPTIONAL :
646 self.
host_c_code.write_line(
"if (NULL != %s)" % (prm.name_lower))
648 if len(prm.data_types) == 0 :
649 self.
host_c_code.write_comment_line(
"< DEVELOPER_TODO: Replace <Add type here> with correct data type >")
653 if Type.IMAGE == prm.type :
654 if len(prm.data_types) > 1 :
657 self.
host_c_code.write_line(
" ((vx_df_image)%s != %s_fmt) &&" % (dt, prm.name_lower))
661 elif Type.PYRAMID == prm.type :
662 if len(prm.data_types) > 1 :
665 self.
host_c_code.write_line(
" ((vx_df_image)%s != %s_fmt) &&" % (dt, prm.name_lower))
669 elif Type.ARRAY == prm.type :
670 if len(prm.data_types) > 1 :
677 self.
host_c_code.write_line(
" (%s_item_type != %s) &&" % (prm.name_lower, dt))
679 self.
host_c_code.write_line(
" (%s_item_size != sizeof(%s)) &&" % (prm.name_lower, dt))
689 elif Type.MATRIX == prm.type
or Type.LUT == prm.type:
690 if len(prm.data_types) > 1 :
693 self.
host_c_code.write_line(
" ((vx_enum)%s != %s_type) &&" % (dt, prm.name_lower))
697 elif Type.is_scalar_type(prm.type) :
698 if len(prm.data_types) > 1 :
701 self.
host_c_code.write_line(
" ((vx_enum)%s != %s_scalar_type) &&" % (dt, prm.name_lower))
705 elif Type.USER_DATA_OBJECT == prm.type :
706 if len(prm.data_types) > 1 :
708 self.
host_c_code.write_line(
" (strncmp(%s_name, \"%s\", sizeof(%s_name)) != 0)) &&" % (prm.name_lower, self.
print_data_type[0], prm.name_lower))
710 self.
host_c_code.write_line(
" ((%s_size != sizeof(%s)) ||" % (prm.name_lower, dt))
711 self.
host_c_code.write_line(
" (strncmp(%s_name, \"%s\", sizeof(%s_name)) != 0)) &&" % (prm.name_lower, dt, prm.name_lower))
713 self.
host_c_code.write_line(
" (strncmp(%s_name, \"%s\", sizeof(%s_name)) != 0)))" % (prm.name_lower, self.
print_data_type[-1], prm.name_lower))
716 self.
host_c_code.write_line(
" (strncmp(%s_name, \"%s\", sizeof(%s_name)) != 0))" % (prm.name_lower, self.
print_data_type[0], prm.name_lower))
719 self.
host_c_code.write_line(
"status = (vx_status)VX_ERROR_INVALID_PARAMETERS;")
720 vowel = [
"a",
"e",
"i",
"o"]
721 if Type.is_scalar_type(prm.type) :
722 self.
host_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"'%s' should be a scalar of type:\\n " % (prm.name_lower), new_line=
False)
725 if prm.type.name[0].lower()
in vowel :
727 self.
host_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"'%s' should be %s %s of type:\\n " % (prm.name_lower, article, prm.type.name.lower()), new_line=
False)
730 self.
host_c_code.write_line(
"or %s " % (dt), new_line=
False, indent=
False)
731 self.
host_c_code.write_line(
"\\n\");", indent=
False)
733 if prm.state
is ParamState.OPTIONAL :
735 if prm
is not self.
kernel.params[-1] :
740 if len(self.
kernel.relationship_list) :
742 self.
host_c_code.write_line(
"/* PARAMETER RELATIONSHIP CHECKING */")
744 self.
host_c_code.write_line(
"if ((vx_status)VX_SUCCESS == status)")
747 for rel
in self.
kernel.relationship_list :
748 if rel.state
is ParamState.OPTIONAL :
749 self.
host_c_code.write_line(
"if (NULL != %s)" % (rel.prm_list[0].name_lower))
751 for attr
in rel.attribute_list :
752 if attr.vx_enum_name() ==
"VX_MATRIX_ORIGIN":
753 self.
host_c_code.write_line(
"if( (%s_%s.x != %s_%s.x) ||" % (rel.prm_list[0].name_lower, attr.value[0], rel.prm_list[1].name_lower, attr.value[0]))
754 self.
host_c_code.write_line(
" (%s_%s.y != %s_%s.y) )" % (rel.prm_list[0].name_lower, attr.value[0], rel.prm_list[1].name_lower, attr.value[0]))
756 if len(rel.prm_list) > 2 :
757 self.
host_c_code.write_line(
"if( (%s_%s != %s_%s) ||" % (rel.prm_list[0].name_lower, attr.value[0], rel.prm_list[1].name_lower, attr.value[0]))
758 for prm
in rel.prm_list[2:-1] :
759 self.
host_c_code.write_line(
" (%s_%s != %s_%s) ||" % (rel.prm_list[0].name_lower, attr.value[0], prm.name_lower, attr.value[0]))
760 self.
host_c_code.write_line(
" (%s_%s != %s_%s))" % (rel.prm_list[0].name_lower, attr.value[0], rel.prm_list[-1].name_lower, attr.value[0]))
761 elif len(rel.prm_list) == 2 :
762 self.
host_c_code.write_line(
"if (%s_%s != %s_%s)" % (rel.prm_list[0].name_lower, attr.value[0], rel.prm_list[1].name_lower, attr.value[0]))
765 self.
host_c_code.write_line(
"status = (vx_status)VX_ERROR_INVALID_PARAMETERS;")
766 self.
host_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"Parameters '%s' and '%s' " % (rel.prm_list[0].name_lower, rel.prm_list[1].name_lower), new_line=
False)
767 for prm
in rel.prm_list[2:] :
768 self.
host_c_code.write_line(
"and '%s' " % (prm.name_lower), new_line=
False, indent=
False)
769 self.
host_c_code.write_line(
"should have the same value for %s\\n\");" % attr.vx_enum_name(), indent=
False)
771 if rel.state
is ParamState.OPTIONAL :
773 if rel
is not self.
kernel.relationship_list[-1] :
778 self.
host_c_code.write_line(
"/* CUSTOM PARAMETER CHECKING */")
780 self.
host_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Add any custom parameter type or range checking not")
781 self.
host_c_code.write_comment_line(
" covered by the code-generation script.) >")
784 self.
host_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) If intending to use a virtual data object, set metas using appropriate TI API.")
785 self.
host_c_code.write_comment_line(
" For a code example, please refer to the validate callback of the follow file:")
786 self.
host_c_code.write_comment_line(
" tiovx/kernels/openvx-core/host/vx_absdiff_host.c. For further information regarding metas,")
787 self.
host_c_code.write_comment_line(
" please refer to the OpenVX 1.1 spec p. 260, or search for vx_kernel_validate_f. >")
794 def generate_host_c_initialize_func_code(self):
795 self.
host_c_code.write_line(
"static vx_status VX_CALLBACK tivxAddKernel%sInitialize(vx_node node," % self.
kernel.name_camel)
796 self.
host_c_code.write_line(
" const vx_reference parameters[ ],")
797 self.
host_c_code.write_line(
" vx_uint32 num_params)")
799 self.
host_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
800 if self.
kernel.getNumImages() > 0 :
801 self.
host_c_code.write_line(
"tivxKernelValidRectParams prms;")
805 self.
host_c_code.write_line(
"if ( (num_params != %s%s_MAX_PARAMS)" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper) )
806 for prm
in self.
kernel.params :
807 if prm.state
is ParamState.REQUIRED :
808 self.
host_c_code.write_line(
" || (NULL == parameters[%s%s_%s_IDX])" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper))
811 self.
host_c_code.write_line(
"status = (vx_status)VX_ERROR_INVALID_PARAMETERS;")
812 self.
host_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"One or more REQUIRED parameters are set to NULL\\n\");")
819 for prm
in self.
kernel.params :
820 if Type.IMAGE == prm.type:
821 if Direction.INPUT == prm.direction:
822 self.
temp_buffer += (
" prms.in_img[%sU] = (vx_image)parameters[%s%s_%s_IDX];\n" %
823 (num_input_image, self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper) )
825 if Direction.OUTPUT == prm.direction:
826 self.
temp_buffer += (
" prms.out_img[%sU] = (vx_image)parameters[%s%s_%s_IDX];\n" %
827 (num_output_image, self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper) )
831 if num_input_image > 0
or num_output_image > 0 :
832 self.
host_c_code.write_line(
"if ((vx_status)VX_SUCCESS == status)")
834 self.
host_c_code.write_line(
"tivxKernelValidRectParams_init(&prms);")
837 self.
host_c_code.write_line(
"prms.num_input_images = %s;" % self.
kernel.getNumInputImages())
838 self.
host_c_code.write_line(
"prms.num_output_images = %s;" % self.
kernel.getNumOutputImages())
840 self.
host_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Set padding values based on valid region if border mode is")
841 self.
host_c_code.write_comment_line(
" set to VX_BORDER_UNDEFINED and remove the #if 0 and #endif lines.")
842 self.
host_c_code.write_comment_line(
" Else, remove this entire #if 0 ... #endif block >")
848 self.
host_c_code.write_line(
"prms.border_mode = VX_BORDER_UNDEFINED;")
851 self.
host_c_code.write_line(
"status = tivxKernelConfigValidRect(&prms);")
859 def generate_host_c_file_code(self):
866 self.
host_c_code.write_include(
"TI/tivx_target_kernel.h")
868 self.
host_c_code.write_line(
"static vx_kernel vx_%s_kernel = NULL;" % (self.
kernel.name_lower))
871 self.
host_c_code.write_line(
"static vx_status VX_CALLBACK tivxAddKernel%sValidate(vx_node node," % self.
kernel.name_camel)
872 self.
host_c_code.write_line(
" const vx_reference parameters[ ],")
874 self.
host_c_code.write_line(
" vx_meta_format metas[]);")
875 self.
host_c_code.write_line(
"static vx_status VX_CALLBACK tivxAddKernel%sInitialize(vx_node node," % self.
kernel.name_camel)
876 self.
host_c_code.write_line(
" const vx_reference parameters[ ],")
877 self.
host_c_code.write_line(
" vx_uint32 num_params);")
878 self.
host_c_code.write_line(
"vx_status tivxAddKernel%s(vx_context context);" % (self.
kernel.name_camel))
879 self.
host_c_code.write_line(
"vx_status tivxRemoveKernel%s(vx_context context);" % (self.
kernel.name_camel))
888 def generate_target_c_add_func_code(self):
889 self.
target_c_code.write_line(
"void tivxAddTargetKernel%s(void)" % self.
kernel.name_camel, files=0)
890 self.
target_c_code.write_line(
"void tivxAddTargetKernelBam%s(void)" % self.
kernel.name_camel, files=1)
892 self.
target_c_code.write_line(
"vx_status status = (vx_status)VX_FAILURE;")
893 self.
target_c_code.write_line(
"char target_name[TIVX_TARGET_MAX_NAME];")
896 self.
target_c_code.write_line(
"self_cpu = tivxGetSelfCpuId();")
898 for target
in self.
kernel.targets :
899 if type(target)
is Target :
900 cpu = Target.get_cpu(target)
901 self.
target_c_code.write_line(
"if ( self_cpu == (vx_enum)%s )" % Cpu.get_vx_enum_name(cpu) )
903 self.
target_c_code.write_line(
"strncpy(target_name, %s, TIVX_TARGET_MAX_NAME);" % Target.get_vx_enum_name(target))
904 self.
target_c_code.write_line(
"status = (vx_status)VX_SUCCESS;")
908 self.
target_c_code.write_line(
"status = (vx_status)VX_FAILURE;")
914 self.
target_c_code.write_line(
"vx_%s_target_kernel = tivxAddTargetKernelByName(" % self.
kernel.name_lower)
927 def generate_target_c_remove_func_code(self):
928 self.
target_c_code.write_line(
"void tivxRemoveTargetKernel%s(void)" % self.
kernel.name_camel, files=0)
929 self.
target_c_code.write_line(
"void tivxRemoveTargetKernelBam%s(void)" % self.
kernel.name_camel, files=1)
931 self.
target_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
933 self.
target_c_code.write_line(
"status = tivxRemoveTargetKernel(vx_%s_target_kernel);" % self.
kernel.name_lower)
942 def extract_local_mem_string_error_check(self, new_str, type, name):
945 if type != Type.ARRAY :
946 if "capacity" in new_str :
948 invalid_str =
"capacity" 949 elif "itemsize" in new_str :
951 invalid_str =
"itemsize" 952 elif "itemtype" in new_str :
954 invalid_str =
"itemtype" 955 if type != Type.ARRAY
and type != Type.OBJECT_ARRAY:
956 if "numitems" in new_str :
958 invalid_str =
"numitems" 959 if type != Type.IMAGE
and type != Type.REMAP:
960 if "width" in new_str :
962 invalid_str =
"width" 963 elif "height" in new_str :
965 invalid_str =
"height" 966 if type != Type.IMAGE :
967 if "stride_x" in new_str :
969 invalid_str =
"stride_x" 970 elif "stride_y" in new_str :
972 invalid_str =
"stride_y" 973 if type != Type.PYRAMID :
974 if "levels" in new_str :
976 invalid_str =
"levels" 977 if type != Type.MATRIX
and type != Type.CONVOLUTION:
978 if "rows" in new_str :
981 elif "columns" in new_str :
983 invalid_str =
"columns" 984 if type != Type.DISTRIBUTION :
985 if "dimensions" in new_str :
987 invalid_str =
"dimensions" 988 elif "range" in new_str :
990 invalid_str =
"range" 991 elif "bins" in new_str :
994 elif "win" in new_str :
997 if type != Type.DISTRIBUTION
and type != Type.LUT:
998 if "offset" in new_str :
1000 invalid_str =
"offset" 1001 if type != Type.LUT:
1002 if "count" in new_str :
1004 invalid_str =
"count" 1005 assert found ==
False,
"'%s' is in invalid string for parameter %s" % (invalid_str, name)
1008 def extract_local_mem_string(self, type, attribute, local):
1010 if type == Type.IMAGE :
1012 new_str = new_str.replace(
"width",
"%s_desc->imagepatch_addr[0].dim_x" % local.prm.name_lower)
1013 new_str = new_str.replace(
"height",
"%s_desc->imagepatch_addr[0].dim_y" % local.prm.name_lower)
1014 new_str = new_str.replace(
"stride_x",
"%s_desc->imagepatch_addr[0].stride_x" % local.prm.name_lower)
1015 new_str = new_str.replace(
"stride_y",
"%s_desc->imagepatch_addr[0].stride_y" % local.prm.name_lower)
1017 elif type == Type.ARRAY :
1019 new_str = new_str.replace(
"capacity",
"%s_desc->capacity" % local.prm.name_lower)
1020 new_str = new_str.replace(
"itemsize",
"%s_desc->item_size" % local.prm.name_lower)
1021 new_str = new_str.replace(
"itemtype",
"%s_desc->item_type" % local.prm.name_lower)
1022 new_str = new_str.replace(
"numitems",
"%s_desc->num_items" % local.prm.name_lower)
1024 elif type == Type.PYRAMID :
1027 new_str = new_str.replace(
"levels",
"%s_desc->num_levels" % local.prm.name_lower)
1029 elif type == Type.MATRIX :
1031 new_str = new_str.replace(
"rows",
"%s_desc->rows" % local.prm.name_lower)
1032 new_str = new_str.replace(
"columns",
"%s_desc->columns" % local.prm.name_lower)
1033 new_str = new_str.replace(
"size",
"%s_desc->mem_size" % local.prm.name_lower)
1035 elif type == Type.DISTRIBUTION :
1037 new_str = new_str.replace(
"dimensions",
"1")
1038 new_str = new_str.replace(
"offset",
"%s_desc->offset" % local.prm.name_lower)
1039 new_str = new_str.replace(
"range",
"%s_desc->range" % local.prm.name_lower)
1040 new_str = new_str.replace(
"bins",
"%s_desc->num_bins" % local.prm.name_lower)
1041 new_str = new_str.replace(
"window",
"%s_desc->num_win" % local.prm.name_lower)
1042 new_str = new_str.replace(
"size",
"%s_desc->mem_size" % local.prm.name_lower)
1044 elif type == Type.LUT :
1046 new_str = new_str.replace(
"count",
"%s_desc->num_items" % local.prm.name_lower)
1047 new_str = new_str.replace(
"size",
"%s_desc->mem_size" % local.prm.name_lower)
1049 elif type == Type.REMAP :
1051 new_str = new_str.replace(
"source_width",
"%s_desc->src_width" % local.prm.name_lower)
1052 new_str = new_str.replace(
"source_height",
"%s_desc->src_height" % local.prm.name_lower)
1053 new_str = new_str.replace(
"destination_width",
"%s_desc->dst_width" % local.prm.name_lower)
1054 new_str = new_str.replace(
"destination_height",
"%s_desc->dst_height" % local.prm.name_lower)
1056 elif type == Type.CONVOLUTION :
1058 new_str = new_str.replace(
"rows",
"%s_desc->rows" % local.prm.name_lower)
1059 new_str = new_str.replace(
"columns",
"%s_desc->columns" % local.prm.name_lower)
1060 new_str = new_str.replace(
"size",
"%s_desc->mem_size" % local.prm.name_lower)
1061 new_str = new_str.replace(
"scale",
"%s_desc->scale" % local.prm.name_lower)
1063 elif type == Type.OBJECT_ARRAY :
1065 new_str = new_str.replace(
"numitems",
"%s_desc->num_items" % local.prm.name_lower)
1069 def is_supported_type(self, type):
1070 if type == Type.IMAGE :
1072 elif type == Type.ARRAY :
1074 elif type == Type.PYRAMID :
1076 elif type == Type.MATRIX :
1078 elif type == Type.DISTRIBUTION :
1080 elif type == Type.REMAP :
1082 elif type == Type.CONVOLUTION :
1084 elif type == Type.LUT :
1086 elif type == Type.OBJECT_ARRAY :
1088 elif type == Type.NULL :
1094 def extract_attribute(self, local, is_first_prm):
1095 invalid_type =
False 1096 if not is_first_prm :
1097 self.
target_c_code.write_line(
"if ((vx_status)VX_SUCCESS == status)")
1099 if local.prm.type != Type.NULL :
1101 if ParamState.OPTIONAL == local.state :
1102 self.
target_c_code.write_line(
"if( %s_desc != NULL)" % local.prm.name_lower)
1104 if local.prm.type == Type.IMAGE :
1107 for num, attr
in enumerate(local.attribute_list, start=1):
1108 if type(attr)
is ImageAttribute :
1109 if Attribute.Image.WIDTH == attr :
1110 append_str = (
"%s_desc->imagepatch_addr[0].dim_x" % local.prm.name_lower)
1111 size_str+=append_str
1112 elif Attribute.Image.HEIGHT == attr :
1113 append_str = (
"%s_desc->imagepatch_addr[0].dim_y" % local.prm.name_lower)
1114 size_str+=append_str
1115 elif type(attr)
is int :
1116 append_str = (
"%s" % attr)
1117 size_str+=append_str
1118 elif type(attr)
is str :
1120 size_str+=append_str
1123 if num < len(local.attribute_list) :
1125 size_str+=append_str
1126 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1127 elif local.prm.type == Type.ARRAY :
1130 for num, attr
in enumerate(local.attribute_list, start=1):
1131 if type(attr)
is ArrayAttribute :
1132 if Attribute.Array.CAPACITY == attr :
1133 append_str = (
"%s_desc->capacity" % local.prm.name_lower)
1134 size_str+=append_str
1135 elif Attribute.Array.ITEMTYPE == attr :
1136 append_str = (
"%s_desc->item_type" % local.prm.name_lower)
1137 size_str+=append_str
1138 elif Attribute.Array.NUMITEMS == attr :
1139 append_str = (
"%s_desc->num_items" % local.prm.name_lower)
1140 size_str+=append_str
1141 elif Attribute.Array.ITEMSIZE == attr :
1142 append_str = (
"%s_desc->item_size" % local.prm.name_lower)
1143 size_str+=append_str
1144 elif type(attr)
is int :
1145 append_str = (
"%s" % attr)
1146 size_str+=append_str
1147 elif type(attr)
is str :
1149 size_str+=append_str
1152 if num < len(local.attribute_list) :
1154 size_str+=append_str
1155 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1156 elif local.prm.type == Type.PYRAMID :
1159 for num, attr
in enumerate(local.attribute_list, start=1):
1160 if type(attr)
is PyramidAttribute :
1161 if Attribute.Pyramid.LEVELS == attr :
1162 append_str = (
"%s_desc->num_levels" % local.prm.name_lower)
1163 size_str+=append_str
1164 elif type(attr)
is int :
1165 append_str = (
"%s" % attr)
1166 size_str+=append_str
1167 elif type(attr)
is str :
1169 size_str+=append_str
1172 if num < len(local.attribute_list) :
1174 size_str+=append_str
1175 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1176 elif local.prm.type == Type.MATRIX :
1179 for num, attr
in enumerate(local.attribute_list, start=1):
1180 if type(attr)
is MatrixAttribute :
1181 if Attribute.Matrix.ROWS == attr :
1182 append_str = (
"%s_desc->rows" % local.prm.name_lower)
1183 size_str+=append_str
1184 elif Attribute.Matrix.COLUMNS == attr :
1185 append_str = (
"%s_desc->columns" % local.prm.name_lower)
1186 size_str+=append_str
1187 elif Attribute.Matrix.SIZE == attr :
1188 append_str = (
"%s_desc->mem_size" % local.prm.name_lower)
1189 size_str+=append_str
1190 elif type(attr)
is int :
1191 append_str = (
"%s" % attr)
1192 size_str+=append_str
1193 elif type(attr)
is str :
1195 size_str+=append_str
1198 if num < len(local.attribute_list) :
1200 size_str+=append_str
1201 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1202 elif local.prm.type == Type.DISTRIBUTION :
1205 for num, attr
in enumerate(local.attribute_list, start=1):
1206 if type(attr)
is DistributionAttribute :
1207 if Attribute.Distribution.DIMENSIONS == attr :
1209 size_str+=append_str
1210 elif Attribute.Distribution.OFFSET == attr :
1211 append_str = (
"%s_desc->offset" % local.prm.name_lower)
1212 size_str+=append_str
1213 elif Attribute.Distribution.RANGE == attr :
1214 append_str = (
"%s_desc->range" % local.prm.name_lower)
1215 size_str+=append_str
1216 elif Attribute.Distribution.BINS == attr :
1217 append_str = (
"%s_desc->num_bins" % local.prm.name_lower)
1218 size_str+=append_str
1219 elif Attribute.Distribution.WINDOW == attr :
1220 append_str = (
"%s_desc->num_win" % local.prm.name_lower)
1221 size_str+=append_str
1222 elif Attribute.Distribution.SIZE == attr :
1223 append_str = (
"%s_desc->mem_size" % local.prm.name_lower)
1224 size_str+=append_str
1225 elif type(attr)
is int :
1226 append_str = (
"%s" % attr)
1227 size_str+=append_str
1228 elif type(attr)
is str :
1230 size_str+=append_str
1233 if num < len(local.attribute_list) :
1235 size_str+=append_str
1236 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1237 elif local.prm.type == Type.LUT :
1240 for num, attr
in enumerate(local.attribute_list, start=1):
1241 if type(attr)
is LutAttribute :
1242 if Attribute.Lut.COUNT == attr :
1243 append_str = (
"%s_desc->num_items" % local.prm.name_lower)
1244 size_str+=append_str
1245 elif Attribute.Lut.SIZE == attr :
1246 append_str = (
"%s_desc->mem_size" % local.prm.name_lower)
1247 size_str+=append_str
1248 elif type(attr)
is int :
1249 append_str = (
"%s" % attr)
1250 size_str+=append_str
1251 elif type(attr)
is str :
1253 size_str+=append_str
1256 if num < len(local.attribute_list) :
1258 size_str+=append_str
1259 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1260 elif local.prm.type == Type.REMAP :
1263 for num, attr
in enumerate(local.attribute_list, start=1):
1264 if type(attr)
is RemapAttribute :
1265 if Attribute.Remap.SOURCE_WIDTH == attr :
1266 append_str = (
"%s_desc->src_width" % local.prm.name_lower)
1267 size_str+=append_str
1268 elif Attribute.Remap.SOURCE_HEIGHT == attr :
1269 append_str = (
"%s_desc->src_height" % local.prm.name_lower)
1270 size_str+=append_str
1271 elif Attribute.Remap.DESTINATION_WIDTH == attr :
1272 append_str = (
"%s_desc->dst_width" % local.prm.name_lower)
1273 size_str+=append_str
1274 elif Attribute.Remap.DESTINATION_HEIGHT == attr :
1275 append_str = (
"%s_desc->dst_height" % local.prm.name_lower)
1276 size_str+=append_str
1277 elif type(attr)
is int :
1278 append_str = (
"%s" % attr)
1279 size_str+=append_str
1280 elif type(attr)
is str :
1282 size_str+=append_str
1285 if num < len(local.attribute_list) :
1287 size_str+=append_str
1288 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1289 elif local.prm.type == Type.OBJECT_ARRAY :
1292 for num, attr
in enumerate(local.attribute_list, start=1):
1293 if type(attr)
is ObjectArrayAttribute :
1294 if Attribute.ObjectArray.NUMITEMS == attr :
1295 append_str = (
"%s_desc->num_items" % local.prm.name_lower)
1296 size_str+=append_str
1297 elif type(attr)
is int :
1298 append_str = (
"%s" % attr)
1299 size_str+=append_str
1300 elif type(attr)
is str :
1302 size_str+=append_str
1305 if num < len(local.attribute_list) :
1307 size_str+=append_str
1308 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1309 elif local.prm.type == Type.CONVOLUTION :
1312 for num, attr
in enumerate(local.attribute_list, start=1):
1313 if type(attr)
is ConvolutionAttribute :
1314 if Attribute.Convolution.ROWS == attr :
1315 append_str = (
"%s_desc->rows" % local.prm.name_lower)
1316 size_str+=append_str
1317 elif Attribute.Convolution.COLUMNS == attr :
1318 append_str = (
"%s_desc->columns" % local.prm.name_lower)
1319 size_str+=append_str
1320 elif Attribute.Convolution.SCALE == attr :
1321 append_str = (
"%s_desc->scale" % local.prm.name_lower)
1322 size_str+=append_str
1323 elif Attribute.Convolution.SIZE == attr :
1324 append_str = (
"%s_desc->mem_size" % local.prm.name_lower)
1325 size_str+=append_str
1326 elif type(attr)
is int :
1327 append_str = (
"%s" % attr)
1328 size_str+=append_str
1329 elif type(attr)
is str :
1331 size_str+=append_str
1334 if num < len(local.attribute_list) :
1336 size_str+=append_str
1337 assert invalid_type ==
False,
"'%s' contains an invalid attribute" % (local.prm.name_lower)
1338 elif local.prm.type == Type.NULL :
1341 for num, attr
in enumerate(local.attribute_list, start=1):
1342 if type(attr)
is int :
1343 append_str = (
"%s" % attr)
1344 size_str+=append_str
1345 elif type(attr)
is str :
1347 size_str+=append_str
1348 if num < len(local.attribute_list) :
1350 size_str+=append_str
1352 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Verify correct amount of memory is allocated >")
1353 self.
target_c_code.write_line(
"prms->%s_size = %s;" % (local.name, size_str) )
1354 self.
target_c_code.write_line(
"prms->%s_ptr = tivxMemAlloc(prms->%s_size, (vx_enum)TIVX_MEM_EXTERNAL);" % (local.name, local.name) )
1356 self.
target_c_code.write_line(
"if (NULL == prms->%s_ptr)" % (local.name) )
1358 self.
target_c_code.write_line(
"status = (vx_status)VX_ERROR_NO_MEMORY;")
1359 self.
target_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"Unable to allocate local memory\\n\");")
1363 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Verify memory setting to clear the correct amount of memory >")
1364 self.
target_c_code.write_line(
"memset(prms->%s_ptr, 0, %s);" % (local.name, size_str) )
1366 if not is_first_prm :
1370 if local.prm.type != Type.NULL :
1372 if ParamState.OPTIONAL == local.state :
1375 def generate_target_c_create_func_code(self):
1376 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sCreate(" % self.
kernel.name_camel)
1377 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
1378 self.
target_c_code.write_line(
" tivx_obj_desc_t *obj_desc[],")
1379 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg)")
1381 self.
target_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
1382 contains_user_data_object =
False 1383 for prm
in self.
kernel.params :
1384 if Type.USER_DATA_OBJECT == prm.type :
1385 contains_user_data_object =
True 1388 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1394 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Add any target kernel create code here (e.g. allocating")
1395 self.
target_c_code.write_comment_line(
" local memory buffers, one time initialization, etc) >")
1396 if self.
prms_needed or contains_user_data_object :
1399 for prm
in self.
kernel.params :
1400 if prm.state
is ParamState.REQUIRED :
1412 for local
in self.
kernel.local_mem_list :
1413 if local.prm.type != Type.NULL :
1414 if not (local.prm.name_lower
in duplicates) :
1415 self.
target_c_code.write_line(
"%s *%s_desc;" % (Type.get_obj_desc_name(local.prm.type), local.prm.name_lower) , files=self.
prms_write)
1416 duplicates.append(local.prm.name_lower)
1417 for prm
in self.
kernel.params :
1418 if Type.USER_DATA_OBJECT == prm.type :
1419 if not (prm.name_lower
in duplicates) :
1420 self.
target_c_code.write_line(
"%s *%s_desc;" % (Type.get_obj_desc_name(prm.type), prm.name_lower) , files=self.
prms_write)
1421 duplicates.append(prm.name_lower)
1426 for local
in self.
kernel.local_mem_list :
1427 if local.prm.type != Type.NULL :
1428 if not (local.prm.name_lower
in duplicates) :
1429 self.
target_c_code.write_line(
"%s_desc = (%s *)obj_desc[%s%s_%s_IDX];" %
1430 (local.prm.name_lower, Type.get_obj_desc_name(local.prm.type), self.
kernel.enum_str_prefix, self.
kernel.name_upper, local.prm.name_upper) , files=self.
prms_write)
1431 duplicates.append(local.prm.name_lower)
1432 for prm
in self.
kernel.params :
1433 if Type.USER_DATA_OBJECT == prm.type :
1434 if not (prm.name_lower
in duplicates) :
1435 self.
target_c_code.write_line(
"%s_desc = (%s *)obj_desc[%s%s_%s_IDX];" %
1436 (prm.name_lower, Type.get_obj_desc_name(prm.type), self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper) , files=self.
prms_write)
1437 duplicates.append(prm.name_lower)
1440 if contains_user_data_object :
1441 for prm
in self.
kernel.params :
1442 if Type.USER_DATA_OBJECT == prm.type :
1443 if len(prm.data_types) == 0 :
1444 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Replace <Add type here> with correct data type >", files=self.
prms_write)
1450 self.
target_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"User data object size on target does not match the size on host, possibly due to misalignment in data structure\\n\");", files=self.
prms_write)
1457 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1459 self.
target_c_code.write_line(
"prms = tivxMemAlloc(sizeof(tivx%sParams), (vx_enum)TIVX_MEM_EXTERNAL);" % self.
kernel.name_camel, files=self.
prms_write)
1464 for local
in self.
kernel.local_mem_list :
1467 is_first_prm =
False 1474 self.
target_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"Unable to allocate local memory\\n\");", files=self.
prms_write)
1481 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Create BAM graph using graph_handle >", files=1)
1493 self.
target_c_code.write_line(
"VX_PRINT(VX_ZONE_ERROR, \"Unable to allocate local memory\\n\");", files=self.
prms_write)
1505 def generate_target_c_delete_func_code(self):
1506 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sDelete(" % self.
kernel.name_camel)
1507 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
1508 self.
target_c_code.write_line(
" tivx_obj_desc_t *obj_desc[],")
1509 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg)")
1511 self.
target_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
1514 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1521 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Add any target kernel delete code here (e.g. freeing")
1522 self.
target_c_code.write_comment_line(
" local memory buffers, etc) >")
1525 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1529 for prm
in self.
kernel.params :
1530 if prm.state
is ParamState.REQUIRED :
1539 self.
target_c_code.write_line(
"tivxGetTargetKernelInstanceContext(kernel, (void **)&prms, &size);", files=self.
prms_write)
1544 for local
in self.
kernel.local_mem_list :
1548 self.
target_c_code.write_line(
"tivxMemFree(prms->%s_ptr, prms->%s_size, (vx_enum)TIVX_MEM_EXTERNAL);" %
1549 (local.name, local.name) , files=self.
prms_write)
1553 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment once BAM graph has been created >", files=1)
1554 self.
target_c_code.write_comment_line(
"tivxBamDestroyHandle(prms->graph_handle);", files=1)
1565 def generate_target_c_control_func_code(self):
1566 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sControl(" % self.
kernel.name_camel)
1567 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
1568 self.
target_c_code.write_line(
" uint32_t node_cmd_id, tivx_obj_desc_t *obj_desc[],")
1569 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg)")
1571 self.
target_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
1573 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Add any target kernel control code here (e.g. commands")
1574 self.
target_c_code.write_comment_line(
" the user can call to modify the processing of the kernel at run-time) >")
1580 def generate_target_c_struct(self):
1583 for local
in self.
kernel.local_mem_list :
1587 self.
target_c_code.write_line(
" tivx_bam_graph_handle graph_handle;" , files=1)
1591 def generate_bam_pointers(self, kernel_params):
1593 for prm
in kernel_params :
1594 if prm.type == Type.IMAGE :
1595 self.
target_c_code.write_line(
"img_ptrs[%s] = %s_addr;" % (idx, prm.name_lower), files=1)
1597 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment once BAM graph has been created >", files=1)
1598 self.
target_c_code.write_comment_line(
"tivxBamUpdatePointers(prms->graph_handle, %sU, %sU, img_ptrs);" % (self.
kernel.getNumInputImages(), self.
kernel.getNumOutputImages()), files=1)
1601 def generate_optional_bam_pointers(self, num_scenarios) :
1602 first_scenario =
True 1604 binary_mask = num_scenarios
1605 for scenario
in range(num_scenarios) :
1608 num_included_optional_input = 0
1609 num_included_optional_output = 0
1611 if binary_mask & (2**idx) :
1612 included_str.append(prm.name_lower)
1613 if first_scenario ==
True and first_param ==
True:
1614 self.
target_c_code.write_line (
"if ( (%s_desc != NULL)" % prm.name_lower, files=1)
1615 first_scenario =
False 1617 elif first_param ==
True :
1618 self.
target_c_code.write_line (
"else if ( (%s_desc != NULL)" % prm.name_lower, files=1)
1619 first_scenario =
False 1622 self.
target_c_code.write_line (
" && (%s_desc != NULL)" % prm.name_lower, files=1)
1623 if prm.direction == Direction.INPUT :
1624 num_included_optional_input += 1
1625 elif prm.direction == Direction.OUTPUT :
1626 num_included_optional_output += 1
1630 for prm
in self.
kernel.params :
1631 if (prm.type == Type.IMAGE
and prm.state == ParamState.REQUIRED)
or \
1632 (prm.name_lower
in included_str):
1633 self.
target_c_code.write_line(
"img_ptrs[%s] = %s_addr;" % (idx, prm.name_lower), files=1)
1635 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment once BAM graph has been created >", files=1)
1636 self.
target_c_code.write_comment_line(
"tivxBamUpdatePointers(prms->graph_handle, %sU, %sU, img_ptrs);" % (self.
kernel.getNumRequiredInputImages()+num_included_optional_input, \
1637 self.
kernel.getNumRequiredOutputImages()+num_included_optional_output), files=1)
1644 for prm
in self.
kernel.params :
1645 if (prm.type == Type.IMAGE
and prm.state == ParamState.REQUIRED) :
1646 self.
target_c_code.write_line(
"img_ptrs[%s] = %s_addr;" % (idx, prm.name_lower), files=1)
1648 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment once BAM graph has been created >", files=1)
1649 self.
target_c_code.write_comment_line(
"tivxBamUpdatePointers(prms->graph_handle, %sU, %sU, img_ptrs);" % (self.
kernel.getNumRequiredInputImages(), \
1650 self.
kernel.getNumRequiredOutputImages()), files=1)
1654 def generate_optional_list(self, kernel_params) :
1656 for prm
in kernel_params :
1657 if prm.type == Type.IMAGE
and prm.state == ParamState.OPTIONAL :
1660 def generate_target_c_process_func_code(self):
1662 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sProcess(" % self.
kernel.name_camel)
1663 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
1664 self.
target_c_code.write_line(
" tivx_obj_desc_t *obj_desc[],")
1665 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg)")
1669 self.
target_c_code.write_line(
"vx_status status = (vx_status)VX_SUCCESS;")
1672 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1677 need_plane_idx_var =
False 1678 need_exposure_idx_var =
False 1679 need_pyramid_idx_var =
False 1680 printed_incrementer =
False 1681 for prm
in self.
kernel.params :
1682 if Type.IMAGE == prm.type
or Type.PYRAMID == prm.type:
1683 if len(prm.data_types) > 1 :
1684 for dt
in prm.data_types[0:-1] :
1685 if DfImage.get_num_planes(DfImage.get_df_enum_from_string(dt)) > 1 :
1686 need_plane_idx_var =
True 1688 if Type.PYRAMID == prm.type:
1689 need_pyramid_idx_var =
True 1690 if Type.RAW_IMAGE == prm.type :
1691 need_exposure_idx_var =
True 1692 self.
target_c_code.write_line(
"%s *%s_desc;" % (Type.get_obj_desc_name(prm.type), prm.name_lower) )
1693 if prm.type == Type.PYRAMID :
1694 self.
target_c_code.write_line(
"%s *img_%s_desc[TIVX_PYRAMID_MAX_LEVEL_OBJECTS];" % (Type.get_obj_desc_name(Type.IMAGE), prm.name_lower) )
1695 if printed_incrementer
is False :
1697 printed_incrementer =
True 1699 if prm.type == Type.OBJECT_ARRAY :
1700 self.
target_c_code.write_line(
"%s *img_%s_desc[TIVX_OBJECT_ARRAY_MAX_ITEMS];" % (Type.get_obj_desc_name(Type.IMAGE), prm.name_lower) )
1701 if printed_incrementer
is False :
1703 printed_incrementer =
True 1704 if need_plane_idx_var
is True :
1706 if need_exposure_idx_var
is True :
1708 if need_pyramid_idx_var
is True and printed_incrementer
is False :
1714 self.
target_c_code.write_line(
"if ( (num_params != %s%s_MAX_PARAMS)" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper) )
1715 for prm
in self.
kernel.params :
1716 if prm.state
is ParamState.REQUIRED :
1717 self.
target_c_code.write_line(
" || (NULL == obj_desc[%s%s_%s_IDX])" % (self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper))
1723 self.
target_c_code.write_line(
"status = (vx_status)VX_FAILURE;")
1727 self.
target_c_code.write_line(
"if((vx_status)VX_SUCCESS == status)")
1732 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1739 for prm
in self.
kernel.params :
1740 self.
target_c_code.write_line(
"%s_desc = (%s *)obj_desc[%s%s_%s_IDX];" %
1741 (prm.name_lower, Type.get_obj_desc_name(prm.type), self.
kernel.enum_str_prefix, self.
kernel.name_upper, prm.name_upper) )
1747 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
1751 self.
target_c_code.write_line(
"if (((vx_status)VX_SUCCESS != status) || (NULL == prms) ||", files=self.
prms_write)
1763 self.
target_c_code.write_line(
"if((vx_status)VX_SUCCESS == status)")
1767 for prm
in self.
kernel.params :
1768 if Type.is_scalar_type(prm.type)
is True :
1769 self.
target_c_code.write_line(
"%s %s_value;" % (Type.get_vx_name(prm.type), prm.name_lower ))
1773 for prm
in self.
kernel.params :
1774 if prm.type == Type.PYRAMID:
1775 self.
target_c_code.write_line(
"void *%s_target_ptr[TIVX_PYRAMID_MAX_LEVEL_OBJECTS] = {NULL};" % prm.name_lower )
1776 elif prm.type == Type.OBJECT_ARRAY :
1777 self.
target_c_code.write_line(
"void *%s_target_ptr[TIVX_OBJECT_ARRAY_MAX_ITEMS] = {NULL};" % prm.name_lower )
1778 elif prm.type == Type.RAW_IMAGE :
1779 self.
target_c_code.write_line(
"void *%s_target_ptr[TIVX_RAW_IMAGE_MAX_EXPOSURES] = {NULL};" % prm.name_lower )
1780 elif prm.type == Type.IMAGE :
1781 if len(prm.data_types) > 1 :
1782 for dt
in prm.data_types[0:-1] :
1783 if DfImage.get_num_planes(DfImage.get_df_enum_from_string(dt)) > 1 :
1784 self.
target_c_code.write_line(
"void *%s_target_ptr[TIVX_IMAGE_MAX_PLANES] = {NULL};" % prm.name_lower )
1786 self.
target_c_code.write_line(
"void *%s_target_ptr;" % prm.name_lower )
1788 self.
target_c_code.write_line(
"void *%s_target_ptr;" % prm.name_lower )
1790 self.
target_c_code.write_line(
"void *%s_target_ptr;" % prm.name_lower )
1794 for prm
in self.
kernel.params :
1795 desc = prm.name_lower +
"_desc" 1796 if Type.is_scalar_type(prm.type)
is False :
1797 if prm.state
is ParamState.OPTIONAL:
1800 if Type.IMAGE == prm.type
or Type.PYRAMID == prm.type
or Type.OBJECT_ARRAY == prm.type
or Type.RAW_IMAGE == prm.type:
1803 if len(prm.data_types) > 1 :
1804 for dt
in prm.data_types[0:-1] :
1805 if DfImage.get_num_planes(DfImage.get_df_enum_from_string(dt)) > 1 :
1808 if prm.type == Type.IMAGE :
1810 self.
target_c_code.write_line(
"for(plane_idx=0; plane_idx<%s->planes; plane_idx++)" % desc )
1812 self.
target_c_code.write_line(
"%s_target_ptr[plane_idx] = tivxMemShared2TargetPtr(&%s->mem_ptr[plane_idx]);" % (prm.name_lower, desc))
1814 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferMap(%s_target_ptr[plane_idx]," % prm.name_lower )
1815 self.
target_c_code.write_line(
" %s->mem_size[plane_idx], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1816 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1819 self.
target_c_code.write_line(
"%s_target_ptr = tivxMemShared2TargetPtr(&%s->mem_ptr[0]);" % (prm.name_lower, desc))
1821 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferMap(%s_target_ptr," % prm.name_lower )
1822 self.
target_c_code.write_line(
" %s->mem_size[0], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1823 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1824 elif prm.type == Type.RAW_IMAGE :
1825 self.
target_c_code.write_line(
"for(exposure_idx=0; exposure_idx<%s->params.num_exposures; exposure_idx++)" % desc )
1827 self.
target_c_code.write_line(
"%s_target_ptr[exposure_idx] = tivxMemShared2TargetPtr(&%s->mem_ptr[exposure_idx]);" % (prm.name_lower, desc))
1829 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferMap(%s_target_ptr[exposure_idx]," % prm.name_lower )
1830 self.
target_c_code.write_line(
" %s->mem_size[exposure_idx], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1831 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1833 elif prm.type == Type.PYRAMID
or prm.type == Type.OBJECT_ARRAY:
1834 if prm.type == Type.PYRAMID :
1835 self.
target_c_code.write_line(
"tivxGetObjDescList(%s->obj_desc_id, (tivx_obj_desc_t**)img_%s, %s->num_levels);" % (desc, desc, desc) )
1837 self.
target_c_code.write_line(
"tivxGetObjDescList(%s->obj_desc_id, (tivx_obj_desc_t**)img_%s, %s->num_items);" % (desc, desc, desc) )
1839 if prm.type == Type.PYRAMID :
1840 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_levels; i++)" % desc )
1842 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_items; i++)" % desc )
1844 self.
target_c_code.write_line(
"for(plane_idx=0; plane_idx<%s->planes; plane_idx++)" % desc )
1846 self.
target_c_code.write_line(
"%s_target_ptr[i] = tivxMemShared2TargetPtr(&img_%s[i]->mem_ptr[plane_idx]);" % (prm.name_lower, desc))
1848 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferMap(%s_target_ptr[i]," % prm.name_lower )
1849 self.
target_c_code.write_line(
" img_%s[i]->mem_size[plane_idx], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1850 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1854 if prm.type == Type.PYRAMID :
1855 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_levels; i++)" % desc )
1857 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_items; i++)" % desc )
1859 self.
target_c_code.write_line(
"%s_target_ptr[i] = tivxMemShared2TargetPtr(&img_%s[i]->mem_ptr[0]);" % (prm.name_lower, desc))
1861 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferMap(%s_target_ptr[i]," % prm.name_lower )
1862 self.
target_c_code.write_line(
" img_%s[i]->mem_size[0], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1863 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1865 elif prm.type != Type.THRESHOLD:
1866 self.
target_c_code.write_line(
"%s_target_ptr = tivxMemShared2TargetPtr(&%s->mem_ptr);" % (prm.name_lower, desc))
1868 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferMap(%s_target_ptr," % prm.name_lower )
1869 self.
target_c_code.write_line(
" %s->mem_size, (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1870 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1871 if prm.state
is ParamState.OPTIONAL:
1877 for prm
in self.
kernel.params :
1878 desc = prm.name_lower +
"_desc" 1879 if (Type.is_scalar_type(prm.type)
is True)
and prm.direction != Direction.OUTPUT :
1880 if prm.state
is ParamState.OPTIONAL:
1883 if "invalid" != Type.get_scalar_obj_desc_data_name(prm.type):
1884 self.
target_c_code.write_line(
"%s_value = %s->data.%s;" % (prm.name_lower, desc, Type.get_scalar_obj_desc_data_name(prm.type)))
1886 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Modify 'scalar data type' below to be correct type >")
1887 self.
target_c_code.write_line(
"/*%s_value = %s->data.<scalar data type>;*/" % (prm.name_lower, desc))
1888 if prm.state
is ParamState.OPTIONAL:
1894 if self.
kernel.getNumImages() > 0:
1895 self.
target_c_code.write_line(
"void *img_ptrs[%s];" % self.
kernel.getNumImages(), files=1)
1898 for prm
in self.
kernel.params :
1899 if prm.type == Type.IMAGE
and (prm.do_map
or prm.do_unmap):
1900 self.
target_c_code.write_line(
"VXLIB_bufParams2D_t vxlib_%s;" % prm.name_lower)
1901 self.
target_c_code.write_line(
"uint8_t *%s_addr = NULL;" % prm.name_lower)
1903 for prm
in self.
kernel.params :
1904 desc = prm.name_lower +
"_desc" 1905 if prm.type == Type.IMAGE
and (prm.do_map
or prm.do_unmap):
1906 if prm.state
is ParamState.OPTIONAL:
1909 self.
target_c_code.write_line(
"tivxInitBufParams(%s, &vxlib_%s);" % (desc, prm.name_lower) )
1910 self.
target_c_code.write_line(
"tivxSetPointerLocation(%s, &%s_target_ptr, &%s_addr);" % (desc, prm.name_lower, prm.name_lower) )
1911 if prm.state
is ParamState.OPTIONAL:
1916 if self.
kernel.getNumImages() > 0:
1918 if self.
kernel.getNumOptionalImages() > 0 :
1919 num_scenarios = (2 ** self.
kernel.getNumOptionalImages()) - 1
1922 if num_scenarios == 1
and self.
kernel.getNumOptionalImages() == 0 :
1924 elif num_scenarios == 1
and self.
kernel.getNumOptionalImages() > 0 :
1928 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment once BAM graph has been created >", files=1)
1929 self.
target_c_code.write_comment_line(
"status = tivxBamProcessGraph(prms->graph_handle);", files=1)
1932 self.
target_c_code.write_comment_line(
"call kernel processing function")
1934 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Add target kernel processing code here >")
1936 self.
target_c_code.write_comment_line(
"kernel processing function complete")
1941 for prm
in self.
kernel.params :
1942 desc = prm.name_lower +
"_desc" 1944 if prm.state
is ParamState.OPTIONAL:
1947 if Type.IMAGE == prm.type
or Type.PYRAMID == prm.type
or Type.OBJECT_ARRAY == prm.type
or Type.RAW_IMAGE == prm.type:
1950 if len(prm.data_types) > 1 :
1951 for dt
in prm.data_types[0:-1] :
1952 if DfImage.get_num_planes(DfImage.get_df_enum_from_string(dt)) > 1 :
1955 if prm.type == Type.IMAGE :
1957 self.
target_c_code.write_line(
"for(plane_idx=0; plane_idx<%s->planes; plane_idx++)" % desc )
1959 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferUnmap(%s_target_ptr[plane_idx]," % prm.name_lower )
1960 self.
target_c_code.write_line(
" %s->mem_size[plane_idx], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1961 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1964 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferUnmap(%s_target_ptr," % prm.name_lower )
1965 self.
target_c_code.write_line(
" %s->mem_size[0], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1966 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1967 elif prm.type == Type.RAW_IMAGE :
1968 self.
target_c_code.write_line(
"for(exposure_idx=0; exposure_idx<%s->params.num_exposures; exposure_idx++)" % desc )
1970 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferUnmap(%s_target_ptr[exposure_idx]," % prm.name_lower )
1971 self.
target_c_code.write_line(
" %s->mem_size[exposure_idx], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1972 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1974 elif prm.type == Type.PYRAMID
or prm.type == Type.OBJECT_ARRAY :
1976 if prm.type == Type.PYRAMID :
1977 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_levels; i++)" % desc )
1979 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_items; i++)" % desc )
1981 self.
target_c_code.write_line(
"for(plane_idx=0; plane_idx<%s->planes; plane_idx++)" % desc )
1983 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferUnmap(%s_target_ptr[i]," % prm.name_lower )
1984 self.
target_c_code.write_line(
" img_%s[i]->mem_size[plane_idx], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1985 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1989 if prm.type == Type.PYRAMID :
1990 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_levels; i++)" % desc )
1992 self.
target_c_code.write_line(
"for(i=0U; i<%s->num_items; i++)" % desc )
1994 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferUnmap(%s_target_ptr[i]," % prm.name_lower )
1995 self.
target_c_code.write_line(
" img_%s[i]->mem_size[0], (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
1996 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
1998 elif prm.type != Type.THRESHOLD :
1999 self.
target_c_code.write_line(
"tivxCheckStatus(&status, tivxMemBufferUnmap(%s_target_ptr," % prm.name_lower )
2000 self.
target_c_code.write_line(
" %s->mem_size, (vx_enum)VX_MEMORY_TYPE_HOST," % desc)
2001 self.
target_c_code.write_line(
" (vx_enum)%s));" % Direction.get_access_type(prm.direction))
2002 if prm.state
is ParamState.OPTIONAL:
2008 for prm
in self.
kernel.params :
2009 desc = prm.name_lower +
"_desc" 2010 if (Type.is_scalar_type(prm.type)
is True)
and prm.direction != Direction.INPUT :
2011 if "invalid" != Type.get_scalar_obj_desc_data_name(prm.type):
2012 self.
target_c_code.write_line(
"%s->data.%s = %s_value;" % (desc, Type.get_scalar_obj_desc_data_name(prm.type), prm.name_lower))
2014 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: (Optional) Modify 'scalar data type' below to be correct type >")
2015 self.
target_c_code.write_line(
"/*%s->data.<scalar data type> = %s_value;*/" % (prm.name_lower, desc))
2025 def generate_target_c_file_code(self):
2038 self.
target_c_code.write_include(
"tivx_kernels_target_utils.h")
2040 self.
target_c_code.write_include(
"tivx_bam_kernel_wrapper.h", files=1)
2045 self.
target_c_code.write_comment_line(
"< DEVELOPER_TODO: Uncomment if kernel context is needed >")
2050 self.
target_c_code.write_line(
"static tivx_target_kernel vx_%s_target_kernel = NULL;" % (self.
kernel.name_lower))
2053 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sProcess(" % self.
kernel.name_camel)
2054 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
2055 self.
target_c_code.write_line(
" tivx_obj_desc_t *obj_desc[],")
2056 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg);")
2057 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sCreate(" % self.
kernel.name_camel)
2058 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
2059 self.
target_c_code.write_line(
" tivx_obj_desc_t *obj_desc[],")
2060 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg);")
2061 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sDelete(" % self.
kernel.name_camel)
2062 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
2063 self.
target_c_code.write_line(
" tivx_obj_desc_t *obj_desc[],")
2064 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg);")
2065 self.
target_c_code.write_line(
"static vx_status VX_CALLBACK tivx%sControl(" % self.
kernel.name_camel)
2066 self.
target_c_code.write_line(
" tivx_target_kernel_instance kernel,")
2067 self.
target_c_code.write_line(
" uint32_t node_cmd_id, tivx_obj_desc_t *obj_desc[],")
2068 self.
target_c_code.write_line(
" uint16_t num_params, void *priv_arg);")
2079 def generate_make_files(self, kernel) :
2080 if self.
env_var ==
'CUSTOM_KERNEL_PATH' or self.
env_var ==
'CUSTOM_APPLICATION_PATH':
2085 self.
concerto_inc_code.write_line(
"# This file contains a list of extension kernel specific static libraries")
2086 self.
concerto_inc_code.write_line(
"# to be included in the PC executables. It is put in this separate file")
2087 self.
concerto_inc_code.write_line(
"# to make it easier to add/extend kernels without needing to modify")
2088 self.
concerto_inc_code.write_line(
"# several concerto.mak files which depend on kernel libraries.")
2091 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2104 self.
concerto_inc_code.write_line(
"# < DEVELOPER_TODO: Add any additional dependent libraries >")
2107 if self.
env_var ==
'CUSTOM_KERNEL_PATH' or self.
env_var ==
'CUSTOM_APPLICATION_PATH':
2112 self.
tools_path_code.write_line(
"# This file can optionally be used to define environment variables which")
2113 self.
tools_path_code.write_line(
"# are needed by the kernel libraries defined in this folder, or can be")
2114 self.
tools_path_code.write_line(
"# used to overwrite environment variables from the psdk_tools_path.mak")
2115 self.
tools_path_code.write_line(
"# and vsdk_tools_path.mak files from the tiovx directory.")
2117 self.
tools_path_code.write_line(
"# < DEVELOPER_TODO: Add any custom PATH environment variables >")
2125 self.
module_host_concerto_code.write_line(
"ifeq ($(TARGET_CPU), $(filter $(TARGET_CPU), X86 x86_64 A15 M4 A72 A53 R5F))")
2131 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2151 targetCpuListString =
"X86 x86_64 " 2152 for tar
in kernel.targets :
2153 if (tar == Target.DSP1
or tar == Target.DSP2)
and (dspAdded ==
False) :
2154 targetCpuListString+=
"C66 " 2156 if (tar == Target.EVE1
or tar == Target.EVE2
or tar == Target.EVE3
or tar == Target.EVE4)
and (eveAdded ==
False) :
2157 targetCpuListString+=
"EVE " 2159 if (tar == Target.A15_0)
and (armAdded ==
False) :
2160 targetCpuListString+=
"A15 A72 " 2162 if (tar == Target.MCU2_0
or tar == Target.MCU2_1
or tar == Target.IPU2)
and (ipuAdded ==
False) :
2163 targetCpuListString+=
"M4 R5F " 2165 if (tar == Target.DSP_C7_1)
and (c7xAdded ==
False) :
2166 targetCpuListString+=
"C71 " 2172 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2178 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2184 if self.
env_var !=
"VISION_APPS_PATH" :
2190 self.
module_target_concerto_code.write_line(
"# < DEVELOPER_TODO: Add any custom preprocessor defines or build options needed using")
2192 self.
module_target_concerto_code.write_line(
"# < DEVELOPER_TODO: Adjust which cores this library gets built on using 'SKIPBUILD'. >")
2217 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2223 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2229 if self.
env_var !=
"VISION_APPS_PATH" :
2278 if self.
env_var !=
"VISION_APPS_PATH" :
2284 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2289 if self.
env_var ==
"CUSTOM_KERNEL_PATH" :
2291 if self.
env_var ==
"CUSTOM_APPLICATION_PATH" :
2302 self.
module_test_concerto_code.write_line(
"ifeq ($(HOST_COMPILER),$(filter $(HOST_COMPILER),GCC GCC_WINDOWS GCC_LINUX GCC_LINUX_ARM))")
2316 def generate_headers(self) :
2317 if( self.
env_var ==
'CUSTOM_KERNEL_PATH' ) :
2379 self.
include_customer_kernels_code.write_line(
" * \\arg <tt>\\ref VX_TYPE_IMAGE</tt> for a <tt>\\ref vx_image</tt> in the size field of <tt>\\ref vxGetParameterByIndex</tt> or <tt>\\ref vxSetParameterByIndex</tt>")
2380 self.
include_customer_kernels_code.write_line(
" * \\arg <tt>\\ref VX_TYPE_ARRAY</tt> for a <tt>\\ref vx_array</tt> in the size field of <tt>\\ref vxGetParameterByIndex</tt> or <tt>\\ref vxSetParameterByIndex</tt>")
2408 self.
include_customer_kernels_code.write_line(
"void tivx" + toCamelCase(self.
module) +
"PrintPerformance(vx_perf_t performance, uint32_t numPixels, const char* testName);")
2424 for prm
in self.
kernel.params :
2425 if(prm.state == ParamState.OPTIONAL) :
2433 self.
include_customer_nodes_code.write_line(
" * \\retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using <tt>\\ref vxGetStatus</tt>")
2436 for prm
in self.
kernel.params[:-1] :
2437 if Type.is_scalar_type(prm.type) :
2490 def generate_sources(self) :
2498 self.
host_node_api_code.write_line(
"VX_API_ENTRY vx_node VX_API_CALL tivx" + self.
kernel.name_camel +
"Node(vx_graph graph,")
2499 for prm
in self.
kernel.params[:-1] :
2500 if Type.is_scalar_type(prm.type) :
2501 self.
host_node_api_code.write_line(
"%-37s %-20s %s," % (
"",
"vx_scalar", prm.name_lower))
2503 self.
host_node_api_code.write_line(
"%-37s %-20s %s," % (
"", prm.type.get_vx_name(), prm.name_lower))
2507 for prm
in self.
kernel.params[:-1] :
2511 self.
host_node_api_code.write_line(
"vx_node node = tivxCreateNodeByKernelName(graph,")
2528 self.
host_kernels_code.write_line(
"static vx_status VX_CALLBACK publishKernels(vx_context context);")
2529 self.
host_kernels_code.write_line(
"static vx_status VX_CALLBACK unPublishKernels(vx_context context);")
2533 self.
host_kernels_code.write_line(
"vx_status tivxAddKernel" + self.
kernel.name_camel +
"(vx_context context);")
2535 self.
host_kernels_code.write_line(
"vx_status tivxRemoveKernel" + self.
kernel.name_camel +
"(vx_context context);")
2537 self.
host_kernels_code.write_line(
"static Tivx_Host_Kernel_List gTivx_host_kernel_list[] = {")
2541 self.
host_kernels_code.write_line(
"static vx_status VX_CALLBACK publishKernels(vx_context context)")
2543 self.
host_kernels_code.write_line(
"return tivxPublishKernels(context, gTivx_host_kernel_list, dimof(gTivx_host_kernel_list));")
2546 self.
host_kernels_code.write_line(
"static vx_status VX_CALLBACK unPublishKernels(vx_context context)")
2548 self.
host_kernels_code.write_line(
"return tivxUnPublishKernels(context, gTivx_host_kernel_list, dimof(gTivx_host_kernel_list));")
2553 self.
host_kernels_code.write_line(
"tivxRegisterModule(TIVX_MODULE_NAME_" + self.
module.upper() +
", publishKernels, unPublishKernels);")
2563 self.
host_kernels_code.write_line(
"if ((0 == gIs" + toCamelCase(self.
module) +
"KernelsLoad) && (NULL != context))")
2568 self.
host_kernels_code.write_line(
"/* These three lines only work on PC emulation mode ...")
2569 self.
host_kernels_code.write_line(
" * this will need to be updated when moving to target */")
2573 for target
in self.
kernel.targets :
2574 self.
host_kernels_code.write_line(
"tivxSetSelfCpuId(%s);" % Cpu.get_vx_enum_name(Target.get_cpu(target)))
2582 self.
host_kernels_code.write_line(
"void tivx" + toCamelCase(self.
module) +
"UnLoadKernels(vx_context context)")
2587 self.
host_kernels_code.write_line(
"if ((0u == gIs" + toCamelCase(self.
module) +
"KernelsLoad) && (NULL != context))")
2592 self.
host_kernels_code.write_line(
"/* This line only work on PC emulation mode ...")
2593 self.
host_kernels_code.write_line(
" * this will need to be updated when moving to target */")
2639 self.
target_kernels_code.write_line(
"static Tivx_Target_Kernel_List gTivx_target_kernel_list[] = {")
2643 self.
target_kernels_code.write_line(
" {&tivxAddTargetKernelBam" + self.
kernel.name_camel +
", &tivxRemoveTargetKernelBam" + self.
kernel.name_camel +
"},")
2656 self.
target_kernels_code.write_line(
"tivxRegisterTargetKernels(gTivx_target_kernel_list, dimof(gTivx_target_kernel_list));")
2661 self.
target_kernels_code.write_line(
"tivxUnRegisterTargetKernels(gTivx_target_kernel_list, dimof(gTivx_target_kernel_list));")
2667 def modify_files(self) :
2677 def modify_test_header(self) :
2682 "TESTCASE(tivx" + toCamelCase(self.
module) + self.
kernel.name_camel +
")",
2685 "TESTCASE(tivx" + toCamelCase(self.
module) + self.
kernel.name_camel +
")\n")
2687 def modify_make_file(self) :
2688 if self.
env_var ==
'CUSTOM_KERNEL_PATH' :
2691 "vx_kernels_" + self.
module,
2692 "STATIC_LIBS += vx_conformance_engine",
2693 "STATIC_LIBS += vx_target_kernels_" + self.
core +
"\n",
2694 "STATIC_LIBS += vx_conformance_engine",
2695 "STATIC_LIBS += vx_conformance_engine",
2696 "STATIC_LIBS += vx_target_kernels_" + self.
core +
"\n")
2699 "vx_kernels_" + self.
module,
2700 "STATIC_LIBS += vx_conformance_engine",
2701 "STATIC_LIBS += vx_target_kernels_" + self.
core +
"_bam\n",
2702 "STATIC_LIBS += vx_conformance_engine",
2703 "STATIC_LIBS += vx_conformance_engine",
2704 "STATIC_LIBS += vx_target_kernels_" + self.
core +
"_bam\n")
2705 elif self.
env_var ==
'CUSTOM_APPLICATION_PATH' :
2708 "vx_kernels_" + self.
module,
2709 "STATIC_LIBS += vx_conformance_engine",
2710 "STATIC_LIBS += vx_target_kernels_" + self.
module +
"_" + self.
core +
"\n",
2711 "STATIC_LIBS += vx_conformance_engine",
2712 "STATIC_LIBS += vx_conformance_engine",
2713 "STATIC_LIBS += vx_target_kernels_" + self.
module +
"_" + self.
core +
"\n")
2716 "vx_kernels_" + self.
module,
2717 "STATIC_LIBS += vx_conformance_engine",
2718 "STATIC_LIBS += vx_target_kernels_" + self.
module +
"_" + self.
core +
"_bam\n",
2719 "STATIC_LIBS += vx_conformance_engine",
2720 "STATIC_LIBS += vx_conformance_engine",
2721 "STATIC_LIBS += vx_target_kernels_" + self.
module +
"_" + self.
core +
"_bam\n")
2724 def modify_kernel_header_file(self) :
2727 self.
insert = (
r"! \\brief Name for OpenVX Extension kernel module: " + self.
module +
"\n" +
2728 " * \\ingroup group_tivx_ext\n" +
2730 "#define TIVX_MODULE_NAME_" + self.
module.upper() +
" \"" + self.
module +
"\"\n\n")
2733 "vxGetKernelByName",
2734 "#define TIVX_MODULE_NAME_" + self.
module.upper() +
" \"" + self.
module +
"\"",
2735 r"/*! \\brief The list of kernels supported",
2736 r"/*! \\brief The list of kernels supported",
2740 r" \\brief The list of kernels supported in " + self.
module +
" module" +
"\n" +
2742 r" * Each kernel listed here can be used with the <tt>\\ref vxGetKernelByEnum</tt> call." +
"\n" +
2743 " * When programming the parameters, use" +
"\n" +
2744 r" * \\arg <tt>\\ref VX_INPUT</tt> for [in]" +
"\n" +
2745 r" * \\arg <tt>\\ref VX_OUTPUT</tt> for [out]" +
"\n" +
2746 r" * \\arg <tt>\\ref VX_BIDIRECTIONAL</tt> for [in,out]" +
"\n" +
2748 " * When programming the parameters, use" +
"\n" +
2749 r" * \\arg <tt>\\ref VX_TYPE_IMAGE</tt> for a <tt>\\ref vx_image</tt> in the size field of <tt>\\ref vxGetParameterByIndex</tt> or <tt>\\ref vxSetParameterByIndex</tt>" +
"\n" +
2750 r" * \\arg <tt>\\ref VX_TYPE_ARRAY</tt> for a <tt>\\ref vx_array</tt> in the size field of <tt>\\ref vxGetParameterByIndex</tt> or <tt>\\ref vxSetParameterByIndex</tt>" +
"\n" +
2751 r" * \\arg or other appropriate types in \\ref vx_type_e." +
"\n" +
2752 " * \\ingroup group_kernel" +
"\n" +
2754 r"/*! \\brief " + self.
kernel.name_lower +
" kernel name" +
"\n" +
2755 " * \\see group_vision_function_" + self.
module +
"\n" +
2757 "#define " + self.
kernel.enum_str_prefix + self.
kernel.name_upper +
"_NAME \"" + self.
kernel.name_str_prefix + self.
module.lower() +
"." + self.
kernel.name_lower +
"\"\n\n" +
2758 "/*! End of group_vision_function_" + self.
module +
" */\n\n" 2761 "The list of kernels supported in",
2762 " Used for the Application to load the",
2763 "The list of kernels supported in " + self.
module +
" module",
2764 r" * \\brief Used for the Application to load the",
2765 r" * \\brief Used for the Application to load the",
2770 r" * \\brief Used for the Application to load the " + self.
module +
" kernels into the context." +
"\n" +
2771 " * \\ingroup group_kernel" +
"\n" +
2773 "void tivx" + toCamelCase(self.
module) +
"LoadKernels(vx_context context);" +
"\n" +
"\n" +
2775 r" * \\brief Used for the Application to unload the " + self.
module +
" kernels from the context." +
"\n" +
2776 " * \\ingroup group_kernel" +
"\n" +
2778 "void tivx" + toCamelCase(self.
module) +
"UnLoadKernels(vx_context context);" +
"\n" +
"\n" +
2780 r" * \\brief Used to print the performance of the kernels." +
"\n" +
2781 " * \\ingroup group_kernel" +
"\n" +
2783 "void tivx" + toCamelCase(self.
module) +
"PrintPerformance(vx_perf_t performance, uint32_t numPixels, const char* testName);" +
"\n" +
"\n" 2787 "#ifdef __cplusplus",
2788 "void tivx" + toCamelCase(self.
module) +
"LoadKernels",
2789 "#ifdef __cplusplus",
2790 "#ifdef __cplusplus",
2794 self.
insert = (
r"/*! \\brief " + self.
kernel.name_lower +
" kernel name\n" +
2795 " * \\see group_vision_function_" + self.
module +
"\n" +
2797 "#define " + self.
kernel.enum_str_prefix + self.
kernel.name_upper +
"_NAME \"" + self.
kernel.name_str_prefix + self.
module.lower() +
"." + self.
kernel.name_lower +
"\"\n\n")
2799 "The list of kernels supported in " + self.
module +
" module",
2800 " End of group_vision_function_" + self.
module,
2801 " " +self.
kernel.enum_str_prefix + self.
kernel.name_upper +
"_NAME",
2802 r"\/\*\! End of group_vision_function_" + self.
module +
" \*\/",
2803 r"/*! End of group_vision_function_" + self.
module +
" */",
2806 def modify_node_header_file(self) :
2808 self.
insert = (
r"/*! \\brief [Graph] Creates a " + self.
kernel.name_upper +
" Node.\n")
2809 self.
insert += (
r" * \\param [in] graph The reference to the graph.\n")
2810 for prm
in self.
kernel.params :
2811 if(prm.state == ParamState.OPTIONAL) :
2815 self.
insert += (
" * \param [" + prm.direction.get_doxygen_name() +
"] " + prm.name_lower + self.
paramstate +
"\n")
2816 self.
insert += (
r" * \\see <tt>" + self.
kernel.enum_str_prefix + self.
kernel.name_upper +
"_NAME</tt>" +
"\n")
2817 self.
insert += (
r" * \\ingroup group_vision_function_" + self.
kernel.name_lower +
"\n")
2818 self.
insert += (
r" * \\return <tt>\\ref vx_node</tt>.\n")
2819 self.
insert += (
r" * \\retval vx_node A node reference. Any possible errors preventing a successful creation should be checked using <tt>\\ref vxGetStatus</tt>\n")
2820 self.
insert += (
r" */\n")
2821 self.
insert += (
"VX_API_ENTRY vx_node VX_API_CALL tivx" + self.
kernel.name_camel +
"Node(vx_graph graph,\n")
2822 for prm
in self.
kernel.params[:-1] :
2823 if Type.is_scalar_type(prm.type) :
2824 self.
insert += (
"%-37s %-20s %s,\n" % (
"",
"vx_scalar", prm.name_lower))
2826 self.
insert += (
"%-37s %-20s %s,\n" % (
"", prm.type.get_vx_name(), prm.name_lower))
2827 if Type.is_scalar_type(self.
kernel.params[-1].type) :
2828 self.
insert += (
"%-37s %-20s %s);\n" % (
"",
"vx_scalar", self.
kernel.params[-1].name_lower))
2830 self.
insert += (
"%-37s %-20s %s);\n" % (
"", self.
kernel.params[-1].type.get_vx_name(), self.
kernel.params[-1].name_lower))
2835 "#ifdef __cplusplus",
2836 " tivx" + self.
kernel.name_camel +
"Node(vx_graph graph,",
2837 "#ifdef __cplusplus",
2838 "#ifdef __cplusplus",
2841 def modify_node_api_source_file(self) :
2844 self.
insert = (
"VX_API_ENTRY vx_node VX_API_CALL tivx" + self.
kernel.name_camel +
"Node(vx_graph graph,\n")
2845 for prm
in self.
kernel.params[:-1] :
2846 if Type.is_scalar_type(prm.type) :
2847 self.
insert += (
"%-37s %-20s %s,\n" % (
"",
"vx_scalar", prm.name_lower))
2849 self.
insert += (
"%-37s %-20s %s,\n" % (
"", prm.type.get_vx_name(), prm.name_lower))
2850 if Type.is_scalar_type(self.
kernel.params[-1].type) :
2851 self.
insert += (
"%-37s %-20s %s)\n" % (
"",
"vx_scalar", self.
kernel.params[-1].name_lower))
2853 self.
insert += (
"%-37s %-20s %s)\n" % (
"", self.
kernel.params[-1].type.get_vx_name(), self.
kernel.params[-1].name_lower))
2855 self.
insert += (
" vx_reference prms[] = {\n")
2856 for prm
in self.
kernel.params[:-1] :
2857 self.
insert += (
"%-11s (vx_reference)%s,\n" % (
"", prm.name_lower))
2858 self.
insert += (
"%-11s (vx_reference)%s\n" % (
"", self.
kernel.params[-1].name_lower))
2860 self.
insert += (
" vx_node node = tivxCreateNodeByKernelName(graph,\n")
2861 self.
insert += (
"%-42s %s_NAME,\n" % (
"", self.
kernel.enum_str_prefix + self.
kernel.name_upper))
2862 self.
insert += (
"%-42s prms,\n" % (
""))
2863 self.
insert += (
"%-42s dimof(prms));\n" % (
""))
2864 self.
insert += (
" return node;\n}\n\n")
2868 def modify_module_host_header_file(self) :
2872 self.
insert += (
r" * \\brief Function to register " + self.
module.upper() +
" Kernels on the " + self.
core +
" Target\n")
2873 self.
insert += (
r" * \\ingroup group_tivx_ext\n")
2874 self.
insert += (
r" */\n")
2875 self.
insert += (
r"void tivxRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels(void);\n\n")
2876 self.
insert += (
r"/*!\n")
2877 self.
insert += (
r" * \\brief Function to un-register " + self.
module.upper() +
" Kernels on the " + self.
core +
" Target\n")
2878 self.
insert += (
r" * \\ingroup group_tivx_ext\n")
2879 self.
insert += (
r" */\n")
2880 self.
insert += (
r"void tivxUnRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels(void);\n\n")
2882 "Interface file for the " + self.
module.upper() +
" kernels",
2883 "#ifdef __cplusplus",
2884 "void tivxRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels(void);",
2885 "\n#ifdef __cplusplus",
2886 "\n#ifdef __cplusplus",
2889 def modify_module_host_source_file(self) :
2892 "vx_status tivxAddKernel",
2893 "vx_status tivxRemoveKernel",
2894 "vx_status tivxAddKernel" + self.
kernel.name_camel +
"(vx_context context);",
2895 "\nvx_status tivxRemoveKernel",
2896 "\nvx_status tivxRemoveKernel",
2897 "vx_status tivxAddKernel" + self.
kernel.name_camel +
"(vx_context context);\n")
2900 "vx_status tivxRemoveKernel",
2901 "Tivx_Host_Kernel_List",
2902 "vx_status tivxRemoveKernel" + self.
kernel.name_camel +
"(vx_context context);",
2903 "\nstatic Tivx_Host_Kernel_List",
2904 "\nstatic Tivx_Host_Kernel_List",
2905 "vx_status tivxRemoveKernel" + self.
kernel.name_camel +
"(vx_context context);\n")
2908 "Tivx_Host_Kernel_List",
2910 " {&tivxAddKernel" + self.
kernel.name_camel +
", &tivxRemoveKernel" + self.
kernel.name_camel +
"}",
2913 " {&tivxAddKernel" + self.
kernel.name_camel +
", &tivxRemoveKernel" + self.
kernel.name_camel +
"},\n")
2916 "tivx" + toCamelCase(self.
module) +
"LoadKernels",
2918 " tivxRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels();",
2919 " tivxSetSelfCpuId\(TIVX_CPU_ID_DSP1\);",
2920 " tivxSetSelfCpuId(TIVX_CPU_ID_DSP1);",
2921 " tivxRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels();\n")
2924 "tivx" + toCamelCase(self.
module) +
"UnLoadKernels",
2926 " tivxUnRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels();",
2927 "\n gIs" + toCamelCase(self.
module) +
"KernelsLoad",
2928 "\n gIs" + toCamelCase(self.
module) +
"KernelsLoad",
2929 " tivxUnRegister" + toCamelCase(self.
module) +
"Target" + toCamelCase(self.
core) +
"Kernels();\n")
2931 def modify_module_target_source_file(self) :
2936 "void tivxAddTargetKernel",
2938 "void tivxAddTargetKernelBam" + self.
kernel.name_camel +
"(void);",
2941 "void tivxAddTargetKernelBam" + self.
kernel.name_camel +
"(void);\n")
2944 "void tivxAddTargetKernel",
2946 "void tivxAddTargetKernel" + self.
kernel.name_camel +
"(void);",
2949 "void tivxAddTargetKernel" + self.
kernel.name_camel +
"(void);\n")
2952 "void tivxAddTargetKernel",
2954 "void tivxAddTargetKernel" + self.
kernel.name_camel +
"(void);",
2961 "void tivxRemoveTargetKernel",
2962 "static Tivx_Target_Kernel_List",
2963 "void tivxRemoveTargetKernelBam" + self.
kernel.name_camel +
"(void);",
2966 "void tivxRemoveTargetKernelBam" + self.
kernel.name_camel +
"(void);\n")
2969 "void tivxRemoveTargetKernel",
2970 "static Tivx_Target_Kernel_List",
2971 "void tivxRemoveTargetKernel" + self.
kernel.name_camel +
"(void);",
2974 "void tivxRemoveTargetKernel" + self.
kernel.name_camel +
"(void);\n")
2977 "void tivxRemoveTargetKernel",
2979 "void tivxRemoveTargetKernel" + self.
kernel.name_camel +
"(void);",
2986 "Tivx_Target_Kernel_List",
2988 " {&tivxAddTargetKernelBam" + self.
kernel.name_camel +
", &tivxRemoveTargetKernelBam" + self.
kernel.name_camel +
"},",
2991 " {&tivxAddTargetKernelBam" + self.
kernel.name_camel +
", &tivxRemoveTargetKernelBam" + self.
kernel.name_camel +
"},\n")
2994 "Tivx_Target_Kernel_List",
2996 " {&tivxAddTargetKernel" + self.
kernel.name_camel +
", &tivxRemoveTargetKernel" + self.
kernel.name_camel +
"},",
2999 " {&tivxAddTargetKernel" + self.
kernel.name_camel +
", &tivxRemoveTargetKernel" + self.
kernel.name_camel +
"},\n")
3002 "Tivx_Target_Kernel_List",
3004 " {&tivxAddTargetKernel" + self.
kernel.name_camel +
", &tivxRemoveTargetKernel" + self.
kernel.name_camel +
"},",
3010 if self.
env_var ==
'CUSTOM_KERNEL_PATH' or self.
env_var ==
'CUSTOM_APPLICATION_PATH':
3021 self.
todo_code.write_line(
"# This file lists the places in the generated code where the developer is expected")
3022 self.
todo_code.write_line(
"# to add custom code beyond what the script can generate. This is generated as ")
3023 self.
todo_code.write_line(
"# part of the KernelExportCode.export() function, but may also be called independently ")
3024 self.
todo_code.write_line(
"# by calling the KernelExportCode.todo() function with the requirement that the ")
3025 self.
todo_code.write_line(
"# "+self.
env_var+
" environment variable is defined. This function simply searches")
3026 self.
todo_code.write_line(
"# for the \"< DEVELOPER_TODO ...>\" string in all the files from this path, and lists them.")
3027 self.
todo_code.write_line(
"# Removing the \"< DEVELOPER_TODO ...>\" comment block from the files will effectively remove those")
3028 self.
todo_code.write_line(
"# lines from showing up in this file the next time KernelExportCode.todo() is run.")
3029 if self.
env_var ==
'CUSTOM_KERNEL_PATH' or self.
env_var ==
'CUSTOM_APPLICATION_PATH':
3034 with open(file,
'rb')
as f:
3035 for num, line
in enumerate(f, 1):
3036 if 'DEVELOPER_TODO'.encode()
in line:
3037 if '>'.encode()
in line:
3041 self.
modLine = re.sub(
"^.*?DEVELOPER_TODO:".encode(),
"".encode(), line)
3046 self.
todo_code.write_line(
"\n" + file, new_line=
False)
3047 self.
todo_code.write_line(
"\n " + str(num) +
": " + self.
modLine.decode(
'utf-8'), new_line=
False)
3051 if '>'.encode()
in line :
3053 self.
modLine = re.sub(
"^.*?DEVELOPER_TODO:".encode(),
"".encode(), line)
3060 self.
todo_code.write_line(
" " + str(num) +
": " + self.
modLine.decode(
'utf-8'), new_line=
False)
3070 self.
h_filename =
"tivx_kernel_" + kernel.name_lower +
".h";
3079 for target in self.kernel.targets : 3080 if target == Target.DSP1 or target == Target.DSP2 : 3081 self.target_uses_dsp = True 3085 if self.
kernel.localMem ==
True :
3099 print (
'Generating C code for OpenVX kernel ...')
3101 print (
'Creating new directories ...')
3103 print (
'Creating new makefiles ...')
3105 print (
'Creating new headers ...')
3107 print (
'Creating new module-level sources ...')
3112 print (
'Creating new kernel-specific files ...')
3119 print (
'Generating C code for OpenVX kernel ... DONE !!!')
include_customer_nodes_code
def generate_headers(self)
def modify_node_header_file(self)
module_test_concerto_filename
def generate_h_file_code(self)
module_host_concerto_code
def generate_target_c_control_func_code(self)
def generate_host_c_remove_func_code(self)
include_customer_kernels_code
def outputNodeList(self, kernel)
def generate_target_c_remove_func_code(self)
def generate_target_c_process_func_code(self)
def generate_target_c_create_func_code(self)
def modify_module_host_header_file(self)
def create_all_directories(self)
def generate_bam_pointers(self, kernel_params)
def generate_host_c_initialize_func_code(self)
def generate_target_c_file_code(self)
def convert_string_to_array_type(self, print_type)
def generate_target_c_add_func_code(self)
def generate_optional_bam_pointers(self, num_scenarios)
def generate_optional_list(self, kernel_params)
module_target_bam_concerto_filename
def getTargetColor(self, target)
def modify_node_api_source_file(self)
def generate_sources(self)
include_custom_kernel_library_tests_code
def create_directory(self, directory)
include_custom_kernel_library_tests_filename
def generate_host_c_file_code(self)
def modify_make_file(self)
def modify_module_host_source_file(self)
def outputNodeConnectionList(self, kernel)
def exportDiagram(self, kernel)
Export object as C source code.
include_customer_header_code
Code object used to generate custom kernel.
module_include_kernels_filename
def check_array_type(self, print_type)
module_include_kernels_code
def modify_kernel_header_file(self)
def is_supported_type(self, type)
def extract_local_mem_string_error_check(self, new_str, type, name)
def generate_host_c_add_func_code(self)
def generate_target_c_delete_func_code(self)
module_test_concerto_code
def outputNode(self, kernel)
include_customer_nodes_filename
def modify_test_header(self)
def extract_attribute(self, local, is_first_prm)
def outputNodeConnection(self, kernel)
def modify_module_target_source_file(self)
def export(self, kernel)
Method for generating files from kernel.
module_target_concerto_code
def generate_make_files(self, kernel)
def extract_local_mem_string(self, type, attribute, local)
module_test_main_filename
include_customer_kernels_filename
def generate_target_c_struct(self)
module_host_concerto_filename
module_target_bam_concerto_code
def getDataColor(self, ref)
module_target_concerto_filename
include_customer_header_filename
def outputData(self, data)
def __init__(self, module="ext1", core="c66", env_var='VISION_APPS_PATH', include_subpath="TI", include_filename="")
Constructor used to create this object.
def outputDataList(self, kernel)
def generate_host_c_validate_func_code(self)
def verify_parameter_relationship_items(self, relationship_list, prm, attribute, name)