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
PAPIInstrumentationPAPIInstrumentation.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_schedulesPAPIInstrumentation.should_instrument_entry()
PAPIUtilsPAPIUtils.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
InstrumentationProviderInstrumentationProvider.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
CPUCodeGenCPUCodeGen.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_finalizerCPUCodeGen.has_initializerCPUCodeGen.languageCPUCodeGen.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_nameCPUCodeGen.titleCPUCodeGen.unparse_tasklet()CPUCodeGen.write_and_resolve_expr()
- dace.codegen.targets.cuda module
CUDACodeGenCUDACodeGen.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_finalizerCUDACodeGen.has_initializerCUDACodeGen.make_ptr_vector_cast()CUDACodeGen.node_dispatch_predicate()CUDACodeGen.preprocess()CUDACodeGen.process_out_memlets()CUDACodeGen.state_dispatch_predicate()CUDACodeGen.target_nameCUDACodeGen.title
cpu_to_gpu_cpred()prod()
- dace.codegen.targets.framecode module
- dace.codegen.targets.mpi module
- dace.codegen.targets.target module
IllegalCopyTargetCodeGeneratorTargetCodeGenerator.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_finalizerTargetCodeGenerator.has_initializerTargetCodeGenerator.preprocess()TargetCodeGenerator.register()TargetCodeGenerator.unregister()
make_absolute()
- dace.codegen.targets.fpga module
FPGACodeGenFPGACodeGen.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_finalizerFPGACodeGen.has_initializerFPGACodeGen.instrument_opencl_kernel()FPGACodeGen.is_multi_pumped_subgraph()FPGACodeGen.languageFPGACodeGen.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_nameFPGACodeGen.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
IntelFPGACodeGenIntelFPGACodeGen.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.languageIntelFPGACodeGen.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_nameIntelFPGACodeGen.titleIntelFPGACodeGen.unparse_tasklet()IntelFPGACodeGen.write_and_resolve_expr()
OpenCLDaceKeywordRemoverOpenCLDaceKeywordRemover.ctypesOpenCLDaceKeywordRemover.nptypesOpenCLDaceKeywordRemover.nptypes_to_ctypesOpenCLDaceKeywordRemover.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:
objectA compiled SDFG object that can be called through Python.
- Todo:
Scalar return values are not handled properly, this is a code gen issue.
- clear_return_values()
- fast_call(callargs, initargs, do_gpu_check=False)
Calls the underlying binary functions directly and bypassing argument sanitation.
This is a faster, but less user friendly version of
__call__(). While__call__()will transforms its Python arguments such that they can be forwarded, this function assumes that this processing was already done by the user.- Parameters:
callargs (
Tuple[Any,...]) – Arguments passed to the actual computation.initargs (
Tuple[Any,...]) – Arguments passed to the initialization function.do_gpu_check (
bool) – Check if errors happened on the GPU.
- Note:
You may use _construct_args() to generate the processed arguments.
- Return type:
Union[Tuple[Any,...],Any]
- 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:
objectA 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.BasicCFBlock(dispatch_state, parent, last_block, state)
Bases:
ControlFlowA CFG basic block, representing a single dataflow 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.
- class dace.codegen.control_flow.BreakCFBlock(dispatch_state, parent, last_block, block)
Bases:
ControlFlowA CFG block that generates a ‘break’ statement.
- 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.
-
block:
BreakBlock
- property first_block: BreakBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- class dace.codegen.control_flow.ContinueCFBlock(dispatch_state, parent, last_block, block)
Bases:
ControlFlowA CFG block that generates a ‘continue’ statement.
- 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.
-
block:
ContinueBlock
- property first_block: ContinueBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- class dace.codegen.control_flow.ControlFlow(dispatch_state, parent, last_block)
Bases:
objectAbstract class representing a control flow block.
- as_cpp(codegen, symbols)
Returns C++ code for this control flow block.
- Parameters:
codegen (DaCeCodeGenerator) – A code generator object, used for allocation information and defined variables in scope.
symbols (
Dict[str,typeclass]) – A dictionary of symbol names and their types.
- Return type:
str- 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_block: ControlFlowBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- generate_transition(sdfg, cfg, edge, successor=None, assignments_only=False, framecode=None)
Helper function that generates a state transition (conditional goto) from a control flow block and an SDFG edge.
- Parameters:
sdfg (
SDFG) – The parent SDFG.edge (
Edge[InterstateEdge]) – The state transition edge to generate.successor (
Optional[ControlFlowBlock]) – If not None, the state that will be generated right after the current state (used to avoid extraneous gotos).assignments_only (
bool) – If True, generates only the assignments of the inter-state edge.framecode (DaCeCodeGenerator) – Code generator object (used for allocation information).
- Return type:
str- Returns:
A c++ string representing the state transition code.
-
last_block:
bool
-
parent:
Optional[ControlFlow]
- class dace.codegen.control_flow.DoWhileScope(dispatch_state, parent, last_block, sdfg, test, body)
Bases:
ControlFlowDo-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, last_block, itervar, guard, init, condition, update, body, init_edges)
Bases:
ControlFlowFor 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_block: SDFGState
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
-
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, last_block, region, elements, gotos_to_ignore, gotos_to_continue, gotos_to_break, assignments_to_ignore, sequential)
Bases:
RegionBlockGeneral (or unrecognized) control flow block with gotos between 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.
-
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_block: ControlFlowBlock | None
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
-
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.GeneralConditionalScope(dispatch_state, parent, last_block, region, branch_bodies)
Bases:
RegionBlockGeneral conditional block based on a conditional control flow region.
- 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.
-
branch_bodies:
List[Tuple[Optional[CodeBlock],ControlFlow]]
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property conditional: ConditionalBlock
- property first_block: ControlFlowBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- class dace.codegen.control_flow.GeneralLoopScope(dispatch_state, parent, last_block, region, body)
Bases:
RegionBlockGeneral loop block based on a loop control flow region.
- 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:
ControlFlow
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_block: ControlFlowBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- property loop: LoopRegion
- class dace.codegen.control_flow.IfElseChain(dispatch_state, parent, last_block, branch_block, body)
Bases:
ControlFlowA 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)
-
branch_block:
ControlFlowBlock Block that branches out to all blocks
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_block: ControlFlowBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- class dace.codegen.control_flow.IfScope(dispatch_state, parent, last_block, branch_block, condition, body, orelse=None)
Bases:
ControlFlowA 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
-
branch_block:
ControlFlowBlock Block that branches out to if/else scopes
- property children: List[ControlFlow]
Returns a list of control flow blocks that exist within this block.
- property first_block: ControlFlowBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
-
orelse:
Optional[GeneralBlock] = None Optional body of else condition
- class dace.codegen.control_flow.RegionBlock(dispatch_state, parent, last_block, region)
Bases:
ControlFlow-
region:
Optional[ControlFlowRegion]
-
region:
- class dace.codegen.control_flow.ReturnCFBlock(dispatch_state, parent, last_block, block)
Bases:
ControlFlowA CFG block that generates a ‘return’ statement.
- 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.
-
block:
ReturnBlock
- property first_block: ReturnBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
- class dace.codegen.control_flow.SwitchCaseScope(dispatch_state, parent, last_block, branch_block, switchvar, cases)
Bases:
ControlFlowSimple 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.
-
branch_block:
ControlFlowBlock Branching 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_block: ControlFlowBlock
Returns the first or initializing block in this control flow block. Used to determine which will be the next block in a control flow block to avoid generating extraneous
gotocalls.
-
switchvar:
str C++ code for switch expression
- class dace.codegen.control_flow.WhileScope(dispatch_state, parent, last_block, guard, test, body)
Bases:
ControlFlowWhile 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.find_next_block(block)
Returns the immediate successor control flow block.
- Return type:
Optional[ControlFlow]
- 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.control_flow.structured_control_flow_tree_with_regions(sdfg, dispatch_state)
Returns a structured control-flow tree (i.e., with constructs such as branches and loops) from an SDFG based on the control flow regions it contains.
- 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: 2>)
Bases:
objectMethods 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:
objectKeeps 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)
- Return type:
None
- 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:
None
- class dace.codegen.dispatcher.DefinedType(value=<no_arg>, names=None, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
AutoNumberEnumData 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:
objectDispatches 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, cfg, dfg, state_id, node, datadesc, function_stream, callsite_stream, declare=True, allocate=True)
Dispatches a code generator for data allocation.
- Return type:
None
- dispatch_copy(src_node, dst_node, edge, sdfg, cfg, dfg, state_id, function_stream, output_stream)
Dispatches a code generator for a memory copy operation.
- Return type:
None
- dispatch_deallocate(sdfg, cfg, dfg, state_id, node, datadesc, function_stream, callsite_stream)
Dispatches a code generator for a data deallocation.
- Return type:
None
- dispatch_node(sdfg, cfg, 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, cfg, dfg, state_id, function_stream, output_stream)
Dispatches a code generator for an output memlet definition in a tasklet.
- Return type:
None
- dispatch_scope(map_schedule, sdfg, cfg, sub_dfg, state_id, function_stream, callsite_stream)
Dispatches a code generator function for a scope in an SDFG state.
- Return type:
None
- dispatch_state(state, function_stream, callsite_stream)
Dispatches a code generator for an SDFG state.
- Return type:
None
- dispatch_subgraph(sdfg, cfg, 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)
- Return type:
- get_copy_dispatcher(src_node, dst_node, edge, sdfg, state)
(Internal) Returns a code generator that should be dispatched for a memory copy operation.
- Return type:
Optional[TargetCodeGenerator]
- 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)
- Return type:
- get_state_dispatcher(sdfg, state)
- Return type:
- 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 (
StorageType) – The data storage type that triggers func.func (
TargetCodeGenerator) – A TargetCodeGenerator object that contains an implementation of data memory management functions.
- See:
TargetCodeGenerator
- Return type:
None
- 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 (
StorageType) – The source data storage type that triggersfunc.dst_storage (
StorageType) – The destination data storage type that triggersfunc.dst_schedule (
ScheduleType) – An optional destination scope schedule type that triggersfunc.func (
TargetCodeGenerator) – A TargetCodeGenerator object that contains an implementation ofcopy_memory.predicate (
Optional[Callable]) – 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
- Return type:
None
- register_map_dispatcher(schedule_type, func)
Registers a function that processes a scope, used when calling
dispatch_subgraphanddispatch_scope.- Parameters:
schedule_type (
Union[List[ScheduleType],ScheduleType]) – The scope schedule that triggers func.func (
TargetCodeGenerator) – A TargetCodeGenerator object that contains an implementation of generate_scope.
- See:
TargetCodeGenerator
- Return type:
None
- register_node_dispatcher(dispatcher, predicate=None)
Registers a code generator that processes a single node, calling
generate_node.- Parameters:
dispatcher (
TargetCodeGenerator) – The code generator to use.predicate (
Optional[Callable]) – 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
- Return type:
None
- 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:
ExceptionAn exception that is raised within SDFG code generation.
- exception dace.codegen.exceptions.CompilationError
Bases:
ExceptionAn exception that is raised whenever a compilation error occurs.
- exception dace.codegen.exceptions.CompilerConfigurationError
Bases:
ExceptionAn exception that is raised whenever CMake encounters a configuration error.
- exception dace.codegen.exceptions.DuplicateDLLError
Bases:
ExceptionAn 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:
StringIOCode I/O stream that automates indentation and mapping of code to SDFG nodes.
- write(contents, cfg=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.
- Return type:
None