fix errors of non-primitive host object when running multiple kernels #171

Merged
pca006132 merged 1 commits from multiple_kernel_err into master 2022-01-27 14:46:23 +08:00
Collaborator

erroneous program:

from numpy import int32
from min_artiq import *

@nac3
class Test:
    a: Kernel[int32]
    def __init__(self, a: int32):
        self.a = a

a = Test(3)
b = Test(4)

@nac3
class Demo:
    core: KernelInvariant[Core]
    a: Kernel[int32]

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

    @kernel
    def run(self):
        print_int32(a.a)
        print_int32(b.a)

if __name__ == "__main__":
    Demo(3).run()
    input("first kernel done")
    a.a = 9
    b.a = 1
    Demo(4).run()

under current master branch (fd4bf12808) and 6d00d4dabb, the output is something like:

first kernel done
thread '<unnamed>' panicked at 'index out of bounds: the len is 207 but the index is 207', nac3core/src/typecheck/unification_table.rs:69:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "/home/cresc/code/nac3/work1/nac3/my_expr/artiq/./multiple.py", line 32, in <module>
    Demo(4).run()
  File "/home/cresc/code/nac3/work1/nac3/my_expr/artiq/min_artiq.py", line 77, in run_on_core
    self.core.run(fake_method, *args, **kwargs)
  File "/home/cresc/code/nac3/work1/nac3/my_expr/artiq/min_artiq.py", line 160, in run
    compiler.compile_method_to_file(obj, name, args, "module.elf")
pyo3_runtime.PanicException: index out of bounds: the len is 207 but the index is 207

under the commit previous to 6d00d4dabb (baa713a3ca), the compilation passes, but when runkernel we get error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: DlOpen { desc: "../my_expr/artiq/module.elf: undefined symbol: 139733055654160" }', runkernel/src/main.rs:50:54

So I modified pyid_to_type and global_object_id to get both the type and the codegen value correctly handled.

This patch should fix the errors.. I am not fully confident whether this is completely safe since the cache strategy is a bit complicated, and hence the WIP.

The dirty patch in the attachment also seems to be enough to fix the error but it certainly breaks the caching.

erroneous program: ```python from numpy import int32 from min_artiq import * @nac3 class Test: a: Kernel[int32] def __init__(self, a: int32): self.a = a a = Test(3) b = Test(4) @nac3 class Demo: core: KernelInvariant[Core] a: Kernel[int32] def __init__(self, a): self.core = Core() self.a = a @kernel def run(self): print_int32(a.a) print_int32(b.a) if __name__ == "__main__": Demo(3).run() input("first kernel done") a.a = 9 b.a = 1 Demo(4).run() ``` under current master branch (https://git.m-labs.hk/M-Labs/nac3/src/commit/fd4bf1280885c55f31e9b055cdd21bd594dc90b4) and https://git.m-labs.hk/M-Labs/nac3/src/commit/6d00d4dabb54f6944a9c97981a1d3416093a3df9, the output is something like: ``` first kernel done thread '<unnamed>' panicked at 'index out of bounds: the len is 207 but the index is 207', nac3core/src/typecheck/unification_table.rs:69:26 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Traceback (most recent call last): File "/home/cresc/code/nac3/work1/nac3/my_expr/artiq/./multiple.py", line 32, in <module> Demo(4).run() File "/home/cresc/code/nac3/work1/nac3/my_expr/artiq/min_artiq.py", line 77, in run_on_core self.core.run(fake_method, *args, **kwargs) File "/home/cresc/code/nac3/work1/nac3/my_expr/artiq/min_artiq.py", line 160, in run compiler.compile_method_to_file(obj, name, args, "module.elf") pyo3_runtime.PanicException: index out of bounds: the len is 207 but the index is 207 ``` under the commit previous to 6d00d4dabb54f6944a9c97981a1d3416093a3df9 (https://git.m-labs.hk/M-Labs/nac3/src/commit/baa713a3cabb90e2b3519f1d323f09c2f881c605), the compilation passes, but when runkernel we get error: ``` thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: DlOpen { desc: "../my_expr/artiq/module.elf: undefined symbol: 139733055654160" }', runkernel/src/main.rs:50:54 ``` So I modified `pyid_to_type` and `global_object_id` to get both the type and the codegen value correctly handled. This patch should fix the errors.. I am not fully confident whether this is completely safe since the cache strategy is a bit complicated, and hence the WIP. The dirty patch in the attachment also seems to be enough to fix the error but it certainly breaks the caching.
ychenfo added 1 commit 2022-01-15 05:08:14 +08:00
ychenfo changed title from WIP: fix errors of non-primitive object when running multiple kernels to WIP: fix errors of non-primitive host object when running multiple kernels 2022-01-15 05:09:39 +08:00
ychenfo changed title from WIP: fix errors of non-primitive host object when running multiple kernels to fix errors of non-primitive host object when running multiple kernels 2022-01-21 03:55:08 +08:00
Author
Collaborator

After some more hand-written testings I think this should be fine..

After some more hand-written testings I think this should be fine..
sb10q requested review from pca006132 2022-01-22 18:24:43 +08:00
pca006132 merged commit 304181fd8c into master 2022-01-27 14:46:23 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
1 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#171
No description provided.