Skip to content

Commit e25ae33

Browse files
committed
Tag didnt work
1 parent 7a06ae6 commit e25ae33

10 files changed

Lines changed: 765 additions & 813 deletions

File tree

.github/workflows/test.yml

Lines changed: 73 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,73 @@
1-
name: chisel test
2-
3-
on:
4-
pull_request:
5-
paths:
6-
- '**.scala'
7-
- '**.sbt'
8-
- Makefile
9-
push:
10-
paths:
11-
- '**.scala'
12-
- '**.sbt'
13-
- Makefile
14-
- .github/workflows/test.yml
15-
16-
jobs:
17-
test:
18-
name: sbt testOnly on ubuntu
19-
runs-on: ubuntu-latest
20-
strategy:
21-
matrix:
22-
scala: [2.13.18]
23-
jvm: ['11', '17']
24-
steps:
25-
- name: Checkout
26-
uses: actions/checkout@v4
27-
28-
- name: Install system dependencies
29-
run: |
30-
sudo apt-get update
31-
sudo apt-get install -y z3 python3 python3-dev python3-pip verilator
32-
33-
- name: Install Python dependencies
34-
run: |
35-
pip3 install numpy
36-
37-
- name: Setup ScalaPy
38-
run: |
39-
# Find and link the appropriate Python library version
40-
PYTHON_VERSION=$(python3 --version | grep -oP '\d+\.\d+' | head -1)
41-
PYTHON_LIB=$(find /usr/lib/x86_64-linux-gnu -name "libpython${PYTHON_VERSION}.so" 2>/dev/null | head -1)
42-
if [ -n "$PYTHON_LIB" ]; then
43-
sudo ln -sf "$PYTHON_LIB" /usr/lib/x86_64-linux-gnu/libpython3.so || true
44-
fi
45-
46-
- name: Setup Java
47-
uses: actions/setup-java@v4
48-
with:
49-
distribution: 'temurin'
50-
java-version: ${{ matrix.jvm }}
51-
52-
- name: Setup Scala
53-
uses: olafurpg/setup-scala@v13
54-
55-
- name: Cache SBT dependencies
56-
uses: actions/cache@v4
57-
with:
58-
path: |
59-
~/.ivy2/cache
60-
~/.sbt
61-
~/.cache/coursier
62-
key: sbt-${{ runner.os }}-${{ hashFiles('**/build.sbt') }}-${{ matrix.scala }}-${{ matrix.jvm }}
63-
restore-keys: |
64-
sbt-${{ runner.os }}-${{ matrix.scala }}-${{ matrix.jvm }}-
65-
sbt-${{ runner.os }}-
66-
67-
- name: Cache firtool
68-
uses: actions/cache@v4
69-
with:
70-
path: |
71-
~/.cache/chisel
72-
key: firtool-${{ runner.os }}
73-
restore-keys: |
74-
firtool-${{ runner.os }}-
75-
76-
- name: Test
77-
run: sbt ++${{ matrix.scala }} "testOnly -- -l RequiresVcs -l RequiresVerilator"
78-
env:
79-
# Ensure firtool can be downloaded if not cached
80-
CHISEL_FIRTOOL_PATH: ""
81-
82-
- name: Test X-ray compression pipeline
83-
run: sbt ++${{ matrix.scala }} "testOnly -z common.XRayCompressionPipelineSpec"
84-
85-
- name: Test numpy reader
86-
run: sbt ++${{ matrix.scala }} "testOnly -z common.NumpyReaderScalaPySpec"
1+
name: chisel test
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**.scala'
7+
- '**.sbt'
8+
- Makefile
9+
push:
10+
paths:
11+
- '**.scala'
12+
- '**.sbt'
13+
- Makefile
14+
- .github/workflows/test.yml
15+
16+
jobs:
17+
test:
18+
name: sbt testOnly on ubuntu
19+
runs-on: ubuntu-latest
20+
strategy:
21+
matrix:
22+
scala: [2.13.18]
23+
jvm: ['11', '17']
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Install system dependencies
29+
run: |
30+
sudo apt-get update
31+
sudo apt-get install -y z3 python3 python3-dev python3-pip verilator
32+
33+
- name: Install Python dependencies
34+
run: |
35+
pip3 install numpy
36+
37+
- name: Setup ScalaPy
38+
run: |
39+
# Find and link the appropriate Python library version
40+
PYTHON_VERSION=$(python3 --version | grep -oP '\d+\.\d+' | head -1)
41+
PYTHON_LIB=$(find /usr/lib/x86_64-linux-gnu -name "libpython${PYTHON_VERSION}.so" 2>/dev/null | head -1)
42+
if [ -n "$PYTHON_LIB" ]; then
43+
sudo ln -sf "$PYTHON_LIB" /usr/lib/x86_64-linux-gnu/libpython3.so || true
44+
fi
45+
46+
- name: Setup Java
47+
uses: actions/setup-java@v4
48+
with:
49+
distribution: 'temurin'
50+
java-version: ${{ matrix.jvm }}
51+
52+
- name: Setup Scala
53+
uses: olafurpg/setup-scala@v13
54+
55+
- name: Cache SBT dependencies
56+
uses: actions/cache@v4
57+
with:
58+
path: |
59+
~/.ivy2/cache
60+
~/.sbt
61+
key: sbt-${{ runner.os }}-${{ hashFiles('**/build.sbt') }}-${{ matrix.scala }}-${{ matrix.jvm }}
62+
restore-keys: |
63+
sbt-${{ runner.os }}-${{ matrix.scala }}-${{ matrix.jvm }}-
64+
sbt-${{ runner.os }}-
65+
66+
- name: Test
67+
run: sbt ++${{ matrix.scala }} "testOnly -- -l RequiresVcs -l RequiresVerilator"
68+
69+
- name: Test X-ray compression pipeline
70+
run: sbt ++${{ matrix.scala }} "testOnly -z common.XRayCompressionPipelineSpec"
71+
72+
- name: Test numpy reader
73+
run: sbt ++${{ matrix.scala }} "testOnly -z common.NumpyReaderScalaPySpec"
Lines changed: 98 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,98 @@
1-
// See LICENSE.txt in the project root for license information.
2-
// Author: Kazutomo Yoshii <[email protected]>
3-
4-
package common
5-
6-
import chisel3._
7-
import chisel3.util._
8-
import chisel3.simulator.ChiselSim
9-
import org.scalatest.flatspec.AnyFlatSpec
10-
import org.scalatest.Tag
11-
12-
@Tag("RequiresVerilator")
13-
class BitShuffleSpec extends AnyFlatSpec with ChiselSim {
14-
behavior.of("BitShuffle")
15-
16-
val c_nelems: Int = 16
17-
val c_elemsize: Int = 8
18-
19-
val pat0 = List.fill(c_nelems)(0)
20-
21-
def genref(p: List[Int]) : List[Int] = {
22-
(0 until c_elemsize).map { sh =>
23-
p.zipWithIndex.map {case (v, i) =>
24-
((v >> sh) & 1) << i}.reduce(_ | _)
25-
}.toList
26-
}
27-
28-
"foo" should "pass" in {
29-
println(genref(pat0))
30-
}
31-
32-
"Zero test" should "pass" in {
33-
simulate(new BitShuffle(c_nelems, c_elemsize)) {
34-
c => {
35-
val hpat = pat0.map(_.U)
36-
val ref = genref(pat0)
37-
for (i<-0 until c_nelems) c.io.in(i).poke(hpat(i))
38-
for (i<-0 until c_elemsize) c.io.out(i).expect(ref(i))
39-
}
40-
}
41-
}
42-
43-
"Random test" should "pass" in {
44-
simulate(new BitShuffle(c_nelems, c_elemsize)) {
45-
46-
c => {
47-
val n = c_nelems
48-
val b = c_elemsize
49-
val maxval = (1 << b) - 1
50-
51-
val ntests = 10 // the number of tests
52-
val seed = 123
53-
val r = new scala.util.Random(seed)
54-
55-
// def pickval(pos: Int) : Int = pos%2
56-
def pickval(pos: Int): Int = {
57-
val v = r.nextInt(1000)
58-
val m = List.tabulate(5)(idx => idx * 100 + 100)
59-
if (v < m(0)) 0
60-
else if (v >= m(0) && v < m(1)) 1
61-
else if (v >= m(1) && v < m(2)) 2
62-
else if (v >= m(2) && v < m(3)) 3
63-
else if (v >= m(3) && v < m(4)) 4
64-
else r.nextInt(maxval + 1 - 5) + 5
65-
}
66-
67-
// if the sh'th bit of v is 1, it returns 1, otherwise returns 0
68-
def bittest(v: Int, sh: Int): Int = if ((v & (1 << sh)) == 0) 0 else 1
69-
70-
for (t <- 0 until ntests) {
71-
val data = List.tabulate(n)(i => pickval(i))
72-
val shuffled = genref(data)
73-
// List.tabulate(b) { bpos =>
74-
// List.tabulate(n) { idx => bittest(data(idx), bpos) << idx } reduce (_ | _)
75-
// }
76-
77-
78-
println("REF:")
79-
shuffled foreach { v => print(f"$v%04x ") }
80-
println()
81-
print("IN :")
82-
for (i <- 0 until n) {
83-
val tmp = data(i)
84-
print(f"$tmp%04x ")
85-
c.io.in(i).poke(tmp)
86-
}
87-
println()
88-
print("OUT:")
89-
for (j <- 0 until b) {
90-
val tmp = c.io.out(j).peek().litValue.toInt
91-
print(f"$tmp%04x ")
92-
c.io.out(j).expect(shuffled(j))
93-
c.clock.step()
94-
}
95-
println()
96-
}
97-
}
98-
}
99-
}
100-
}
1+
// See LICENSE.txt in the project root for license information.
2+
// Author: Kazutomo Yoshii <[email protected]>
3+
4+
package common
5+
6+
import chisel3._
7+
import chisel3.util._
8+
import chisel3.simulator.ChiselSim
9+
import org.scalatest.flatspec.AnyFlatSpec
10+
11+
class BitShuffleSpec extends AnyFlatSpec with ChiselSim {
12+
behavior.of("BitShuffle")
13+
14+
val c_nelems: Int = 16
15+
val c_elemsize: Int = 8
16+
17+
val pat0 = List.fill(c_nelems)(0)
18+
19+
def genref(p: List[Int]) : List[Int] = {
20+
(0 until c_elemsize).map { sh =>
21+
p.zipWithIndex.map {case (v, i) =>
22+
((v >> sh) & 1) << i}.reduce(_ | _)
23+
}.toList
24+
}
25+
26+
"foo" should "pass" in {
27+
println(genref(pat0))
28+
}
29+
30+
"Zero test" should "pass" in {
31+
simulate(new BitShuffle(c_nelems, c_elemsize)) {
32+
c => {
33+
val hpat = pat0.map(_.U)
34+
val ref = genref(pat0)
35+
for (i<-0 until c_nelems) c.io.in(i).poke(hpat(i))
36+
for (i<-0 until c_elemsize) c.io.out(i).expect(ref(i))
37+
}
38+
}
39+
}
40+
41+
"Random test" should "pass" in {
42+
simulate(new BitShuffle(c_nelems, c_elemsize)) {
43+
44+
c => {
45+
val n = c_nelems
46+
val b = c_elemsize
47+
val maxval = (1 << b) - 1
48+
49+
val ntests = 10 // the number of tests
50+
val seed = 123
51+
val r = new scala.util.Random(seed)
52+
53+
// def pickval(pos: Int) : Int = pos%2
54+
def pickval(pos: Int): Int = {
55+
val v = r.nextInt(1000)
56+
val m = List.tabulate(5)(idx => idx * 100 + 100)
57+
if (v < m(0)) 0
58+
else if (v >= m(0) && v < m(1)) 1
59+
else if (v >= m(1) && v < m(2)) 2
60+
else if (v >= m(2) && v < m(3)) 3
61+
else if (v >= m(3) && v < m(4)) 4
62+
else r.nextInt(maxval + 1 - 5) + 5
63+
}
64+
65+
// if the sh'th bit of v is 1, it returns 1, otherwise returns 0
66+
def bittest(v: Int, sh: Int): Int = if ((v & (1 << sh)) == 0) 0 else 1
67+
68+
for (t <- 0 until ntests) {
69+
val data = List.tabulate(n)(i => pickval(i))
70+
val shuffled = genref(data)
71+
// List.tabulate(b) { bpos =>
72+
// List.tabulate(n) { idx => bittest(data(idx), bpos) << idx } reduce (_ | _)
73+
// }
74+
75+
76+
println("REF:")
77+
shuffled foreach { v => print(f"$v%04x ") }
78+
println()
79+
print("IN :")
80+
for (i <- 0 until n) {
81+
val tmp = data(i)
82+
print(f"$tmp%04x ")
83+
c.io.in(i).poke(tmp)
84+
}
85+
println()
86+
print("OUT:")
87+
for (j <- 0 until b) {
88+
val tmp = c.io.out(j).peek().litValue.toInt
89+
print(f"$tmp%04x ")
90+
c.io.out(j).expect(shuffled(j))
91+
c.clock.step()
92+
}
93+
println()
94+
}
95+
}
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)