dace.codegen.instrumentation package
Submodules
dace.codegen.instrumentation.fpga module
- class dace.codegen.instrumentation.fpga.FPGAInstrumentationProvider
Bases:
InstrumentationProvider
Dummy provider to register the instrumentation type.
dace.codegen.instrumentation.gpu_events module
- class dace.codegen.instrumentation.gpu_events.GPUEventProvider
Bases:
InstrumentationProvider
Timing instrumentation that reports GPU/copy time using CUDA/HIP events.
- on_node_begin(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_node_end(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_scope_entry(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of a scope (on generating an EntryNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The EntryNode object from which code is generated.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_scope_exit(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of a scope (on generating an ExitNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The ExitNode object from which code is generated.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_sdfg_begin(sdfg, local_stream, global_stream, codegen)
Event called at the beginning of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
codegen – An instance of the code generator.
- on_state_begin(sdfg, state, local_stream, global_stream)
Event called at the beginning of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_state_end(sdfg, state, local_stream, global_stream)
Event called at the end of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
dace.codegen.instrumentation.papi module
Implements the PAPI counter performance instrumentation provider. Used for collecting CPU performance counters.
- class dace.codegen.instrumentation.papi.PAPIInstrumentation
Bases:
InstrumentationProvider
Instrumentation provider that reports CPU performance counters using the PAPI library.
- configure_papi()
- get_unique_number()
- static has_surrounding_perfcounters(node, dfg)
Returns true if there is a possibility that this node is part of a section that is profiled.
- on_consume_entry(sdfg, state, node, outer_stream, inner_stream)
- on_copy_begin(sdfg, state, src_node, dst_node, edge, local_stream, global_stream, copy_shape, src_strides, dst_strides)
Event called at the beginning of generating a copy operation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
src_node – The source node of the copy.
dst_node – The destination node of the copy.
edge – An edge in the memlet path of the copy.
local_stream – Code generator for the internal code.
global_stream – Code generator for global (external) code.
copy_shape – Tuple representing the shape of the copy.
src_strides – Element-skipping strides for each dimension of the copied source.
dst_strides – Element-skipping strides for each dimension of the copied destination.
- on_copy_end(sdfg, state, src_node, dst_node, edge, local_stream, global_stream)
Event called at the end of generating a copy operation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
src_node – The source node of the copy.
dst_node – The destination node of the copy.
edge – An edge in the memlet path of the copy.
local_stream – Code generator for the internal code.
global_stream – Code generator for global (external) code.
- on_map_entry(sdfg, state, node, outer_stream, inner_stream)
- on_node_begin(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_node_end(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_scope_entry(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of a scope (on generating an EntryNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The EntryNode object from which code is generated.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_scope_exit(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of a scope (on generating an ExitNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The ExitNode object from which code is generated.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_sdfg_begin(sdfg, local_stream, global_stream, codegen)
Event called at the beginning of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
codegen – An instance of the code generator.
- on_sdfg_end(sdfg, local_stream, global_stream)
Event called at the end of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_state_begin(sdfg, state, local_stream, global_stream)
Event called at the beginning of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- static perf_counter_end_measurement_string(unified_id)
- perf_counter_start_measurement_string(unified_id, iteration, core_str='PAPI_thread_id()')
- perf_counter_string()
Creates a performance counter template string.
- static perf_counter_string_from_string_list(counterlist)
Creates a performance counter typename string.
- static perf_get_supersection_start_string(node, dfg, unified_id)
- static perf_section_start_string(unified_id, size, in_size, core_str='PAPI_thread_id()')
- static perf_supersection_start_string(unified_id)
- perf_whitelist_schedules = [<ScheduleType.CPU_Multicore: 4>, <ScheduleType.CPU_Persistent: 5>, <ScheduleType.Sequential: 2>]
- static should_instrument_entry(map_entry)
Returns True if this entry node should be instrumented.
- Return type:
bool
- class dace.codegen.instrumentation.papi.PAPIUtils
Bases:
object
General-purpose utilities for working with PAPI.
- static accumulate_byte_movement(outermost_node, node, dfg, sdfg, state_id)
- static all_maps(map_entry, dfg)
Returns all scope entry nodes within a scope entry.
- Return type:
List
[EntryNode
]
- static available_counters()
Returns the available PAPI counters on this machine. Only works on *nix based systems with
grep
andpapi-tools
installed.- Return type:
Dict
[str
,int
]- Returns:
A set of available PAPI counters in the form of a dictionary mapping from counter name to the number of native hardware events.
- static get_iteration_count(map_entry, mapvars)
Get the number of iterations for this map, allowing other variables as bounds.
- static get_memlet_byte_size(sdfg, memlet)
Returns the memlet size in bytes, depending on its data type.
- static get_memory_input_size(node, sdfg, state_id)
- Return type:
str
- static get_out_memlet_costs(sdfg, state_id, node, dfg)
- static get_tasklet_byte_accesses(tasklet, dfg, sdfg, state_id)
Get the amount of bytes processed by tasklet. The formula is sum(inedges * size) + sum(outedges * size)
- Return type:
str
- static is_papi_used(sdfg)
Returns True if any of the SDFG elements includes PAPI counter instrumentation.
- Return type:
bool
- static reduce_iteration_count(begin, end, step, rparams)
dace.codegen.instrumentation.provider module
- class dace.codegen.instrumentation.provider.InstrumentationProvider
Bases:
object
Instrumentation provider for SDFGs, states, scopes, and memlets. Emits code on event.
- extensions()
- static get_provider_mapping()
Returns a dictionary that maps instrumentation types to provider class types, given the currently-registered extensions of this class.
- Return type:
Dict
[Union
[InstrumentationType
,DataInstrumentationType
],Type
[InstrumentationProvider
]]
- on_copy_begin(sdfg, state, src_node, dst_node, edge, local_stream, global_stream, copy_shape, src_strides, dst_strides)
Event called at the beginning of generating a copy operation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
src_node – The source node of the copy.
dst_node – The destination node of the copy.
edge – An edge in the memlet path of the copy.
local_stream – Code generator for the internal code.
global_stream – Code generator for global (external) code.
copy_shape – Tuple representing the shape of the copy.
src_strides – Element-skipping strides for each dimension of the copied source.
dst_strides – Element-skipping strides for each dimension of the copied destination.
- on_copy_end(sdfg, state, src_node, dst_node, edge, local_stream, global_stream)
Event called at the end of generating a copy operation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
src_node – The source node of the copy.
dst_node – The destination node of the copy.
edge – An edge in the memlet path of the copy.
local_stream – Code generator for the internal code.
global_stream – Code generator for global (external) code.
- on_node_begin(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_node_end(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_scope_entry(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of a scope (on generating an EntryNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The EntryNode object from which code is generated.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_scope_exit(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of a scope (on generating an ExitNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The ExitNode object from which code is generated.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_sdfg_begin(sdfg, local_stream, global_stream, codegen)
Event called at the beginning of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
codegen – An instance of the code generator.
- on_sdfg_end(sdfg, local_stream, global_stream)
Event called at the end of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_state_begin(sdfg, state, local_stream, global_stream)
Event called at the beginning of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_state_end(sdfg, state, local_stream, global_stream)
Event called at the end of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- register(**kwargs)
- unregister()
dace.codegen.instrumentation.report module
Implementation of the performance instrumentation report.
- class dace.codegen.instrumentation.report.CounterEvent(name, category, uuid, timestamp, counters, pid, tid=-1)
Bases:
object
Instrumentation report event of a counter (e.g., performance counters).
-
category:
str
Category
-
counters:
Dict
[str
,float
] Counter names and their values
-
name:
str
Event name
-
pid:
int
Process ID
- save()
- Return type:
Dict
[str
,Any
]
-
tid:
int
= -1 Thread ID (or -1 if not applicable)
-
timestamp:
int
Event time (in microseconds)
-
uuid:
Tuple
[int
,int
,int
] Unique locator for SDFG/state/node/edge
-
category:
- class dace.codegen.instrumentation.report.DurationEvent(name, category, uuid, timestamp, duration, pid, tid=-1, additional_info=None)
Bases:
object
Instrumentation report event of a duration (e.g., execution time).
-
additional_info:
Optional
[Dict
[str
,Any
]] = None More arguments in the event
-
category:
str
Category
-
duration:
float
Duration (in microseconds)
-
name:
str
Event name
-
pid:
int
Process ID
- save()
- Return type:
Dict
[str
,Any
]
-
tid:
int
= -1 Thread ID (or -1 if not applicable)
-
timestamp:
int
Beginning time (in microseconds)
-
uuid:
Tuple
[int
,int
,int
] Unique locator for SDFG/state/node/edge
-
additional_info:
- class dace.codegen.instrumentation.report.InstrumentationReport(filename)
Bases:
object
An object that represents a DaCe program instrumentation report. Such reports may include runtimes of all or parts of an SDFG, as well as performance counters.
Instrumentation reports are stored as JSON files, in the Chrome Tracing format.
- as_csv()
Generates a CSV version of the report.
- Return type:
Tuple
[str
,str
]- Returns:
A tuple of two strings: (durations CSV, counters CSV).
- static get_event_uuid_and_other_info(event)
- Return type:
Tuple
[Tuple
[int
,int
,int
],Dict
[str
,Any
]]
- getkey(element)
- process_events()
Summarizes the events in the report into dictionaries.
- save(filename)
Stores an instrumentation report to a file in the Chrome Tracing JSON format.
- Parameters:
filename (
str
) – The file name to store.- Return type:
None
- sortby(column, ascending=False)
dace.codegen.instrumentation.timer module
- class dace.codegen.instrumentation.timer.TimerProvider
Bases:
InstrumentationProvider
Timing instrumentation that reports wall-clock time directly after timed execution is complete.
- on_node_begin(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_node_end(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of generating a node.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The generated node.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_scope_entry(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the beginning of a scope (on generating an EntryNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The EntryNode object from which code is generated.
outer_stream – Code generator for the internal code before the scope is opened.
inner_stream – Code generator for the internal code within the scope (at the beginning).
global_stream – Code generator for global (external) code.
- on_scope_exit(sdfg, state, node, outer_stream, inner_stream, global_stream)
Event called at the end of a scope (on generating an ExitNode).
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
node – The ExitNode object from which code is generated.
outer_stream – Code generator for the internal code after the scope is closed.
inner_stream – Code generator for the internal code within the scope (at the end).
global_stream – Code generator for global (external) code.
- on_sdfg_begin(sdfg, local_stream, global_stream, codegen)
Event called at the beginning of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
codegen – An instance of the code generator.
- on_sdfg_end(sdfg, local_stream, global_stream)
Event called at the end of SDFG code generation.
- Parameters:
sdfg – The generated SDFG object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_state_begin(sdfg, state, local_stream, global_stream)
Event called at the beginning of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_state_end(sdfg, state, local_stream, global_stream)
Event called at the end of SDFG state code generation.
- Parameters:
sdfg – The generated SDFG object.
state – The generated SDFGState object.
local_stream – Code generator for the in-function code.
global_stream – Code generator for global (external) code.
- on_tbegin(stream, sdfg=None, state=None, node=None)
- on_tend(timer_name, stream, sdfg=None, state=None, node=None)
dace.codegen.instrumentation.data module
- class dace.codegen.instrumentation.data.data_report.InstrumentedDataReport(sdfg, folder)
Bases:
object
Instrumented data reports are folders saved by the Save data instrumentation provider. Their goal is to represent a set of data contents for completely reproducing a run of an SDFG. This can be used to create consistent inputs for benchmarking, or for retrieving intermediate data automatically for correctness checking / data debugging.
The folder structure of a data report is as follows: /path/to/report/<array or symbol name>/<uuid>_<version>.bin where <array or symbol name> is the array or symbol in the SDFG, <uuid> is a unique identifier to the access node (or state for symbols) from which this array or symbol was saved, and <version> is a running number for the currently-saved array or symbol (e.g., when an access node is written to multiple times in a loop).
The files themselves are direct binary representations of the whole data (with padding and strides), for complete reproducibility. When accessed from the report, a numpy wrapper shows the user-accessible view of that array. Example of reading a file:
dreport = sdfg.get_instrumented_data() # returns a report print(dreport.keys()) # will print 'A', 'versioned' array = dreport['A'] # return value is a single array if there is only one version varrays = dreport['versioned'] # otherwise, return value is a sorted list of versions # after loading, arrays can be used normally with numpy assert np.allclose(array, real_A) for arr in varrays: print(arr[5, :])
- Seealso:
dace.dtypes.DataInstrumentationType.Save
- Seealso:
dace.dtypes.DataInstrumentationType.Restore
-
files:
Dict
[str
,List
[str
]]
-
folder:
str
- get_first_version(item)
Returns the first version of the instrumented (saved) data from the report according to the data descriptor (array) or symbol name.
- Parameters:
item (
str
) – Name of the array or symbol to read.- Return type:
Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]],Number
]- Returns:
The array or symbol value from the report.
- keys()
Returns the array names available in this data report.
- Return type:
Set
[str
]
-
loaded_values:
Dict
[Tuple
[str
,int
],Union
[_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,int
,float
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]],Number
]]
- update_report()
Stores the retrieved arrays from the report back to the files. Can be used to modify data that will be loaded when restoring a data instrumentation report.
- See:
dace.dtypes.DataInstrumentationType.Restore