Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocation of nested array #165

Closed
NeuralCoder3 opened this issue Dec 16, 2022 · 6 comments
Closed

Allocation of nested array #165

NeuralCoder3 opened this issue Dec 16, 2022 · 6 comments
Labels
bug Something isn't working

Comments

@NeuralCoder3
Copy link
Collaborator

The alloc2malloc phase seems to have a problem with the allocation of nested arrays:

%mem.alloc («a; «b; .Idx 4294967296»»,0) mem

Example: https://github.com/NeuralCoder3/thorin2/blob/matrix_dialect/lit/mem/nested_alloc.thorin

It might be the case, that my application of alloc is wrong in this case.

Error:

lit/mem/nested_alloc.thorin:9:9-11:23: error: cannot pass argument 
  '(mem_1264932_303941, %core.trait.size «__1264888_303893#0:(.Idx 2); «__1264888_303893#1:(.Idx 2); .Idx 4294967296»»)' of type 
  '[%mem.M, «__1264888_303893#0:(.Idx 2); «__1264888_303893#1:(.Idx 2); .Idx 4294967296»»]' to 
  '%mem.malloc («__1264888_303893#0:(.Idx 2); «__1264888_303893#1:(.Idx 2); .Idx 4294967296»», 0)' of domain 
  '[%mem.M, .Nat]'
@NeuralCoder3 NeuralCoder3 added the bug Something isn't working label Dec 16, 2022
leissa added a commit that referenced this issue Dec 16, 2022
@leissa
Copy link
Member

leissa commented Dec 16, 2022

So there are two things at place here.

  1. There was a bug with the returned type of a core.trait.size (which I've just fixed)
  2. Rn, core.trait.size only deals with structural Arr%ays. We need to add sth in its normalizers to do the right thing for parameterized Arr%ays.

@leissa
Copy link
Member

leissa commented Dec 16, 2022

So, the bug is fixed. The other issue is more an enhancement to make it work in the llvm backend.

@leissa
Copy link
Member

leissa commented Dec 16, 2022

And this is not entirely trivial and clear to me, how to do that properly. Ideas?
E.g., what is the size of this thing here?

<<i: n; <<i as Nat; T>>

@NeuralCoder3
Copy link
Collaborator Author

NeuralCoder3 commented Dec 16, 2022

Is this a triangle array?
I am not sure if we can view it in a holistic way.
For many cases, we could find iteration strategies with tight bounds or at least some upper bounds.
But I think it is generally not computable what the correct size is in one go.
We would basically need to evaluate n and for [0...n-1] evaluate the inner function to get the bounds.
Overall, this would be the same as unrolling it entirely and having a standard deep initialization.

@leissa
Copy link
Member

leissa commented Dec 16, 2022

Yes, this is a triangle array. I think this is a case of: "we support this and that and for other stuff you are out of luck".
The example above at least is a parameterized array.

@leissa
Copy link
Member

leissa commented Dec 16, 2022

I'll close this for now and open a new enhancement issue.

@leissa leissa closed this as completed Dec 16, 2022
leissa added a commit to NeuralCoder3/thorin2 that referenced this issue Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants