Beispiel #1
0
def precopy(filepath, dictionary, link):
    reg = r"^<<generate_for_(?P<key>[A-Za-z0-9_]+)>>"
    m = re.match(reg, shutil2.basename(filepath))

    if m is None:
        return
    else:
        shutil2.remove(filepath)

    if m.group("key") in dictionary:
        for f in dictionary[m.group("key")]:
            if link:
                shutil2.linktree(f, shutil2.dirname(filepath))
            else:
                shutil2.copytree(f, shutil2.dirname(filepath), True)
Beispiel #2
0
def precopy(filepath, dictionary, link):
	reg = r"^<<generate_for_(?P<key>[A-Za-z0-9_]+)>>"
	m = re.match(reg, shutil2.basename(filepath))

	if m is None:
		return
	else:
		shutil2.remove(filepath)

	if m.group("key") in dictionary:
		for f in dictionary[m.group("key")]:
			if link:
				shutil2.linktree(f, shutil2.dirname(filepath))
			else:
				shutil2.copytree(f, shutil2.dirname(filepath), True)
Beispiel #3
0
def _export_hw_thread_ise_vivado(prj, hwdir, link, thread):
    ''' 
	Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project.
	
	It checks whether vhdl or hls sources shall be used and generates the hardware thread
	from the source templates. 
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	thread is the name of the hardware thread to generate
	'''
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower(
    )

    log.info("Exporting thread " + thread + " to directory '" + hwdir + "'")

    threads = [_ for _ in prj.threads if _.name == thread]
    if (len(threads) == 1):
        thread = threads[0]

        if thread.hwsource is None:
            log.info("No hardware source specified")
    else:
        log.error("Thread '" + thread + "' not found")
        return

    if thread.hwsource == "vhdl":
        dictionary = {}
        dictionary["ID"] = thread.id
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                            thread.hwsource)
        dictionary["SOURCES"] = [srcs]
        incls = shutil2.listfiles(srcs, True)
        dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            dictionary["RESOURCES"].append(d)
        dictionary["PORTS"] = thread.ports

        log.info("Generating export files ...")
        prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link)

    elif thread.hwsource == "hls":
        tmp = tempfile.TemporaryDirectory()

        dictionary = {}
        dictionary["PART"] = prj.impinfo.part
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                            thread.hwsource)
        dictionary["SOURCES"] = [srcs]
        files = shutil2.listfiles(srcs, True)
        dictionary["FILES"] = [{"File": _} for _ in files]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            d["Type"] = r.type
            d["TypeUpper"] = r.type.upper()
            dictionary["RESOURCES"].append(d)

        log.info("Generating temporary HLS project in " + tmp.name + " ...")
        prj.apply_template("thread_hls_build", dictionary, tmp.name)

        log.info("Starting Vivado HLS ...")
        if "bbd" in thread.hwoptions:
            if "vivado" in thread.hwoptions:
                subprocess.call("""
				  source /opt/Xilinx/Vivado/{1}/settings64.sh;
				  cd {0};
				  vivado_hls -f script_csynth.tcl;
				  vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;"""
                                .format(tmp.name, prj.impinfo.hls[1]),
                                shell=True,
                                executable='/bin/bash')

                dictionary = {}
                dictionary["NAME"] = thread.name.lower()
                dictionary["MEM"] = thread.mem
                dictionary["MEM_N"] = not thread.mem
                srcs = shutil2.join(tmp.name, "rt_imp.edn")
                dictionary["SOURCES"] = [srcs]
                incls = ["rt_imp.edn"]
                dictionary["INCLUDES"] = [{"File": _} for _ in incls]
            else:
                log.error("No bbd tool found")
                return

            log.info("Generating export files ...")
            prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir)

        else:
            subprocess.call("""
			  source /opt/Xilinx/Vivado/{1}/settings64.sh;
			  cd {0};
			  vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
                            shell=True,
                            executable='/bin/bash')

            dictionary = {}
            dictionary["NAME"] = thread.name.lower()
            dictionary["MEM"] = thread.mem
            dictionary["MEM_N"] = not thread.mem
            srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl")
            dictionary["SOURCES"] = [srcs]
            incls = shutil2.listfiles(srcs, True)
            dictionary["INCLUDES"] = [{
                "File": shutil2.trimext(_)
            } for _ in incls]

            log.info("Generating export files ...")
            prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir)

        shutil2.rmtree("/tmp/test")
        shutil2.mkdir("/tmp/test")
        shutil2.copytree(tmp.name, "/tmp/test")
Beispiel #4
0
 def apply_template(self, name, dictionary, output, link=False):
     shutil2.mkdir(output)
     shutil2.copytree(self.get_template(name), output, followlinks=True)
     template.generate(output, dictionary, "overwrite", link)
Beispiel #5
0
def _export_hw_thread_vivado(prj, hwdir, link, thread):
    ''' 
	Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project.
	
	It checks whether vhdl or hls sources shall be used and generates the hardware thread
	from the source templates. 
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	thread is the name of the hardware thread to generate
	'''
    hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower(
    )

    log.info("Exporting thread " + thread + " to directory '" + hwdir + "'")

    threads = [_ for _ in prj.threads if _.name == thread]
    if (len(threads) == 1):
        thread = threads[0]

        if thread.hwsource is None:
            log.info("No hardware source specified")
    else:
        log.error("Thread '" + thread + "' not found")
        return

    if thread.hwsource == "vhdl":
        dictionary = {}
        dictionary["ID"] = thread.id
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        dictionary["HWSOURCE"] = thread.hwsource

        # "reconf" thread for partial reconfiguration is taken from template directory
        if prj.impinfo.pr == "true" and thread.name.lower() == "reconf":
            srcs = shutil2.join(prj.get_template("thread_rt_reconf"),
                                thread.hwsource)
        else:
            srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                                thread.hwsource)

        dictionary["SOURCES"] = [srcs]
        incls = shutil2.listfiles(srcs, True)
        dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            dictionary["RESOURCES"].append(d)
        dictionary["PORTS"] = thread.ports

        log.info("Generating export files ...")
        prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link)

        #For each slot: Generate .prj file listing sources for PR flow
        if thread.slots[0].reconfigurable == "true":
            for _ in thread.slots:
                dictionary["SLOTID"] = _.id
                prj.apply_template("thread_prj", dictionary, hwdir, link)

    elif thread.hwsource == "hls":
        tmp = tempfile.TemporaryDirectory()

        dictionary = {}

        #Added
        dictionary["MSGINCLUDEDIR"] = ""

        msg_install_path = prj.dir + "/build.msg/install/"
        if shutil2.exists(msg_install_path):
            msg_packages = [
                f for f in listdir(msg_install_path)
                if isdir(join(msg_install_path, f))
            ]
            #print(msg_packages)
            for msg_pack in msg_packages:
                dictionary[
                    "MSGINCLUDEDIR"] += "-I" + msg_install_path + msg_pack + "/include/ "

        #End Added

        dictionary["PART"] = prj.impinfo.part
        dictionary["NAME"] = thread.name.lower()
        dictionary["MEM"] = thread.mem
        dictionary["MEM_N"] = not thread.mem
        dictionary["HWSOURCE"] = thread.hwsource
        dictionary["CLKPRD"] = min(
            [_.clock.get_periodns() for _ in thread.slots])
        # "reconf" thread for partial reconfiguration is taken from template directory
        if prj.impinfo.pr == "true" and thread.name.lower() == "reconf":
            srcs = shutil2.join(prj.get_template("thread_rt_reconf"),
                                thread.hwsource)
        else:
            srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(),
                                thread.hwsource)
        dictionary["SOURCES"] = [srcs]
        files = shutil2.listfiles(srcs, True)
        dictionary["FILES"] = [{"File": _} for _ in files]
        dictionary["RESOURCES"] = []
        for i, r in enumerate(thread.resources):
            d = {}
            d["NameUpper"] = (r.group + "_" + r.name).upper()
            d["NameLower"] = (r.group + "_" + r.name).lower()
            d["LocalId"] = i
            d["HexLocalId"] = "%08x" % i
            d["Type"] = r.type
            d["TypeUpper"] = r.type.upper()
            dictionary["RESOURCES"].append(d)

        log.info("Generating temporary HLS project in " + tmp.name + " ...")
        prj.apply_template("thread_hls_build", dictionary, tmp.name)

        log.info("Starting Vivado HLS ...")
        if "bbd" in thread.hwoptions:
            if "vivado" in thread.hwoptions:
                subprocess.call("""
				  source /opt/Xilinx/Vivado/{1}/settings64.sh;
				  cd {0};
				  vivado_hls -f script_csynth.tcl;
				  vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;"""
                                .format(tmp.name, prj.impinfo.hls[1]),
                                shell=True)

                dictionary = {}
                dictionary["NAME"] = thread.name.lower()
                dictionary["MEM"] = thread.mem
                dictionary["MEM_N"] = not thread.mem
                srcs = shutil2.join(tmp.name, "rt_imp.edn")
                dictionary["SOURCES"] = [srcs]
                incls = ["rt_imp.edn"]
                dictionary["INCLUDES"] = [{"File": _} for _ in incls]
            else:
                log.error("No bbd tool found")
                return

            log.info("Generating export files ...")
            prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir)

        else:
            subprocess.call("""
			  source /opt/Xilinx/Vivado/{1}/settings64.sh;
			  cd {0};
			  vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
                            shell=True)

            dictionary = {}
            dictionary["NAME"] = thread.name.lower()
            dictionary["MEM"] = thread.mem
            dictionary["MEM_N"] = not thread.mem
            srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl")
            #HLS instantiates subcores (e.g. floating point units) in VHDL form during the export step
            #The path above contains only .tcl instantiations, which our IP Packager flow doesn't understand
            #So we add extract the convenient .vhd definitions from the following path:
            srcs2 = shutil2.join(tmp.name, "hls", "sol", "impl", "ip", "hdl",
                                 "ip")
            dictionary["SOURCES"] = [srcs, srcs2]
            incls = shutil2.listfiles(srcs, True)
            incls += shutil2.listfiles(srcs2, True)
            dictionary["INCLUDES"] = [{
                "File": shutil2.trimext(_)
            } for _ in incls]

            log.info("Generating export files ...")
            if thread.videoout == 0:
                prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir)
            else:
                print("Found Video Out! \n")
                prj.apply_template("thread_hls_pcore_video_vhdl", dictionary,
                                   hwdir)

            #For each slot: Generate .prj file listing sources for PR flow
            if thread.slots[0].reconfigurable == "true":
                for _ in thread.slots:
                    dictionary["SLOTID"] = _.id
                    prj.apply_template("thread_prj", dictionary, hwdir, link)

        #Save temporary HLS project directory for analysis:
        shutil2.mkdir("/tmp/test")
        save_dir_hls_prj = shutil2.join(hwdir, "..",
                                        "tmp_hls_prj_" + thread.name.lower())
        shutil2.copytree(tmp.name, "/tmp/test")
        shutil2.rmtree(save_dir_hls_prj)
        shutil2.mkdir(save_dir_hls_prj)
        shutil2.copytree(tmp.name, save_dir_hls_prj)
