Hello ARTIQ community,
I am wondering what the fastest way is to access elements of a list in a kernel, ideally reaching <5us. I believe this should be possible because writing to a list takes <500ns. I was able to get this information by looking at the rtio_counter using artiq_coreanalyzer with some test code to investigate how long it takes to write/read from a list between ttl pulses:
`
class TTLdelaytest(EnvExperiment):
kernel_invariants = {"delay_time"}
def build(self):
self.setattr_device("core")
self.setattr_device("ttl6") `
def prepare(self):
self.delay_time = 1 * us
self.temp_data = [0] * 2
self.list = np.array([5,6])*us
@kernel
def run(self):
self.core.reset()
self.ttl6.pulse(50*ns)
#delay(self.list[0])
self.temp_data[0] = 1
self.ttl6.pulse(50*ns)`
The line self.temp_data[0] = 1 takes <500ns on average while delay(self.list[0]) takes >25us. This seems quite odd to me since I would assume a "get()" operation in machine code would be a lot faster than a "put()". To me, this likely points to something going on with the ARTIQ compiler not optimizing correctly with lists. Overall, I have a pre-allocated list I would like to sweep over the elements which is why I am using a list in the first place. If I can modify ARTIQ's source code to be able to do this, I would be more than happy to make it work, but I am wondering if this is possible to do.
If there is a faster way to access elements in a list, I would greatly appreciate any advice! I've played around with:
- making the list in the kernel itself and then accessing it
- trying different types of lists like np.int32 or float
- setting the list to a variable in another kernel and then accessing it
- setting the wanted element in the list to a variable and then using it
but they have all shown the 25us delay.