Skip to content

Commit 91f7a2a

Browse files
committed
Make emulator output CSV optional
1 parent a86a8ef commit 91f7a2a

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ tensil compile -a /demo/arch/pynqz1.tarch -m /demo/models/resnet20v2_cifar.pb -o
5858
## Run bit accurate Tensil emulator
5959

6060
```
61-
tensil emulate -m resnet20v2_cifar_onnx_pynqz1.tmodel -i ./models/data/resnet_input_1x32x32x8.csv -o resnet_output.csv
61+
tensil emulate -m resnet20v2_cifar_onnx_pynqz1.tmodel -i ./models/data/resnet_input_1x32x32x8.csv
6262
```
6363

6464
## Make Verilog RTL
@@ -111,7 +111,7 @@ rm main.tar.gz
111111
### Run emulator from source code
112112

113113
```
114-
./mill emulator.run -m resnet20v2_cifar_onnx_pynqz1.tmodel -i ./models/data/resnet_input_1x32x32x8.csv -o resnet_output.csv
114+
./mill emulator.run -m resnet20v2_cifar_onnx_pynqz1.tmodel -i ./models/data/resnet_input_1x32x32x8.csv
115115
```
116116

117117
### Run full test suite

emulator/src/tensil/tools/emulator/Main.scala

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import tensil.{
2222
ArchitectureDataTypeWithBase,
2323
InstructionLayout,
2424
FloatAsIfIntegralWithMAC,
25-
NumericWithMAC
25+
NumericWithMAC,
26+
TablePrinter,
27+
TableLine
2628
}
2729
import tensil.tools.ArchitectureDataTypeUtil
2830
import tensil.tools.model.Model
@@ -51,7 +53,6 @@ object Main extends App {
5153
.text("Input (.csv) files")
5254

5355
opt[Seq[File]]('o', "outputs")
54-
.required()
5556
.valueName("<file>, ...")
5657
.action((x, c) => c.copy(outputFiles = x))
5758
.text("Output (.csv) files")
@@ -137,7 +138,7 @@ object Main extends App {
137138
traceContext: ExecutiveTraceContext
138139
): Unit = {
139140
require(model.inputs.size == inputFiles.size)
140-
require(model.outputs.size == outputFiles.size)
141+
require(outputFiles.size == 0 || model.outputs.size == outputFiles.size)
141142

142143
val emulator = new Emulator(
143144
dataType = dataType,
@@ -179,10 +180,16 @@ object Main extends App {
179180
}
180181

181182
val outputPreps =
182-
for ((output, file) <- model.outputs.zip(outputFiles)) yield {
183-
val outputPrep = new ByteArrayOutputStream()
184-
(output, file, outputPrep, new DataOutputStream(outputPrep))
185-
}
183+
if (outputFiles.size != 0)
184+
for ((output, file) <- model.outputs.zip(outputFiles)) yield {
185+
val outputPrep = new ByteArrayOutputStream()
186+
(output, Some(file), outputPrep, new DataOutputStream(outputPrep))
187+
}
188+
else
189+
for (output <- model.outputs) yield {
190+
val outputPrep = new ByteArrayOutputStream()
191+
(output, None, outputPrep, new DataOutputStream(outputPrep))
192+
}
186193

187194
for (_ <- 0 until numberOfRuns) {
188195
val trace = new ExecutiveTrace(traceContext)
@@ -211,13 +218,46 @@ object Main extends App {
211218
new ByteArrayInputStream(outputPrep.toByteArray())
212219
)
213220

214-
ArchitectureDataTypeUtil.readToCsv(
215-
dataType,
216-
outputStream,
217-
model.arch.arraySize,
218-
output.size * numberOfRuns,
219-
file.getAbsolutePath()
220-
)
221+
if (file.isDefined)
222+
ArchitectureDataTypeUtil.readToCsv(
223+
dataType,
224+
outputStream,
225+
model.arch.arraySize,
226+
output.size * numberOfRuns,
227+
file.get.getAbsolutePath()
228+
)
229+
else {
230+
val r = ArchitectureDataTypeUtil.readResult(
231+
dataType,
232+
outputStream,
233+
model.arch.arraySize,
234+
output.size.toInt * numberOfRuns * model.arch.arraySize
235+
)
236+
237+
for (i <- 0 until numberOfRuns) {
238+
val tb = new TablePrinter(Some(s"OUTPUT ${output.name}, RUN ${i}"))
239+
240+
for (j <- 0 until output.size.toInt) {
241+
val offset = (i * output.size.toInt + j) * model.arch.arraySize
242+
val vector = r.slice(offset, offset + model.arch.arraySize)
243+
244+
tb.addLine(
245+
TableLine(
246+
f"${j}%08d",
247+
vector
248+
.grouped(8)
249+
.map(_.map(v => {
250+
val s = f"$v%.4f"
251+
" " * (12 - s.length()) + s
252+
}).mkString)
253+
.toIterable
254+
)
255+
)
256+
}
257+
258+
print(tb.toString())
259+
}
260+
}
221261
}
222262
}
223263
}

0 commit comments

Comments
 (0)