dace.codegen package
Subpackages
- dace.codegen.instrumentation package
- Submodules
- dace.codegen.instrumentation.gpu_tx_markers module
GPUTXMarkersProviderGPUTXMarkersProvider.NVTX_HEADER_INCLUDEGPUTXMarkersProvider.ROCTX_HEADER_INCLUDEGPUTXMarkersProvider.on_allocation_begin()GPUTXMarkersProvider.on_allocation_end()GPUTXMarkersProvider.on_copy_begin()GPUTXMarkersProvider.on_copy_end()GPUTXMarkersProvider.on_deallocation_begin()GPUTXMarkersProvider.on_deallocation_end()GPUTXMarkersProvider.on_scope_entry()GPUTXMarkersProvider.on_scope_exit()GPUTXMarkersProvider.on_sdfg_begin()GPUTXMarkersProvider.on_sdfg_end()GPUTXMarkersProvider.on_sdfg_exit_begin()GPUTXMarkersProvider.on_sdfg_exit_end()GPUTXMarkersProvider.on_sdfg_init_begin()GPUTXMarkersProvider.on_sdfg_init_end()GPUTXMarkersProvider.on_state_begin()GPUTXMarkersProvider.on_state_end()GPUTXMarkersProvider.print_include()GPUTXMarkersProvider.print_range_pop()GPUTXMarkersProvider.print_range_push()
- 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_allocation_begin()InstrumentationProvider.on_allocation_end()InstrumentationProvider.on_copy_begin()InstrumentationProvider.on_copy_end()InstrumentationProvider.on_deallocation_begin()InstrumentationProvider.on_deallocation_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_sdfg_exit_begin()InstrumentationProvider.on_sdfg_exit_end()InstrumentationProvider.on_sdfg_init_begin()InstrumentationProvider.on_sdfg_init_end()InstrumentationProvider.on_state_begin()InstrumentationProvider.on_state_end()InstrumentationProvider.register()InstrumentationProvider.unregister()
- dace.codegen.instrumentation.report module
CounterEventDurationEventInstrumentationReportInstrumentationReport.as_csv()InstrumentationReport.countersInstrumentationReport.durationsInstrumentationReport.eventsInstrumentationReport.get_event_uuid_and_other_info()InstrumentationReport.getkey()InstrumentationReport.process_events()InstrumentationReport.save()InstrumentationReport.sdfg_hashInstrumentationReport.sortby()
- 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.emit_interstate_variable_declaration()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.ptr()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.emit_interstate_variable_declaration()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.ptr()CUDACodeGen.state_dispatch_predicate()CUDACodeGen.target_nameCUDACodeGen.title
cpu_to_gpu_cpred()prod()
- dace.codegen.targets.framecode module
DaCeCodeGeneratorDaCeCodeGenerator.allocate_arrays_in_scope()DaCeCodeGenerator.deallocate_arrays_in_scope()DaCeCodeGenerator.determine_allocation_lifetime()DaCeCodeGenerator.dispatcherDaCeCodeGenerator.free_symbols()DaCeCodeGenerator.generate_code()DaCeCodeGenerator.generate_constants()DaCeCodeGenerator.generate_external_memory_management()DaCeCodeGenerator.generate_fileheader()DaCeCodeGenerator.generate_footer()DaCeCodeGenerator.generate_header()DaCeCodeGenerator.generate_state()DaCeCodeGenerator.generate_states()DaCeCodeGenerator.preprocess()DaCeCodeGenerator.symbols_and_constants()
- dace.codegen.targets.mpi module
- Module contents
Submodules
dace.codegen.codegen module
- dace.codegen.codegen.generate_code(sdfg, validate=True)
Generates code as a list of code objects for a given SDFG.
- Parameters:
sdfg (
SDFG) – The SDFG to usevalidate – If True, validates the SDFG before generating the code.
- Return type:
List[CodeObject]- Returns:
List of code objects that correspond to files to compile.
- dace.codegen.codegen.generate_dummy(sdfg, frame)
Generates a C program calling this SDFG. Since we do not know the purpose/semantics of the program, we allocate the right types and and guess values for scalars.
- Return type:
str
- dace.codegen.codegen.generate_headers(sdfg, frame)
Generate a header file for the SDFG
- Return type:
str
dace.codegen.codeobject module
- class dace.codegen.codeobject.CodeObject(*args, **kwargs)
Bases:
object- property clean_code
- code
The code attached to this object
- create_source_map(sdfg)
- Return type:
None
- 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.
This class makes an SDFG binary callable. Normally a user will not create it directly, instead, it is generated by utilities such as
SDFG.compile().The class performs the following tasks:
- It ensures that the SDFG object is properly initialized, either by a direct
call to
initialize()or the first time it is called. Furthermore, it will also take care of the finalization if it goes out of scope.
It marshalls Python arguments into C arguments.
There are two ways in which a compiled SDFG can be called. The first is using
__call__(), i.e. as a normal function. However, this always processes the arguments and performs type checks, which introduces overhead (especially with many arguments). The second way is the advanced interface, which allows to decompose the calling into three steps:construct_arguments(),fast_call(), andconvert_return_values(). This way, the argument processing is only done once, and the user can callfast_call()multiple times with minimal overhead.- Note:
In previous versions, the arrays used as return values were sometimes reused. However, this was changed and every time
construct_arguments()is called new arrays are allocated.- Note:
It is not possible to return Python scalars. Instead, NumPy arrays of size 1 are returned. Note that currently using scalars as return values triggers a validation error in
SDFG.validate. The only exception are Python objects (pyobjects) returned directly.
- clear_return_values()
- construct_arguments(*args, **kwargs)
Construct the argument vectors suitable for from its argument.
The function returns a pair of tuples that are suitable for
fast_call(). The first element thereof iscallargs, i.e., the full set of marshalled arguments. The second element isinitargs, which are only used/needed the first time an SDFG is called.It is important that this function will also allocate new return values. The array objects are managed by
selfand remain valid until this function is called again. However, they are also returned byself.__call__().It is also possible to pass return-value arrays directly as arguments. In that case, the allocation for that return value will be skipped.
- Note:
In case of arrays, the returned argument vectors only contain the pointers to the underlying memory. Thus, it is the user’s responsibility to ensure that the memory remains allocated until the argument vector is used.
- Note:
This is an advanced interface.
- Return type:
Tuple[Tuple[Any],Tuple[Any]]
- convert_return_values()
Convert the return arguments.
Execute the
returnstatement and return. This function should only be called afterfast_call()has been run. Keep in mind that it is not possible to return scalars (with the exception ofpyobject``s), they will be always returned as an array with shape ``(1,).- Note:
This is an advanced interface.
- Note:
After
fast_call()returns it is only allowed to call this function once.- Return type:
Any|Tuple[Any,...]
- 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 transform its Python arguments such that they can be forwarded and allocate memory for the return values, this function assumes that this processing was already done by the user. To build the argument vectors you should useself.construct_arguments().- Parameters:
callargs (
Sequence[Any]) – Arguments passed to the actual computation.initargs (
Sequence[Any]) – Arguments passed to the initialization function.do_gpu_check (
bool) – Check if errors happened on the GPU.
- Note:
This is an advanced interface.
- Note:
In previous versions this function also called
convert_return_values().- Return type:
None
- 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:
Callable[...,Any] |None- 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.
Note that the function queries the sizes of the last call that was made by
__call__()orinitialize(). Calls made byfast_call()orsafe_call()will not be considered.- 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.
- Note:
It is the user’s responsibility that all arguments, especially the array arguments, remain valid between the call to
__call__()orinitialize()and the call to this function.
- 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.
- safe_call(*args, **kwargs)
Forwards the Python call to the compiled
SDFGin a separate process to avoid crashes in the main process. Raises an exception if the SDFG execution fails.- Note:
The current implementation does not handle return values. Thus output can only be transmitted through in/out arguments.
- property sdfg
- set_workspace(storage, workspace)
Sets the workspace for the given storage type to the given buffer.
Note that the function queries the sizes of the last call that was made by
__call__()orinitialize(). Calls made byfast_call()orsafe_call()will not be considered.- Parameters:
storage (
StorageType) – The storage type to fill.workspace (
Any) – An array-convertible object (through__[cuda_]array_interface__, seearray_interface_ptr) to use for the workspace.
- Note:
It is the user’s responsibility that all arguments, especially the array arguments, remain valid between the call to
__call__()orinitialize()and the call to this function.
- class dace.codegen.compiled_sdfg.ReloadableDLL(library_filename, **kwargs)
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, folder_mode=None)
Configures and compiles a DaCe program in the specified folder into a shared library file.
This function respects the
compiler.build_folder_modeconfiguration variable, thus depending on its value the content might be different.- 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).
- Return type:
Path- Returns:
Path to the compiled shared library file.
- dace.codegen.compiler.generate_program_folder(sdfg, code_objects, out_path, config=None, folder_mode=None)
Writes all files required to configure and compile the DaCe program into the specified folder.
This function respects the
compiler.build_folder_modeconfiguration variable, thus depending on its value the content might be different. However, in any case the source files are always generated.- 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.folder_mode (
str|None) – Select which files should be saved in the program build folder; if not given,compiler.build_folder_modeis used.
- Return type:
str- Returns:
Path to the program folder.
- Note:
The
configargument is retained for compatibility and should not be used.
- dace.codegen.compiler.get_binary_name(object_folder, sdfg_name, lib_extension=None, folder_mode=None)
Returns the supposed location of the compiled library given the boundary conditions.
- Parameters:
object_folder (
Path|str) – The build folder of the SDFG, i.e. sdfg.build_folder.sdfg_name (
str) – The name of the SDFG, i.e. sdfg.name.lib_extension (
str|None) – The extension of the library, i.e. file extension. If not given the config option compiler.library_extension is used.folder_mode (
str|None) – The save mode for the build folder. If not given the config option compiler.build_folder_mode is used.
- Return type:
Path
- 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_folder_mode(object_folder, probe=False)
- Overloads:
object_folder (Union[pathlib.Path, str]), probe (Literal[False]) → str
object_folder (Union[pathlib.Path, str]), probe (Literal[True]) → Optional[str]
object_folder (Union[pathlib.Path, str]), probe (bool) → Optional[str]
Inspect object_folder and determine which save mode the folder has.
If the function finds the
FOLDER_MODEfile it will examine it to get the save mode. If the folder mode file is absent the function assumes that it is thedevelopmentformat, however, some sanity checks are performed.The function also has the optional argument
probeif given and the folder save mode could not be inferred the function will returnNoneinstead of generating an error.
- dace.codegen.compiler.get_program_handle(library_path, sdfg, stub_library_path=None)
Construct a
CompiledSDFGform a precompiled library directly.This function is similar to the (preferred)
load_precompiled_sdfg(). However, instead of passing the build folder of the SDFG to the function, the path to the compiled library is passed directly.- Parameters:
library_path (
Path|str) – Path to the compiled library representingsdfg.sdfg (
SDFG) – The SDFG, will be referenced by the returnedCompiledSDFG.stub_library_path (
Path|str|None) – The path to the stub library.
- Return type:
- dace.codegen.compiler.identical_file_exists(filename, file_contents)
- dace.codegen.compiler.load_from_file(sdfg, binary_filename)
- dace.codegen.compiler.load_precompiled_sdfg(folder, sdfg=None)
Loads a precompiled SDFG from
folder.If
sdfgis not given then the function expects to find theprogram.sdfg(z)dump file insidefolder. If the folder does not contain aFOLDER_MODEfile it assumes that it is an old styledevelopmentfolder otherwise, the information fromFOLDER_MODEis consulted.- Parameters:
folder (
Path|str) – Path to SDFG output folder, i.e. its build folder.sdfg (
SDFG|None) – If given thenprogram.sdfg(z)does not need to be present.
- Return type:
- Returns:
A callable CompiledSDFG object.
- Note:
If
sdfgis given then it is referenced by the returnedCompiledSDFG.
- dace.codegen.compiler.unique_flags(flags)
dace.codegen.control_flow module
Functions for generating C++ code for control flow in SDFGs using control flow regions.
- dace.codegen.control_flow.control_flow_region_to_code(region, dispatch_state, codegen, symbols, start=None, stop=None, generate_children_of=None, ptree=None, visited=None)
Converts a control flow region to C++ code with the correct control flow expressions.
- Parameters:
region (
AbstractControlFlowRegion) – The control flow region to convert.dispatch_state (
Callable[[SDFGState],str]) – A callback to generate code for a given SDFG state.codegen (
DaCeCodeGenerator) – The 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 region.
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(*values)
Bases:
ExtensibleAttributeEnumData types for DefinedMemlets.
- See:
DefinedMemlets
- Object = 3
- Pointer = 1
- Scalar = 2
- Stream = 4
- StreamArray = 5
- 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.
- frame: fc.DaCeCodeGenerator
- 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:
TargetCodeGenerator|None
- 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:
- instrumentation: Dict[dtypes.InstrumentationType | dtypes.DataInstrumentationType, instrumentation.InstrumentationProvider]
- 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 (
Callable|None) – 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 (
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 (
Callable|None) – 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
dace.codegen.target module
- class dace.codegen.target.IllegalCopy
Bases:
TargetCodeGeneratorA code generator that is triggered when invalid copies are specified by the SDFG. Only raises an exception on failure.
- copy_memory(sdfg, cfg, dfg, state_id, src_node, dst_node, edge, function_stream, callsite_stream)
Generates code for copying memory, either from a data access node (array/stream) to another, a code node (tasklet/nested SDFG) to another, or a combination of the two.
- Parameters:
sdfg – The SDFG to generate code from.
dfg – The SDFG state to generate code from.
state_id – The node ID of the state in the given SDFG.
src_node – The source node to generate copy code for.
dst_node – The destination node to generate copy code for.
edge – The edge representing the copy (in the innermost scope, adjacent to either the source or destination node).
function_stream – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.
callsite_stream – A CodeIOStream object that points to the current location (call-site) in the code.
- class dace.codegen.target.TargetCodeGenerator
Bases:
objectInterface dictating functions that generate code for:
Array allocation/deallocation/initialization/copying
Scope (map, consume) code generation
- allocate_array(sdfg, cfg, dfg, state_id, node, nodedesc, global_stream, declaration_stream, allocation_stream)
Generates code for allocating an array, outputting to the given code streams.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.dfg (
SDFGState) – The SDFG state to generate code from.state_id (
int) – The node ID of the state in the given SDFG.node (
Node) – The data node to generate allocation for.nodedesc (
Data) – The data descriptor to allocate.global_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.declaration_stream (
CodeIOStream) – A CodeIOStream object that points to the point of array declaration.allocation_stream (
CodeIOStream) – A CodeIOStream object that points to the call-site of array allocation.
- Return type:
None
- static cmake_files()
Returns a list of CMake file paths that should be included during the CMake configuration step.
- Return type:
List[str]
- static cmake_options()
Returns a list of CMake options that this target needs to be passed into the
cmakecommand during configuration.- Return type:
List[str]
- copy_memory(sdfg, cfg, dfg, state_id, src_node, dst_node, edge, function_stream, callsite_stream)
Generates code for copying memory, either from a data access node (array/stream) to another, a code node (tasklet/nested SDFG) to another, or a combination of the two.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.dfg (
SDFGState) – The SDFG state to generate code from.state_id (
int) – The node ID of the state in the given SDFG.src_node (
Node) – The source node to generate copy code for.dst_node (
Node) – The destination node to generate copy code for.edge (
MultiConnectorEdge[Memlet]) – The edge representing the copy (in the innermost scope, adjacent to either the source or destination node).function_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.callsite_stream (
CodeIOStream) – A CodeIOStream object that points to the current location (call-site) in the code.
- Return type:
None
- deallocate_array(sdfg, cfg, dfg, state_id, node, nodedesc, function_stream, callsite_stream)
Generates code for deallocating an array, outputting to the given code streams.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.dfg (
SDFGState) – The SDFG state to generate code from.state_id (
int) – The node ID of the state in the given SDFG.node (
Node) – The data node to generate deallocation for.nodedesc (
Data) – The data descriptor to deallocate.function_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.callsite_stream (
CodeIOStream) – A CodeIOStream object that points to the current location (call-site) in the code.
- Return type:
None
- declare_array(sdfg, cfg, dfg, state_id, node, nodedesc, global_stream, declaration_stream)
Generates code for declaring an array without allocating it, outputting to the given code streams.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.dfg (
SDFGState) – The SDFG state to generate code from.state_id (
int) – The node ID of the state in the given SDFG.node (
Node) – The data node to generate allocation for.nodedesc (
Data) – The data descriptor to allocate.global_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.declaration_stream (
CodeIOStream) – A CodeIOStream object that points to the point of array declaration.
- Return type:
None
- emit_interstate_variable_declaration(name, dtype, callsite_stream, sdfg)
Emits the declaration of an interstate variable at the given call-site.
- Parameters:
name (
str) – The name of the variable.dtype (
typeclass) – The data type of the variable.callsite_stream (
CodeIOStream) – ACodeIOStreamobject that points to the current location (call-site) in the code.sdfg (
SDFG) – The SDFG in which the variable is declared.
- extensions()
- generate_node(sdfg, cfg, dfg, state_id, node, function_stream, callsite_stream)
Generates code for a single node, outputting it to the given code streams.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.dfg (
SDFGState) – The SDFG state to generate code from.state_id (
int) – The node ID of the state in the given SDFG.node (
Node) – The node to generate code from.function_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.callsite_stream (
CodeIOStream) – A CodeIOStream object that points to the current location (call-site) in the code.
- Return type:
None
- generate_scope(sdfg, cfg, dfg_scope, state_id, function_stream, callsite_stream)
Generates code for an SDFG state scope (from a scope-entry node to its corresponding scope-exit node), outputting it to the given code streams.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.dfg_scope (
ScopeSubgraphView) – The ScopeSubgraphView to generate code from.state_id (
int) – The node ID of the state in the given SDFG.function_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.callsite_stream (
CodeIOStream) – A CodeIOStream object that points to the current location (call-site) in the code.
- Return type:
None
- generate_state(sdfg, cfg, state, function_stream, callsite_stream, generate_state_footer)
Generates code for an SDFG state, outputting it to the given code streams.
- Parameters:
sdfg (
SDFG) – The SDFG to generate code from.state (
SDFGState) – The SDFGState to generate code from.function_stream (
CodeIOStream) – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.callsite_stream (
CodeIOStream) – A CodeIOStream object that points to the current location (call-site) in the code.
- Return type:
None
- get_framecode_generator()
Returns the frame-code generator associated with this target.
- Return type:
- Returns:
The frame-code generator.
- get_generated_codeobjects()
Returns a list of generated
CodeObjectclasses corresponding to files with generated code. If an empty list is returned (default) then this code generator does not create new files.- See:
CodeObject
- Return type:
List[CodeObject]
- get_includes()
Returns a dictionary mapping backends to lists of include files required by this target.
- Return type:
dict[str,list[str]]- Returns:
A dictionary of backend names to lists of include files.
- property has_finalizer: bool
Returns True if the target generates a __dace_exit_<TARGET> function that should be called on finalization.
- property has_initializer: bool
Returns True if the target generates a __dace_init_<TARGET> function that should be called on initialization.
- preprocess(sdfg)
Called before code generation on any target that will be dispatched. Used for making modifications on the SDFG prior to code generation.
- Note:
Post-conditions assume that the SDFG will NOT be changed after this point.
- Parameters:
sdfg (
SDFG) – The SDFG to modify in-place.- Return type:
None
- register(**kwargs)
- unregister()
- dace.codegen.target.make_absolute(path)
Finds an executable and returns an absolute path out of it. Used when finding compiler executables.
- Parameters:
path (
str) – Executable name, relative path, or absolute path.- Return type:
str- Returns:
Absolute path pointing to the same file as
path.