Beispiel #6
0
def _export_hw_thread_ise_vivado(prj, hwdir, link, thread):
	''' 
	Generates sources for one hardware thread for ReconOS in an ISE/XPS or Vivado project.
	
	It checks whether vhdl or hls sources shall be used and generates the hardware thread
	from the source templates. 
	
	hwdir gives the name of the project directory
	link boolean; if true files will be linked instead of copied
	thread is the name of the hardware thread to generate
	'''
	hwdir = hwdir if hwdir is not None else prj.basedir + ".hw" + "." + thread.lower()

	log.info("Exporting thread " + thread + " to directory '" + hwdir + "'")

	threads = [_ for _ in prj.threads if _.name == thread]
	if (len(threads) == 1):
		thread = threads[0]

		if thread.hwsource is None:
			log.info("No hardware source specified")
	else:
		log.error("Thread '" + thread  + "' not found")
		return

	if thread.hwsource == "vhdl":
		dictionary = {}
		dictionary["ID"] = thread.id
		dictionary["NAME"] = thread.name.lower()
		dictionary["MEM"] = thread.mem
		dictionary["MEM_N"] = not thread.mem
		dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots])
		srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource)
		dictionary["SOURCES"] = [srcs]
		incls = shutil2.listfiles(srcs, True)
		dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]
		dictionary["RESOURCES"] = []
		for i, r in enumerate(thread.resources):
			d = {}
			d["NameUpper"] = (r.group + "_" + r.name).upper()
			d["NameLower"] = (r.group + "_" + r.name).lower()
			d["LocalId"] = i
			d["HexLocalId"] =  "%08x" % i
			dictionary["RESOURCES"].append(d)
		dictionary["PORTS"] = thread.ports

		log.info("Generating export files ...")
		prj.apply_template("thread_vhdl_pcore", dictionary, hwdir, link)

	elif thread.hwsource == "hls":
		tmp = tempfile.TemporaryDirectory()

		dictionary = {}
		dictionary["PART"] = prj.impinfo.part
		dictionary["NAME"] = thread.name.lower()
		dictionary["MEM"] = thread.mem
		dictionary["MEM_N"] = not thread.mem
		dictionary["CLKPRD"] = min([_.clock.get_periodns() for _ in thread.slots])
		srcs = shutil2.join(prj.dir, "src", "rt_" + thread.name.lower(), thread.hwsource)
		dictionary["SOURCES"] = [srcs]
		files = shutil2.listfiles(srcs, True)
		dictionary["FILES"] = [{"File": _} for _ in files]
		dictionary["RESOURCES"] = []
		for i, r in enumerate(thread.resources):
			d = {}
			d["NameUpper"] = (r.group + "_" + r.name).upper()
			d["NameLower"] = (r.group + "_" + r.name).lower()
			d["LocalId"] = i
			d["HexLocalId"] =  "%08x" % i
			d["Type"] = r.type
			d["TypeUpper"] = r.type.upper()
			dictionary["RESOURCES"].append(d)

		log.info("Generating temporary HLS project in " + tmp.name + " ...")
		prj.apply_template("thread_hls_build", dictionary, tmp.name)

		log.info("Starting Vivado HLS ...")
		if "bbd" in thread.hwoptions:
			if "vivado" in thread.hwoptions:
				subprocess.call("""
				  source /opt/Xilinx/Vivado/{1}/settings64.sh;
				  cd {0};
				  vivado_hls -f script_csynth.tcl;
				  vivado -mode batch -notrace -nojournal -nolog -source script_vivado_edn.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
				  shell=True)

				dictionary = {}
				dictionary["NAME"] = thread.name.lower()
				dictionary["MEM"] = thread.mem
				dictionary["MEM_N"] = not thread.mem
				srcs = shutil2.join(tmp.name, "rt_imp.edn")
				dictionary["SOURCES"] = [srcs]
				incls = ["rt_imp.edn"]
				dictionary["INCLUDES"] = [{"File": _} for _ in incls]
			else:
				log.error("No bbd tool found")
				return

			log.info("Generating export files ...")
			prj.apply_template("thread_hls_pcore_bbd", dictionary, hwdir)

		else:
			subprocess.call("""
			  source /opt/Xilinx/Vivado/{1}/settings64.sh;
			  cd {0};
			  vivado_hls -f script_csynth.tcl;""".format(tmp.name, prj.impinfo.hls[1]),
			  shell=True)

			dictionary = {}
			dictionary["NAME"] = thread.name.lower()
			dictionary["MEM"] = thread.mem
			dictionary["MEM_N"] = not thread.mem
			srcs = shutil2.join(tmp.name, "hls", "sol", "syn", "vhdl")
			dictionary["SOURCES"] = [srcs]
			incls = shutil2.listfiles(srcs, True)
			dictionary["INCLUDES"] = [{"File": shutil2.trimext(_)} for _ in incls]

			log.info("Generating export files ...")
			prj.apply_template("thread_hls_pcore_vhdl", dictionary, hwdir)

		shutil2.rmtree("/tmp/test")
		shutil2.mkdir("/tmp/test")
		shutil2.copytree(tmp.name, "/tmp/test")