handle host objects #33

Closed
opened 2021-09-28 17:05:04 +08:00 by pca006132 · 10 comments

M-Labs/nac3-spec#5

KernelInvariants

https://git.m-labs.hk/M-Labs/nac3-spec/issues/5 KernelInvariants
sb10q added the
high-priority
label 2021-09-29 08:44:59 +08:00

Added simple support for host values. Object support would be added soon.

We can now compile something like:

from language import *
from artiq_builtins import *
from numpy import int32, int64

test_int = 123
test_float = 123.456
test_list = [1] * 100000
test_list_fail = [1, 2, 3.0]

test_tuple = (1, 2, 3.0)

@kernel
class Demo:
    @kernel
    def run(self):
        while True:
            test_list
            delay_mu(round64(test_float * 2.0))
            delay_mu(int64(test_int))
            delay_mu(int64(test_list[0]))
            delay_mu(int64(test_tuple[0]))
            delay_mu(int64(test_tuple[2]))


if __name__ == "__main__":
    Demo().run()

No constant folding for now except ints/floats/bools.

Just to confirm, we expect host variables to be constant right? Can their fields/elements change?

Added simple support for host values. Object support would be added soon. We can now compile something like: ```python from language import * from artiq_builtins import * from numpy import int32, int64 test_int = 123 test_float = 123.456 test_list = [1] * 100000 test_list_fail = [1, 2, 3.0] test_tuple = (1, 2, 3.0) @kernel class Demo: @kernel def run(self): while True: test_list delay_mu(round64(test_float * 2.0)) delay_mu(int64(test_int)) delay_mu(int64(test_list[0])) delay_mu(int64(test_tuple[0])) delay_mu(int64(test_tuple[2])) if __name__ == "__main__": Demo().run() ``` No constant folding for now except ints/floats/bools. Just to confirm, we expect host variables to be constant right? Can their fields/elements change?

Is constant folding a high priority task? It may be a bit hard to do with the current code, we may need to do constant folding on the AST (or graph if we want to, but this may require quite a lot of code as we have to change all AST code to use a new IR).

Is constant folding a high priority task? It may be a bit hard to do with the current code, we may need to do constant folding on the AST (or graph if we want to, but this may require quite a lot of code as we have to change all AST code to use a new IR).

Great!
Constant folding for scalar values is high-priority, but that works already, correct?

Great! Constant folding for scalar values is high-priority, but that works already, correct?

Also your demo code is actually #41

Also your demo code is actually https://git.m-labs.hk/M-Labs/nac3/issues/41

Great!
Constant folding for scalar values is high-priority, but that works already, correct?

Only if they are just constants. Object fields, list elements would not be constant folded for now.

Also your demo code is actually #41

That is the prerequisite of this.

> Great! > Constant folding for scalar values is high-priority, but that works already, correct? Only if they are just constants. Object fields, list elements would not be constant folded for now. > Also your demo code is actually https://git.m-labs.hk/M-Labs/nac3/issues/41 That is the prerequisite of this.

Only if they are just constants. Object fields, list elements would not be constant folded for now.

That should cover many practical cases.

> Only if they are just constants. Object fields, list elements would not be constant folded for now. That should cover many practical cases.
pca006132 referenced this issue from a commit 2021-10-07 15:59:14 +08:00
pca006132 referenced this issue from a commit 2021-10-07 15:59:14 +08:00

Sorry, forgot that generic is not yet handled now. It should not be too hard though.

Sorry, forgot that generic is not yet handled now. It should not be too hard though.
pca006132 added
low-priority
and removed
high-priority
labels 2021-10-07 16:21:27 +08:00

Done

Done

Does not seem to work. This simple example (with the min_artiq code in 5749141efb):

from min_artiq import *


@kernel
class Demo:
    core: Core

    def __init__(self):
        self.core = Core()

    @kernel
    def main_kernel(self):
        self.core.reset()

    def run(self):
        self.core.run(self.main_kernel)


if __name__ == "__main__":
    Demo().run()

crashes with:

thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', nac3core/src/codegen/expr.rs:395:58

Does not seem to work. This simple example (with the min_artiq code in 5749141efb0364f869cedc8de8d63c22e484490c): ```python from min_artiq import * @kernel class Demo: core: Core def __init__(self): self.core = Core() @kernel def main_kernel(self): self.core.reset() def run(self): self.core.run(self.main_kernel) if __name__ == "__main__": Demo().run() ``` crashes with: ``` thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', nac3core/src/codegen/expr.rs:395:58 ```
sb10q reopened this issue 2021-10-09 11:21:58 +08:00
sb10q added
high-priority
and removed
low-priority
labels 2021-10-09 11:42:44 +08:00

No, the implementation works, the problem is how you compile the code.

You did not set the self argument and the SymbolResolver has no way to get what the self argument is... In addition to that, the codegen method signature (takes no argument) does not match with the method signature (takes a self argument).

No, the implementation works, the problem is how you compile the code. You did not set the self argument and the SymbolResolver has no way to get what the `self` argument is... In addition to that, the codegen method signature (takes no argument) does not match with the method signature (takes a self argument).
sb10q closed this issue 2021-10-09 15:39:54 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#33
There is no content yet.