From 6388b82455fff075c610e5bc48bf0d58e90aeb09 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 26 Feb 2022 16:28:17 +0800 Subject: [PATCH] coredevice/cache: port to nac3 --- artiq/coredevice/cache.py | 22 ++++++++++++++-------- artiq/examples/nac3devices/nac3devices.py | 3 +++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/artiq/coredevice/cache.py b/artiq/coredevice/cache.py index 6c222bb6f..7db1d0128 100644 --- a/artiq/coredevice/cache.py +++ b/artiq/coredevice/cache.py @@ -1,23 +1,29 @@ -from artiq.language.core import * -from artiq.language.types import * +from numpy import int32 + +from artiq.language.core import nac3, extern, kernel, KernelInvariant +from artiq.coredevice.core import Core -@syscall(flags={"nounwind"}) -def cache_get(key: TStr) -> TList(TInt32): +@extern +def cache_get(key: str) -> list[int32]: raise NotImplementedError("syscall not simulated") -@syscall -def cache_put(key: TStr, value: TList(TInt32)) -> TNone: +@extern +def cache_put(key: str, value: list[int32]): raise NotImplementedError("syscall not simulated") +@nac3 class CoreCache: """Core device cache access""" + + core: KernelInvariant[Core] + def __init__(self, dmgr, core_device="core"): self.core = dmgr.get(core_device) @kernel - def get(self, key): + def get(self, key: str) -> list[int32]: """Extract a value from the core device cache. After a value is extracted, it cannot be replaced with another value using :meth:`put` until all kernel functions finish executing; attempting @@ -34,7 +40,7 @@ class CoreCache: return cache_get(key) @kernel - def put(self, key, value): + def put(self, key: str, value: list[int32]): """Put a value into the core device cache. The value will persist until reboot. To remove a value from the cache, call :meth:`put` with an empty list. diff --git a/artiq/examples/nac3devices/nac3devices.py b/artiq/examples/nac3devices/nac3devices.py index 474aa0cd7..051e56e0f 100644 --- a/artiq/examples/nac3devices/nac3devices.py +++ b/artiq/examples/nac3devices/nac3devices.py @@ -1,5 +1,6 @@ from artiq.experiment import * from artiq.coredevice.core import Core +from artiq.coredevice.cache import CoreCache from artiq.coredevice.zotino import Zotino from artiq.coredevice.mirny import Mirny as MirnyCPLD from artiq.coredevice.adf5356 import ADF5356 @@ -12,6 +13,7 @@ from artiq.coredevice.edge_counter import EdgeCounter @nac3 class NAC3Devices(EnvExperiment): core: KernelInvariant[Core] + core_cache: KernelInvariant[CoreCache] zotino0: KernelInvariant[Zotino] mirny0_cpld: KernelInvariant[MirnyCPLD] mirny0_ch0: KernelInvariant[ADF5356] @@ -22,6 +24,7 @@ class NAC3Devices(EnvExperiment): def build(self): self.setattr_device("core") + self.setattr_device("core_cache") self.setattr_device("zotino0") self.setattr_device("mirny0_cpld") self.setattr_device("mirny0_ch0")