task_id
stringclasses
24 values
path
stringlengths
30
94
left_context
stringlengths
13
172k
right_context
stringlengths
0
96.2k
groundtruth
stringlengths
10
665
crossfile_context
stringclasses
1 value
chiffre
chiffre/le-chiffre/src/main/scala/leChiffre/Header.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
// scalastyle:off magic.number case class ChiffreParameters ( checksumWidth: Int = 32, cycleWidth: Int = 32 ) trait LeChiffreH { implicit val p: Parameters val f_ECHO = 0 val f_CYCLE = 1 val f_ENABLE = 2 val cycleWidth = p(BuildChiffre).cycleWidth val checksumWidth = p(BuildChiffre).checksumWidth ...
case object BuildChiffre extends Field[ChiffreParameters]
chiffre
chiffre/le-chiffre/src/main/scala/leChiffre/LeChiffre.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
assert(RegNext(state) =/= s_ERROR, "[ERROR] LeChiffre: Hit error state\n") }
when (do_unknown) { state := s_ERROR }
chiffre
chiffre/le-chiffre/src/main/scala/rocketchip/Configs.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
class LeChiffreConfig extends Config(new WithLeChiffre ++ new DefaultConfig)
chiffre
chiffre/src/main/scala/chiffre/InjectorInfo.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
.stripMargin } def toBits(): String = fields.map(_.toBits()).mkString def bind(in: Seq[ScanField]): InjectorInfo = { val widthIn = in.foldLeft(0)( (l, r) => l + r.width ) if (width != widthIn) { throw new InjectorInfoBindingException(s"Unable to bind, widths differ ($width vs. $widthIn) betw...
|${fields.map(a => s"${a.serialize(tab + " ")}").mkString("\n")}"""
chiffre
chiffre/src/main/scala/chiffre/Instrumentation.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
def transformClass = classOf[FaultInstrumentationTransform] }) } }
def toFirrtl = FaultInjectionAnnotation(component.toNamed, id, gen)
chiffre
chiffre/src/main/scala/chiffre/ScanChain.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
|${injector.serialize(indent + " ")}""" .stripMargin def toBits(): String = injector.toBits() }
s"""|${indent}- $name:
chiffre
chiffre/src/main/scala/chiffre/ScanField.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
trait HasWidth { val width: Int } trait HasName { val name: String } /** A configurable field of the scan chain */ trait ScanField extends HasName with HasWidth with Equals { var value: Option[BigInt] = None val name: String = this.getClass.getSimpleName if (width < 1) { throw new ScanFieldException(...
case class ScanFieldBindingException(msg: String) extends Exception(msg)
chiffre
chiffre/src/main/scala/chiffre/inject/CycleInjector.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
case class CycleInject(width: Int) extends ScanField case class CycleInjectorInfo(bitWidth: Int, cycleWidth: Int) extends InjectorInfo { val fields = Seq(Cycle(cycleWidth), CycleInject(bitWidth)) } class CycleInjector(bitWidth: Int, val cycleWidth: Int) extends Injector(bitWidth) { val cycleTarget = Reg(UInt(cycl...
case class Cycle(width: Int) extends ScanField
chiffre
chiffre/src/main/scala/chiffre/inject/IdentityInjector.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
val info = NoInjectorInfo io.out := io.in io.scan.out := io.scan.in }
case object NoInjectorInfo extends InjectorInfo { val fields = Seq.empty }
chiffre
chiffre/src/main/scala/chiffre/inject/Injector.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
} /** An injector composed of individual single-bit injectors */ abstract class InjectorBitwise(bitWidth: Int, gen: => Injector) extends Injector(bitWidth) { lazy val injectors = Seq.fill(bitWidth)(Module(gen)) var scanLast = io.scan.in injectors .zipWithIndex .map{ case (injector, i) => injector....
when (io.scan.en) { enabled := ~enabled }
chiffre
chiffre/src/main/scala/chiffre/inject/LfsrInjector.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
case class LfsrInjectorInfo(bitWidth: Int, lfsrWidth: Int) extends InjectorInfo { val fields = Seq.fill(bitWidth)(Seq(Seed(lfsrWidth), Difficulty(lfsrWidth))).flatten } sealed class LfsrInjector(val lfsrWidth: Int) extends Injector(1) { val difficulty = RegInit(0.U(lfsrWidth.W)) val seed = RegInit(1.U(lfsrWidth...
case class Difficulty(width: Int) extends ScanField with ProbabilityBind
chiffre
chiffre/src/main/scala/chiffre/inject/StuckAt.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
class StuckAtInjectorWithId(bitWidth: Int, val scanId: String) extends StuckAtInjector(bitWidth) with ChiffreInjector
chiffre
chiffre/src/main/scala/chiffre/passes/FaultInstrumentation.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
|${renames.map{case (a, b) => s"$indent - $a: $b"}.mkString("\n")}""" .stripMargin } class FaultInstrumentation(compMap: Map[String, Seq[(ComponentName, String, Class[_ <: Injector])]]) extends Transform { def inputForm: CircuitForm = MidForm def outputForm: CircuitForm = MidForm def execute(state...
|${indent}renames:
chiffre
chiffre/src/main/scala/chiffre/passes/FaultInstrumentationTransform.scala
// Copyright 2017 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
def outputForm: CircuitForm = HighForm def transforms(compMap: Map[String, Seq[(ComponentName, String, Class[_ <: Injector])]]): Seq[Transform] = Seq( new FaultInstrumentation(compMap), /* After FaultInstrumentation, the inline compilation needs to be cleaned * up. this massive list is what is helping ...
def inputForm: CircuitForm = MidForm
chiffre
chiffre/src/main/scala/chiffre/passes/ScanChainTransform.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
|${tab}description: |${description.map{case(k,v)=>s"${tab} ${k.name}: $v"}.mkString("\n")}""" .stripMargin // scalastyle:on line.size.limit def toFaultyComponent: Seq[FaultyComponent] = injectors .map{ case(c, m) => FaultyComponent(c.serialize, description(c)) } .toSeq } sealed trai...
|${injectors.map{ case (k, v) => s"${tab} ${v.name}, ${k.module.name}, ${slaveIn(k).module.name}.${slaveIn(k).name}, ${slaveOut(k).module.name}.${slaveOut(k).name}"}.mkString("\n")}
chiffre
chiffre/src/main/scala/chiffre/scan/JsonProtocol.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
object JsonProtocol { /** The name/key to use for the name--value pair holding a Scala class * * @note this matches what FIRRTL does */ val classId: String = "class" // A base serialization format private val baseFormat = DefaultFormats .preservingEmptyValues .withTypeHintFieldName(classId...
case class JsonSerializationException(msg: String) extends Exception(msg)
chiffre
chiffre/src/main/scala/chiffre/util/Bits.scala
package chiffre.util import firrtl.bitWidth import firrtl.ir._ import firrtl.Mappers._ object removeZeroWidth {
def apply(t: Type): Type = t match { case tx @ (_: GroundType | _: VectorType) => tx case tx: BundleType => tx.copy(fields = tx.fields filter (f => bitWidth(f.tpe) > 0)) map apply }
chiffre
chiffre/src/main/scala/chiffre/util/ScanChainConfig.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
println(s"[info] bytes: ${raw.grouped(8).toArray.map(BigInt(_, 2).toByte).mkString(" ")}") require(raw.size % 32 == 0) raw.grouped(8).toArray.reverse.map(BigInt(_, 2).toByte) } // scalastyle:on magic.number } object Driver { val parser = new OptionParser[Arguments]("ScanChainConfig") { help("help...
s"""[info] raw: ${raw.grouped(4).toList.map(BigInt(_, 2).toString(16)).mkString.grouped(16).mkString(" ")}""")
chiffre
chiffre/src/test/scala/chiffreTests/ChiffreSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
}
def backToInt(f: ScanField): Int = Integer.parseInt(f.toBits, 2)
chiffre
chiffre/src/test/scala/chiffreTests/InjectorInfoSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
case class F(i: Option[BigInt] = None, width: Int = 4) extends ScanField { bind(i) } case class G(i: Option[BigInt] = None, width: Int = 5) extends ScanField { bind(i) } def f(): F = F() def f(x: Int): F = F(Some(x)) def g(): G = G() def g(x: Int): G = G(i = Some(x)) behavior of "The InjectoInfo trait"...
case class DummyInjectorInfo(fields: Seq[ScanField]) extends InjectorInfo
chiffre
chiffre/src/test/scala/chiffreTests/InstrumentationSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
behavior of "Chiffree Injectee annotation" it should "emit an annotation" in { val circuit = ChiselStage.elaborate(new DummyInjectee)
chiffre
chiffre/src/test/scala/chiffreTests/ScanChainConfigSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
val scanChain: ScanChain = Map( "id-0" -> Seq( FaultyComponent("Top.Top.x", StuckAtInjectorInfo(5)), FaultyComponent("Top.Top.y", LfsrInjectorInfo(4, 32)), FaultyComponent("Top.Top.z", CycleInjectorInfo(3, 8)) ) ) val scanFile = s"$test_dir/scan-chain.json" writeScanChainToFile(scanCh...
val test_dir = s"test_run_dir/${this.getClass.getSimpleName}"
chiffre
chiffre/src/test/scala/chiffreTests/ScanFieldSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
info(s"""${x.getOrElse("u")} $op ${y.getOrElse("u")}""") a == b should be (pass) } } val sameTypeSameWidth = Map( (None, None) -> true, (Some(1), None) -> false, (Some(1), Some(1)) -> true, (Some(2...
val op = if (pass) "==" else "!="
chiffre
chiffre/src/test/scala/chiffreTests/inject/CycleInjectorSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
} }
Driver(() => new CycleInjector(13, 8)) { dut => new TimingTester(dut, 42) }
chiffre
chiffre/src/test/scala/chiffreTests/inject/IdentityInjectorSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
} it should "do nothing when enabled" in { Driver(() => new IdentityInjector(21, "dummy")) { dut => new IdentityInjectorTester(dut) } } }
Driver(() => new IdentityInjector(42, "dummy")) { dut => new IdentityInjectorTransparencyTester(dut) }
chiffre
chiffre/src/test/scala/chiffreTests/inject/InjectorSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
class InjectorTester[T <: Injector](dut: T) extends PeekPokeTester(dut) { private def load(bitString: String): String = { val out = new StringBuilder(bitString.size) bitString.reverse.map(x => s"$x".toInt).foreach{ bit => poke(dut.io.scan.clk, 0) poke(dut.io.scan.in, bit) out ++= peek(dut.i...
case class Chunk(width: Int) extends ScanField
chiffre
chiffre/src/test/scala/chiffreTests/inject/LfsrInjectorSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
} ) behavior of "LfsrInjectorN" it should "be able to cycle a configuration" in { Driver(() => new LfsrInjectorN(4, 16, "main")) { dut => new InjectorCycleTester(dut) } } }
Driver(() => new LfsrInjector(8)) { dut => new ProbabilisticTester(dut, probability) }
chiffre
chiffre/src/test/scala/chiffreTests/inject/StuckAtInjectorSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
} }
Driver(() => new StuckAtInjector(8)) { dut => new StuckAtTester(dut) }
chiffre
chiffre/src/test/scala/chiffreTests/passes/FaultInstrumentationSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
val circuit = Parser.parse(input) val state = CircuitState(circuit, MidForm, Seq.empty, None) val connections = new ArrayBuffer[Connect]() f.execute(state).circuit.modules.filter(_.name == component.module.name).foreach(_.mapStmt(collect(connections))) connections.map(_.serialize) should contain ("x...
| input in: $tpe | output out: $tpe | reg x: $tpe, Clock | x <= in
chiffre
chiffre/src/test/scala/chiffreTests/passes/FaultInstrumentationTransformSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
class InjectorB(bitWidth: Int, id: String) extends InjectorA(bitWidth, id) class InjectorC(bitWidth: Int, id: String) extends InjectorB(bitWidth, id) class TestInjector(bitWidth: Int, scanId: String) extends IdentityInjector(bitWidth, scanId) { assert(io.scan.clk =/= io.scan.en) io.out := ~io.in } class TestContr...
class InjectorA(bitWidth: Int, id: String) extends IdentityInjector(bitWidth, id)
chiffre
chiffre/src/test/scala/chiffreTests/passes/ScanChainTransformSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
| input clock: Clock |""".stripMargin val circuit = Parser.parse(input) val m = ModuleName("Top", CircuitName("Top")) val annos = Seq( ScanChainAnnotation(ComponentName("controller.io.scan", m), "master", "scan", "foo", None), ScanChainInjectorAnnotation(ComponentName("x", ...
| input clock: Clock | reg x: UInt<1>, clock | inst controller of Controller | inst injector of Injector
chiffre
chiffre/src/test/scala/chiffreTests/scan/JsonProtocolSpec.scala
// Copyright 2018 IBM // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing,...
info("unbinding the bound value causes it to not match") roundTrip should not be (scanChain) }
diagrammer
diagrammer/src/main/scala/dotvisualizer/FirrtlDiagrammer.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import dotvisualizer.stage.DiagrammerStage import firrtl.FileUtils.isCommandAvailable import firrtl._ /** * This library implements a graphviz dot file render. */ object FirrtlDiagrammer {
private val LinuxPattern = """.*n[iu]x.*""".r private val WindowsPattern = """.*win.*""".r def getOpenForOs: String = { System.getProperty("os.name").toLowerCase match { case MacPattern() => "open" case LinuxPattern() if isCommandAvailable(Seq("x...
def main(args: Array[String]): Unit = { (new DiagrammerStage).execute(args, Seq.empty) }
diagrammer
diagrammer/src/main/scala/dotvisualizer/RenderSvg.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import java.io.{File, PrintWriter} import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.duration.Duration import scala.concurrent.{blocking, Await, Future, TimeoutException} import scala.sys.process._ class RenderSvg(dotProgra...
| --> |<!-- Title: TopLevel Pages: 1 --> |<svg width="351pt" height="44pt" | viewBox="0.00 0.00 351.26 44.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">...
|<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" | "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
diagrammer
diagrammer/src/main/scala/dotvisualizer/Scope.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer case class Scope(depth: Int = -1, maxDepth: Int = -1) { def doComponents(): Boolean = { val result = depth >= 0 && (maxDepth == -1 || depth < maxDepth) result }
def descend: Scope = { if (depth == -1) { Scope() } else { val newDepth = if (depth == maxDepth) -1 else depth + 1 Scope(newDepth, maxDepth) } } override def toString: String = { val s = (depth, maxDepth) match { case (-1, -1) => "out" case (_, -1) => "in, no depth...
def doPorts(): Boolean = depth >= 0 && (maxDepth == -1 || depth <= maxDepth)
diagrammer
diagrammer/src/main/scala/dotvisualizer/ToLoFirrtl.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import firrtl.CompilerUtils.getLoweringTransforms import firrtl.Mappers._ import firrtl.PrimOps.Dshl import firrtl._ import firrtl.ir._ import firrtl.options.{Dependency, Phase} import firrtl.stage.{FirrtlCircuitAnnotation, Forms} import firrtl.transforms.B...
def execute(state: CircuitState): CircuitState = { state.copy(circuit = state.circuit.map(onMod)) } }
private def onMod(mod: DefModule): DefModule = mod.map(onStmt)
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/DotNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes import scala.collection.mutable.ArrayBuffer trait DotNode { def render: String def name: String def parentOpt: Option[DotNode] def absoluteName: String = { parentOpt match {
case _ => name } } def in: String = absoluteName def out: String = absoluteName def asRhs: String = absoluteName val children: ArrayBuffer[DotNode] = new ArrayBuffer[DotNode] }
case Some(parent) => s"${parent.absoluteName}_$name"
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/LiteralNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes case class LiteralNode(name: String, value: BigInt, parentOpt: Option[DotNode]) extends DotNode {
def render: String = { s"""$absoluteName [shape="circle" style="filled" BGCOLOR="#C0C0C0" label="$value"] """.stripMargin }
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/MemNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes import firrtl.ir.DefMemory import scala.collection.mutable case class MemNode( name: String, parentOpt: Option[DotNode], firrtlName: String, defMem: DefMemory, nameToNode: mutable.HashMap[String, DotNode]) extends DotNode...
} defMem.readers.foreach { readerName => addMemoryPort("read port", readerName, Seq("en", "addr", "data", "clk")) } defMem.writers.foreach { readerName => addMemoryPort("write port", readerName, Seq("en", "addr", "data", "mask", "clk")) } defMem.readwriters.foreach { readerName => addMemoryPort...
fields.foreach { portName => addPort(memPortName, firrtlMemPortName, portName) }
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/ModuleNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes import dotvisualizer.transforms.MakeOneDiagram import firrtl.graph.DiGraph import scala.annotation.tailrec import scala.collection.mutable import scala.collection.mutable.ArrayBuffer case class ModuleNode( name: String, parentOpt: ...
| bgcolor="$backgroundColor" | ${children.map(_.render).mkString("\n")} | | ${connections.map { case (k, v) => s"$v -> $k" }.mkString("", "\n ", "")} | ${analogConnections.map { case (k, v) => expandBiConnects(k, v) }.mkString("", "\n ", "...
| URL="${url_string.getOrElse("")}"
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/MuxNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes import java.io.{File, PrintWriter} case class MuxNode( name: String, parentOpt: Option[DotNode], arg0ValueOpt: Option[String] = None, arg1ValueOpt: Option[String] = None) extends DotNode { val select: String = s"$...
writer.println(s"\n${mux2.out} -> ${reg1.in}") writer.println(s"\n${reg1.out} -> ${mux2.in2}") writer.println(s"}") writer.close() "dot -Tpng -O mux1.dot".!! "open mux1.dot.png".!! } }
writer.println(s"\n${mux1.out} -> ${mux2.in1}")
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/NodeNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes
case class NodeNode(name: String, parentOpt: Option[DotNode]) extends DotNode { def render: String = s"""$absoluteName [label = "$name" shape="rectangle"]; """ }
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/PortNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes case class PortNode(name: String, parentOpt: Option[DotNode], rank: Int = 10, isInput: Boolean = false) extends DotNode { def render: String = { val color = if (!isInput) { s"#E0FFFF" }
s"""$absoluteName [shape = "rectangle" style="filled" fillcolor="$color" label="$name" rank="$rank"] """.stripMargin } }
else { s"#CCCCCC" }
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/PrimOpNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes object PrimOpNode { /* the pseudoHash is necessary because case classes with identical args have identical hashes */ var pseudoHash: Long = 0 def hash: Long = { pseudoHash += 1 pseudoHash } val BlackDot = "&#x25cf;" } case class...
override val asRhs: String = s"$absoluteName:out" def render: String = { s""" |$absoluteName [shape = "plaintext" label=< |<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4" BGCOLOR="#D8BFD8"> | <TR> | <TD PORT="in1">${arg0ValueOpt.getOrElse(PrimOpNode.Black...
override val absoluteName: String = s"op_${name}_${PrimOpNode.hash}"
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/PrintfNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes import scala.collection.mutable case class PrintfNode(name: String, formatString: String, parentOpt: Option[DotNode]) extends DotNode { val text = new mutable.StringBuilder() override def absoluteName: String = "struct_" + super.absoluteName...
def render: String = { s""" |<TR><TD PORT="$connectTarget">$name</TD></TR> """.stripMargin }
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/RegisterNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes case class RegisterNode(name: String, parentOpt: Option[DotNode]) extends DotNode { override val in: String = s"struct_$absoluteName:in" override val out: String = s"struct_$absoluteName:out" override val asRhs: String = s"struct_$absolu...
| </TR> |</TABLE>>];""".stripMargin } }
| <TD PORT="out">${PrimOpNode.BlackDot}</TD>
diagrammer
diagrammer/src/main/scala/dotvisualizer/dotnodes/ValidIfNode.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.dotnodes case class ValidIfNode(name: String, parentOpt: Option[DotNode]) extends DotNode { val select: String = s"$name:select" val in1: String = s"$name:in1" override val asRhs: String = s"$name:out"
| <TD PORT="out">&#x25cf;</TD> | </TR> |</TABLE>>]; """.stripMargin } }
def render: String = { s""" |$name [shape = "plaintext" label=< |<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4" BGCOLOR="#FA8072">
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/DiagrammerAnnotations.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage import firrtl.annotations.{Annotation, NoTargetAnnotation} import firrtl.options.{HasShellOptions, ShellOption, Unserializable} sealed trait DiagrammerAnnotation { this: Annotation => } case class StartModuleNameAnnotation(name: String) extend...
object RankDirAnnotation extends HasShellOptions { val options = Seq( new ShellOption[String]( longOption = "rank-dir", toAnnotationSeq = (a: String) => Seq(RankDirAnnotation(a)), helpText = "use to set ranking direction, default is LR, TB is good alternative" ) ) } case object RankEleme...
case class RankDirAnnotation(name: String) extends DiagrammerAnnotation with NoTargetAnnotation with Unserializable
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/DiagrammerCli.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage import firrtl.options.Shell trait DiagrammerCli { this: Shell => parser.note("Diagrammer Front End Options") Seq( StartModuleNameAnnotation, OpenCommandAnnotation, SetRenderProgramAnnotation, JustTopLevelAnnotation, RankDi...
DotTimeoutSecondsAnnotation ).foreach(_.addOptions(parser)) }
ShowPrintfsAnnotation,
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/DiagrammerException.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage
class DiagrammerException(msg: String) extends Exception(msg)
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/DiagrammerPhase.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage import dotvisualizer.stage.phase.{ CheckPhase, GenerateDotFilePhase, GetFirrtlCircuitPhase, OptionallyBuildTargetDirPhase } import firrtl.options.phases.DeletedWrapper import firrtl.options.{Dependency, Phase, PhaseManager} class DiagrammerPh...
) }
val targets: Seq[PhaseManager.PhaseDependency] = Seq( Dependency[CheckPhase], Dependency[GetFirrtlCircuitPhase],
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/DiagrammerStage.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage import chisel3.stage.ChiselCli import firrtl.AnnotationSeq import firrtl.options.{Shell, Stage} import firrtl.stage.FirrtlCli /** DiagrammerState creates a diagram of a firrtl circuit. The firrtl circuit can be in any one of the following * forms ...
(new DiagrammerPhase).transform(annotations) } }
val shell: Shell = new Shell("chisel") with DiagrammerCli with ChiselCli with FirrtlCli
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/phase/CheckPhase.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage.phase import chisel3.stage.ChiselGeneratorAnnotation import dotvisualizer.stage.DiagrammerException import firrtl.AnnotationSeq import firrtl.options.{Phase, TargetDirAnnotation} import firrtl.stage.{FirrtlFileAnnotation, FirrtlSourceAnnotation} clas...
}
if (targetCount > 1) { throw new DiagrammerException(s"Error: There can only be 1 TargetDir, $targetCount found") }
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/phase/GenerateDotFilePhase.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage.phase import java.io.{File, PrintWriter} import dotvisualizer.RenderSvg import dotvisualizer.stage.{ DotTimeoutSecondsAnnotation, JustTopLevelAnnotation, OpenCommandAnnotation, SetRenderProgramAnnotation } import dotvisualizer.transforms.{Mak...
override def optionalPrerequisites = Seq.empty override def optionalPrerequisiteOf = Seq.empty override def invalidates(a: Phase) = false /** * Make a simple css file that controls highlighting * * @param targetDir where to put the css */ def addCss(targetDir: String): Unit = { val fil...
override def prerequisites = Seq(Dependency[OptionallyBuildTargetDirPhase])
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/phase/GetFirrtlCircuitPhase.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage.phase import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage} import dotvisualizer.ToLoFirrtl import dotvisualizer.stage.DiagrammerException import firrtl.options.{Dependency, Phase} import firrtl.stage.{FirrtlCircuitAnnotation, FirrtlFileAnnota...
override def optionalPrerequisites = Seq.empty override def optionalPrerequisiteOf = Seq.empty override def invalidates(a: Phase) = false def buildFirrtlCircuitAnnotation(firrtlText: String): FirrtlCircuitAnnotation = { val rawFirrtl = firrtl.Parser.parse(firrtlText) val processedFirrtlCircuit = (new T...
override def prerequisites = Seq(Dependency[CheckPhase])
diagrammer
diagrammer/src/main/scala/dotvisualizer/stage/phase/OptionallyBuildTargetDirPhase.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.stage.phase import java.io.File import dotvisualizer.stage.DiagrammerException import firrtl.options.{Dependency, Phase, TargetDirAnnotation} import firrtl.stage.FirrtlCircuitAnnotation import firrtl.{AnnotationSeq, FileUtils} class OptionallyBuildTargetD...
} } else { FileUtils.makeDirectory(targetDir) if (!targetDirFile.exists()) { <TARGET> } } case _ => } newAnnotations } }
throw new DiagrammerException(s"Error: Target dir ${targetDir} exists and is not a directory")
diagrammer
diagrammer/src/main/scala/dotvisualizer/transforms/MakeDiagramGroup.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.transforms import dotvisualizer._ import dotvisualizer.stage.StartModuleNameAnnotation import firrtl.options.TargetDirAnnotation import firrtl.{CircuitForm, CircuitState, DependencyAPIMigration, LowForm, Transform} import scala.collection.mutable class Ma...
override def invalidates(a: Transform) = false /** * Creates a series of diagrams starting with the startModule and continuing * through all descendant sub-modules. * @param state the state to be diagrammed * @return */ override def execute(state: CircuitState): CircuitState = { val tar...
override def optionalPrerequisites = Seq.empty
diagrammer
diagrammer/src/main/scala/dotvisualizer/transforms/MakeOneDiagram.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.transforms import java.io.PrintWriter import dotvisualizer._ import dotvisualizer.dotnodes._ import dotvisualizer.stage.{RankDirAnnotation, RankElementsAnnotation, ShowPrintfsAnnotation, StartModuleNameAnnotation} import firrtl.PrimOps._ import firrtl.ir._...
moduleNode += uInt uInt.absoluteName case c: SIntLiteral => <TARGET> moduleNode += uInt uInt.absoluteName case other => // throw new Exception(s"renameExpression:error: unhandled expression $expression") other.getClass.getName ...
val uInt = LiteralNode(s"lit${PrimOpNode.hash}", c.value, Some(moduleNode))
diagrammer
diagrammer/src/main/scala/dotvisualizer/transforms/ModuleLevelDiagrammer.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.transforms import java.io.PrintWriter import dotvisualizer.RenderSvg import dotvisualizer.stage.StartModuleNameAnnotation import firrtl.Mappers._ import firrtl._ import firrtl.ir.{Block, Statement} import firrtl.options.TargetDirAnnotation import scala.co...
override def optionalPrerequisites = Seq.empty override def optionalPrerequisiteOf = Seq.empty override def invalidates(a: Transform) = false def execute(circuitState: CircuitState): CircuitState = { val c = circuitState.circuit val targetDir = circuitState.annotations.collectFirst { case TargetDirA...
override def prerequisites = Seq.empty
diagrammer
diagrammer/src/main/scala/dotvisualizer/transforms/RemoveTempWires.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer.transforms import dotvisualizer.ToLoFirrtl import dotvisualizer.stage.DiagrammerException import firrtl.ir._ import firrtl.stage.FirrtlCircuitAnnotation import firrtl.{ CircuitForm, CircuitState, DependencyAPIMigration, FileUtils, LowForm, Parse...
if (node.name.startsWith(RemoveTempWires.GenPrefix) || node.name.startsWith(RemoveTempWires.TempPrefix)) { None } else { Some(node.mapExpr(removeGen)) } case other: Statement => Some(other.mapExpr(removeGen)) case _ => Some(...
val result = Some(Block(block.stmts.flatMap { substatement => removeGenStatement(substatement) }))
diagrammer
diagrammer/src/test/scala/dotvisualizer/AttachExample.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import java.io.{ByteArrayOutputStream, PrintStream} import dotvisualizer.stage.{DiagrammerStage, OpenCommandAnnotation} import firrtl.FileUtils import firrtl.options.TargetDirAnnotation import firrtl.stage.FirrtlSourceAnnotation import org.scalatest.freesp...
} } }
lines.exists { line => line.contains(target) } should be(true)
diagrammer
diagrammer/src/test/scala/dotvisualizer/FirExample.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import java.io.{ByteArrayOutputStream, File, PrintStream} import chisel3._ import chisel3.stage.ChiselStage import dotvisualizer.stage.{DiagrammerStage, OpenCommandAnnotation, RankDirAnnotation, RankElementsAnnotation} import firrtl.options.TargetDirAnnota...
output should include("There is no program identified which will render the svg files") targetFile.exists() should be(true) } }
output should include("creating dot file test_run_dir/fir_example/MyManyDynamicElementVecFir.dot")
diagrammer
diagrammer/src/test/scala/dotvisualizer/GCD.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import java.io.{ByteArrayOutputStream, File, PrintStream} import chisel3._ import chisel3.stage.ChiselGeneratorAnnotation import dotvisualizer.stage.DiagrammerStage import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers imp...
when(io.e) { x := io.a; y := io.b } io.z := x io.v := y === 0.U } class GCDTester extends AnyFreeSpec with Matchers { "GCD circuit to visualize" in { val targetDir = "test_run_dir/gcd" val targetFile = new File(s"$targetDir/GCD.dot.svg") if (targetFile.exists()) { targetFile.delete() } ...
when(x > y) { x := x - y }.otherwise { y := y - x }
diagrammer
diagrammer/src/test/scala/dotvisualizer/HierarchicalModulesExample.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import java.io.{ByteArrayOutputStream, File, PrintStream} import chisel3._ import chisel3.stage.{ChiselGeneratorAnnotation, ChiselStage} import dotvisualizer.stage.{DiagrammerStage, OpenCommandAnnotation, RankDirAnnotation, RankElementsAnnotation} import f...
y := modA.io.out + io.in2 + modB.io.out + modC.io.out io.out := y modB.io.in := x modC.io.in := x } class HierarchicalModulesExample extends AnyFreeSpec with Matchers { """This is an example of a module with hierarchical submodules """ in { val targetFile = new File("test_run_dir/visualizer/VizModC_4.d...
}.otherwise { x := io.in2 io.memOut := myMem(io.in1) }
diagrammer
diagrammer/src/test/scala/dotvisualizer/PrintfSpec.scala
// SPDX-License-Identifier: Apache-2.0 package dotvisualizer import chisel3._ import chisel3.stage.ChiselGeneratorAnnotation import dotvisualizer.stage._ import firrtl.FileUtils import firrtl.annotations.Annotation import firrtl.options.TargetDirAnnotation import org.scalatest.freespec.AnyFreeSpec import org.scalates...
else { Seq.empty[Annotation] }) val outputBuf = new ByteArrayOutputStream() Console.withOut(new PrintStream(outputBuf)) { (new DiagrammerStage).transform(annos) } val output = outputBuf.toString output should include(s"creating dot file test_run_dir/has_printf_$showPrin...
) ++ (if (showPrintfs) { Seq(ShowPrintfsAnnotation) }
dana
dana/src/main/scala/dana/ActivationFunction.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import cde._ import dana.abi._ class ActivationFunctionReq(implicit p: Parameters) extends DanaBundle()(p) { val decimal = UInt(decimalPointWidth.W) val steepness ...
} // FANN_THRESHOLD_SYMMETRIC is (e_FANN_THRESHOLD_SYMMETRIC) { when (inD0 < 0.S) { out := negOne } .elsewhen(inD0 === 0.S) { out := 0.S } .otherwise { out := one } } // FANN_SIGMOID and STEPWISE is (e_FANN_SIGMOID) { DSP(slopeSig, inD0-offsetX, decimal) ...
} .otherwise { out := one }
dana
dana/src/main/scala/dana/AsidNnidTableWalker.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import rocket.{HellaCacheReq, MT_D} import uncore.tilelink.{HasTileLinkParameters, ClientUncachedTileLinkIO, Get, GetBlock, PutBlock} import uncore.util._ import uncore.agents.{CacheBlo...
when (gnt.fire() && autlFinished) { io.cache.store.req.valid := true.B // Indicate fence/sync completion state := s_IDLE } } io.probes.interrupt := state === s_INTERRUPT io.probes.cause := interruptCode when (state === s_INTERRUPT) { // Add interrupt/exception support (#4) // [TODO] #4...
when (gnt.fire()) {configPointer := configPointer + (1.U<<autlBlockOffset)}
dana
dana/src/main/scala/dana/CSRs.scala
// See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import cde._ object Causes { val unknown = 0x80 // ASID--NNID Table Walker val no_antp = 0x90 val invalid_asid = 0x91 val invalid_nnid = 0x92 val null_read = 0x93 val zero_size = 0x94 val...
CSRs.fence -> reg_fence, CSRs.learn_rate -> reg_learn_rate, CSRs.weight_decay -> reg_weight_decay ) def backend_writes = { val d = io.wdata when (addrIs(CSRs.pe_size)) { reg_pe_size := d } when (addrIs(CSRs.cache_size)) { reg_cache_size := d } when (addrIs(C...
CSRs.antp -> reg_antp, CSRs.num_asids -> reg_num_asids,
dana
dana/src/main/scala/dana/Cache.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import cde._ import dana.abi._ // [TODO] // * I don't think that the location bit is used at all. Remove this // if it isn't case object CacheInit extends Field[Seq[CacheInitPara...
def fDerefNnid(x: CacheState, y: UInt, z: UInt): Bool = { x.valid && x.nnid === y && x.asid === z } // The check on whether or not an entry is done fetching depends, in // the absolute worst case, on the number of cycles it takes for // data to be written back to the call-by-name parameter // genSram, i....
def fIsUnused(x: CacheState): Bool = { (x.inUseCount ## x.notifyMask) === 0.U }
dana
dana/src/main/scala/dana/Configs.scala
// See LICENSE.IBM for license details. package dana import chisel3._ import cde._ import xfiles.{BuildXFilesBackend, XFilesBackendParameters} import dana.util._ import dana.abi._ class DefaultHardwareConfig extends Config ( topDefinitions = { (pname,site,here) => pname match { // ANTW Parameters case Ant...
case class CacheInitParameters(asid: Int, nnid: Int) class CacheInitialized extends Config( topDefinitions = { (pname,site,here) => pname match { case CacheInit => Seq( CacheInitParameters(asid = 1, nnid = 0)) case _ => throw new CDEMatchError }}) class DanaAsicConfig extends Config( new DanaConfi...
case CacheSizeBytes => cacheSize case ScratchpadBytes => scratchpad case _ => throw new CDEMatchError
dana
dana/src/main/scala/dana/Control.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import cde._ import dana.abi._ class ControlCacheInterfaceResp(implicit p: Parameters) extends DanaBundle()(p) { val fetch = Bool() val tableIndex = UInt(log2Up...
class ControlLearn(implicit p: Parameters) extends ControlBase()(p) { override lazy val io = IO(new ControlInterfaceLearn) io.regFile.req.bits.totalWrites := io.cache.resp.bits.totalWritesMul * infoAsLayer.neuronsInLayer io.peTable.req.bits.inAddr := Mux((io.tTable.req.bits.stateLearn === e_TTABLE_...
class Control(implicit p: Parameters) extends ControlBase()(p)
dana
dana/src/main/scala/dana/Dana.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import rocket.XLen import xfiles._ import cde._ import dana.abi._ case object ElementsPerBlock extends Field[Int] case object NnidWidth extends Field[Int] case object PeTableNumEntries ...
with UsrCmdRegWriteRs2 with UsrCmdRs1 // [TODO] These are all unused legacy interfaces that were originally // used for testing. These need to be cleaned up. class XFilesArbiterReq(implicit p: Parameters) extends DanaBundle()(p) { val tid = UInt(tidWidth.W) val readOrWrite = Bool() val isNew = ...
class UsrCmdRegWrite(implicit p: Parameters) extends DanaBundle()(p)
dana
dana/src/main/scala/dana/ProcessingElement.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import Chisel._ import cde._ import dana.abi._ class ProcessingElementReq(implicit p: Parameters) extends DanaBundle()(p) { val numWeights = UInt(p(NeuronInfo).num_weights.W) val index = UInt(log2Up(...
dataOut := Mux(af.io.resp.valid, af.io.resp.bits.out, dataOut) } is (PE_states('e_PE_DONE)) { nextState := PE_states('e_PE_UNALLOCATED) reqNoResp() io.resp.bits.incWriteCount := true.B io.resp.valid := true.B } } assert (!(state === PE_states('e_PE_ERROR)), printfSigil ++ ...
} is (PE_states('e_PE_ACTIVATION_FUNCTION)) { reqAf()
dana
dana/src/main/scala/dana/ProcessingElementTable.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import cde._ import dana.abi._ class PECacheInterfaceResp(implicit p: Parameters) extends DanaBundle()(p) { val field = UInt(log2Up(6).W) // [TODO] fragile on Dana enum val ...
when (inUse =/= 0.U) { when (cooldown < io.status.pe_cooldown) { cooldown := Mux(allUsed, cooldown - 1.U, io.status.pe_cooldown) } .elsewhen (cooldown > io.status.pe_cooldown) { cooldown := Mux(allUsed, io.status.pe_cooldown, cooldown + 1.U) } .otherwise { cooldown := Mux(a...
when (inUse === 0.U) { cooldown := io.status.pe_cooldown }
dana
dana/src/main/scala/dana/RegisterFile.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import scala.math.pow import xfiles.{TransactionTableNumEntries} import cde._ import dana.abi._ class RegisterFileInterface(implicit p: Parameters) extends DanaStatusIO()(p) { lazy va...
"The total writes to a Regsiter File entry exceeded the number expected") // A request to change the total number of writes should only happen // to a state entry marked as valid if it's countWrites is equal to // the totalWrites. assert(!(io.control.req.valid && state(io.control.req.bits.tIdx << 1.U |...
// the number of expected writes. assert(!Vec((0 until transactionTableNumEntries * 2).map( i => (state(i).valid &&
dana
dana/src/main/scala/dana/TransactionTable.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ import rocket.{RoCCCommand, RoCCResponse, MStatus} import cde._ import _root_.util.ParameterizedBundle import xfiles.{TransactionTableNumEntries, TableEntry, HasTable, XFilesResponseCo...
} assert(!(regWrite && cmd.regId =/= e_TTABLE_WRITE_REG_BATCH_ITEMS), "Deprecated regWrite register\n") printfInfo("saw reg write TID/Reg/Value 0x%x/0x%x/0x%x\n", cmd.tid, cmd.regId, cmd.regValue) } // IO Arbiter when (ioArbiter.out.valid) { val entry = table(ioArbiter.chosen) // ...
is (e_TTABLE_WRITE_REG_BATCH_ITEMS) { e.numBatchItems := cmd.regValue }
dana
dana/src/main/scala/dana/abi/Configs.scala
// See LICENSE.IBM for license details package dana.abi import chisel3._ import cde._
ptr_weights: Int ) case class LayerInfo_t ( ptr_neuron: Int, num_neurons: Int, num_neurons_previous: Int ) case class NeuronInfo_t ( ptr_weight_offset: Int, num_weights: Int, activation_function: Int, steepness: Int, _unused_0: Int, _unused_1: Int, bias: Int ) class Abi32Bit extends Config ( to...
case class GlobalInfo_t ( decimal_point: Int, error_function: Int, binary_format: Int, _unused_0: Int,
dana
dana/src/main/scala/dana/abi/Encodings.scala
// See LICENSE.IBM for license details package dana.abi import chisel3._ import cde.{Parameters, Field} import _root_.util.ParameterizedBundle case object DanaPtrBits extends Field[Int] case object DanaDataBits extends Field[Int]
case object LayerInfo extends Field[LayerInfo_t] case object NeuronInfo extends Field[NeuronInfo_t] case object DecimalPointOffset extends Field[Int] case object SteepnessOffset extends Field[Int] class NnConfigHeader(implicit p: Parameters) extends ParameterizedBundle()(p) { val info = p(GlobalInfo) val weightsPo...
case object GlobalInfo extends Field[GlobalInfo_t]
dana
dana/src/main/scala/dana/util/Memory.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana.util import chisel3._ import chisel3.util._ import cde._ import dana._ class MemoryInterface(implicit p: Parameters) extends DanaBundle()(p) { val cache = Flipped(new CacheAntwInterface) } class Memory(implicit p: Paramet...
assert(!(io.cache.cmd.valid === true.B), "Black box memory module received a valid request from the cache") }
dana
dana/src/main/scala/dana/util/Util.scala
// See LICENSE.IBM for license details. package dana.util import chisel3._ object divUp { def apply(dividend: Int, divisor: Int): Int = { (dividend + divisor - 1) / divisor} } object packInfo {
def apply(epb: Int, pes: Int, cache: Int): Int = { var x = epb << (6 + 4); x = x | pes << 4; x = x | cache; x}
dana
dana/src/main/scala/rocketchip/Configs.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package rocketchip import chisel3._ import rocket._ import cde._ class HasDanaRocc extends Config ( topDefinitions = { (pname,site,here) => pname match { case BuildRoCC => Seq( RoccParameters( opcodes = OpcodeSet.custo...
new xfiles.DefaultXFilesConfig ++ new dana.DanaConfig( numPes = 4, cache = 1, cacheSize = 512 * 1024, scratchpad = 16 * 1024) ++ new dana.DefaultDanaConfig ++ new BaseConfig)
nPTWPorts = 1)) case RoccMaxTaggedMemXacts => 1 case uncore.agents.CacheName => "L1D" }})
dana
dana/src/main/scala/rocketchip/XFilesDanaTestSuite.scala
// See LICENSE.IBM for license details. package xfiles import chisel3._ import scala.collection.mutable.LinkedHashSet
} object XFilesDanaTestSuites { val smoke = LinkedHashSet ( "debug", "id" ) val nets = LinkedHashSet ( "xorSigmoidSymmetric", "xorSigmoidSymmetric-smp" ) val xfilesDanaRegrTestNames = LinkedHashSet ( "xfiles-dana-smoke-p-debug", "xfiles-dana-nets-p-xorSigmoidSymmetric", "xfiles-...
class AssemblyTests(rocc: String, testDir: String, names: LinkedHashSet[String])(envName: String) extends rocketchip.AssemblyTestSuite(rocc + "-" + testDir, names)(envName) { override val dir = s"$$(base_dir)/$rocc/tests/build/$testDir" }
dana
dana/src/main/scala/standalone/Configs.scala
// See LICENSE.IBM for license details. package xfiles.standalone import cde._ import rocket._ import rocketchip._ import uncore.tilelink._
class AsStandalone extends Config ( topDefinitions = { (pname, site, here) => { pname match { case TileLinkRAMSize => 1024 * 1024} }})
dana
dana/src/main/scala/standalone/Main.scala
// See LICENSE.IBM for license details. package xfiles.standalone // import chisel3._ import chisel3.internal.firrtl.Circuit // import java.io._ import _root_.util.GeneratorApp
object Standalone extends GeneratorApp { val longName = names.topModuleProject + "." + names.configs generateFirrtl }
dana
dana/src/main/scala/standalone/Standalone.scala
// See LICENSE.IBM for license details. package xfiles.standalone import chisel3._ import chisel3.util._ import chisel3.testers.BasicTester import cde._ import rocket.{RoCCCommand, RoCCResponse, RoCC, RoccNPTWPorts} import xfiles._ import dana._ import uncore.devices.TileLinkTestRAM import uncore.tilelink.HasTileLink...
} class RoccTester[T <: RoCC](gen: => T)(implicit val p: Parameters) extends Module with HasTileLinkParameters { val io = IO(new Bundle { val cmd = Flipped(Decoupled(new RoCCCommand)) val resp = Decoupled(new RoCCResponse) val busy = Output(Bool()) val interrupt = Output(Bool()) val exception...
when (io.req.valid) { printf(s"[WARN] HoneyPot: $i") }
dana
dana/src/main/scala/standalone/XFilesTests.scala
// See LICENSE.IBM for license details. package xfiles.standalone import chisel3._ import chisel3.util._ import cde._ import xfiles.XFilesUserRequests
abstract class XFilesTests(implicit p: Parameters) extends XFilesTester { // New Transaction
dana
dana/src/main/scala/util/QueueAf.scala
// See LICENSE.BU for license details. package xfiles import chisel3._ import chisel3.util._ class QueueIOAf[T <: Data](gen: T, entries: Int) extends QueueIO[T](gen, entries) { val almostFull = Output(Bool())
} class QueueAf[T <: Data](gen: T, entries: Int, almostFullEntries: Int, pipe: Boolean = false, flow: Boolean = false, override_reset: Option[Bool] = None) extends Module(override_reset = override_reset) { val io = IO(new QueueIOAf(gen, entries)) val queue = Module(new Queue(gen, entries, pipe, flow, over...
override def cloneType = new QueueIOAf(gen, entries).asInstanceOf[this.type]
dana
dana/src/main/scala/util/SRAM.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ class SRAMInterface( val dataWidth: Int, val numReadPorts: Int, val numWritePorts: Int, val numReadWritePorts: Int, val sramDepth: Int ) extends Bundle { override def cloneTy...
when (io.re(i)) { io.dout(i) := mem(io.addr(i)) }} for (i <- 0 until numReadPorts) { when (io.reR(i)) { io.doutR(i) := mem(io.addrR(i)) }} for (i <- 0 until numWritePorts) { when (io.weW(i)) { mem(io.addrW(i)) := io.dinW(i) ...
when (io.we(i)) { mem(io.addr(i)) := io.din(i) }
dana
dana/src/main/scala/util/SRAMBlockIncrement.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ // SRAMBlock variant that allows for element _and_ block writes with // the option of writing a block that is accumualted with the elements // of the existing block. Forwarding is allowa...
def writeBlock(a: Vec[UInt], b: UInt) { val bTupled = (((x: Int, y: Int) => b.apply(x, y)) tupled) (0 until elementsPerBlock).map(j => a(j) := bTupled(index(j))) } def writeBlockIncrement(a: Vec[UInt], b: UInt, c: UInt) { val bTupled = (((x: Int, y: Int) => b.apply(x, y)) tupled) val cTupled = (((x:...
def index(j: Int): (Int, Int) = (elementWidth*(j+1) - 1, elementWidth * j)
dana
dana/src/main/scala/util/SRAMElement.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ // [TODO] Miscellaneous todos: // * A read immediately following a write is going to result in screwy // behavior. It's reasonable that either this should be prohibited // via pushba...
val addr = Vec(numPorts, new Bundle { val addrHi = Wire(UInt(log2Up(sramDepth).W)) val addrLo = Wire(UInt(log2Up(elementsPerBlock).W))}) val writePending = Reg(Vec(numPorts, new WritePendingBundle( elementWidth = elementWidth, dataWidth = dataWidth, sramDepth = sramDepth))) val tmp = Wire(V...
def index(j: Int): (Int, Int) = (elementWidth*(j+1) - 1, elementWidth * j)
dana
dana/src/main/scala/util/SRAMElementCounter.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ // [TODO] This module is currently non-working. It was an initial // solution to the problem of dealing with random writes from the // Processing Elements and needing to maintain a recor...
} class SRAMElementCounterInterface ( val dataWidth: Int, val sramDepth: Int, val numPorts: Int, val elementWidth: Int ) extends Bundle { override def cloneType = new SRAMElementInterface( dataWidth = dataWidth, sramDepth = sramDepth, numPorts = numPorts, elementWidth = elementWidth).asInstan...
override def cloneType = new SRAMElementCounterResp ( sramDepth = sramDepth).asInstanceOf[this.type]
dana
dana/src/main/scala/util/SRAMElementIncrement.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package dana import chisel3._ import chisel3.util._ // SRAMElement variant that allows for element _and_ block writes with // the option of writing a block that is accumualted with the elements // of the existing block. Forwarding is allo...
def writeBlock(a: Vec[UInt], b: UInt) { val bTupled = (((x: Int, y: Int) => b.apply(x, y)) tupled) (0 until elementsPerBlock).map(j => a(j) := bTupled(index(j))) } def writeBlockIncrement(a: Vec[UInt], b: UInt, c: UInt) { val bTupled = (((x: Int, y: Int) => b.apply(x, y)) tupled) val cTupled = (((x:...
def index(j: Int): (Int, Int) = (elementWidth*(j+1) - 1, elementWidth * j)
dana
dana/src/main/scala/util/SRAMVariant.scala
// See LICENSE.BU for license details. package dana import chisel3._ import chisel3.util._ import scala.Array import scala.math.min case class Dimension(width: Int, height: Int) class SRAMVariantInterface( val dataWidth: Int, val sramDepth: Int, val numPorts: Int ) extends Bundle { override def cloneType = ...
def divUp (dividend: Int, divisor: Int): Int = { (dividend + divisor - 1) / divisor} lazy val io = IO(new SRAMVariantInterface( dataWidth = dataWidth, sramDepth = sramDepth, numPorts = numPorts)) val blockSize = Dimension(min(32, dataWidth), min(1024, sramDepth)) val rows = divUp(sramDepth, b...
def writeElement(a: Vec[UInt], index: UInt, b: UInt) { a(index) := b }
dana
dana/src/main/scala/xfiles/Arbiter.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package xfiles import chisel3._ import chisel3.util._ import rocket._ import cde._ class XFilesArbiterInterface(implicit p: Parameters) extends Bundle { val core = new RoCCInterface val backend = Flipped(new XFilesBackendInterface) } ...
// Other connections io.core.interrupt := csrFile.io.interrupt io.core.busy := io.backend.rocc.busy // Connections to the backend. [TODO] Clean these up such that the // backend gets a single RoCC interface and some special lines for // dealing with Transactions. tTable.xfiles.cmd.valid := coreQueue.deq...
when (debugUnit.resp.valid) { io.core.resp.bits := debugUnit.resp.bits }
dana
dana/src/main/scala/xfiles/Backend.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package xfiles import chisel3._ import chisel3.util._ import rocket.{RoCCInterface, HasCoreParameters, HellaCacheReq} import cde._ import _root_.util.ParameterizedBundle
case class XFilesBackendParameters( generator: Parameters => XFilesBackend, csrFile_gen: Parameters => CSRFile, csrStatus_gen: Parameters => XFStatus, csrProbes_gen: Parameters => BackendProbes, info: Long = 0 ) class XFilesBackendReq(implicit p: Parameters) extends XFilesBundle()(p) { val tidx = Decoupled...
case object BuildXFilesBackend extends Field[XFilesBackendParameters]
dana
dana/src/main/scala/xfiles/CSRs.scala
// See LICENSE.IBM for license details. package xfiles import chisel3._ import chisel3.util._ import cde._ object Causes { val xfiles_generic = 0x0 val backend_generic = 0x1 val illegal_instruction = 0x2 } object CSRs { // Supervisor read/write val cause = 0x100 val ttable_size = 0x101 val asi...
when(addrIs(CSRs.ttable_size)) { reg_ttable_size := d } when(addrIs(CSRs.asid)) { reg_asid := d } when(addrIs(CSRs.tid)) { reg_tid := d } backend_writes printfInfo("Write CSR[0x%x] value 0x%x\n", io.addr, d) } when (ren) { printfInfo("Read CSR[0x%x] value 0x%x\n", io....
when(addrIs(CSRs.cause)) { reg_cause := d }
dana
dana/src/main/scala/xfiles/Configs.scala
// See LICENSE.IBM for license details. package xfiles import chisel3._ import cde._ import dana.DefaultDanaConfig class DefaultXFilesConfig extends Config ( topDefinitions = { (pname,site,here) => pname match { case TidWidth => 16 case AsidWidth => 16 case TableDeb...
case EnablePrintfs => true case EnableAsserts => true case _ => throw new CDEMatchError
dana
dana/src/main/scala/xfiles/DebugUnit.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package xfiles import chisel3._ import chisel3.util._ import uncore.constants.MemoryOpConstants.{M_XRD, M_XWR} import uncore.tilelink.{HasTileLinkParameters, Get, Put, GetBlock} import rocket.{RoCCInterface, PTE, MT_D} import cde._ class ...
when (state === s_('TRANSLATE_WAIT) & ptw.resp.fire()) { pte := ptw.resp.bits.pte state := s_('TRANSLATE_RESP) } when (state === s_('TRANSLATE_RESP)) { val offset = addr_d(pgIdxBits - 1, 0) io.resp.bits.data := Mux(pte.leaf(), Cat(pte.ppn, offset), ~0.U(xLen.W)) printfDebug("Seeing: 0x%x\n",...
when (ptw.req.fire()) { state := s_('TRANSLATE_WAIT) }
dana
dana/src/main/scala/xfiles/TransactionTable.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package xfiles import chisel3._ import chisel3.util._ import rocket.{RoCCCommand, RoCCResponse, RoCCInterface} import cde._ case object TransactionTableQueueSize extends Field[Int] trait FlagsVDIO { val valid = Bool() // Eligible for ...
} object XFilesTransactionTable { trait Printfs extends XFilesTransactionTable { val readDataPollCount = Reg(init = 0.U(32.W)) when (newRequest) { printfInfo("newRequest(ASID 0x%x, TID 0x%x)\n", asid, tid) } when (unknownCmd) { printfInfo("unknownCmd(ASID 0x%x, TID 0x%x)\n", asid, tid) } ...
when (reset) { (0 until numEntries).map(i => { table(i).reset() })}
dana
dana/src/main/scala/xfiles/XFiles.scala
// See LICENSE.BU for license details. // See LICENSE.IBM for license details. package xfiles import chisel3._ import chisel3.util._ import rocket.{RoCC, HasCoreParameters, CoreModule, CoreBundle} import cde._ import math.pow import _root_.util.ParameterizedBundle import perfect.util.UniformPrintfs case object TidWi...
case object EnableAsserts extends Field[Boolean] trait XFilesErrorCodes { val err_XFILES_UNKNOWN = 0 val err_XFILES_NOASID = 1 val err_XFILES_TTABLEFULL = 2 val err_XFILES_INVALIDTID = 3 val int_INVREQ = 0 } trait XFilesSupervisorRequests { // Supervisor requests are < 4 val t_SUP_UPDATE_ASID = 0 val...
case object EnablePrintfs extends Field[Boolean]