Skip to content

Commit

Permalink
Moving the location of global state file saving (#1402)
Browse files Browse the repository at this point in the history
* Moved the caching function from the parser to the device, in all cases we want the cache to be generated only after download so it makes more sense here.

* increasing version to 3.0.1
  • Loading branch information
STFleming committed Oct 20, 2022
1 parent a056b84 commit 2172d9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion pynq/__init__.py
Expand Up @@ -17,7 +17,7 @@
from .uio import UioController

__all__ = ["lib", "tests"]
__version__ = "3.0.0"
__version__ = "3.0.1"
# This ID will always be tied to a specific release tag
# since the file will be modified to edit the version
__git_id__ = "$Id$"
51 changes: 23 additions & 28 deletions pynq/pl_server/embedded_device.py
Expand Up @@ -277,35 +277,8 @@ def get_parser(self, partial:bool=False):
parser.bin_data = self.get_bin_data()
parser.xclbin_data = xclbin_data
parser.dtbo_data = self.get_dtbo_data()
self._cache_metadata(parser)
return parser

def _cache_metadata(self, parser, name:str="Unknown")->None:
""" Caches the metadata and global state """
if not hasattr(parser, "_from_cache"):

t = datetime.datetime.now()
ts = "{}/{}/{} {}:{}:{} +{}".format(
t.year, t.month, t.day, t.hour, t.minute, t.second, t.microsecond
)

gs = GlobalState(bitfile_name=str(self._filepath),
timestamp=ts,
active_name=name,
psddr=parser.mem_dict.get("PSDDR", {}))
ip =parser.ip_dict
for sd_name, details in ip.items():
if details["type"] in ["xilinx.com:ip:pr_axi_shutdown_manager:1.0",
"xilinx.com:ip:dfx_axi_shutdown_manager:1.0",]:
gs.add(name=sd_name, addr=details["phys_addr"])
save_global_state(gs)

if hasattr(parser, "systemgraph"):
if not parser.systemgraph is None:
STATE_DIR = os.path.dirname(__file__)
pickle.dump(parser, open(f"{STATE_DIR}/_current_metadata.pkl", "wb"))



class BitfileHandler(BitstreamHandler):
def get_bin_data(self):
Expand Down Expand Up @@ -663,7 +636,28 @@ def set_axi_port_width(self, parser):

def gen_cache(self, bitstream, parser=None):
""" Generates the cache of the metadata even if no download occurred """
super()._cache_metadata(parser, bitstream, self.name)
if not hasattr(parser, "_from_cache"):
t = datetime.datetime.now()
ts = "{}/{}/{} {}:{}:{} +{}".format(
t.year, t.month, t.day, t.hour, t.minute, t.second, t.microsecond
)

if os.path.exists(bitstream.bitfile_name):
gs=GlobalState(bitfile_name=str(bitstream.bitfile_name),
timestamp=ts,
active_name=self.name,
psddr=parser.mem_dict.get("PSDDR", {}))
ip=parser.ip_dict
for sd_name, details in ip.items():
if details["type"] in ["xilinx.com:ip:pr_axi_shutdown_manager:1.0",
"xilinx.com:ip:dfx_axi_shutdown_manager:1.0",]:
gs.add(name=sd_name, addr=details["phys_addr"])
save_global_state(gs)

if hasattr(parser, "systemgraph"):
if not parser.systemgraph is None:
STATE_DIR = os.path.dirname(__file__)
pickle.dump(parser, open(f"{STATE_DIR}/_current_metadata.pkl", "wb"))

def download(self, bitstream, parser=None):

Expand All @@ -677,6 +671,7 @@ def download(self, bitstream, parser=None):

if not bitstream.partial:
self.shutdown()
self.gen_cache(bitstream, parser)
flag = 0
else:
flag = 1
Expand Down

0 comments on commit 2172d9f

Please sign in to comment.