Ejemplo n.º 1
0
def insert_byte_marker(args):
    """
    Inserts byte markers into an assembly file using kerncraft.

    :param args: arguments given from :class:`~argparse.ArgumentParser` after parsing
    """
    try:
        from kerncraft.incore_model import asm_instrumentation
    except ImportError:
        print(
            'Module kerncraft not installed. Use \'pip install --user '
            'kerncraft\' for installation.\nFor more information see '
            'https://github.com/RRZE-HPC/kerncraft',
            file=sys.stderr,
        )
        sys.exit(1)

    assembly = args.file.read()
    unmarked_assembly = io.StringIO(assembly)
    marked_assembly = io.StringIO()
    asm_instrumentation(
        input_file=unmarked_assembly,
        output_file=marked_assembly,
        block_selection='manual',
        pointer_increment='auto_with_manual_fallback',
        isa=MachineModel.get_isa_for_arch(args.arch),
    )

    marked_assembly.seek(0)
    assembly = marked_assembly.read()
    with open(args.file.name, 'w') as f:
        f.write(assembly)
Ejemplo n.º 2
0
def mark(asm_path, compiler, cflags, isa, overwrite=False):
    # Mark assembly for IACA, OSACA and LLVM-MCA
    marked_asm_path = Path(asm_path).with_suffix(".marked.s")
    if not marked_asm_path.exists() or overwrite:
        overwrite = True
        with open(asm_path) as fa, open(marked_asm_path, 'w') as fm:
            try:
                _, pointer_increment = asm_instrumentation(fa, fm, isa=isa)
            except KeyboardInterrupt:
                fm.close()
                marked_asm_path.unlink()
        print(". ", end="", flush=True)
    else:
        # use maked assembly and extract asm_block and pointer_increment
        with open(marked_asm_path) as f:
            marked_asm = f.read()
        m = re.search(r'pointer_increment=([0-9]+)', marked_asm)
        if m:
            pointer_increment = int(m.group(1))
        else:
            os.unlink(marked_asm_path)
            raise ValueError(
                "Could not find `pointer_increment=<byte increment>`. Plase place into file.")
        print("! ", end="", flush=True)

    # Compile marked assembly to object for IACA
    marked_obj = Path(asm_path).with_suffix(".marked.o")
    if not marked_obj.exists():
        check_call([compiler] + ['-c', str(marked_asm_path), '-o', str(marked_obj)])
    
    return str(marked_asm_path), str(marked_obj), pointer_increment, overwrite
Ejemplo n.º 3
0
 def test_increment_detection(self):
     test_cases = [("""
         .L19:
             vmovupd	(%rcx), %ymm4
             vmovupd	32(%rcx), %ymm13
             vmovupd	64(%rcx), %ymm8
             vmovupd	96(%rcx), %ymm5
             subq	$-128, %rcx
             cmpq	%rcx, %r15
             jne	.L19
         """, 128)]
     for code, correct_increment in test_cases:
         block_lines, pointer_increment = asm_instrumentation(
             StringIO(code))
         self.assertEqual(pointer_increment, correct_increment)
Ejemplo n.º 4
0
    def test_matvec_trans(self):
        with open(self._find_file('matvec_trans.s')) as f:
            block_lines, pointer_increment = asm_instrumentation(f)

        self.assertEqual(block_lines[0]['label'], 'LBB0_30')
        self.assertEqual(pointer_increment, 64)
Ejemplo n.º 5
0
    def test_3d25pt_semi(self):
        with open(self._find_file('3d-25pt_semi.s')) as f:
            block_lines, pointer_increment = asm_instrumentation(
                f, pointer_increment=8)

        self.assertEqual(block_lines[0]['label'], 'LBB0_62')
Ejemplo n.º 6
0
    def test_2d5pt_varcoeffs(self):
        with open(self._find_file('2d-5pt-varcoeffs.s')) as f:
            block_lines, pointer_increment = asm_instrumentation(f)

        self.assertEqual(block_lines[0]['label'], '.L43')
        self.assertEqual(pointer_increment, 16)