artiq
artiq copied to clipboard
Documentation: Kernel <-> Host Attribute Synchronisation/writeback
Question
Category: Attribute Writeback
Description
The kernel-host attribute synchronisation behaviour is not apparent to new users from reading the documentation.
The code below is intended to demonstrate the current behaviour:
from artiq.experiment import *
class AttributeTest(EnvExperiment):
def build(self):
self.setattr_device("core")
def prepare(self):
self.a = "A"
@kernel
def run(self):
print("krun")
print(self.a)
self.rpc()
print("krun after rpc")
print(self.a)
self.a = "A_2"
print(self.a)
self.rpc()
def rpc(self):
print("rpc")
print(self.a)
self.a = "A_1"
print("rpc modified")
print(self.a)
This prints:
krun
A
rpc
A
rpc modified
A_1
krun after rpc
A
A_2
rpc
A_1
rpc modified
A_1
I've been aware of this behaviour for some time. However, I can't quite decide if it is intended behaviour or a bug. It also raises the question of why kernel_invariants need to be explicitly specified (given that attribute changes outside the compiler are not synchronised to the core device).
Attribute writeback happens only when the kernel terminates, not before/after RPCs.
I haven't looked at the docs for this in a long time, maybe they could be improved.
kernel_invariants
is for modifications done by the kernel, where assuming values to be constant enables compiler optimisations. (Currently, this isn't taken advantage of nearly as well as it could.)