osaca.semantics package¶
Semantic part of OSACA.
osaca.semantics.arch_semantics module¶
Semantics opbject responsible for architecture specific semantic operations
-
class
ArchSemantics
(machine_model: osaca.semantics.hw_model.MachineModel, path_to_yaml=None)[source]¶ Bases:
osaca.semantics.isa_semantics.ISASemantics
-
GAS_SUFFIXES
= 'bswlqt'¶
-
add_semantics
(kernel)[source]¶ Applies performance data (throughput, latency, port pressure) and source/destination distribution to each instruction of a given kernel.
Parameters: kernel (list) – kernel to apply semantics
-
assign_optimal_throughput
(kernel)[source]¶ Assign optimal throughput port pressure to a kernel. This is done in steps of
0.01cy
.Parameters: kernel (list) – kernel to apply optimal port utilization
Hide loads behind stores if architecture supports hidden loads (depricated)
-
osaca.semantics.hw_model module¶
-
class
MachineModel
(arch=None, path_to_yaml=None, isa=None, lazy=False)[source]¶ Bases:
object
-
WILDCARD
= '*'¶
-
get_instruction_from_dict
(name, operands)[source]¶ Find and return instruction data from name and operands stored in dictionary.
-
average_port_pressure
(port_pressure)[source]¶ Construct average port pressure list from instruction data.
-
set_instruction
(name, operands=None, latency=None, port_pressure=None, throughput=None, uops=None)[source]¶ Import instruction form information.
-
get_ISA
()[source]¶ Return ISA of
MachineModel
.
-
get_arch
()[source]¶ Return micro-architecture code of
MachineModel
.
-
get_ports
()[source]¶ Return port model of
MachineModel
.
Return if model has hidden loads.
-
osaca.semantics.isa_semantics module¶
osaca.semantics.kernel_dg module¶
-
class
KernelDG
(parsed_kernel, parser, hw_model: osaca.semantics.hw_model.MachineModel)[source]¶ Bases:
networkx.classes.digraph.DiGraph
-
create_DG
(kernel)[source]¶ Create directed graph from given kernel
Parameters: kernel – Parsed asm kernel with assigned semantic information Returns: DiGraph
– directed graph object
-
check_for_loopcarried_dep
(kernel)[source]¶ Try to find loop-carried dependencies in given kernel.
Parameters: kernel (list) – Parsed asm kernel with assigned semantic information Returns: dict – dependency dictionary with all cyclic LCDs
-
get_loopcarried_dependencies
()[source]¶ Return all LCDs from kernel (after
check_for_loopcarried_dep()
was run)
-
find_depending
(instruction_form, kernel, include_write=False, flag_dependencies=False)[source]¶ Find instructions in kernel depending on a given instruction form.
Parameters: - instruction_form (dict) – instruction form to check for dependencies
- kernel (list) – kernel containing the instructions to check
- include_write (boolean, optional) – indicating if instruction ending the dependency chain should be included, defaults to False
- flag_dependencies (boolean, optional) – indicating if dependencies of flags should be considered, defaults to False
Returns: iterator if all directly dependent instruction forms
-
osaca.semantics.marker_utils module¶
-
reduce_to_section
(kernel, isa)[source]¶ Finds OSACA markers in given kernel and returns marked section
Parameters: - kernel (list) – kernel to check
- isa (str) – ISA of given kernel
Returns: list – marked section of kernel as list of instruction forms
-
find_marked_kernel_AArch64
(lines)[source]¶ Find marked section for AArch64
Parameters: lines (list) – kernel Returns: tuple of int – start and end line of marked section
-
find_marked_kernel_x86ATT
(lines)[source]¶ Find marked section for x86
Parameters: lines (list) – kernel Returns: tuple of int – start and end line of marked section
-
find_marked_section
(lines, parser, mov_instr, mov_reg, mov_vals, nop_bytes, reverse=False, comments=None)[source]¶ Return indexes of marked section
Parameters: - lines (list) – kernel
- parser (
BaseParser
) – parser to use for checking - mov_instr (list of str) – all MOV instruction possible for the marker
- mov_reg (str) – register used for the marker
- mov_vals (list of int) – values needed to be moved to
mov_reg
for valid marker - nop_bytes (list of int) – bytes representing opcode of NOP
- reverse (boolean, optional) – indicating if ISA syntax requires reverse operand order, defaults to False
- comments (dict, optional) – dictionary with start and end markers in comment format, defaults to None
Returns: tuple of int – start and end line of marked section
-
find_jump_labels
(lines)[source]¶ Find and return all labels which are followed by instructions until the next label
Returns: OrderedDict of mapping from label name to associated line index
Module contents¶
Tools for semantic analysis of parser result.
Only the classes below will be exported, so please add new semantic tools to __all__.
-
class
MachineModel
(arch=None, path_to_yaml=None, isa=None, lazy=False)[source]¶ Bases:
object
-
WILDCARD
= '*'¶
-
get_instruction_from_dict
(name, operands)[source]¶ Find and return instruction data from name and operands stored in dictionary.
-
average_port_pressure
(port_pressure)[source]¶ Construct average port pressure list from instruction data.
-
set_instruction
(name, operands=None, latency=None, port_pressure=None, throughput=None, uops=None)[source]¶ Import instruction form information.
-
get_ISA
()[source]¶ Return ISA of
MachineModel
.
-
get_arch
()[source]¶ Return micro-architecture code of
MachineModel
.
-
get_ports
()[source]¶ Return port model of
MachineModel
.
Return if model has hidden loads.
-
-
class
KernelDG
(parsed_kernel, parser, hw_model: osaca.semantics.hw_model.MachineModel)[source]¶ Bases:
networkx.classes.digraph.DiGraph
-
create_DG
(kernel)[source]¶ Create directed graph from given kernel
Parameters: kernel – Parsed asm kernel with assigned semantic information Returns: DiGraph
– directed graph object
-
check_for_loopcarried_dep
(kernel)[source]¶ Try to find loop-carried dependencies in given kernel.
Parameters: kernel (list) – Parsed asm kernel with assigned semantic information Returns: dict – dependency dictionary with all cyclic LCDs
-
get_loopcarried_dependencies
()[source]¶ Return all LCDs from kernel (after
check_for_loopcarried_dep()
was run)
-
find_depending
(instruction_form, kernel, include_write=False, flag_dependencies=False)[source]¶ Find instructions in kernel depending on a given instruction form.
Parameters: - instruction_form (dict) – instruction form to check for dependencies
- kernel (list) – kernel containing the instructions to check
- include_write (boolean, optional) – indicating if instruction ending the dependency chain should be included, defaults to False
- flag_dependencies (boolean, optional) – indicating if dependencies of flags should be considered, defaults to False
Returns: iterator if all directly dependent instruction forms
-
-
reduce_to_section
(kernel, isa)[source]¶ Finds OSACA markers in given kernel and returns marked section
Parameters: - kernel (list) – kernel to check
- isa (str) – ISA of given kernel
Returns: list – marked section of kernel as list of instruction forms
-
class
ArchSemantics
(machine_model: osaca.semantics.hw_model.MachineModel, path_to_yaml=None)[source]¶ Bases:
osaca.semantics.isa_semantics.ISASemantics
-
GAS_SUFFIXES
= 'bswlqt'¶
-
add_semantics
(kernel)[source]¶ Applies performance data (throughput, latency, port pressure) and source/destination distribution to each instruction of a given kernel.
Parameters: kernel (list) – kernel to apply semantics
-
assign_optimal_throughput
(kernel)[source]¶ Assign optimal throughput port pressure to a kernel. This is done in steps of
0.01cy
.Parameters: kernel (list) – kernel to apply optimal port utilization
Hide loads behind stores if architecture supports hidden loads (depricated)
-
-
class
INSTR_FLAGS
[source]¶ Bases:
object
Flags used for unknown or special instructions
-
LD
= 'is_load_instruction'¶
-
TP_UNKWN
= 'tp_unknown'¶
-
LT_UNKWN
= 'lt_unknown'¶
-
NOT_BOUND
= 'not_bound'¶
-
HIDDEN_LD
= 'hidden_load'¶
-
HAS_LD
= 'performs_load'¶
-
HAS_ST
= 'performs_store'¶
-
-
find_basic_blocks
(lines)[source]¶ Find and return basic blocks (asm sections which can only be executed as complete block).
Blocks always start at a label and end at the next jump/break possibility.
Returns: OrderedDict with labels as keys and list of lines as value