Пример #1
0
 def compile(output_dir, file_paths, out):
     res = subprocess.check_output([
         compiler, '-I' + output_dir, file_paths, '-lopencv_core',
         '-lopencv_imgproc', "-o", out, '-Wno-deprecated-gpu-targets'
     ],
                                   stderr=subprocess.STDOUT)
     helper.print_out(res)
Пример #2
0
    def java(self, line, cell):
        args = line.split()

        if '-v' in args or '--version' in args:
            self.run_version()
            return

        line = cell.split("\n")

        name_file = "Main"
        for l in line:
            if l:
                if "public class " in l:
                    name_file = l.replace("public class ","").replace("{","").replace(" ","")
                    break

        file_path = name_file
        #print(file_path)
        #print(cell)
        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.compile(file_path, args)
            self.run_java(file_path)
        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #3
0
 def compile(output_dir, file_paths, out, compiler=DEFAULT_COMPILER):
     res = subprocess.check_output([
         compiler, '-I' + output_dir, file_paths, "-o", out,
         '-Wno-deprecated-gpu-targets'
     ],
                                   stderr=subprocess.STDOUT)
     helper.print_out(res)
Пример #4
0
 def compile(file_path):
     args = [
         compiler, file_path + ext, "-o", file_path + ".out",
         '-Wno-deprecated-gpu-targets'
     ]
     helper.print_out(args)
     subprocess.check_output(args, stderr=subprocess.STDOUT)
Пример #5
0
    def nv_nsight(self, line, cell):
        try:
            args = self.argparser.parse_args(line.split())
        except SystemExit as e:
            self.argparser.print_help()
            return

        with tempfile.TemporaryDirectory() as tmp_dir:
            file_path = os.path.join(tmp_dir, str(uuid.uuid4()))
            with open(file_path + ext, "w") as f:
                f.write(cell)
            try:
                compile_args = []
                if args.compile_custom:
                    compile_args = input(
                        "Please provide custom compile arguments: ").split()
                self.compile(file_path, compile_args)
                args_custom = []
                if args.custom:
                    args_custom = args.custom
                output = self.nsight_run(file_path,
                                         timeit=args.timeit,
                                         custom_commands=args_custom)
            except subprocess.CalledProcessError as e:
                helper.print_out(e.output.decode("utf8"))
                output = None
        return output
Пример #6
0
    def cuda(self, line='', cell=None):
        args = parse_argstring(self.cuda, line)
        ex = args.name.split('.')[-1]
        if ex not in ['cu', 'h']:
            raise Exception('name must end with .cu or .h')

        if not os.path.exists(self.output_dir):
            print(f'Output directory does not exist, creating')
            try:
                os.mkdir(self.output_dir)
            except OSError:
                print(f"Creation of the directory {self.output_dir} failed")
            else:
                print(f"Successfully created the directory {self.output_dir}")

        file_path = os.path.join(self.output_dir, args.name)
        with open(file_path, "w") as f:
            f.write(cell)

        if args.compile:
            try:
                self.compile(self.output_dir,
                             file_path,
                             self.out,
                             compiler=args.path)
                output = self.run(timeit=args.timeit)
            except subprocess.CalledProcessError as e:
                helper.print_out(e.output.decode("utf8"))
                output = None
        else:
            output = f'File written in {file_path}'

        return output
Пример #7
0
    def run_gcc(self, file_path):
        args = [file_path + ".out", "< 10"]

        output = subprocess.check_output(args, stderr=subprocess.STDOUT)
        output = output.decode('utf8')

        helper.print_out(output)
Пример #8
0
    def run_cpp(self, file_path):

        output = subprocess.check_output([file_path + ".out", "< 10"],
                                         stderr=subprocess.STDOUT)
        output = output.decode('utf8')

        helper.print_out(output)
