17 function_name: str =
None,
18 output_directory: str =
".",
22 Name of the generated C++ function. Defaults to the name of the
23 Python DSL function passed in as function.
26 Directory the kernels/ subdirectory with the generated files is
27 created in, usually the Peano project's directory.
29 @remark Existing files are appended to, not overwritten
30 Several functions of one project end up in the same files
31 (kernels/{output_file_name}.h and .cpph/.cpp), so the translation appends.
32 Running a generator script a second time in the same directory therefore
33 duplicates the kernels, and the project does not compile
34 ("redefinition of ..."). Remove the kernels/ directory before you
36 @todo The generators should write every function into a file of its
37 own (and a thin header that includes them). Then each file can simply
38 be overwritten, and regenerating in place becomes safe.
40 if target == Target.Accelerator
and stateless ==
False:
41 raise Exception(
"Accelerated kernels must be stateless")
43 reduced_functor_parameters = []
44 for functor
in functor_parameters:
45 function_in_pde_terms =
False
46 for pde_term
in pde_terms:
47 if pde_term.NAME == functor.id:
48 function_in_pde_terms =
True
49 if function_in_pde_terms:
50 reduced_functor_parameters.append(functor)
56 reduced_functor_parameters,
58 namespace=function_namespace,
60 use_accelerator=(target==Target.Accelerator),
61 function_name=function_name,
64 function_declaration = tree.print_declaration()
65 if target == Target.Accelerator:
66 function_definition = tree.print_omp()
68 function_definition = tree.print_cpp()
69 function_declaration_with_timer = tree.print_declaration_with_timer()
70 function_definition_with_timer = tree.print_definition_with_timer()
72 kernels_directory = os.path.join(output_directory,
"kernels")
73 os.makedirs(kernels_directory, exist_ok=
True)
74 file = open(os.path.join(kernels_directory, f
"{output_file_name}.h"),
"a")
75 file.write(function_declaration)
76 file.write(function_declaration_with_timer)
79 file = open(os.path.join(kernels_directory, f
"{output_file_name}.cpph"),
"a")
80 file.write(function_definition)
81 file.write(function_definition_with_timer)
translate_dslhype_function(function, function_namespace, template_parameters, functor_parameters, pde_terms, output_file_name, Target target, bool stateless, str function_name=None, str output_directory=".")
function_name: str Name of the generated C++ function.