dace.codegen.targets package
Submodules
dace.codegen.targets.cpu module
- class dace.codegen.targets.cpu.CPUCodeGen(frame_codegen, sdfg)
Bases:
TargetCodeGenerator
SDFG CPU code generator.
- allocate_array(sdfg, cfg, dfg, state_id, node, nodedesc, function_stream, declaration_stream, allocation_stream, allocate_nested_data=True)
Generates code for allocating an array, outputting to the given code streams.
- Parameters:
sdfg (
SDFG
) – The SDFG to generate code from.dfg (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – The data node to generate allocation for.nodedesc (
Data
) – The data descriptor to allocate.global_stream – 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
- allocate_reference(sdfg, cfg, dfg, state_id, node, global_stream, declaration_stream, allocation_stream)
- Return type:
None
- allocate_view(sdfg, cfg, dfg, state_id, node, global_stream, declaration_stream, allocation_stream)
Allocates (creates pointer and refers to original) a view of an existing array, scalar, or view.
- Return type:
None
- static cmake_options()
Returns a list of CMake options that this target needs to be passed into the
cmake
command during configuration.
- 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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.src_node (
Union
[Tasklet
,AccessNode
]) – The source node to generate copy code for.dst_node (
Union
[Tasklet
,AccessNode
]) – The destination node to generate copy code for.edge (
Tuple
[Node
,Optional
[str
],Node
,Optional
[str
],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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – 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, function_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 (
StateSubgraphView
) – 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 – 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
- define_out_memlet(sdfg, cfg, state_dfg, state_id, src_node, dst_node, edge, function_stream, callsite_stream)
- Return type:
None
- 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 (
ScopeSubgraphView
) – 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_nsdfg_arguments(sdfg, cfg, dfg, state, node)
- generate_nsdfg_call(sdfg, cfg, state, node, memlet_references, sdfg_label, state_struct=True)
- generate_nsdfg_header(sdfg, cfg, state, state_id, node, memlet_references, sdfg_label, state_struct=True)
- 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_scope_postamble(sdfg, dfg_scope, state_id, function_stream, outer_stream, inner_stream)
Generates code for the end of an SDFG scope, outputting it to the given code streams.
- Parameters:
sdfg – The SDFG to generate code from.
dfg_scope – The ScopeSubgraphView to generate code from.
state_id – The node ID of the state in the given SDFG.
function_stream – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.
outer_stream – A CodeIOStream object that points to the code after the scope (e.g., after for-loop closing braces or kernel invocations).
inner_stream – A CodeIOStream object that points to the end of the inner scope code (e.g., before for-loop closing braces or end of kernel).
- generate_scope_preamble(sdfg, dfg_scope, state_id, function_stream, outer_stream, inner_stream)
Generates code for the beginning of an SDFG scope, outputting it to the given code streams.
- Parameters:
sdfg – The SDFG to generate code from.
dfg_scope – The ScopeSubgraphView to generate code from.
state_id – The node ID of the state in the given SDFG.
function_stream – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.
outer_stream – A CodeIOStream object that points to the code before the scope generation (e.g., before for-loops or kernel invocations).
inner_stream – A CodeIOStream object that points to the beginning of the scope code (e.g., inside for-loops or beginning of kernel).
- generate_tasklet_postamble(sdfg, cfg, dfg_scope, state_id, node, function_stream, before_memlets_stream, after_memlets_stream)
Generates code for the end of a tasklet. This method is intended to be overloaded by subclasses.
- Parameters:
sdfg – The SDFG to generate code from.
dfg_scope – The ScopeSubgraphView to generate code from.
state_id – The node ID of the state in the given SDFG.
node – The tasklet node in the state.
function_stream – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.
before_memlets_stream – A CodeIOStream object that will emit code before output memlets are generated.
after_memlets_stream – A CodeIOStream object that will emit code after output memlets are generated.
- generate_tasklet_preamble(sdfg, cfg, dfg_scope, state_id, node, function_stream, before_memlets_stream, after_memlets_stream)
Generates code for the beginning of a tasklet. This method is intended to be overloaded by subclasses.
- Parameters:
sdfg – The SDFG to generate code from.
dfg_scope – The ScopeSubgraphView to generate code from.
state_id – The node ID of the state in the given SDFG.
node – The tasklet node in the state.
function_stream – A CodeIOStream object that will be generated outside the calling code, for use when generating global functions.
before_memlets_stream – A CodeIOStream object that will emit code before input memlets are generated.
after_memlets_stream – A CodeIOStream object that will emit code after input memlets are generated.
- 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
- property has_finalizer
Returns True if the target generates a __dace_exit_<TARGET> function that should be called on finalization.
- property has_initializer
Returns True if the target generates a __dace_init_<TARGET> function that should be called on initialization.
- language = 'cpp'
- make_ptr_assignment(src_expr, src_dtype, dst_expr, dst_dtype, codegen=None)
Write source to destination, where the source is a scalar, and the destination is a pointer.
- Returns:
String of C++ performing the write.
- make_ptr_vector_cast(*args, **kwargs)
- memlet_ctor(sdfg, memlet, dtype, is_output)
- Return type:
str
- memlet_definition(sdfg, memlet, output, local_name, conntype=None, allow_shadowing=False, codegen=None)
- memlet_stream_ctor(sdfg, memlet)
- Return type:
str
- memlet_view_ctor(sdfg, memlet, dtype, is_output)
- Return type:
str
- process_out_memlets(sdfg, cfg, state_id, node, dfg, dispatcher, result, locals_defined, function_stream, skip_wcr=False, codegen=None)
- target_name = 'cpu'
- title = 'CPU'
- unparse_tasklet(sdfg, cfg, state_id, dfg, node, function_stream, inner_stream, locals, ldepth, toplevel_schedule)
- write_and_resolve_expr(sdfg, memlet, nc, outname, inname, indices=None, dtype=None)
Emits a conflict resolution call from a memlet.
dace.codegen.targets.cuda module
- class dace.codegen.targets.cuda.CUDACodeGen(frame_codegen, sdfg)
Bases:
TargetCodeGenerator
GPU (CUDA/HIP) code generator.
- allocate_array(sdfg, cfg, dfg, state_id, node, nodedesc, function_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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – The data node to generate allocation for.nodedesc (
Data
) – The data descriptor to allocate.global_stream – 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
- allocate_stream(sdfg, cfg, dfg, state_id, node, nodedesc, function_stream, declaration_stream, allocation_stream)
- Return type:
None
- static cmake_options()
Returns a list of CMake options that this target needs to be passed into the
cmake
command during configuration.
- copy_memory(sdfg, cfg, dfg, state_id, src_node, dst_node, memlet, 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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.src_node (
Union
[Tasklet
,AccessNode
]) – The source node to generate copy code for.dst_node (
Union
[CodeNode
,AccessNode
]) – 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 (
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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – 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
- deallocate_stream(sdfg, cfg, dfg, state_id, node, nodedesc, function_stream, callsite_stream)
- Return type:
None
- declare_array(sdfg, cfg, dfg, state_id, node, nodedesc, function_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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – The data node to generate allocation for.nodedesc (
Data
) – The data descriptor to allocate.global_stream – 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
- define_out_memlet(sdfg, cfg, state_dfg, state_id, src_node, dst_node, edge, function_stream, callsite_stream)
- Return type:
None
- generate_devicelevel_scope(sdfg, cfg, dfg_scope, state_id, function_stream, callsite_stream)
- Return type:
None
- generate_devicelevel_state(sdfg, cfg, state, function_stream, callsite_stream)
- Return type:
None
- generate_kernel_scope(sdfg, cfg, dfg_scope, state_id, kernel_map, kernel_name, grid_dims, block_dims, has_tbmap, has_dtbmap, kernel_params, function_stream, kernel_stream)
- Return type:
None
- 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 (
StateSubgraphView
) – 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_nsdfg_arguments(sdfg, cfg, dfg, state, node)
- generate_nsdfg_call(sdfg, cfg, state, node, memlet_references, sdfg_label)
- generate_nsdfg_header(sdfg, cfg, state, state_id, node, memlet_references, sdfg_label)
- 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 (
StateSubgraphView
) – 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=False)
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_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
- get_kernel_dimensions(dfg_scope)
Determines a GPU kernel’s grid/block dimensions from map scopes.
Ruleset for kernel dimensions:
- If only one map (device-level) exists, of an integer set
S
, the block size is
32x1x1
and grid size isceil(|S|/32)
in 1st dimension.
- If only one map (device-level) exists, of an integer set
- If nested thread-block maps exist
(T_1,...,T_n)
, grid size is
|S|
and block size ismax(|T_1|,...,|T_n|)
with block specialization.
- If nested thread-block maps exist
- If block size can be overapproximated, it is (for
dynamically-sized blocks that are bounded by a predefined size).
- If nested device maps exist, they generate extra grid dimensions (block size 1)
as the sum of all their sizes
(|T_1| + ... + |T_n|)
- Note:
Kernel dimensions are separate from the map variables, and they should be treated as such.
- Note:
To make use of the grid/block 3D registers, we use multi- dimensional kernels up to 3 dimensions, and flatten the rest into the third dimension.
- get_next_scope_entries(dfg, scope_entry)
- get_tb_maps_recursive(subgraph)
- property has_finalizer
Returns True if the target generates a __dace_exit_<TARGET> function that should be called on finalization.
- property has_initializer
Returns True if the target generates a __dace_init_<TARGET> function that should be called on initialization.
- make_ptr_vector_cast(*args, **kwargs)
- node_dispatch_predicate(sdfg, state, node)
- 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
- process_out_memlets(*args, **kwargs)
- state_dispatch_predicate(sdfg, state)
- target_name = 'cuda'
- title = 'CUDA'
- dace.codegen.targets.cuda.cpu_to_gpu_cpred(sdfg, state, src_node, dst_node)
Copy predicate from CPU to GPU that determines when a copy is illegal. Returns True if copy is illegal, False otherwise.
- dace.codegen.targets.cuda.prod(iterable)
dace.codegen.targets.framecode module
dace.codegen.targets.mpi module
- class dace.codegen.targets.mpi.MPICodeGen(frame_codegen, sdfg)
Bases:
TargetCodeGenerator
An MPI code generator.
- static cmake_options()
Returns a list of CMake options that this target needs to be passed into the
cmake
command during configuration.
- 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 (
StateSubgraphView
) – 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
- 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
- property has_finalizer
Returns True if the target generates a __dace_exit_<TARGET> function that should be called on finalization.
- property has_initializer
Returns True if the target generates a __dace_init_<TARGET> function that should be called on initialization.
- language = 'cpp'
- target_name = 'mpi'
- title = 'MPI'
dace.codegen.targets.target module
- class dace.codegen.targets.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, 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.targets.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_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
- 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_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
]
- 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.targets.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
.
dace.codegen.targets.fpga module
- class dace.codegen.targets.fpga.FPGACodeGen(frame_codegen, sdfg)
Bases:
TargetCodeGenerator
- allocate_array(sdfg, cfg, dfg, state_id, node, nodedesc, function_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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – The data node to generate allocation for.nodedesc (
Data
) – The data descriptor to allocate.global_stream – 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
- 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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.src_node (
Union
[CodeNode
,AccessNode
]) – The source node to generate copy code for.dst_node (
Union
[CodeNode
,AccessNode
]) – 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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – 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, function_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 (
StateSubgraphView
) – The SDFG state to generate code from.state_id (
int
) – The node ID of the state in the given SDFG.node (
AccessNode
) – The data node to generate allocation for.nodedesc (
Data
) – The data descriptor to allocate.global_stream – 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
- define_out_memlet(sdfg, cfg, state_dfg, state_id, src_node, dst_node, edge, function_stream, callsite_stream)
- Return type:
None
- find_rtl_tasklet(subgraph)
Finds a tasklet with SystemVerilog as its language, within the given subgraph, if it contains one.
- Parameters:
subgraph (
ScopeSubgraphView
) – The subgraph to check.- Returns:
The tasklet node if one exists, None otherwise.
- generate_host_function_boilerplate(sdfg, cfg, state, nested_global_transients, host_code_stream)
Generates global transients that must be passed to the state (required by a kernel)
- generate_kernel(sdfg, cfg, state, kernel_name, subgraphs, function_stream, callsite_stream, state_host_header_stream, state_host_body_stream, instrumentation_stream, state_parameters, kernel_id=None)
Entry point for generating an FPGA Kernel out of the given subgraphs.
- Parameters:
sdfg (
SDFG
)state (
SDFGState
)kernel_name (
str
) – the generated kernel name.subgraphs (
list
) – the connected components that constitute this kernel.function_stream (
CodeIOStream
) – CPU code stream, contains global declarations.callsite_stream (
CodeIOStream
) – CPU code stream, contains code for invoking kernels, …state_host_header_stream (
CodeIOStream
) – Device-specific host code stream: contains the host code for the state global declarations.state_host_body_stream (
CodeIOStream
) – Device-specific host code stream: contains all the code related to this state, for creating transient buffers, spawning kernels, and synchronizing them.instrumentation_stream (
CodeIOStream
) – Code for profiling kernel execution time.state_parameters (
list
) – a list of parameters that must be passed to the state. It will get populated considering all the parameters needed by the kernels in this state.kernel_id (
Optional
[int
]) – Unique ID of this kernels as computed in the generate_state function
- generate_modules(sdfg, cfg, state, kernel_name, subgraphs, subgraph_parameters, module_stream, entry_stream, host_stream, instrumentation_stream)
Generate all PEs inside an FPGA Kernel.
- generate_nested_state(sdfg, cfg, state, nest_name, subgraphs, function_stream, callsite_stream)
- Return type:
None
- 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 (
StateSubgraphView
) – 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_nsdfg_arguments(sdfg, cfg, dfg, state, node)
- generate_nsdfg_call(sdfg, cfg, state, node, memlet_references, sdfg_label)
- generate_nsdfg_header(sdfg, cfg, state, state_id, node, memlet_references, sdfg_label)
- 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 (
StateSubgraphView
) – 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 an FPGA State, possibly comprising multiple Kernels and/or PEs.
- Parameters:
sdfg (
SDFG
)state (
SDFGState
)function_stream (
CodeIOStream
) – CPU code stream: contains global declarations (e.g. exported forward declaration of device specific host functions).callsite_stream (
CodeIOStream
) – CPU code stream, contains the actual code (for creating global buffers, invoking device host functions, and so on).
- Return type:
None
- generate_tasklet_postamble(sdfg, cfg, dfg, state_id, node, function_stream, before_memlets_stream, after_memlets_stream)
- Return type:
None
- generate_tasklet_preamble(*args, **kwargs)
- get_next_scope_entries(sdfg, dfg, scope_entry)
- property has_finalizer
Returns True if the target generates a __dace_exit_<TARGET> function that should be called on finalization.
- property has_initializer
Returns True if the target generates a __dace_init_<TARGET> function that should be called on initialization.
- instrument_opencl_kernel(kernel_name, state_id, cfg_id, code_stream)
Emits code to instrument the OpenCL kernel with the given kernel_name.
- is_multi_pumped_subgraph(subgraph)
Checks whether the given subgraph is a multi-pumped subgraph. A subgraph is multi-pumped if it contains a map whose schedule is set to multi-pumped.
- Parameters:
subgraph (
ScopeSubgraphView
) – The subgraph to check.- Returns:
True if the given subgraph is a multi-pumped subgraph.
- language = None
- static make_opencl_parameter(name, desc)
- make_parameters(sdfg, state, subgraphs)
Determines the parameters that must be passed to the passed list of subgraphs, as well as to the global kernel.
- Returns:
A tuple with the following six entries: - Data container parameters that should be passed from the host to the FPGA kernel. - Data containers that are local to the kernel, but must be allocated by the host prior to invoking the kernel. - A dictionary mapping from each processing element subgraph to which parameters it needs (from the total list of parameters). - Parameters that must be passed to the kernel from the host, but that do not exist before the CPU calls the kernel wrapper. - A dictionary of which memory interfaces should be assigned to which memory banks. - External streams that connect different FPGA kernels, and must be defined during the compilation flow.
- make_ptr_assignment(*args, **kwargs)
- make_ptr_vector_cast(*args, **kwargs)
- partition_kernels(state, default_kernel=0)
Associate node to different kernels. This field is applied to all FPGA maps, tasklets, and library nodes that can be executed in parallel in separate kernels.
- Parameters:
state (
SDFGState
) – the state to analyze.default_kernel (
int
) – The Kernel ID to start counting from.
- Returns:
a tuple containing the number of kernels and the dependencies among them
- 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
- process_out_memlets(*args, **kwargs)
Returns a set of data objects that are shared between two or more of the specified subgraphs.
- target_name = None
- title = None
- dace.codegen.targets.fpga.fpga_ptr(name, desc=None, sdfg=None, subset_info=None, is_write=None, dispatcher=None, ancestor=0, is_array_interface=False, interface_id=None, decouple_array_interfaces=False)
Returns a string that points to the data based on its name, and various other conditions that may apply for that data field.
- Parameters:
name (
str
) – Data name.desc (
Optional
[Data
]) – Data descriptor.subset_info (
Union
[Subset
,int
,None
]) – Any additional information about the accessed subset.ancestor (
int
) – The ancestor level where the variable should be searched for if is_array_interface is True when dispatcher is not Noneis_array_interface (
bool
) – Data is pointing to an interface in FPGA-Kernel compilationinterface_id (
Optional
[int
]) – An optional interface id that will be added to the name (only for array interfaces)decouple_array_interfaces (
bool
) – if True it will qualify the name of an array interface, depending whether it is used for reading from or writing to memory
- Returns:
C-compatible name that can be used to access the data.
- dace.codegen.targets.fpga.get_multibank_ranges_from_subset(subset, sdfg)
Returns the upper and lower end of the accessed multibank-range, evaluated using the constants on the SDFG.
- Return type:
Tuple
[int
,int
]- Returns:
(low, high) where low = the lowest accessed bank and high the highest accessed bank + 1.
- dace.codegen.targets.fpga.is_external_stream(node, subgraph)
Given a node and a subgraph, returns whether this is an external stream (the other endpoint is in another FPGA Kernel) or not.
- Returns:
True if node represent an external stream, False otherwise
- dace.codegen.targets.fpga.is_fpga_array(array)
- Returns:
True if this array is placed on FPGA memory
- dace.codegen.targets.fpga.is_multibank_array(array)
- Returns:
True if this array is placed on HBM/DDR on FPGA Global memory
- dace.codegen.targets.fpga.is_multibank_array_with_distributed_index(array)
- Parameters:
array (
Data
) – access node to be checked- Returns:
True if this array is placed on HBM/DDR and has an extra first dimension equal to the number of banks is placed on. For HBM/DDR arrays spanning across multiple banks this is always true.
- dace.codegen.targets.fpga.is_vendor_supported(fpga_vendor)
Returns wheter the given vendor is supported or not, by looking among the registered FPGA code-generators.
- Parameters:
fpga_vendor (
str
) – the fpga vendor- Return type:
bool
- dace.codegen.targets.fpga.iterate_distributed_subset(desc, access_memlet, is_write, sdfg)
- Parameters:
- Returns:
if access_memlet contains a distributed subset the method will count from the lower to the upper end of it. Otherwise returns 0 once.
- dace.codegen.targets.fpga.iterate_multibank_interface_ids(array, interface_ids)
Works on the interface_ids generated by make_parameter. If the array is a hbm/ddr multibank array, interface_ids is a list of tuples of the form (bank, id), and the method will yield the values one by one. If it is not, it will return a tuple of 0 (bank) and the interface id once.
- dace.codegen.targets.fpga.modify_distributed_subset(subset, change)
Modifies the first index of :param subset: (the one used for distributed subsets).
- Parameters:
subset – is deepcopied before any modification to it is done.
change (
int
) – the first index is set to this value, unless it’s (-1) in which case the first index is completly removed
- dace.codegen.targets.fpga.parse_location_bank(array)
- Parameters:
array (
Array
) – an array on FPGA global memory- Return type:
Tuple
[str
,str
]- Returns:
None if an array is given which does not have a location[‘memorytype’] value. Otherwise it will return a tuple (bank_type, bank_assignment), where bank_type is one of ‘DDR’, ‘HBM’ and bank_assignment a string that describes which banks are used.
- dace.codegen.targets.fpga.unqualify_fpga_array_name(sdfg, arr_name)
Returns the unqualified array name if it refers to an array interface. Otherwise return it as it is.
- Parameters:
name – array name to unqualify
- dace.codegen.targets.fpga.vector_element_type_of(dtype)
dace.codegen.targets.xilinx module
dace.codegen.targets.intel_fpga module
- class dace.codegen.targets.intel_fpga.IntelFPGACodeGen(*args, **kwargs)
Bases:
FPGACodeGen
- allocate_view(sdfg, cfg, dfg, state_id, node, global_stream, declaration_stream, allocation_stream)
Allocates (creates pointer and refers to original) a view of an existing array, scalar, or view. Specifically tailored for Intel FPGA
- Return type:
None
- static cmake_options()
Returns a list of CMake options that this target needs to be passed into the
cmake
command during configuration.
- create_mangled_channel_name(var_name, kernel_id, external_stream)
Memorize and returns the mangled name of a global channel The dictionary is organized as
(var_name) : {kernel_id: mangled_name}
- Parameters:
external_stream – indicates whether this channel is an external stream (inter-FPGA Kernel) or not. If this is the case, it will not actually mangle the name by appending a suffix.
- create_mangled_module_name(module_name, kernel_id)
Memorize and returns the mangled name of a module (OpenCL kernel) The dictionary is organized as {module_name: {kernel_id: mangled_name}}
- define_local_array(var_name, desc, array_size, function_stream, kernel_stream, sdfg, state_id, node)
- define_shift_register(*args, **kwargs)
- define_stream(dtype, buffer_size, var_name, array_size, function_stream, kernel_stream, sdfg)
Defines a stream
- Returns:
a tuple containing the type of the created variable, and boolean indicating whether this is a global variable or not
- generate_channel_writes(sdfg, cfg, dfg, node, callsite_stream, state_id)
- generate_constants(sdfg, callsite_stream)
- generate_converters(sdfg, cfg, function_stream)
- static generate_flatten_loop_post(kernel_stream, sdfg, cfg, state_id, node)
- static generate_flatten_loop_pre(kernel_stream, sdfg, cfg, state_id, node)
- generate_host_function_body(sdfg, cfg, state, host_stream, kernel_name, predecessors)
Generate the host-specific code for spawning and synchronizing the given kernel.
- Parameters:
sdfg (
SDFG
)state (
SDFGState
)host_stream (
CodeIOStream
) – Device-specific code streamkernel_name (
str
)predecessors (
list
) – list containing all the name of kernels that must be finished before starting this one
- Return type:
None
- generate_host_function_prologue(sdfg, cfg, state, host_stream, kernel_name)
- generate_kernel_internal(sdfg, cfg, state, kernel_name, predecessors, subgraphs, kernel_stream, state_host_header_stream, state_host_body_stream, instrumentation_stream, function_stream, callsite_stream, state_parameters)
Generates Kernel code, both device and host side.
- Parameters:
sdfg (
SDFG
)state (
SDFGState
)kernel_name (
str
)predecessors (
list
) – list containing all the name of kernels from which this one dependssubgraphs (
list
)kernel_stream (
CodeIOStream
) – Device code stream, contains the kernel codestate_host_header_stream (
CodeIOStream
) – Device-specific code stream: contains the host code for the state global declarations.state_host_body_stream (
CodeIOStream
) – Device-specific code stream: contains all the code related to this state, for creating transient buffers, spawning kernels, and synchronizing them.instrumentation_stream (
CodeIOStream
) – Code for profiling kernel execution time.function_stream (
CodeIOStream
) – CPU code stream.callsite_stream (
CodeIOStream
) – CPU code stream.state_parameters (
list
) – list of state parameters. The kernel-specific parameters will be appended to it.
- Return type:
None
- generate_memlet_definition(sdfg, cfg, dfg, state_id, src_node, dst_node, edge, callsite_stream)
- generate_module(sdfg, cfg, state, kernel_name, module_name, subgraph, parameters, module_stream, host_header_stream, host_body_stream, instrumentation_stream)
- static generate_no_dependence_post(kernel_stream, sdfg, cfg, state_id, node, var_name=None, accessed_subset=None)
- static generate_no_dependence_pre(kernel_stream, sdfg, cfg, state_id, node, var_name=None)
Adds pre-loop pragma for ignoring loop carried dependencies on a given variable (if var_name is provided) or all variables
- generate_nsdfg_arguments(sdfg, cfg, dfg, state, node)
- generate_nsdfg_header(sdfg, cfg, state, state_id, node, memlet_references, sdfg_label)
- static generate_pipeline_loop_post(kernel_stream, sdfg, cfg, state_id, node)
- static generate_pipeline_loop_pre(kernel_stream, sdfg, cfg, state_id, node)
- generate_tasklet_postamble(sdfg, cfg, dfg, state_id, node, function_stream, callsite_stream, after_memlets_stream)
- generate_undefines(sdfg, cfg, dfg, node, callsite_stream)
- static generate_unroll_loop_post(kernel_stream, factor, sdfg, cfg, state_id, node)
- static generate_unroll_loop_pre(kernel_stream, factor, sdfg, cfg, state_id, node)
- 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
- get_mangled_channel_name(var_name, kernel_id)
Returns the mangled name of a channel if it is a global channel, or var_name if it is an alias (generated through #define)
- language = 'hls'
- make_kernel_argument(data, var_name, is_output, with_vectorization)
- make_ptr_vector_cast(dst_expr, dst_dtype, src_dtype, is_scalar, defined_type)
Cast a destination pointer so the source expression can be written to it.
- Parameters:
dst_expr – Expression of the target pointer.
dst_dtype – Type of the target pointer.
src_dtype – Type of the variable that needs to be written.
is_scalar – Whether the variable to be written is a scalar.
defined_type – The code generated variable type of the destination.
- make_read(defined_type, dtype, var_name, expr, index, is_pack, packing_factor)
- make_shift_register_write(defined_type, dtype, var_name, write_expr, index, read_expr, wcr, is_unpack, packing_factor, sdfg)
- static make_vector_type(dtype, is_const)
- make_write(defined_type, dtype, var_name, write_expr, index, read_expr, wcr, is_unpack, packing_factor)
Creates write expression, taking into account wcr if present
- process_out_memlets(sdfg, cfg, state_id, node, dfg, dispatcher, result, locals_defined, function_stream, **kwargs)
- target_name = 'intel_fpga'
- title = 'Intel FPGA'
- unparse_tasklet(sdfg, cfg, state_id, dfg, node, function_stream, callsite_stream, locals, ldepth, toplevel_schedule)
- Return type:
str
- write_and_resolve_expr(sdfg, memlet, nc, outname, inname, indices=None, dtype=None)
- class dace.codegen.targets.intel_fpga.OpenCLDaceKeywordRemover(sdfg, defined_vars, memlets, codegen)
Bases:
DaCeKeywordRemover
Removes Dace Keywords and enforces OpenCL compliance
- ctypes = ['bool', 'char', 'cl_char', 'unsigned char', 'uchar', 'cl_uchar', 'short', 'cl_short', 'unsigned short', 'ushort', 'int', 'unsigned int', 'uint', 'long', 'unsigned long', 'ulong', 'float', 'half', 'size_t', 'ptrdiff_t', 'intptr_t', 'uintptr_t', 'void', 'double']
- nptypes = ['float64', 'float32', 'int32', 'int64']
- nptypes_to_ctypes = {'float32': 'float', 'float64': 'double', 'int32': 'int', 'int64': 'long'}
- visit_Assign(node)
- visit_Attribute(node)
- visit_BinOp(node)
- visit_Call(node)
- visit_Name(node)