dace.codegen package
Subpackages
- dace.codegen.instrumentation package
- Submodules
- dace.codegen.instrumentation.fpga module
- dace.codegen.instrumentation.gpu_events module
- dace.codegen.instrumentation.papi module
PAPIInstrumentation
PAPIInstrumentation.configure_papi()
PAPIInstrumentation.get_unique_number()
PAPIInstrumentation.has_surrounding_perfcounters()
PAPIInstrumentation.on_consume_entry()
PAPIInstrumentation.on_copy_begin()
PAPIInstrumentation.on_copy_end()
PAPIInstrumentation.on_map_entry()
PAPIInstrumentation.on_node_begin()
PAPIInstrumentation.on_node_end()
PAPIInstrumentation.on_scope_entry()
PAPIInstrumentation.on_scope_exit()
PAPIInstrumentation.on_sdfg_begin()
PAPIInstrumentation.on_sdfg_end()
PAPIInstrumentation.on_state_begin()
PAPIInstrumentation.perf_counter_end_measurement_string()
PAPIInstrumentation.perf_counter_start_measurement_string()
PAPIInstrumentation.perf_counter_string()
PAPIInstrumentation.perf_counter_string_from_string_list()
PAPIInstrumentation.perf_get_supersection_start_string()
PAPIInstrumentation.perf_section_start_string()
PAPIInstrumentation.perf_supersection_start_string()
PAPIInstrumentation.perf_whitelist_schedules
PAPIInstrumentation.should_instrument_entry()
PAPIUtils
PAPIUtils.accumulate_byte_movement()
PAPIUtils.all_maps()
PAPIUtils.available_counters()
PAPIUtils.get_iteration_count()
PAPIUtils.get_memlet_byte_size()
PAPIUtils.get_memory_input_size()
PAPIUtils.get_out_memlet_costs()
PAPIUtils.get_parents()
PAPIUtils.get_tasklet_byte_accesses()
PAPIUtils.is_papi_used()
PAPIUtils.reduce_iteration_count()
- dace.codegen.instrumentation.provider module
InstrumentationProvider
InstrumentationProvider.extensions()
InstrumentationProvider.get_provider_mapping()
InstrumentationProvider.on_copy_begin()
InstrumentationProvider.on_copy_end()
InstrumentationProvider.on_node_begin()
InstrumentationProvider.on_node_end()
InstrumentationProvider.on_scope_entry()
InstrumentationProvider.on_scope_exit()
InstrumentationProvider.on_sdfg_begin()
InstrumentationProvider.on_sdfg_end()
InstrumentationProvider.on_state_begin()
InstrumentationProvider.on_state_end()
InstrumentationProvider.register()
InstrumentationProvider.unregister()
- dace.codegen.instrumentation.report module
- dace.codegen.instrumentation.timer module
- dace.codegen.instrumentation.data module
- Module contents
- dace.codegen.targets package
- Submodules
- dace.codegen.targets.cpu module
CPUCodeGen
CPUCodeGen.allocate_array()
CPUCodeGen.allocate_reference()
CPUCodeGen.allocate_view()
CPUCodeGen.cmake_options()
CPUCodeGen.copy_memory()
CPUCodeGen.deallocate_array()
CPUCodeGen.declare_array()
CPUCodeGen.define_out_memlet()
CPUCodeGen.generate_node()
CPUCodeGen.generate_nsdfg_arguments()
CPUCodeGen.generate_nsdfg_call()
CPUCodeGen.generate_nsdfg_header()
CPUCodeGen.generate_scope()
CPUCodeGen.generate_scope_postamble()
CPUCodeGen.generate_scope_preamble()
CPUCodeGen.generate_tasklet_postamble()
CPUCodeGen.generate_tasklet_preamble()
CPUCodeGen.get_generated_codeobjects()
CPUCodeGen.has_finalizer
CPUCodeGen.has_initializer
CPUCodeGen.language
CPUCodeGen.make_ptr_assignment()
CPUCodeGen.make_ptr_vector_cast()
CPUCodeGen.memlet_ctor()
CPUCodeGen.memlet_definition()
CPUCodeGen.memlet_stream_ctor()
CPUCodeGen.memlet_view_ctor()
CPUCodeGen.process_out_memlets()
CPUCodeGen.target_name
CPUCodeGen.title
CPUCodeGen.unparse_tasklet()
CPUCodeGen.write_and_resolve_expr()
- dace.codegen.targets.cuda module
CUDACodeGen
CUDACodeGen.allocate_array()
CUDACodeGen.allocate_stream()
CUDACodeGen.cmake_options()
CUDACodeGen.copy_memory()
CUDACodeGen.deallocate_array()
CUDACodeGen.deallocate_stream()
CUDACodeGen.declare_array()
CUDACodeGen.define_out_memlet()
CUDACodeGen.generate_devicelevel_scope()
CUDACodeGen.generate_devicelevel_state()
CUDACodeGen.generate_kernel_scope()
CUDACodeGen.generate_node()
CUDACodeGen.generate_nsdfg_arguments()
CUDACodeGen.generate_nsdfg_call()
CUDACodeGen.generate_nsdfg_header()
CUDACodeGen.generate_scope()
CUDACodeGen.generate_state()
CUDACodeGen.get_generated_codeobjects()
CUDACodeGen.get_kernel_dimensions()
CUDACodeGen.get_next_scope_entries()
CUDACodeGen.get_tb_maps_recursive()
CUDACodeGen.has_finalizer
CUDACodeGen.has_initializer
CUDACodeGen.make_ptr_vector_cast()
CUDACodeGen.node_dispatch_predicate()
CUDACodeGen.preprocess()
CUDACodeGen.process_out_memlets()
CUDACodeGen.state_dispatch_predicate()
CUDACodeGen.target_name
CUDACodeGen.title
cpu_to_gpu_cpred()
prod()
- dace.codegen.targets.framecode module
- dace.codegen.targets.mpi module
- dace.codegen.targets.target module
IllegalCopy
TargetCodeGenerator
TargetCodeGenerator.allocate_array()
TargetCodeGenerator.cmake_options()
TargetCodeGenerator.copy_memory()
TargetCodeGenerator.deallocate_array()
TargetCodeGenerator.declare_array()
TargetCodeGenerator.extensions()
TargetCodeGenerator.generate_node()
TargetCodeGenerator.generate_scope()
TargetCodeGenerator.generate_state()
TargetCodeGenerator.get_generated_codeobjects()
TargetCodeGenerator.has_finalizer
TargetCodeGenerator.has_initializer
TargetCodeGenerator.preprocess()
TargetCodeGenerator.register()
TargetCodeGenerator.unregister()
make_absolute()
- dace.codegen.targets.fpga module
FPGACodeGen
FPGACodeGen.allocate_array()
FPGACodeGen.copy_memory()
FPGACodeGen.deallocate_array()
FPGACodeGen.declare_array()
FPGACodeGen.define_out_memlet()
FPGACodeGen.find_rtl_tasklet()
FPGACodeGen.generate_host_function_boilerplate()
FPGACodeGen.generate_kernel()
FPGACodeGen.generate_modules()
FPGACodeGen.generate_nested_state()
FPGACodeGen.generate_node()
FPGACodeGen.generate_nsdfg_arguments()
FPGACodeGen.generate_nsdfg_call()
FPGACodeGen.generate_nsdfg_header()
FPGACodeGen.generate_scope()
FPGACodeGen.generate_state()
FPGACodeGen.generate_tasklet_postamble()
FPGACodeGen.generate_tasklet_preamble()
FPGACodeGen.get_next_scope_entries()
FPGACodeGen.has_finalizer
FPGACodeGen.has_initializer
FPGACodeGen.instrument_opencl_kernel()
FPGACodeGen.is_multi_pumped_subgraph()
FPGACodeGen.language
FPGACodeGen.make_opencl_parameter()
FPGACodeGen.make_parameters()
FPGACodeGen.make_ptr_assignment()
FPGACodeGen.make_ptr_vector_cast()
FPGACodeGen.partition_kernels()
FPGACodeGen.preprocess()
FPGACodeGen.process_out_memlets()
FPGACodeGen.shared_data()
FPGACodeGen.target_name
FPGACodeGen.title
fpga_ptr()
get_multibank_ranges_from_subset()
is_external_stream()
is_fpga_array()
is_multibank_array()
is_multibank_array_with_distributed_index()
is_vendor_supported()
iterate_distributed_subset()
iterate_multibank_interface_ids()
modify_distributed_subset()
parse_location_bank()
unqualify_fpga_array_name()
vector_element_type_of()
- dace.codegen.targets.xilinx module
- dace.codegen.targets.intel_fpga module
IntelFPGACodeGen
IntelFPGACodeGen.allocate_view()
IntelFPGACodeGen.cmake_options()
IntelFPGACodeGen.create_mangled_channel_name()
IntelFPGACodeGen.create_mangled_module_name()
IntelFPGACodeGen.define_local_array()
IntelFPGACodeGen.define_shift_register()
IntelFPGACodeGen.define_stream()
IntelFPGACodeGen.generate_channel_writes()
IntelFPGACodeGen.generate_constants()
IntelFPGACodeGen.generate_converters()
IntelFPGACodeGen.generate_flatten_loop_post()
IntelFPGACodeGen.generate_flatten_loop_pre()
IntelFPGACodeGen.generate_host_function_body()
IntelFPGACodeGen.generate_host_function_prologue()
IntelFPGACodeGen.generate_kernel_internal()
IntelFPGACodeGen.generate_memlet_definition()
IntelFPGACodeGen.generate_module()
IntelFPGACodeGen.generate_no_dependence_post()
IntelFPGACodeGen.generate_no_dependence_pre()
IntelFPGACodeGen.generate_nsdfg_arguments()
IntelFPGACodeGen.generate_nsdfg_header()
IntelFPGACodeGen.generate_pipeline_loop_post()
IntelFPGACodeGen.generate_pipeline_loop_pre()
IntelFPGACodeGen.generate_tasklet_postamble()
IntelFPGACodeGen.generate_undefines()
IntelFPGACodeGen.generate_unroll_loop_post()
IntelFPGACodeGen.generate_unroll_loop_pre()
IntelFPGACodeGen.get_generated_codeobjects()
IntelFPGACodeGen.get_mangled_channel_name()
IntelFPGACodeGen.language
IntelFPGACodeGen.make_kernel_argument()
IntelFPGACodeGen.make_ptr_vector_cast()
IntelFPGACodeGen.make_read()
IntelFPGACodeGen.make_shift_register_write()
IntelFPGACodeGen.make_vector_type()
IntelFPGACodeGen.make_write()
IntelFPGACodeGen.process_out_memlets()
IntelFPGACodeGen.target_name
IntelFPGACodeGen.title
IntelFPGACodeGen.unparse_tasklet()
IntelFPGACodeGen.write_and_resolve_expr()
OpenCLDaceKeywordRemover
OpenCLDaceKeywordRemover.ctypes
OpenCLDaceKeywordRemover.nptypes
OpenCLDaceKeywordRemover.nptypes_to_ctypes
OpenCLDaceKeywordRemover.visit_Assign()
OpenCLDaceKeywordRemover.visit_Attribute()
OpenCLDaceKeywordRemover.visit_BinOp()
OpenCLDaceKeywordRemover.visit_Call()
OpenCLDaceKeywordRemover.visit_Name()
- Module contents
Submodules
dace.codegen.codegen module
dace.codegen.codeobject module
- class dace.codegen.codeobject.CodeObject(*args, **kwargs)
Bases:
object
- property clean_code
- code
The code attached to this object
- environments
Environments required by CMake to build and run this code node.
- extra_compiler_kwargs
Additional compiler argument variables to add to template
- language
Language used for this code (same as its file extension)
- linkable
Should this file participate in overall linkage?
- name
Filename to use
- properties()
- target
Target to use for compilation
- target_type
Sub-target within target (e.g., host or device code)
- title
Title of code for GUI
dace.codegen.compiled_sdfg module
Contains functionality to load, use, and invoke compiled SDFG libraries.
- class dace.codegen.compiled_sdfg.CompiledSDFG(sdfg, lib, argnames=None)
Bases:
object
A compiled SDFG object that can be called through Python.
- clear_return_values()
- property filename
- finalize()
- get_exported_function(name, restype=None)
Tries to find a symbol by name in the compiled SDFG, and convert it to a callable function with the (optionally) given return type (void by default). If no such function exists, returns None.
- Parameters:
name (
str
) – Name of the function to query.- Return type:
Optional
[Callable
[...
,Any
]]- Returns:
Callable to the function, or None if doesn’t exist.
- get_state_struct()
Attempt to parse the SDFG source code and extract the state struct. This method will parse the first consecutive entries in the struct that are pointers. As soon as a non-pointer or other unparseable field is encountered, the method exits early. All fields defined until then will nevertheless be available in the structure.
- Return type:
Structure
- Returns:
the ctypes.Structure representation of the state struct.
- get_workspace_sizes()
Returns the total external memory size to be allocated for this SDFG.
- Return type:
Dict
[StorageType
,int
]- Returns:
A dictionary mapping storage types to the number of bytes necessary to allocate for the SDFG to work properly.
- initialize(*args, **kwargs)
Initializes the compiled SDFG without invoking it.
- Parameters:
args – Arguments to call SDFG with.
kwargs – Keyword arguments to call SDFG with.
- Returns:
If successful, returns the library handle (as a ctypes pointer).
- Note:
This call requires the same arguments as it would when normally calling the program.
- property sdfg
- set_workspace(storage, workspace)
Sets the workspace for the given storage type to the given buffer.
- Parameters:
storage (
StorageType
) – The storage type to fill.workspace (
Any
) – An array-convertible object (through__[cuda_]array_interface__
, see_array_interface_ptr
) to use for the workspace.
- class dace.codegen.compiled_sdfg.ReloadableDLL(library_filename, program_name)
Bases:
object
A reloadable shared object (or dynamically linked library), which bypasses Python’s dynamic library reloading issues.
- get_symbol(name, restype=<class 'ctypes.c_int'>)
Returns a symbol (e.g., function name) in the loaded library.
- is_loaded()
Checks if the library is already loaded.
- Return type:
bool
- load()
Loads the internal library using the stub.
- unload()
Unloads the internal library using the stub.
dace.codegen.compiler module
Handles compilation of code objects. Creates the proper folder structure, compiles each target separately, links all targets to one binary, and returns the corresponding CompiledSDFG object.
- dace.codegen.compiler.configure_and_compile(program_folder, program_name=None, output_stream=None)
Configures and compiles a DaCe program in the specified folder into a shared library file.
- Parameters:
program_folder – Folder containing all files necessary to build, equivalent to what was passed to generate_program_folder.
output_stream – Additional output stream to write to (used for other clients such as the vscode extension).
- Returns:
Path to the compiled shared library file.
- dace.codegen.compiler.generate_program_folder(sdfg, code_objects, out_path, config=None)
Writes all files required to configure and compile the DaCe program into the specified folder.
- Parameters:
sdfg – The SDFG to generate the program folder for.
code_objects (
List
[CodeObject
]) – List of generated code objects.out_path (
str
) – The folder in which the build files should be written.
- Returns:
Path to the program folder.
- dace.codegen.compiler.get_binary_name(object_folder, object_name, lib_extension='so')
- dace.codegen.compiler.get_environment_flags(environments)
Returns the CMake environment and linkage flags associated with the given input environments/libraries.
- Parameters:
environments – A list of
@dace.library.environment
-decorated classes.- Return type:
Tuple
[List
[str
],Set
[str
]]- Returns:
A 2-tuple of (environment CMake flags, linkage CMake flags)
- dace.codegen.compiler.get_program_handle(library_path, sdfg)
- dace.codegen.compiler.identical_file_exists(filename, file_contents)
- dace.codegen.compiler.load_from_file(sdfg, binary_filename)
- dace.codegen.compiler.unique_flags(flags)
dace.codegen.control_flow module
Various classes to facilitate the code generation of structured control
flow elements (e.g., for
, if
, while
) from state machines in SDFGs.
SDFGs are state machines of dataflow graphs, where each node is a state and each
edge may contain a state transition condition and assignments. As such, when
generating code from an SDFG, the straightforward way would be to generate code
for each state and conditional goto
statements for the state transitions.
However, this inhibits compiler optimizations on the generated code, which rely
on loops and branches.
This file contains analyses that extract structured control flow constructs from
the state machine and emit code with the correct C keywords. It does so by
iteratively converting the SDFG into a control flow tree when certain control
flow patterns are detected (using the structured_control_flow_tree
function). The resulting tree classes (which all extend ControlFlow
) contain
the original states, and upon code generation are traversed recursively into
the tree rather than in arbitrary order.
Each individual state is first wrapped with the SingleState
control flow
“block”, and then upon analysis can be grouped into larger control flow blocks,
such as ForScope
or IfElseChain
. If no structured control flow pattern
is detected (or this analysis is disabled in configuration), the group of states
is wrapped in a GeneralBlock
, which generates the aforementioned conditional
goto
code.
For example, the following SDFG:
x < 5
/------>[s2]--------\
[s1] \ ->[s5]
------>[s3]->[s4]--/
x >= 5
would create the control flow tree below:
GeneralBlock({
IfScope(condition=x<5, body={
GeneralBlock({
SingleState(s2)
})
}, orelse={
GeneralBlock({
SingleState(s3),
SingleState(s4),
})
}),
SingleState(s5)
})
- class dace.codegen.control_flow.ControlFlow(dispatch_state, parent)
Bases:
object
Abstract class representing a control flow block.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Returns:
C++ string with the generated code of the control flow block.
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_state: SDFGState
Returns the first or initializing state in this control flow block. Used to determine which will be the next state in a control flow block to avoid generating extraneous
goto
calls.
-
parent:
Optional
[ControlFlow
]
- class dace.codegen.control_flow.DoWhileScope(dispatch_state, parent, sdfg, test, body)
Bases:
ControlFlow
Do-while loop block (without break or continue statements).
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
body:
GeneralBlock
Loop body as control flow block
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- class dace.codegen.control_flow.ForScope(dispatch_state, parent, itervar, guard, init, condition, update, body, init_edges)
Bases:
ControlFlow
For loop block (without break or continue statements).
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
body:
GeneralBlock
Loop body as a control flow block
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_state: SDFGState
Returns the first or initializing state in this control flow block. Used to determine which will be the next state in a control flow block to avoid generating extraneous
goto
calls.
-
init:
str
C++ code for initializing iteration variable
-
init_edges:
List
[InterstateEdge
] All initialization edges
-
itervar:
str
Name of iteration variable
-
update:
str
C++ code for updating iteration variable
- class dace.codegen.control_flow.GeneralBlock(dispatch_state, parent, elements, gotos_to_ignore, gotos_to_continue, gotos_to_break, assignments_to_ignore, sequential)
Bases:
ControlFlow
General (or unrecognized) control flow block with gotos between states.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
assignments_to_ignore:
Sequence
[Edge
[InterstateEdge
]]
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
-
elements:
List
[ControlFlow
]
- property first_state: SDFGState
Returns the first or initializing state in this control flow block. Used to determine which will be the next state in a control flow block to avoid generating extraneous
goto
calls.
-
gotos_to_break:
Sequence
[Edge
[InterstateEdge
]]
-
gotos_to_continue:
Sequence
[Edge
[InterstateEdge
]]
-
gotos_to_ignore:
Sequence
[Edge
[InterstateEdge
]]
-
sequential:
bool
- class dace.codegen.control_flow.IfElseChain(dispatch_state, parent, sdfg, branch_state, body)
Bases:
ControlFlow
A control flow scope of “if, else if, …, else” chain of blocks.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
body:
List
[Tuple
[CodeBlock
,GeneralBlock
]] List of (condition, block)
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- class dace.codegen.control_flow.IfScope(dispatch_state, parent, sdfg, branch_state, condition, body, orelse=None)
Bases:
ControlFlow
A control flow scope of an if (else) block.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
body:
GeneralBlock
Body of if condition
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_state: SDFGState
Returns the first or initializing state in this control flow block. Used to determine which will be the next state in a control flow block to avoid generating extraneous
goto
calls.
-
orelse:
Optional
[GeneralBlock
] = None Optional body of else condition
- class dace.codegen.control_flow.SingleState(dispatch_state, parent, state, last_state=False)
Bases:
ControlFlow
A control flow element containing a single state.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
- property first_state: SDFGState
Returns the first or initializing state in this control flow block. Used to determine which will be the next state in a control flow block to avoid generating extraneous
goto
calls.
- generate_transition(sdfg, edge, successor=None, assignments_only=False, framecode=None)
Helper function that generates a state transition (conditional goto) from a state and an SDFG edge.
- Parameters:
sdfg – The parent SDFG.
edge – The state transition edge to generate.
successor – If not None, the state that will be generated right after the current state (used to avoid extraneous gotos).
assignments_only – If True, generates only the assignments of the inter-state edge.
framecode – Code generator object (used for allocation information).
- Returns:
A c++ string representing the state transition code.
-
last_state:
bool
= False
- class dace.codegen.control_flow.SwitchCaseScope(dispatch_state, parent, sdfg, branch_state, switchvar, cases)
Bases:
ControlFlow
Simple switch-case scope without fall-through cases.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
cases:
Dict
[str
,GeneralBlock
] Mapping of cases to control flow blocks
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_state: SDFGState
Returns the first or initializing state in this control flow block. Used to determine which will be the next state in a control flow block to avoid generating extraneous
goto
calls.
-
switchvar:
str
C++ code for switch expression
- class dace.codegen.control_flow.WhileScope(dispatch_state, parent, guard, test, body)
Bases:
ControlFlow
While loop block (without break or continue statements).
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen – A code generator object, used for allocation information and defined variables in scope.
symbols – A dictionary of symbol names and their types.
- Return type:
str
- Returns:
C++ string with the generated code of the control flow block.
-
body:
GeneralBlock
Loop body as control flow block
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- dace.codegen.control_flow.structured_control_flow_tree(sdfg, dispatch_state)
Returns a structured control-flow tree (i.e., with constructs such as branches and loops) from an SDFG, which can be used to generate its code in a compiler- and human-friendly way.
- Parameters:
sdfg (
SDFG
) – The SDFG to iterate over.- Return type:
- Returns:
Control-flow block representing the entire SDFG.
dace.codegen.cppunparse module
- class dace.codegen.cppunparse.CPPLocals
Bases:
LocalScheme
- clear_scope(from_indentation)
Clears all locals defined in indentation ‘from_indentation’ and deeper
- define(local_name, lineno, depth, dtype=None)
- get_name_type_associations()
- is_defined(local_name, current_depth)
- class dace.codegen.cppunparse.CPPUnparser(tree, depth, locals, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, indent_output=True, expr_semicolon=True, indent_offset=0, type_inference=False, defined_symbols=None, language=Language.CPP)
Bases:
object
Methods in this class recursively traverse an AST and output C++ source code for the abstract syntax; original formatting is disregarded.
- binop = {'Add': '+', 'BitAnd': '&', 'BitOr': '|', 'BitXor': '^', 'Div': '/', 'LShift': '<<', 'Mod': '%', 'Mult': '*', 'RShift': '>>', 'Sub': '-'}
- boolops = {<class 'ast.And'>: '&&', <class 'ast.Or'>: '||'}
- callbools = {'And': <class 'ast.And'>, 'Or': <class 'ast.Or'>}
- callcmps = {'Eq': <class 'ast.Eq'>, 'Ge': <class 'ast.GtE'>, 'Gt': <class 'ast.Gt'>, 'GtE': <class 'ast.GtE'>, 'Le': <class 'ast.LtE'>, 'Lt': <class 'ast.Lt'>, 'LtE': <class 'ast.LtE'>, 'Ne': <class 'ast.NotEq'>, 'NotEq': <class 'ast.NotEq'>}
- cmpops = {'Eq': '==', 'Gt': '>', 'GtE': '>=', 'Is': '==', 'IsNot': '!=', 'Lt': '<', 'LtE': '<=', 'NotEq': '!='}
- dispatch(tree)
Dispatcher function, dispatching tree type T to method _T.
- dispatch_lhs_tuple(targets)
- enter()
Print ‘{’, and increase the indentation.
- fill(text='')
Indent a piece of text, according to the current indentation level
- format_conversions = {97: 'a', 114: 'r', 115: 's'}
- funcops = {'FloorDiv': (' /', 'dace::math::ifloor'), 'MatMult': (',', 'dace::gemm')}
- leave()
Decrease the indentation and print ‘}’.
- unop = {'Invert': '~', 'Not': '!', 'UAdd': '+', 'USub': '-'}
- unop_lambda = {'Invert': <function CPPUnparser.<lambda>>, 'Not': <function CPPUnparser.<lambda>>, 'UAdd': <function CPPUnparser.<lambda>>, 'USub': <function CPPUnparser.<lambda>>}
- write(text)
Append a piece of text to the current line
- class dace.codegen.cppunparse.LocalScheme
Bases:
object
- clear_scope(from_indentation)
- define(local_name, lineno, depth)
- is_defined(local_name, current_depth)
- dace.codegen.cppunparse.cppunparse(node, expr_semicolon=True, locals=None, defined_symbols=None)
- dace.codegen.cppunparse.interleave(inter, f, seq, **kwargs)
Call f on each item in seq, calling inter() in between. f can accept optional arguments (kwargs)
- dace.codegen.cppunparse.py2cpp(code, expr_semicolon=True, defined_symbols=None)
- dace.codegen.cppunparse.pyexpr2cpp(expr)
dace.codegen.dispatcher module
Contains the DaCe code generator target dispatcher, which is responsible for flexible code generation with multiple backends by dispatching certain functionality to registered code generators based on user-defined predicates.
- class dace.codegen.dispatcher.DefinedMemlets
Bases:
object
Keeps track of the type of defined memlets to ensure that they are referenced correctly in nested scopes and SDFGs. The ones defined in the first (top) scope, refer to global variables.
- add(name, dtype, ctype, ancestor=0, allow_shadowing=False)
- add_global(name, dtype, ctype)
Adds a global variable (top scope)
- enter_scope(parent, can_access_parent=True)
- exit_scope(parent)
- get(name, ancestor=0, is_global=False)
- Return type:
Tuple
[DefinedType
,str
]
- has(name, ancestor=0)
- remove(name, ancestor=0, is_global=False)
- Return type:
Tuple
[DefinedType
,str
]
- class dace.codegen.dispatcher.DefinedType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
AutoNumberEnum
Data types for DefinedMemlets.
- See:
DefinedMemlets
- ArrayInterface = 7
- FPGA_ShiftRegister = 6
- Object = 3
- Pointer = 1
- Scalar = 2
- Stream = 4
- StreamArray = 5
- register(*args)
- class dace.codegen.dispatcher.TargetDispatcher(framecode)
Bases:
object
Dispatches sub-SDFG generation (according to scope), storage<->storage copies, and storage<->tasklet copies to targets.
- property declared_arrays: DefinedMemlets
Returns a list of declared variables.
This is used for variables that must have their declaration and allocation separate. It includes all such variables that have been declared by the dispatcher.
- property defined_vars: DefinedMemlets
Returns a list of defined variables.
This includes all variables defined by the dispatcher.
- dispatch_allocate(sdfg, dfg, state_id, node, datadesc, function_stream, callsite_stream, declare=True, allocate=True)
Dispatches a code generator for data allocation.
- dispatch_copy(src_node, dst_node, edge, sdfg, dfg, state_id, function_stream, output_stream)
Dispatches a code generator for a memory copy operation.
- dispatch_deallocate(sdfg, dfg, state_id, node, datadesc, function_stream, callsite_stream)
Dispatches a code generator for a data deallocation.
- dispatch_node(sdfg, dfg, state_id, node, function_stream, callsite_stream)
Dispatches a code generator for a single node.
- dispatch_output_definition(src_node, dst_node, edge, sdfg, dfg, state_id, function_stream, output_stream)
Dispatches a code generator for an output memlet definition in a tasklet.
- dispatch_scope(map_schedule, sdfg, sub_dfg, state_id, function_stream, callsite_stream)
Dispatches a code generator function for a scope in an SDFG state.
- dispatch_state(sdfg, state, function_stream, callsite_stream)
Dispatches a code generator for an SDFG state.
- dispatch_subgraph(sdfg, dfg, state_id, function_stream, callsite_stream, skip_entry_node=False, skip_exit_node=False)
Dispatches a code generator for a scope subgraph of an SDFGState.
- get_array_dispatcher(storage)
- get_copy_dispatcher(src_node, dst_node, edge, sdfg, state)
(Internal) Returns a code generator that should be dispatched for a memory copy operation.
- get_generic_node_dispatcher()
Returns the default node dispatcher.
- get_generic_state_dispatcher()
Returns the default state dispatcher.
- get_node_dispatcher(sdfg, state, node)
- get_predicated_node_dispatchers()
Returns a list of node dispatchers with predicates.
- get_predicated_state_dispatchers()
Returns a list of state dispatchers with predicates.
- get_scope_dispatcher(schedule)
- get_state_dispatcher(sdfg, state)
- register_array_dispatcher(storage_type, func)
Registers a function that processes data allocation, initialization, and deinitialization. Used when calling
dispatch_allocate/deallocate/initialize
.- Parameters:
storage_type – The data storage type that triggers func.
func – A TargetCodeGenerator object that contains an implementation of data memory management functions.
- See:
TargetCodeGenerator
- register_copy_dispatcher(src_storage, dst_storage, dst_schedule, func, predicate=None)
Registers code generation of data-to-data (or data from/to tasklet, if src/dst storage is StorageType.Register) copy functions. Can also be target-schedule specific, or dst_schedule=None if the function will be invoked on any schedule.
- Parameters:
src_storage – The source data storage type that triggers
func
.dst_storage – The destination data storage type that triggers
func
.dst_schedule – An optional destination scope schedule type that triggers
func
.func – A TargetCodeGenerator object that contains an implementation of
copy_memory
.predicate – A lambda function that accepts the SDFG, state, and source and destination nodes, and triggers the code generator when True is returned. If None, always dispatches with this dispatcher.
- See:
TargetCodeGenerator
- register_map_dispatcher(schedule_type, func)
Registers a function that processes a scope, used when calling
dispatch_subgraph
anddispatch_scope
.- Parameters:
schedule_type – The scope schedule that triggers func.
func – A TargetCodeGenerator object that contains an implementation of generate_scope.
- See:
TargetCodeGenerator
- register_node_dispatcher(dispatcher, predicate=None)
Registers a code generator that processes a single node, calling
generate_node
.- Parameters:
dispatcher – The code generator to use.
predicate – A lambda function that accepts the SDFG, state, and node, and triggers the code generator when True is returned. If None, registers dispatcher as the default node dispatcher.
- See:
TargetCodeGenerator
- register_state_dispatcher(dispatcher, predicate=None)
Registers a code generator that processes a single state, calling
generate_state
.- Parameters:
dispatcher – The code generator to use.
predicate – A lambda function that accepts the SDFG and state, and triggers the code generator when True is returned. If None, registers dispatcher as the default state dispatcher.
- See:
TargetCodeGenerator
- property used_environments
Returns a list of environments required to build and run the code.
- property used_targets
Returns a list of targets (code generators) that were triggered during generation.
dace.codegen.exceptions module
Specialized exception classes for code generator.
- exception dace.codegen.exceptions.CodegenError
Bases:
Exception
An exception that is raised within SDFG code generation.
- exception dace.codegen.exceptions.CompilationError
Bases:
Exception
An exception that is raised whenever a compilation error occurs.
- exception dace.codegen.exceptions.CompilerConfigurationError
Bases:
Exception
An exception that is raised whenever CMake encounters a configuration error.
- exception dace.codegen.exceptions.DuplicateDLLError
Bases:
Exception
An exception that is raised whenever a library is loaded twice.
dace.codegen.prettycode module
Code I/O stream that automates indentation and mapping of code to SDFG nodes.
- class dace.codegen.prettycode.CodeIOStream(base_indentation=0)
Bases:
StringIO
Code I/O stream that automates indentation and mapping of code to SDFG nodes.
- write(contents, sdfg=None, state_id=None, node_id=None)
Write string to file.
Returns the number of characters written, which is always equal to the length of the string.