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
set_hidden_loads(kernel)[source]

Hide loads behind stores if architecture supports hidden loads (depricated)

assign_tp_lt(instruction_form)[source]

Assign throughput and latency to an instruction form.

substitute_mem_address(operands)[source]

Create memory wildcard for all memory operands

convert_op_to_reg(reg_type, reg_id='0')[source]

Create register operand for a memory addressing operand

static get_throughput_sum(kernel)[source]

Get the overall throughput sum separated by port of all instructions of a kernel.

osaca.semantics.hw_model module

class MachineModel(arch=None, path_to_yaml=None, isa=None, lazy=False)[source]

Bases: object

WILDCARD = '*'
get_instruction(name, operands)[source]

Find and return instruction data from name and operands.

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.

set_instruction_entry(entry)[source]

Import instruction as entry object form information.

add_port(port)[source]

Add port in port model of current machine model.

get_ISA()[source]

Return ISA of MachineModel.

get_arch()[source]

Return micro-architecture code of MachineModel.

get_ports()[source]

Return port model of MachineModel.

has_hidden_loads()[source]

Return if model has hidden loads.

get_load_latency(reg_type)[source]

Return load latency for given register type.

get_load_throughput(memory)[source]

Return load thorughput for given register type.

get_store_latency(reg_type)[source]

Return store latency for given register type.

get_store_throughput(memory)[source]

Return store throughput for given register type.

get_data_ports()[source]

Return all data ports (i.e., ports with D-suffix) of current model.

static get_full_instruction_name(instruction_form)[source]

Get one instruction name string including the mnemonic and all operands.

static get_isa_for_arch(arch)[source]

Return ISA for given micro-arch arch.

dump(stream=None)[source]

Dump machine model to stream or return it as a str if no stream is given.

osaca.semantics.isa_semantics module

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'
class ISASemantics(isa, path_to_yaml=None)[source]

Bases: object

GAS_SUFFIXES = 'bswlqt'
process(instruction_forms)[source]

Process a list of instruction forms.

assign_src_dst(instruction_form)[source]

Update instruction form dictionary with source, destination and flag information.

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_critical_path()[source]

Find and return critical path after the creation of a directed graph.

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

get_dependent_instruction_forms(instr_form=None, line_number=None)[source]

Returns iterator

is_read(register, instruction_form)[source]

Check if instruction form reads from given register

is_written(register, instruction_form)[source]

Check if instruction form writes in given register

export_graph(filepath=None)[source]

Export graph with highlighted CP and LCDs as DOT file. Writes it to ‘osaca_dg.dot’ if no other path is given.

Parameters:filepath (str, optional) – path to write DOT file, defaults to None.

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
get_marker(isa, comment='')[source]

Return tuple of start and end marker lines.

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

match_bytes(lines, index, byte_list)[source]

Match bytes directives of markers

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
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
find_basic_loop_bodies(lines)[source]

Find and return basic loop bodies (asm section which loop back on itself with no other egress).

Returns:OrderedDict with labels as keys and list of lines as value

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(name, operands)[source]

Find and return instruction data from name and operands.

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.

set_instruction_entry(entry)[source]

Import instruction as entry object form information.

add_port(port)[source]

Add port in port model of current machine model.

get_ISA()[source]

Return ISA of MachineModel.

get_arch()[source]

Return micro-architecture code of MachineModel.

get_ports()[source]

Return port model of MachineModel.

has_hidden_loads()[source]

Return if model has hidden loads.

get_load_latency(reg_type)[source]

Return load latency for given register type.

get_load_throughput(memory)[source]

Return load thorughput for given register type.

get_store_latency(reg_type)[source]

Return store latency for given register type.

get_store_throughput(memory)[source]

Return store throughput for given register type.

get_data_ports()[source]

Return all data ports (i.e., ports with D-suffix) of current model.

static get_full_instruction_name(instruction_form)[source]

Get one instruction name string including the mnemonic and all operands.

static get_isa_for_arch(arch)[source]

Return ISA for given micro-arch arch.

dump(stream=None)[source]

Dump machine model to stream or return it as a str if no stream is given.

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_critical_path()[source]

Find and return critical path after the creation of a directed graph.

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

get_dependent_instruction_forms(instr_form=None, line_number=None)[source]

Returns iterator

is_read(register, instruction_form)[source]

Check if instruction form reads from given register

is_written(register, instruction_form)[source]

Check if instruction form writes in given register

export_graph(filepath=None)[source]

Export graph with highlighted CP and LCDs as DOT file. Writes it to ‘osaca_dg.dot’ if no other path is given.

Parameters:filepath (str, optional) – path to write DOT file, defaults to None.
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
set_hidden_loads(kernel)[source]

Hide loads behind stores if architecture supports hidden loads (depricated)

assign_tp_lt(instruction_form)[source]

Assign throughput and latency to an instruction form.

substitute_mem_address(operands)[source]

Create memory wildcard for all memory operands

convert_op_to_reg(reg_type, reg_id='0')[source]

Create register operand for a memory addressing operand

static get_throughput_sum(kernel)[source]

Get the overall throughput sum separated by port of all instructions of a kernel.

class ISASemantics(isa, path_to_yaml=None)[source]

Bases: object

GAS_SUFFIXES = 'bswlqt'
process(instruction_forms)[source]

Process a list of instruction forms.

assign_src_dst(instruction_form)[source]

Update instruction form dictionary with source, destination and flag information.

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
find_basic_loop_bodies(lines)[source]

Find and return basic loop bodies (asm section which loop back on itself with no other egress).

Returns:OrderedDict with labels as keys and list of lines as value
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