Пример #9
0
    def rangecachegrind(self, line, cell):

        if not self.already_install:
            self.already_install = True
            self.updateInstall()

        datacache = [4]
        ways = [2]
        lines = [32]
        bargraph = ['misses', 'miss_rate']

        line = line.strip().replace(" ", "").split(";")

        for l in line:
            if 'datacache' in l:
                datacache = []
                l = l.replace('datacache=',
                              '').replace('(', '').replace(')', '').split(',')
                for d in l:
                    datacache.append(int(d))
            elif 'ways' in l:
                ways = []
                l = l.replace('ways=',
                              '').replace('(', '').replace(')', '').split(',')
                for d in l:
                    ways.append(int(d))
            elif 'line' in l:
                lines = []
                l = l.replace('line=',
                              '').replace('(', '').replace(')', '').split(',')
                for d in l:
                    lines.append(int(d))
            elif 'bargraph' in l:
                bargraph = []
                l = l.replace('bargraph=',
                              '').replace('(', '').replace(')', '').split(',')
                for d in l:
                    bargraph.append(d)

        file_path = '/content/valgrind_code'

        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.run_cpp(file_path)

            results = {}
            for b in bargraph:
                results[b] = []

            for i in range(len(datacache)):
                for j in range(len(ways)):
                    for k in range(len(lines)):
                        args = [datacache[i], ways[j], lines[k]]
                        self.exec_range_cache(args, results)
            self.print_bar(datacache, results)

        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #10
0
    def run_cpp(self, file_path):

        self.compile(file_path)
        args = [file_path + ".out"]

        output = subprocess.check_output(args, stderr=subprocess.STDOUT)
        output = output.decode('utf8')

        helper.print_out(output)
Пример #11
0
    def run_yosys(self, file_path):
        args = [yosys_run, "-Q", "-T", "-q", "-s", script_run]

        output = subprocess.check_output(args, stderr=subprocess.STDOUT)
        output = output.decode('utf8')
        helper.print_out(output)

        # Printer dot
        display(Image(filename="/content/code.png"))
Пример #12
0
    def print_verilog(self, line, cell):
        args = line.split()

        file_path = os.path.join('/content/code')
        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.run_yosys(file_path)
        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #13
0
 def cpp(self, line, cell):
     args = line.split()
     with tempfile.TemporaryDirectory() as tmp_dir:
         file_path = os.path.join(tmp_dir, str(uuid.uuid4()))
         with open(file_path + ext, "w") as f:
             f.write(cell)
         try:
             self.compile(file_path, args)
             self.run_cpp(file_path)
         except subprocess.CalledProcessError as e:
             helper.print_out(e.output.decode("utf8"))
Пример #14
0
    def ptx(self, line='', cell=None):
        args = line.split()

        file_path = os.path.join('/content/code')
        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.compile_ptx(file_path, args)
            self.run_ptx(file_path)
        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #15
0
 def run(self, file_path, timeit=False):
     if timeit:
         stmt = f"subprocess.check_output(['{file_path}.out'], stderr=subprocess.STDOUT)"
         output = self.shell.run_cell_magic(
             magic_name="timeit", line="-q -o import subprocess", cell=stmt)
     else:
         output = subprocess.check_output(
             [file_path + ".out"], stderr=subprocess.STDOUT)
         output = output.decode('utf8')
         
     helper.print_out(output)
     return None
Пример #16
0
    def gem5(self, line, cell):
        if not self.already_install:
            self.already_install = True
            self.updateInstall()
        args = line.split()

        file_path = '/content/gem5_code'

        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.run_gem5(file_path, args)
        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #17
0
    def instructioncache(self, line, cell):
        if not self.already_install:
            self.already_install = True
            self.updateInstall()

        file_path = '/content/valgrind_code'

        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.run_cpp(file_path)
            self.create_visual('inst')
        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #18
0
    def run_nvprof(self, file_path, flags):

        if len(flags) == 0:
            args = ["nvprof", file_path + ".out"]
        else:
            flag = ""
            for f in flags:
                flag += " -m " + f

            args = ["sh", "/content/cad4u/nvcc/metric.sh", flag]

        output = subprocess.check_output(args, stderr=subprocess.STDOUT)
        output = output.decode('utf8')
        helper.print_out(output)
