dace.codegen package

Subpackages

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 use

  • validate – 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: object

A 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(), and convert_return_values(). This way, the argument processing is only done once, and the user can call fast_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 is callargs, i.e., the full set of marshalled arguments. The second element is initargs, 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 self and remain valid until this function is called again. However, they are also returned by self.__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 return statement and return. This function should only be called after fast_call() has been run. Keep in mind that it is not possible to return scalars (with the exception of pyobject``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 use self.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__() or initialize(). Calls made by fast_call() or safe_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__() or initialize() 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 SDFG in 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__() or initialize(). Calls made by fast_call() or safe_call() will not be considered.

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.

Note:

It is the user’s responsibility that all arguments, especially the array arguments, remain valid between the call to __call__() or initialize() and the call to this function.

class dace.codegen.compiled_sdfg.ReloadableDLL(library_filename, **kwargs)

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, 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_mode configuration 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_mode configuration 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_mode is used.

Return type:

str

Returns:

Path to the program folder.

Note:

The config argument 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_MODE file it will examine it to get the save mode. If the folder mode file is absent the function assumes that it is the development format, however, some sanity checks are performed.

The function also has the optional argument probe if given and the folder save mode could not be inferred the function will return None instead of generating an error.

dace.codegen.compiler.get_program_handle(library_path, sdfg, stub_library_path=None)

Construct a CompiledSDFG form 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 representing sdfg.

  • sdfg (SDFG) – The SDFG, will be referenced by the returned CompiledSDFG.

  • stub_library_path (Path | str | None) – The path to the stub library.

Return type:

CompiledSDFG

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 sdfg is not given then the function expects to find the program.sdfg(z) dump file inside folder. If the folder does not contain a FOLDER_MODE file it assumes that it is an old style development folder otherwise, the information from FOLDER_MODE is consulted.

Parameters:
  • folder (Path | str) – Path to SDFG output folder, i.e. its build folder.

  • sdfg (SDFG | None) – If given then program.sdfg(z) does not need to be present.

Return type:

CompiledSDFG

Returns:

A callable CompiledSDFG object.

Note:

If sdfg is given then it is referenced by the returned CompiledSDFG.

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: 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)

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: ExtensibleAttributeEnum

Data types for DefinedMemlets.

See:

DefinedMemlets

Object = 3
Pointer = 1
Scalar = 2
Stream = 4
StreamArray = 5
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, 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:

TargetCodeGenerator

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:

TargetCodeGenerator

get_state_dispatcher(sdfg, state)
Return type:

TargetCodeGenerator

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 triggers func.

  • dst_storage (StorageType) – The destination data storage type that triggers func.

  • dst_schedule (ScheduleType) – An optional destination scope schedule type that triggers func.

  • func (TargetCodeGenerator) – A TargetCodeGenerator object that contains an implementation of copy_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_subgraph and dispatch_scope.

Parameters:
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: 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, 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: TargetCodeGenerator

A 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: object

Interface 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 cmake command 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) – A CodeIOStream object 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:

DaCeCodeGenerator

Returns:

The frame-code generator.

get_generated_codeobjects()

Returns a list of generated CodeObject classes 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.

Module contents