gpt4 book ai didi

scala - 在 Chisel 中使用 Vec[Mem] 会很好

转载 作者:行者123 更新时间:2023-12-02 03:41:37 33 4
gpt4 key购买 nike

对于 Vec[Mem] 来说,集合关联缓存会很好。

不幸的是 Chisel 不支持 Vec[Mem] 构造:

val tag_ram2    = Vec.fill(num_ways) {Mem(new TagType(), num_sets , seqRead = true )}

确实:

inferred type arguments [Chisel.Mem[cache.TagType]] do not conform to method fill's type     parameter bounds [T <: Chisel.Data]
[error] Error occurred in an application involving default arguments.
[error] val tag_ram2 = Vec.fill(num_ways) {Mem(new TagType(), num_sets , seqRead = true )}
[error] ^
[error] /home/asamoilov/work/projects/my-chisel/Cache.scala:139: type mismatch;
[error] found : Chisel.Mem[cache.TagType]
[error] required: T
[error] Error occurred in an application involving default arguments.
[error] val tag_ram2 = Vec.fill(num_ways) {Mem(new TagType(), num_sets , seqRead = true )}

然而,一个简单的解决方法就可以了:

val tag_ram2    = Array.fill(num_ways) {Mem(new TagType(), num_sets , seqRead = true )}
[...]
is (read_tag) {

set_idx := req_idx % UInt(num_sets) // FIXME
for (way_no <- 0 until num_ways) {
tag_read_vec(way_no) := tag_ram2(way_no)(set_idx)
}
controller_state := compare_tag
}

并用于编写标签(在某些 when(...) 子句下)

            for (way_no <- 0 until num_ways) {
when (UInt(way_no) === way_idx) {
printf("writing to way %d set %d tag %x\n", way_idx, set_idx, tag_write.toBits)
tag_ram2(way_no)(set_idx) := tag_write
}
}

意见,改进建议方案的建议?谢谢!

最佳答案

对于标签数组,尝试使用宽度为 (n_tag_sz*n_ways) 的一维位向量。在缓存访问中,您无论如何都要读出整行,并且您希望将其存储在尽可能密集的地方。所以像这样:

val tag_array = Mem(Bits(width = tagbits*n_ways), n_sets, seqRead = true)  

下面是一段用于 i-cache 的内存库的伪代码,它涵盖了 ifgen、ic_access 和 ic_response 的 3 个周期(s0、s1、s2):

val s1_tag_match = Vec.fill(n_ways){Bool()}
val s2_tag_hit = Vec.fill(n_ways){Bool()}
val s2_dout = Vec.fill(n_ways){Reg(Bits())}

for (i <- 0 until n_ways)
{
// notice each cycle of refill gets its own line
val data_array = Mem(Bits(width = n_code_width), n_sets*REFILL_CYCLES, seqRead = true)
val s1_raddr = Reg(UInt())
// refill
when (io.mem.resp.valid && repl_way === UInt(i))
{
data_array(Cat(s2_idx,rf_cnt)) := io.mem.resp.bits.data
}
// read enable
.elsewhen (s0_valid)
{
s1_raddr := s0_raddr
}

// read
when (s1_valid && s1_tag_match(i) && ready)
{
s2_dout(i) := data_array(s1_raddr)
}
}

io.resp.bits.data := Mux1H(s2_tag_hit, s2_dout)

关于scala - 在 Chisel 中使用 Vec[Mem] 会很好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19659346/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com