Пример #19
0
    def verilog(self, line, cell):

        if not self.already_install:
            self.already_install = True
            self.updateInstall()

        args = line.split()

        with tempfile.TemporaryDirectory() as tmp_dir:
            file_path = os.path.join(tmp_dir, str(uuid.uuid4()))
            with open(file_path + ext, "w") as f:
                f.write(cell)
            try:
                self.compile(file_path, args)
                self.run_verilog(file_path)
            except subprocess.CalledProcessError as e:
                helper.print_out(e.output.decode("utf8"))
Пример #20
0
    def nvprof(self, line, cell):
        try:
            args = self.argparser.parse_args(line.split())
        except SystemExit as e:
            self.argparser.print_help()
            return

        with tempfile.TemporaryDirectory() as tmp_dir:
            file_path = os.path.join(tmp_dir, str(uuid.uuid4()))
            with open(file_path + ext, "w") as f:
                f.write(cell)
            try:
                self.compile(file_path)
                output = self.nvprof_run(file_path, timeit=args.timeit)
            except subprocess.CalledProcessError as e:
                helper.print_out(e.output.decode("utf8"))
                output = None
        return output
Пример #21
0
    def nsight_run(self, file_path, timeit=False, custom_commands=[]):
        if timeit:
            stmt = f"subprocess.check_output(['{nsight_excutable}',] + [" + ", ".join(
                custom_commands
            ) + f"] + ['{file_path}.out'], stderr=subprocess.STDOUT)"
            print(stmt)
            output = self.shell.run_cell_magic(magic_name="timeit",
                                               line="-q -o import subprocess",
                                               cell=stmt)
        else:
            output = subprocess.check_output([
                nsight_excutable,
            ] + custom_commands + [
                file_path + ".out",
            ],
                                             stderr=subprocess.STDOUT)
            output = output.decode('utf8')

        helper.print_out(output)
        return None
Пример #22
0
    def cuda_run(self, line='', cell=None):
        try:
            args = self.argparser.parse_args(line.split())
        except SystemExit:
            self.argparser.print_help()
            return

        try:
            cuda_src = os.listdir(self.output_dir)
            cuda_src = [
                os.path.join(self.output_dir, x) for x in cuda_src
                if x[-3:] == '.cu'
            ]
            print(f'found sources: {cuda_src}')
            self.compile(self.output_dir, ' '.join(cuda_src), self.out)
            output = self.run(timeit=args.timeit)
        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
            output = None

        return output
Пример #23
0
    def cachegrind(self, line, cell):

        if not self.already_install:
            self.already_install = True
            self.updateInstall()

        print_file = False
        if '--file' in line:
            line.replace("--file", "")
            print_file = True

        args = line.split()

        file_path = '/content/valgrind_code'

        with open(file_path + ext, "w") as f:
            f.write(cell)
        try:
            self.run_cpp(file_path)
            self.executeValgrind(args, print_file)

        except subprocess.CalledProcessError as e:
            helper.print_out(e.output.decode("utf8"))
Пример #24
0
 def execution(self, args):
     output = subprocess.check_output(args, stderr=subprocess.STDOUT)
     output = output.decode('utf8')
     helper.print_out(output)
Пример #25
0
 def run_ptx(self, file_path):
     args = ["cat", file_path + ".ptx"]
     output = subprocess.check_output(args, stderr=subprocess.STDOUT)
     output = output.decode('utf8')
     helper.print_out(output)
Пример #26
0
 def run_nvprof_all_metrics(self, file_path):
     args = ["nvprof", "--metrics", "all", file_path + ".out"]
     output = subprocess.check_output(args, stderr=subprocess.STDOUT)
     output = output.decode('utf8')
     helper.print_out(output)
Пример #27
0
 def run_version(self):
     args = ['java', '--version']
     output = subprocess.check_output(args, stderr=subprocess.STDOUT)
     output = output.decode('utf8')
     helper.print_out(output)
Пример #28
0
 def run_java(self, file_path):
     
     output = subprocess.check_output(["java", file_path], stderr=subprocess.STDOUT)
     output = output.decode('utf8')
         
     helper.print_out(output)