[英]Chisel3 type mismatch with Array of FixedPoint
In Scala one way we could declare an ArrayBuffer of array of Doubles,Long and Boolean is as such: 在Scala中,我们可以这样声明Doubles,Long和Boolean数组的ArrayBuffer如下:
val A = new ArrayBuffer[Array[(Long, Array[Double], Array[Double], Double, Boolean)]]
I would like to do same in chisel. 我想用凿子做同样的事情。
In chisel I know one way of declaring a vector of length n as input is as follows: 在凿子中,我知道一种将长度为n的向量声明为输入的方法如下:
val X = Input(Vec(n,FixedPoint(16.W, 8.BP)))
where n is Int, And this works . 其中n是Int,这可行。
Now I tried to initialise an array of n FixedPoint too, and did the following: 现在,我也尝试初始化n个FixedPoint数组,并执行以下操作:
val C = Array(Array.ofDim(FixedPoint(16.W, 8.BP)))(n,0)
Inspired from initialisation of an array 受阵列初始化的启发
But this did not work. 但这没有用。 I get the error
我得到错误
type mismatch;
[error] found : chisel3.core.FixedPoint
[error] required: Int
[error] val tabHash1 = Array(Array.ofDim(FixedPoint(16.W, 8.BP)))(n,0)
Please, can someone give the correct way of declaring A above of FixedPoint, and an Array of FixedPoint numbers in chisel? 请,有人可以给出正确的方法来声明FixedPoint以上的A,以及凿子中FixedPoint数字数组吗? Thanks!
谢谢! for your attention and your responses.
您的关注和回应。
Chisel will follow the ordinary rules of Scala collection declarations. Chisel将遵循Scala集合声明的一般规则。 I am not sure what you are trying to create here but the parameters are not quite right Array.ofDim is for creating multi-dimensional arrays, so if you are trying to create a 2 dimensional array of FixedPoint you want.
我不确定您要在此处创建什么,但是参数不是很正确。Array.ofDim用于创建多维数组,因此,如果您要创建二维的FixedPoint数组,则需要。
val C = Array.ofDim[FixedPoint](m, n)
Where n and m are the sizes in the two dimensions. 其中n和m是二维尺寸。 You have wrapped the Array.ofDim in another Array, so maybe you actually want a 3 dimensional array of FixedPoint, which would be
您已经将Array.ofDim包装在另一个Array中,所以也许您实际上想要的是FixedPoint的3维数组,
val C = Array.ofDim[FixedPoint](k, m, n)
Both of these techniques will give arrays that have all the slots for FixePoint but they will not be filled in, so probably what you really want is 这两种技术都将提供具有FixePoint的所有插槽的数组,但不会被填充,因此您可能真正想要的是
val C = Array.fill(k, m, n)(FixedPoint(16.W, 8.BP)
You can then wire these FixedPoints together how ever you want. 然后,您可以根据需要将这些FixedPoints连接在一起。
C(0, 0,0) := C(1, 1, 1) + C(2, 2, 2)
might be an example. 可能是一个例子。
If you need to access your FixedPoint elements using hardware indexing you will need a Vec instead of an Array. 如果需要使用硬件索引访问FixedPoint元素,则将需要Vec而不是数组。 The easiest way to initialize Vec is with a Seq of Elements.
初始化Vec的最简单方法是使用Seq of Elements。 A 2 dimensional Vec of FixedPoint could be created with
可以使用以下方式创建FixedPoint的二维Vec
val c = Vec(Seq.fill(n)(Vec(Seq.fill(m)(FixedPoint(16.W, 8.BP)))))
I would suggest looking at Scala Land vs Chisel Land for some background on using Chisel in Scala. 我建议您查看Scala Land与Chisel Land,了解在Scala中使用Chisel的一些背景知识。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.