Comments (5)
Is the idea here to dynamically set one index of arr
? If so, you could try using set_index
magma/magma/primitives/set_index.py
Lines 7 to 13 in e0a49bb
class Test1(m.Circuit):
io = m.IO(
A=m.In(m.UInt[2]),
B=m.In(m.UInt[4]),
O=m.Out(m.UInt[4]),
)
arr = m.Register(m.Array[4, m.UInt[4]])()
arr.I @= m.set_index(arr.O, io.B, io.A)
io.O @= arr.O[0]
I'll have to investigate this error which is not very helpful, but I don't think this syntax would necessarily work in general because you'd want to specify a default value for the values that aren't written. The function set_index
style implies that the value is unchanged for the indices which I think is more explicit.
from magma.
Hi @leonardt, yes, the intention was to dynamically set specific indices of a register array. As you mentioned, in the arr.I[io.A] @= io.B
syntax, not specifying a default value for other indices is the issue.
In a Register
, could the previous O
values be considered as the default for I
s that are not explicitly wired? Are there potential issues with that?
from magma.
As an extension, how can one dynamically set an index of an N-D array?
Based on the function signature of set_index
, it appears that idx
is UInt
only.
class Test1(m.Circuit):
io = m.IO(
X=m.In(m.UInt[2]),
Y=m.In(m.UInt[2]),
B=m.In(m.UInt[4]),
O=m.Out(m.UInt[4]),
)
arr = m.Register(m.Array[(4, 4), m.UInt[4]])()
# Intention:
# arr.I[io.Y][io.X] @= io.B
arr.I @= m.set_index(arr.O, io.B, (io.X, io.Y)) # TypeError: Expected value to be the same type as `target`'s contents
io.O @= arr.O[0][0]
from magma.
Figured out this can be done recursively like so:
arr.I @= m.set_index(arr.O, m.set_index(arr.O[io.Y], io.B, io.X), io.Y)
# Equivalent to:
# arr.I[io.Y][io.X] @= io.B and all other inputs wired to defaults
However, the syntax can look messy when dealing with N-D arrays having multiple indices. Thought it might be better to simplify it to:
arr.I @= m.set_index(arr.O, io.B, [io.Y, io.X])
Have opened a PR for this #1330.
from magma.
Merged in #1353
from magma.
Related Issues (20)
- pip install -e . fails HOT 11
- DefineCircuit depreciated HOT 4
- [RFC] Mantle Style Conventions HOT 2
- DeclareCircuit HOT 2
- Recursive Circuit Definitions HOT 7
- [Discussion] Magma N-D Arrays have unintuitive behavior HOT 2
- [Types] Tuple field wiring check needs to happen recursively
- How to "group" assign to a Product type? HOT 3
- Add support for key/value pair arguments to product constructor
- Type of IOs appear flipped HOT 3
- Creating intermediate values using `Wire` gives `TypeError` HOT 2
- Reducing compile time HOT 1
- Cannot pickle (or jsonify) magma structures HOT 1
- Should sv=True be default for mlir-verilog? HOT 1
- Automatic formatter HOT 1
- [IO] Unintuitive behavior with IO objects HOT 1
- Installation on latest `main` branch is failing HOT 5
- Migrate output_filelist attribute to use emit dialect HOT 1
- Warning when wiring enable using __call__ syntax HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magma.