incorrect ndarray indexing crashes compiler #466

Closed
opened 2024-07-21 13:28:15 +08:00 by sb10q · 6 comments
Owner
from numpy import array as np_array

from artiq.experiment import *
from artiq.coredevice.core import Core

@nac3
class Test(EnvExperiment):
    core: KernelInvariant[Core]

    def build(self):
        self.setattr_device("core")

    @kernel
    def run(self):
        x = np_array([[1.0, 3.0], [1.09, 2.42]])
        y = x + np_array([[1.0, 20.0], [100.0, 200.0]])
        for i in range(len(x)):
            print_rpc(y[i])
...
thread 'codegen-worker-main' panicked at /home/sb/nac3/nac3core/src/codegen/mod.rs:378:13:
Both operands to a binary operator are not of the same type!
  %377 = mul i32 %371, i64 ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64), !dbg !13
Both operands to a binary operator are not of the same type!
  %416 = mul i32 %384, i64 ptrtoint (double* getelementptr (double, double* null, i32 1) to i64), !dbg !13
...
pyo3_runtime.PanicException: tasks panicked
``` from numpy import array as np_array from artiq.experiment import * from artiq.coredevice.core import Core @nac3 class Test(EnvExperiment): core: KernelInvariant[Core] def build(self): self.setattr_device("core") @kernel def run(self): x = np_array([[1.0, 3.0], [1.09, 2.42]]) y = x + np_array([[1.0, 20.0], [100.0, 200.0]]) for i in range(len(x)): print_rpc(y[i]) ``` ``` ... thread 'codegen-worker-main' panicked at /home/sb/nac3/nac3core/src/codegen/mod.rs:378:13: Both operands to a binary operator are not of the same type! %377 = mul i32 %371, i64 ptrtoint (i32* getelementptr (i32, i32* null, i32 1) to i64), !dbg !13 Both operands to a binary operator are not of the same type! %416 = mul i32 %384, i64 ptrtoint (double* getelementptr (double, double* null, i32 1) to i64), !dbg !13 ... pyo3_runtime.PanicException: tasks panicked ```
sb10q added the
high-priority
label 2024-07-21 13:28:15 +08:00
lyken was assigned by sb10q 2024-07-21 13:28:15 +08:00
Author
Owner

Same bug with y = 2.0*x and y = x @ np_array([[1.0, 0.0], [0.0, 1.0]])

Same bug with ``y = 2.0*x`` and ``y = x @ np_array([[1.0, 0.0], [0.0, 1.0]])``
Author
Owner

This actually happens because of the incorrect indexing in the print_rpc call.

This actually happens because of the incorrect indexing in the print_rpc call.
sb10q changed title from 2D ndarray addition crashes compiler to incorrect ndarray indexing crashes compiler 2024-07-21 13:32:55 +08:00
sb10q removed the
high-priority
label 2024-07-21 13:32:58 +08:00
Collaborator

Crash happens when nac3core's CodeGenerator's size_t is 32 bits - and doesn't when size_t is 64 bits - likely due to an oversight in nac3core.

This type of error is very common in nac3core,
like this one: #442.

PR later

Crash happens when `nac3core`'s `CodeGenerator`'s `size_t` is 32 bits - and doesn't when `size_t` is 64 bits - likely due to an oversight in `nac3core`. This type of error is very common in `nac3core`, like this one: https://git.m-labs.hk/M-Labs/nac3/pulls/442. PR later
Collaborator

#477 by derppening can fix this issue if it is the proper solution.

https://git.m-labs.hk/M-Labs/nac3/pulls/477 by derppening can fix this issue if it is the proper solution.
Collaborator

This is fixed by 693b2a8863.

Should this be closed? @sb10q

This is fixed by https://git.m-labs.hk/M-Labs/nac3/commit/693b2a8863cbdb390f4820260281b7ab8f2503f9. Should this be closed? @sb10q
Author
Owner

Yes, confirmed that it no longer crashes.

Yes, confirmed that it no longer crashes.
sb10q closed this issue 2024-08-27 14:09:06 +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#466
No description provided.