├── Day1 ├── CorrectOutput.txt ├── Makefile ├── README ├── lib │ ├── CReg.bsv │ └── Fifo.bsv ├── scripts │ └── compile └── src │ ├── PriorityArbiter.bsv │ └── Testbenches │ └── Testbench.bsv ├── Day2 ├── Makefile ├── README ├── lib │ ├── CReg.bsv │ └── Fifo.bsv ├── scripts │ └── compile └── src │ ├── DataReplicator.bsv │ ├── FixedAdder.bsv │ ├── FixedMultiplier.bsv │ ├── FixedTypes.bsv │ └── Testbenches │ ├── AdderTestbench.bsv │ ├── MultiplierTestbench.bsv │ └── ReplicatorTestbench.bsv ├── Day3 ├── FixedAdder.bsv ├── FixedMultiplier.bsv ├── FixedTypes.bsv ├── Makefile ├── NeuralNetworkConfig.bsv ├── NoCs │ ├── common │ │ └── MatrixArbiter.bsv │ └── microswitch │ │ ├── BottomSwitch.bsv │ │ ├── MicroswitchController.bsv │ │ ├── MicroswitchNetwork.bsv │ │ ├── MiddleSwitch.bsv │ │ └── TopSwitch.bsv ├── README ├── TopModule.bsv ├── WS_PE.bsv ├── WS_PE_Array.bsv ├── accelerator │ ├── global_buffer │ │ ├── GlobalBuffer.bsv │ │ ├── GlobalBufferMicroswitchNIC.bsv │ │ └── GlobalBufferUnit.bsv │ └── processing_element │ │ └── WS │ │ ├── WS_MicroswitchNIC.bsv │ │ └── WS_PE_Unit.bsv ├── common_lib │ ├── CReg.bsv │ └── Fifo.bsv ├── configs │ ├── microswitch_types │ │ ├── MicroswitchMessageTypes.bsv │ │ ├── MicroswitchNetworkTypes.bsv │ │ └── MicroswitchTypes.bsv │ └── neuralnetwork_types │ │ ├── .gitignore │ │ ├── DerivedNeuralNetworkConfig.bsv │ │ ├── GlobalBufferTypes.bsv │ │ ├── NeuralNetworkTypes.bsv │ │ ├── RowStationaryPE_Types.bsv │ │ └── WeightStationaryPE_Types.bsv └── scripts │ └── compile ├── Documents ├── BSV_Manuals │ ├── bsv-reference-card.pdf │ ├── bsv-reference-guide.pdf │ └── bsv_by_example.pdf ├── Designing_CNN_Acclerator_Day1.pdf ├── Designing_CNN_Acclerator_Day2.pdf └── Designing_CNN_Acclerator_Day3.pdf ├── README └── vim_syntax ├── README ├── ftdetect └── bsv.vim ├── indent └── bsv.vim └── syntax └── bsv.vim /Day1/CorrectOutput.txt: -------------------------------------------------------------------------------- 1 | ./scripts/compile -r 2 | 3 | Cycle 0 ---------------------------------------------------- 4 | Requests from 1, 2, 3 5 | Requester 1 won the arbitration 6 | ** Correct Output ** 7 | 8 | Cycle 1 ---------------------------------------------------- 9 | Requests from 2, 3 10 | Requester 2 won the arbitration 11 | ** Correct Output ** 12 | 13 | Cycle 2 ---------------------------------------------------- 14 | Requests from 0, 3 15 | Requester 0 won the arbitration 16 | ** Correct Output ** 17 | 18 | Cycle 3 ---------------------------------------------------- 19 | Requests from 3 20 | Requester 3 won the arbitration 21 | ** Correct Output ** 22 | 23 | Cycle 4 ---------------------------------------------------- 24 | Requests from 2, 3 25 | Requester 2 won the arbitration 26 | ** Correct Output ** 27 | 28 | Cycle 5 ---------------------------------------------------- 29 | Requests from 0, 1, 2, 3 30 | Requester 0 won the arbitration 31 | ** Correct Output ** 32 | 33 | Cycle 6 ---------------------------------------------------- 34 | No requests 35 | 36 | Cycle 7 ---------------------------------------------------- 37 | No requests 38 | 39 | Cycle 8 ---------------------------------------------------- 40 | Requests from 1, 3 41 | Requester 1 won the arbitration 42 | ** Correct Output ** 43 | 44 | Cycle 9 ---------------------------------------------------- 45 | No requests 46 | 47 | Cycle 10 ---------------------------------------------------- 48 | No requests 49 | -------------------------------------------------------------------------------- /Day1/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SCRIPT_DIR:=./scripts 3 | BUILD_DIR:=./build 4 | 5 | ArbiterTest: 6 | $(SCRIPT_DIR)/compile -c ./Testbench.bsv mkTestbench 1 7 | 8 | run: 9 | $(SCRIPT_DIR)/compile -r 10 | 11 | clean: 12 | $(SCRIPT_DIR)/compile -clean 13 | 14 | -------------------------------------------------------------------------------- /Day1/README: -------------------------------------------------------------------------------- 1 | - Code license (MIT license) 2 | 3 | Copyright (c) 2017 4 | Hyoukjun Kwon (hyoukjun@gatech.edu) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | 25 | - Directory Structure 26 | 27 | lib: library files 28 | scripts: compilation scripts 29 | src: source file directory 30 | 31 | - Which source file to edit? 32 | ./src/PriorityArbiter.bsv 33 | 34 | - How to compile the code? 35 | > make 36 | 37 | - How to run the testbench? 38 | > make run 39 | 40 | - How to clean up codebase? 41 | > make clean 42 | 43 | -------------------------------------------------------------------------------- /Day1/lib/CReg.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2012 Muralidaran Vijayaraghavan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | 14 | /* 15 | Comments: This EHR design generates the following scheduling constraints (forall i): 16 | forall j >= i, r[i] < w[j] 17 | forall j < i, r[i] > w[j] 18 | forall j > i, w[i] < w[j] 19 | w[i] conflicts with w[i] 20 | forall j, r[i] is conflict free with r[j] 21 | */ 22 | 23 | import Vector::*; 24 | import RWire::*; 25 | 26 | typedef Vector#(n, Reg#(t)) CReg#(numeric type n, type t); 27 | 28 | module mkCReg#(t init)(CReg#(n, t)) provisos(Bits#(t, tSz)); 29 | Vector#(n, RWire#(t)) lat <- replicateM(mkUnsafeRWire); 30 | 31 | Vector#(n, Vector#(n, RWire#(Maybe#(t)))) dummy <- replicateM(replicateM(mkUnsafeRWire)); 32 | Vector#(n, Reg#(Bool)) dummy2 <- replicateM(mkReg(True)); 33 | 34 | Reg#(t) rl <- mkReg(init); 35 | 36 | CReg#(n, t) r = newVector; 37 | 38 | rule canon; 39 | t upd = rl; 40 | for(Integer i = 0; i < valueOf(n); i = i + 1) 41 | if(lat[i].wget matches tagged Valid .x) 42 | upd = x; 43 | rl <= upd; 44 | endrule 45 | 46 | for(Integer i = 0; i < valueOf(n); i = i + 1) 47 | r[i] = (interface Reg; 48 | method Action _write(t x); 49 | lat[i].wset(x); 50 | dummy2[i] <= True; 51 | for(Integer j = 0; j < i; j = j + 1) 52 | dummy[i][j].wset(lat[j].wget); 53 | endmethod 54 | 55 | method t _read; 56 | t upd = rl; 57 | Bool yes = True; 58 | for(Integer j = i; j < valueOf(n); j = j + 1) 59 | yes = yes && dummy2[j]; 60 | for(Integer j = 0; j < i; j = j + 1) 61 | begin 62 | if(lat[j].wget matches tagged Valid .x) 63 | upd = x; 64 | end 65 | return yes? upd : ?; 66 | endmethod 67 | endinterface); 68 | 69 | return r; 70 | endmodule 71 | 72 | -------------------------------------------------------------------------------- /Day1/lib/Fifo.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2012 4 | 5 | Arvind 6 | Muralidaran Vijayaraghavan 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | */ 15 | 16 | 17 | /* 18 | This file contains many FIFO implementations 19 | 1) Conflict Free FIFO with 2 elements 20 | 2) Pipeline FIFO with 1 element 21 | 3) Bypass FIFO with 1 element 22 | 4) Conflict Free FIFO with n elements (ptr based implementation) 23 | 5) Pipeline FIFO with n elements (ptr based implementation) 24 | 6) Searchable n-element FIFO has an extra search method added to the n-element FIFOs 25 | a) Searchable conflict-free n-element FIFO 26 | b) Searchable pipelined n-element FIFO 27 | 28 | Clear always happens after enq and deq (but before canonicalize when applicable) 29 | All these FIFOs have been tested with various pipelines. In particular n-element FIFO can be put in place of the respective 2-element or 1-element FIFO 30 | 31 | */ 32 | 33 | import CReg::*; 34 | import Vector::*; 35 | 36 | interface Fifo#(numeric type n, type t); 37 | method Bool notFull; 38 | method Action enq(t x); 39 | method Bool notEmpty; 40 | method Action deq; 41 | method t first; 42 | method Action clear; 43 | endinterface 44 | 45 | /* 46 | // This Fifo2 <- mkCFFifo generates a two element FIFO where enq and deq are conflict free 47 | // {notEmpty, first} < deq < clear < canon 48 | // notFull < enq < clear < canon 49 | // deq conflict free with enq 50 | module mkCFFifo(Fifo#(2, t)) provisos(Bits#(t, tSz)); 51 | CReg#(3, t) da <- mkCReg(?); 52 | CReg#(3, Bool) va <- mkCReg(False); 53 | CReg#(3, t) db <- mkCReg(?); 54 | CReg#(3, Bool) vb <- mkCReg(False); 55 | 56 | rule canon if(vb[2] && !va[2]); 57 | da[2] <= db[2]; 58 | va[2] <= True; 59 | vb[2] <= False; 60 | endrule 61 | 62 | method Bool notFull = !vb[0]; 63 | 64 | method Action enq(t x) if(!vb[0]); 65 | db[0] <= x; 66 | vb[0] <= True; 67 | endmethod 68 | 69 | method Bool notEmpty = va[0]; 70 | 71 | method Action deq if (va[0]); 72 | va[0] <= False; 73 | endmethod 74 | 75 | method t first if(va[0]); 76 | return da[0]; 77 | endmethod 78 | 79 | method Action clear; 80 | vb[1] <= False; 81 | va[1] <= False; 82 | endmethod 83 | endmodule 84 | */ 85 | 86 | /* 87 | // This generates a one element FIFO where deq < enq 88 | // {notEmpty, first} < deq < notFull < enq < clear 89 | module mkPipelineFifo(Fifo#(1, t)) provisos(Bits#(t, tSz)); 90 | Reg#(t) data <- mkRegU; 91 | CReg#(3, Bool) full <- mkCReg(False); 92 | 93 | method Bool notFull = !full[1]; 94 | 95 | method Action enq(t x) if(!full[1]); 96 | data <= x; 97 | full[1] <= True; 98 | endmethod 99 | 100 | method Bool notEmpty = full[0]; 101 | 102 | method Action deq if(full[0]); 103 | full[0] <= False; 104 | endmethod 105 | 106 | method t first if(full[0]); 107 | return data; 108 | endmethod 109 | 110 | method Action clear; 111 | full[2] <= False; 112 | endmethod 113 | endmodule 114 | */ 115 | 116 | /* 117 | // A bypass FIFO implementation 118 | // notFull < enq < {notEmpty, first} < deq < clear 119 | module mkBypassFifo(Fifo#(1, t)) provisos(Bits#(t, tSz)); 120 | CReg#(2, t) data <- mkCReg(?); 121 | CReg#(3, Bool) full <- mkCReg(False); 122 | 123 | method Bool notFull = !full[0]; 124 | 125 | method Action enq(t x) if(!full[0]); 126 | data[0] <= x; 127 | full[0] <= True; 128 | endmethod 129 | 130 | method Bool notEmpty = full[1]; 131 | 132 | method Action deq if(full[1]); 133 | full[1] <= False; 134 | endmethod 135 | 136 | method t first if(full[1]); 137 | return data[1]; 138 | endmethod 139 | 140 | method Action clear; 141 | full[2] <= False; 142 | endmethod 143 | endmodule 144 | */ 145 | // A Conflict free implementation of n element FIFO 146 | // {notEmpty, first} < deq < clear < canonicalize 147 | // notFull < enq < clear < canonicalize 148 | // deq conflict free with enq 149 | // canonicalize has no effect after clear anyway 150 | 151 | module mkCFFifo(Fifo#(n, t)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 152 | Integer ni = valueOf(n); 153 | Bit#(sz1) nb = fromInteger(ni); 154 | Bit#(sz1) n2 = 2*nb; 155 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 156 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 157 | CReg#(3, Bit#(sz1)) deqP <- mkCReg(0); 158 | CReg#(3, Bool) enqEn <- mkCReg(True); 159 | CReg#(3, Bool) deqEn <- mkCReg(False); 160 | CReg#(2, t) tempData <- mkCReg(?); 161 | CReg#(2, Maybe#(Bit#(sz1))) tempEnqP <- mkCReg(Invalid); 162 | 163 | rule canonicalize; 164 | Bit#(sz1) cnt = enqP[2] >= deqP[2]? enqP[2] - deqP[2]: 165 | (enqP[2]%nb + nb) - deqP[2]%nb; 166 | if(!enqEn[2] && cnt != nb) enqEn[2] <= True; 167 | if(!deqEn[2] && cnt != 0) deqEn[2] <= True; 168 | 169 | if(isValid(tempEnqP[1])) 170 | begin 171 | data[validValue(tempEnqP[1])] <= tempData[1]; 172 | tempEnqP[1] <= Invalid; 173 | end 174 | endrule 175 | 176 | method Bool notFull = enqEn[0]; 177 | 178 | method Action enq(t x) if(enqEn[0]); 179 | tempData[0] <= x; 180 | tempEnqP[0] <= Valid (enqP[0]%nb); 181 | enqP[0] <= (enqP[0] + 1)%n2; 182 | enqEn[0] <= False; 183 | endmethod 184 | 185 | method Bool notEmpty = deqEn[0]; 186 | 187 | method Action deq if(deqEn[0]); 188 | deqP[0] <= (deqP[0] + 1)%n2; 189 | deqEn[0] <= False; 190 | endmethod 191 | 192 | method t first if(deqEn[0]); 193 | return data[deqP[0]%nb]; 194 | endmethod 195 | 196 | method Action clear; 197 | enqP[1] <= 0; 198 | deqP[1] <= 0; 199 | enqEn[1] <= True; 200 | deqEn[1] <= False; 201 | endmethod 202 | endmodule 203 | 204 | // A pipelined implementation of n element FIFO 205 | // {notEmpty, first} < deq < notFull < enq < clear 206 | 207 | module mkPipelineFifo(Fifo#(n, t)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 208 | Integer ni = valueOf(n); 209 | Bit#(sz1) nb = fromInteger(ni); 210 | Bit#(sz1) n2 = 2*nb; 211 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 212 | CReg#(2, Bit#(sz1)) enqP <- mkCReg(0); 213 | CReg#(2, Bit#(sz1)) deqP <- mkCReg(0); 214 | 215 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 216 | (enqP[0]%nb + nb) - deqP[0]%nb; 217 | Bit#(sz1) cnt1 = enqP[0] >= deqP[1]? enqP[0] - deqP[1]: 218 | (enqP[0]%nb + nb) - deqP[1]%nb; 219 | 220 | method Bool notFull = cnt1 < nb; 221 | 222 | method Action enq(t x) if(cnt1 < nb); 223 | enqP[0] <= (enqP[0] + 1)%n2; 224 | data[enqP[0]%nb] <= x; 225 | endmethod 226 | 227 | method Bool notEmpty = cnt0 != 0; 228 | 229 | method Action deq if(cnt0 != 0); 230 | deqP[0] <= (deqP[0] + 1)%n2; 231 | endmethod 232 | 233 | method t first if(cnt0 != 0); 234 | return data[deqP[0]%nb]; 235 | endmethod 236 | 237 | method Action clear; 238 | enqP[1] <= 0; 239 | deqP[1] <= 0; 240 | endmethod 241 | endmodule 242 | 243 | // A Bypass implementation of n element FIFO 244 | // notFull < enq < {notEmpty, first} < deq < clear 245 | 246 | module mkBypassFifo(Fifo#(n, t)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 247 | Integer ni = valueOf(n); 248 | Bit#(sz1) nb = fromInteger(ni); 249 | Bit#(sz1) n2 = 2*nb; 250 | Vector#(n, CReg#(2, t)) data <- replicateM(mkCReg(?)); 251 | CReg#(2, Bit#(sz1)) enqP <- mkCReg(0); 252 | CReg#(2, Bit#(sz1)) deqP <- mkCReg(0); 253 | 254 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 255 | (enqP[0]%nb + nb) - deqP[0]%nb; 256 | Bit#(sz1) cnt1 = enqP[1] >= deqP[0]? enqP[1] - deqP[0]: 257 | (enqP[1]%nb + nb) - deqP[0]%nb; 258 | 259 | method Bool notFull = cnt0 < nb; 260 | 261 | method Action enq(t x) if(cnt0 < nb); 262 | enqP[0] <= (enqP[0] + 1)%n2; 263 | data[enqP[0]%nb][0] <= x; 264 | endmethod 265 | 266 | method Bool notEmpty = cnt1 != 0; 267 | 268 | method Action deq if(cnt1 != 0); 269 | deqP[0] <= (deqP[0] + 1)%n2; 270 | endmethod 271 | 272 | method t first if(cnt1 != 0); 273 | return data[deqP[0]%nb][1]; 274 | endmethod 275 | 276 | method Action clear; 277 | enqP[1] <= 0; 278 | deqP[1] <= 0; 279 | endmethod 280 | endmodule 281 | 282 | 283 | 284 | // Searchable FIFO has an extra search method 285 | interface SFifo#(numeric type n, type t, type st); 286 | method Bool notFull; 287 | method Action enq(t x); 288 | method Bool notEmpty; 289 | method Action deq; 290 | method Bool search(st s); 291 | method t first; 292 | method Action clear; 293 | endinterface 294 | 295 | // search is conflict-free with {enq, deq, first, notFull, notEmpty} 296 | // search < clear < canonicalize 297 | module mkCFSFifo#(function Bool isFound(t v, st k))(SFifo#(n, t, st)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 298 | Integer ni = valueOf(n); 299 | Bit#(sz1) nb = fromInteger(ni); 300 | Bit#(sz1) n2 = 2*nb; 301 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 302 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 303 | CReg#(3, Bit#(sz1)) deqP <- mkCReg(0); 304 | CReg#(3, Bool) enqEn <- mkCReg(True); 305 | CReg#(3, Bool) deqEn <- mkCReg(False); 306 | CReg#(2, t) tempData <- mkCReg(?); 307 | CReg#(2, Maybe#(Bit#(sz1))) tempEnqP <- mkCReg(Invalid); 308 | CReg#(2, Maybe#(Bit#(sz1))) tempDeqP <- mkCReg(Invalid); 309 | 310 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 311 | (enqP[0]%nb + nb) - deqP[0]%nb; 312 | Bit#(sz1) cnt2 = enqP[2] >= deqP[2]? enqP[2] - deqP[2]: 313 | (enqP[2]%nb + nb) - deqP[2]%nb; 314 | rule canonicalize; 315 | if(!enqEn[2] && cnt2 != nb) enqEn[2] <= True; 316 | if(!deqEn[2] && cnt2 != 0) deqEn[2] <= True; 317 | 318 | if(isValid(tempEnqP[1])) 319 | begin 320 | data[validValue(tempEnqP[1])] <= tempData[1]; 321 | tempEnqP[1] <= Invalid; 322 | end 323 | 324 | if(isValid(tempDeqP[1])) 325 | begin 326 | deqP[0] <= validValue(tempDeqP[1]); 327 | tempDeqP[1] <= Invalid; 328 | end 329 | endrule 330 | 331 | method Bool notFull = enqEn[0]; 332 | 333 | method Action enq(t x) if(enqEn[0]); 334 | tempData[0] <= x; 335 | tempEnqP[0] <= Valid (enqP[0]%nb); 336 | enqP[0] <= (enqP[0] + 1)%n2; 337 | enqEn[0] <= False; 338 | endmethod 339 | 340 | method Bool notEmpty = deqEn[0]; 341 | 342 | method Action deq if(deqEn[0]); 343 | tempDeqP[0] <= Valid ((deqP[0] + 1)%n2); 344 | deqEn[0] <= False; 345 | endmethod 346 | 347 | method t first if(deqEn[0]); 348 | return data[deqP[0]%nb]; 349 | endmethod 350 | 351 | method Bool search(st s); 352 | Bool ret = False; 353 | for(Bit#(sz1) i = 0; i < nb; i = i + 1) 354 | begin 355 | let ptr = (deqP[0] + i)%nb; 356 | if(isFound(data[ptr], s) && i < cnt0) 357 | ret = True; 358 | end 359 | return ret; 360 | endmethod 361 | 362 | method Action clear; 363 | enqP[1] <= 0; 364 | deqP[1] <= 0; 365 | enqEn[1] <= True; 366 | deqEn[1] <= False; 367 | endmethod 368 | endmodule 369 | 370 | // {notEmpty, first} < deq < search 371 | // search CF {enq, notFull} 372 | // search < clear 373 | module mkPipelineSFifo#(function Bool isFound(t v, st k))(SFifo#(n, t, st)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1), Bits#(st, stz)); 374 | Integer ni = valueOf(n); 375 | Bit#(sz1) nb = fromInteger(ni); 376 | Bit#(sz1) n2 = 2*nb; 377 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 378 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 379 | CReg#(2, Bit#(sz1)) deqP <- mkCReg(0); 380 | 381 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 382 | (enqP[0]%nb + nb) - deqP[0]%nb; 383 | Bit#(sz1) cnt1 = enqP[0] >= deqP[1]? enqP[0] - deqP[1]: 384 | (enqP[0]%nb + nb) - deqP[1]%nb; 385 | 386 | method Bool notFull = cnt1 < nb; 387 | 388 | method Action enq(t x) if(cnt1 < nb); 389 | enqP[0] <= (enqP[0] + 1)%n2; 390 | data[enqP[0]%nb] <= x; 391 | endmethod 392 | 393 | method Bool notEmpty = cnt0 != 0; 394 | 395 | method Action deq if(cnt0 != 0); 396 | deqP[0] <= (deqP[0] + 1)%n2; 397 | endmethod 398 | 399 | method t first if(cnt0 != 0); 400 | return data[deqP[0]%nb]; 401 | endmethod 402 | 403 | method Bool search(st s); 404 | Bool ret = False; 405 | for(Bit#(sz1) i = 0; i < nb; i = i + 1) 406 | begin 407 | let ptr = (deqP[1] + i)%nb; 408 | if(isFound(data[ptr], s) && i < cnt1) 409 | ret = True; 410 | end 411 | return ret; 412 | endmethod 413 | 414 | method Action clear; 415 | enqP[2] <= 0; 416 | deqP[1] <= 0; 417 | endmethod 418 | endmodule 419 | 420 | // Searchable Count FIFO has an extra search method which returns the count of the number of elements found 421 | interface SCountFifo#(numeric type n, type t, type st); 422 | method Bool notFull; 423 | method Action enq(t x); 424 | method Bool notEmpty; 425 | method Action deq; 426 | method Bit#(TLog#(TAdd#(n, 1))) search(st s); 427 | method t first; 428 | method Action clear; 429 | endinterface 430 | 431 | // search is conflict-free with {enq, deq, first, notFull, notEmpty} 432 | // search < clear < canonicalize 433 | module mkCFSCountFifo#(function Bool isFound(t v, st k))(SCountFifo#(n, t, st)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 434 | Integer ni = valueOf(n); 435 | Bit#(sz1) nb = fromInteger(ni); 436 | Bit#(sz1) n2 = 2*nb; 437 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 438 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 439 | CReg#(3, Bit#(sz1)) deqP <- mkCReg(0); 440 | CReg#(3, Bool) enqEn <- mkCReg(True); 441 | CReg#(3, Bool) deqEn <- mkCReg(False); 442 | CReg#(2, t) tempData <- mkCReg(?); 443 | CReg#(2, Maybe#(Bit#(sz1))) tempEnqP <- mkCReg(Invalid); 444 | CReg#(2, Maybe#(Bit#(sz1))) tempDeqP <- mkCReg(Invalid); 445 | 446 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 447 | (enqP[0]%nb + nb) - deqP[0]%nb; 448 | Bit#(sz1) cnt2 = enqP[2] >= deqP[2]? enqP[2] - deqP[2]: 449 | (enqP[2]%nb + nb) - deqP[2]%nb; 450 | rule canonicalize; 451 | if(!enqEn[2] && cnt2 != nb) enqEn[2] <= True; 452 | if(!deqEn[2] && cnt2 != 0) deqEn[2] <= True; 453 | 454 | if(isValid(tempEnqP[1])) 455 | begin 456 | data[validValue(tempEnqP[1])] <= tempData[1]; 457 | tempEnqP[1] <= Invalid; 458 | end 459 | 460 | if(isValid(tempDeqP[1])) 461 | begin 462 | deqP[0] <= validValue(tempDeqP[1]); 463 | tempDeqP[1] <= Invalid; 464 | end 465 | endrule 466 | 467 | method Bool notFull = enqEn[0]; 468 | 469 | method Action enq(t x) if(enqEn[0]); 470 | tempData[0] <= x; 471 | tempEnqP[0] <= Valid (enqP[0]%nb); 472 | enqP[0] <= (enqP[0] + 1)%n2; 473 | enqEn[0] <= False; 474 | endmethod 475 | 476 | method Bool notEmpty = deqEn[0]; 477 | 478 | method Action deq if(deqEn[0]); 479 | tempDeqP[0] <= Valid ((deqP[0] + 1)%n2); 480 | deqEn[0] <= False; 481 | endmethod 482 | 483 | method t first if(deqEn[0]); 484 | return data[deqP[0]%nb]; 485 | endmethod 486 | 487 | method Bit#(TLog#(TAdd#(n, 1))) search(st s); 488 | Bit#(TLog#(TAdd#(n, 1))) ret = 0; 489 | for(Bit#(sz1) i = 0; i < nb; i = i + 1) 490 | begin 491 | let ptr = (deqP[0] + i)%nb; 492 | if(isFound(data[ptr], s) && i < cnt0) 493 | ret = ret + 1; 494 | end 495 | return ret; 496 | endmethod 497 | 498 | method Action clear; 499 | enqP[1] <= 0; 500 | deqP[1] <= 0; 501 | enqEn[1] <= True; 502 | deqEn[1] <= False; 503 | endmethod 504 | endmodule 505 | 506 | -------------------------------------------------------------------------------- /Day1/scripts/compile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Copyright (c) 2017 3 | #Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | #Permission is hereby granted, free of charge, to any person obtaining a copy 6 | #of this software and associated documentation files (the "Software"), to deal 7 | #in the Software without restriction, including without limitation the rights 8 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | #copies of the Software, and to permit persons to whom the Software is 10 | #furnished to do so, subject to the following conditions: 11 | 12 | #The above copyright notice and this permission notice shall be included in all 13 | #copies or substantial portions of the Software. 14 | 15 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | #SOFTWARE. 22 | 23 | SRCPATH=./ 24 | LOGDIR=./Log 25 | BUILDDIR=./build 26 | CXXFLAGS="-Wall -Wno-unused -O0 -g -D_FILE_OFFSET_BITS=64 -j 2" 27 | 28 | SRCDIR="./src" 29 | LIBDIR="./lib" 30 | TBDIR="$SRCDIR/Testbenches" 31 | 32 | INCLUDE="$LIBDIR:$SRCDIR" 33 | 34 | DEBUGFLAGS=' 35 | -D DUMMY 36 | ' 37 | 38 | function clean { 39 | rm -rf $BUILDDIR 40 | rm -rf $LOGDIR 41 | rm -rf Verilog 42 | rm -rf *.v 43 | rm -rf ./bdir 44 | rm -rf ./build 45 | rm -f ./sim.so 46 | rm -f ./sim 47 | } 48 | 49 | 50 | function compile_arg { 51 | mkdir -p $BUILDDIR 52 | mkdir -p $BUILDDIR/bdir 53 | bsc -u -D $2 $DEBUGFLAGS -sim +RTS -K1024M -RTS -aggressive-conditions -no-warn-action-shadowing -parallel-sim-link 2 -warn-scheduler-effort -simdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -bdir $BUILDDIR/bdir -p +:$INCLUDE $TBDIR/$1 54 | bsc -u -D $2 $DEBUGFLAGS -sim -e mkTestbench +RTS -K1024M -RTS -bdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -simdir $BUILDDIR/bdir -warn-scheduler-effort -parallel-sim-link 2 -Xc++ -O0 -o sim 55 | mv sim $BUILDDIR/bdir 56 | mv sim.so $BUILDDIR/bdir 57 | } 58 | 59 | function run_test { 60 | ./$BUILDDIR/bdir/sim 61 | } 62 | 63 | case "$1" in 64 | -c) 65 | echo "Compiling Testbench: $2"; 66 | compile_arg $2 $3;; 67 | -clean) clean;; 68 | -r) run_test;; 69 | -h|--help|*) echo " "; 70 | echo "Usage : $0 (flag) (routing)"; 71 | echo "flag list: [-c : compile all] [-clean : cleanup build files] [ -r : run test ] "; 72 | echo " ";; 73 | esac 74 | -------------------------------------------------------------------------------- /Day1/src/PriorityArbiter.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import Vector::*; 25 | import RWire::*; 26 | 27 | typedef 4 NumRequesters; 28 | typedef Bit#(TAdd#(1, TLog#(NumRequesters))) RequesterIdx; 29 | 30 | interface ArbitReq; 31 | method Action reqArbit; 32 | endinterface 33 | 34 | interface ArbitResp; 35 | method Bit#(1) respArbit; 36 | endinterface 37 | 38 | interface PriorityArbiter; 39 | interface Vector#(NumRequesters, ArbitReq) arbitReqPorts; 40 | interface Vector#(NumRequesters, ArbitResp) arbitRespPorts; 41 | endinterface 42 | 43 | 44 | (* synthesize *) 45 | module mkPriorityArbiter(PriorityArbiter); 46 | 47 | Vector#(NumRequesters, RWire#(Bit#(1))) reqs <-replicateM(mkRWire); 48 | Vector#(NumRequesters, RWire#(Bit#(1))) resps <- replicateM(mkRWire); 49 | 50 | 51 | rule doArbitration; 52 | Vector#(NumRequesters, Bit#(1)) requests = newVector; 53 | Bool existsWinner = False; 54 | RequesterIdx winnerIdx = ?; 55 | 56 | for(Integer prt = 0; prt < valueOf(NumRequesters) ; prt = prt +1) begin 57 | requests[prt] = isValid(reqs[prt].wget)? 1: 0; 58 | end 59 | 60 | /****************************************** TODO **********************************************/ 61 | // At this point, you have requester information in the vector requests. 62 | // if(reqests[0] == 1), requester 0 requested a hardware resource managed 63 | // by this arbiter 64 | // 65 | // 1) Based on the priority (requester 0 < requester 1 < requester 2 < requester 3), 66 | // implement a logic that determines a winner (investigate reqs[0] ~ reqs[3] and 67 | // use that information. (hint: apply if-else if statements) 68 | // 69 | // 2) If no one requested the resource, mark "existsWinner" as False. 70 | // If the logic finds a winner, makr existsWinner as True. 71 | // 72 | // 3) Store winner index in "winnerIdx." e.g., if requester 1 won the resource, "winnerIdx = 1;" 73 | 74 | // Implement here 75 | 76 | 77 | /***********************************************************************************************/ 78 | 79 | if(existsWinner) begin 80 | resps[winnerIdx].wset(1); 81 | end 82 | 83 | endrule 84 | 85 | Vector#(NumRequesters, ArbitReq) arbitReqPortsTmp; 86 | Vector#(NumRequesters, ArbitResp) arbitRespPortsTmp; 87 | 88 | for(Integer prt = 0; prt < valueOf(NumRequesters); prt = prt + 1) begin 89 | arbitReqPortsTmp[prt] = 90 | interface ArbitReq 91 | method Action reqArbit; 92 | reqs[prt].wset(1); 93 | endmethod 94 | endinterface; 95 | 96 | arbitRespPortsTmp[prt] = 97 | interface ArbitResp 98 | method Bit#(1) respArbit; 99 | if(!isValid(resps[prt].wget)) begin 100 | return 0; 101 | end 102 | else begin 103 | let ret = validValue(resps[prt].wget); 104 | return ret; 105 | end 106 | endmethod 107 | endinterface; 108 | end 109 | 110 | interface arbitReqPorts = arbitReqPortsTmp; 111 | interface arbitRespPorts = arbitRespPortsTmp; 112 | 113 | endmodule 114 | -------------------------------------------------------------------------------- /Day1/src/Testbenches/Testbench.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import PriorityArbiter::*; 25 | import RWire::*; 26 | 27 | (*synthesize*) 28 | module mkTestbench(); 29 | 30 | Reg#(Bit#(16)) cycles <- mkReg(0); 31 | RWire#(Bit#(3)) winner <- mkRWire; 32 | PriorityArbiter arbiter <- mkPriorityArbiter; 33 | 34 | rule proceedTest; 35 | if(cycles == 10) begin 36 | $finish; 37 | end 38 | else begin 39 | cycles <= cycles + 1; 40 | end 41 | endrule 42 | 43 | rule generateInputs; 44 | $display("\nCycle %d ----------------------------------------------------", cycles); 45 | if(cycles == 0) begin 46 | arbiter.arbitReqPorts[1].reqArbit; 47 | arbiter.arbitReqPorts[2].reqArbit; 48 | arbiter.arbitReqPorts[3].reqArbit; 49 | $display("Requests from 1, 2, 3"); 50 | winner.wset(1); 51 | end 52 | else if (cycles == 1) begin 53 | arbiter.arbitReqPorts[2].reqArbit; 54 | arbiter.arbitReqPorts[3].reqArbit; 55 | $display("Requests from 2, 3"); 56 | winner.wset(2); 57 | end 58 | else if (cycles == 2) begin 59 | arbiter.arbitReqPorts[0].reqArbit; 60 | arbiter.arbitReqPorts[3].reqArbit; 61 | $display("Requests from 0, 3"); 62 | winner.wset(0); 63 | end 64 | else if (cycles == 3) begin 65 | arbiter.arbitReqPorts[3].reqArbit; 66 | $display("Requests from 3"); 67 | winner.wset(3); 68 | end 69 | else if (cycles == 4) begin 70 | arbiter.arbitReqPorts[2].reqArbit; 71 | arbiter.arbitReqPorts[3].reqArbit; 72 | $display("Requests from 2, 3"); 73 | winner.wset(2); 74 | end 75 | else if (cycles == 5) begin 76 | arbiter.arbitReqPorts[0].reqArbit; 77 | arbiter.arbitReqPorts[1].reqArbit; 78 | arbiter.arbitReqPorts[2].reqArbit; 79 | arbiter.arbitReqPorts[3].reqArbit; 80 | $display("Requests from 0, 1, 2, 3"); 81 | winner.wset(0); 82 | end 83 | else if (cycles == 8) begin 84 | arbiter.arbitReqPorts[1].reqArbit; 85 | arbiter.arbitReqPorts[3].reqArbit; 86 | $display("Requests from 1, 3"); 87 | winner.wset(1); 88 | end 89 | else begin 90 | $display("No requests"); 91 | end 92 | 93 | endrule 94 | 95 | 96 | rule readWinners; 97 | for(Integer prt = 0; prt < valueOf(NumRequesters); prt = prt+1) begin 98 | let resp = arbiter.arbitRespPorts[prt].respArbit; 99 | if(resp == 1) begin 100 | $display("Requester %d won the arbitration", prt); 101 | if(isValid(winner.wget)) begin 102 | if(fromInteger(prt) == validValue(winner.wget)) begin 103 | $display("** Correct Output **"); 104 | end 105 | else begin 106 | $display("** Warning! Incorrect Output **"); 107 | end 108 | end 109 | end 110 | end 111 | endrule 112 | 113 | 114 | endmodule 115 | -------------------------------------------------------------------------------- /Day2/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SCRIPT_DIR:=./scripts 3 | BUILD_DIR:=./build 4 | 5 | ReplicatorTest: 6 | $(SCRIPT_DIR)/compile -c ./ReplicatorTestbench.bsv mkTestbench 1 7 | 8 | AdderTest: 9 | $(SCRIPT_DIR)/compile -c ./AdderTestbench.bsv mkTestbench 1 10 | 11 | MultiplierTest: 12 | $(SCRIPT_DIR)/compile -c ./MultiplierTestbench.bsv mkTestbench 1 13 | 14 | run: 15 | $(SCRIPT_DIR)/compile -r 16 | 17 | clean: 18 | $(SCRIPT_DIR)/compile -clean 19 | 20 | -------------------------------------------------------------------------------- /Day2/README: -------------------------------------------------------------------------------- 1 | - Code license (MIT license) 2 | 3 | Copyright (c) 2017 4 | Hyoukjun Kwon (hyoukjun@gatech.edu) 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | 25 | - Directory Structure 26 | 27 | lib: library files 28 | scripts: compilation scripts 29 | src: source file directory 30 | 31 | - Which source file to edit? 32 | ./src/DataReplicator.bsv 33 | ./src/FixedAdder.bsv 34 | ./src/FixedMultiplier.bsv 35 | 36 | - How to compile the code? 37 | for data replicator 38 | > make ReplicatorTest 39 | 40 | for fixed point adder 41 | > make AdderTest 42 | 43 | for fixed point multiplier 44 | > make MultiplierTest 45 | 46 | - How to run the testbench? 47 | > make run 48 | 49 | - How to clean up codebase? 50 | > make clean 51 | 52 | -------------------------------------------------------------------------------- /Day2/lib/CReg.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2012 Muralidaran Vijayaraghavan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | 14 | /* 15 | Comments: This EHR design generates the following scheduling constraints (forall i): 16 | forall j >= i, r[i] < w[j] 17 | forall j < i, r[i] > w[j] 18 | forall j > i, w[i] < w[j] 19 | w[i] conflicts with w[i] 20 | forall j, r[i] is conflict free with r[j] 21 | */ 22 | 23 | import Vector::*; 24 | import RWire::*; 25 | 26 | typedef Vector#(n, Reg#(t)) CReg#(numeric type n, type t); 27 | 28 | module mkCReg#(t init)(CReg#(n, t)) provisos(Bits#(t, tSz)); 29 | Vector#(n, RWire#(t)) lat <- replicateM(mkUnsafeRWire); 30 | 31 | Vector#(n, Vector#(n, RWire#(Maybe#(t)))) dummy <- replicateM(replicateM(mkUnsafeRWire)); 32 | Vector#(n, Reg#(Bool)) dummy2 <- replicateM(mkReg(True)); 33 | 34 | Reg#(t) rl <- mkReg(init); 35 | 36 | CReg#(n, t) r = newVector; 37 | 38 | rule canon; 39 | t upd = rl; 40 | for(Integer i = 0; i < valueOf(n); i = i + 1) 41 | if(lat[i].wget matches tagged Valid .x) 42 | upd = x; 43 | rl <= upd; 44 | endrule 45 | 46 | for(Integer i = 0; i < valueOf(n); i = i + 1) 47 | r[i] = (interface Reg; 48 | method Action _write(t x); 49 | lat[i].wset(x); 50 | dummy2[i] <= True; 51 | for(Integer j = 0; j < i; j = j + 1) 52 | dummy[i][j].wset(lat[j].wget); 53 | endmethod 54 | 55 | method t _read; 56 | t upd = rl; 57 | Bool yes = True; 58 | for(Integer j = i; j < valueOf(n); j = j + 1) 59 | yes = yes && dummy2[j]; 60 | for(Integer j = 0; j < i; j = j + 1) 61 | begin 62 | if(lat[j].wget matches tagged Valid .x) 63 | upd = x; 64 | end 65 | return yes? upd : ?; 66 | endmethod 67 | endinterface); 68 | 69 | return r; 70 | endmodule 71 | 72 | -------------------------------------------------------------------------------- /Day2/lib/Fifo.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2012 4 | 5 | Arvind 6 | Muralidaran Vijayaraghavan 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 11 | 12 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 13 | 14 | */ 15 | 16 | 17 | /* 18 | This file contains many FIFO implementations 19 | 1) Conflict Free FIFO with 2 elements 20 | 2) Pipeline FIFO with 1 element 21 | 3) Bypass FIFO with 1 element 22 | 4) Conflict Free FIFO with n elements (ptr based implementation) 23 | 5) Pipeline FIFO with n elements (ptr based implementation) 24 | 6) Searchable n-element FIFO has an extra search method added to the n-element FIFOs 25 | a) Searchable conflict-free n-element FIFO 26 | b) Searchable pipelined n-element FIFO 27 | 28 | Clear always happens after enq and deq (but before canonicalize when applicable) 29 | All these FIFOs have been tested with various pipelines. In particular n-element FIFO can be put in place of the respective 2-element or 1-element FIFO 30 | 31 | */ 32 | 33 | import CReg::*; 34 | import Vector::*; 35 | 36 | interface Fifo#(numeric type n, type t); 37 | method Bool notFull; 38 | method Action enq(t x); 39 | method Bool notEmpty; 40 | method Action deq; 41 | method t first; 42 | method Action clear; 43 | endinterface 44 | 45 | /* 46 | // This Fifo2 <- mkCFFifo generates a two element FIFO where enq and deq are conflict free 47 | // {notEmpty, first} < deq < clear < canon 48 | // notFull < enq < clear < canon 49 | // deq conflict free with enq 50 | module mkCFFifo(Fifo#(2, t)) provisos(Bits#(t, tSz)); 51 | CReg#(3, t) da <- mkCReg(?); 52 | CReg#(3, Bool) va <- mkCReg(False); 53 | CReg#(3, t) db <- mkCReg(?); 54 | CReg#(3, Bool) vb <- mkCReg(False); 55 | 56 | rule canon if(vb[2] && !va[2]); 57 | da[2] <= db[2]; 58 | va[2] <= True; 59 | vb[2] <= False; 60 | endrule 61 | 62 | method Bool notFull = !vb[0]; 63 | 64 | method Action enq(t x) if(!vb[0]); 65 | db[0] <= x; 66 | vb[0] <= True; 67 | endmethod 68 | 69 | method Bool notEmpty = va[0]; 70 | 71 | method Action deq if (va[0]); 72 | va[0] <= False; 73 | endmethod 74 | 75 | method t first if(va[0]); 76 | return da[0]; 77 | endmethod 78 | 79 | method Action clear; 80 | vb[1] <= False; 81 | va[1] <= False; 82 | endmethod 83 | endmodule 84 | */ 85 | 86 | /* 87 | // This generates a one element FIFO where deq < enq 88 | // {notEmpty, first} < deq < notFull < enq < clear 89 | module mkPipelineFifo(Fifo#(1, t)) provisos(Bits#(t, tSz)); 90 | Reg#(t) data <- mkRegU; 91 | CReg#(3, Bool) full <- mkCReg(False); 92 | 93 | method Bool notFull = !full[1]; 94 | 95 | method Action enq(t x) if(!full[1]); 96 | data <= x; 97 | full[1] <= True; 98 | endmethod 99 | 100 | method Bool notEmpty = full[0]; 101 | 102 | method Action deq if(full[0]); 103 | full[0] <= False; 104 | endmethod 105 | 106 | method t first if(full[0]); 107 | return data; 108 | endmethod 109 | 110 | method Action clear; 111 | full[2] <= False; 112 | endmethod 113 | endmodule 114 | */ 115 | 116 | /* 117 | // A bypass FIFO implementation 118 | // notFull < enq < {notEmpty, first} < deq < clear 119 | module mkBypassFifo(Fifo#(1, t)) provisos(Bits#(t, tSz)); 120 | CReg#(2, t) data <- mkCReg(?); 121 | CReg#(3, Bool) full <- mkCReg(False); 122 | 123 | method Bool notFull = !full[0]; 124 | 125 | method Action enq(t x) if(!full[0]); 126 | data[0] <= x; 127 | full[0] <= True; 128 | endmethod 129 | 130 | method Bool notEmpty = full[1]; 131 | 132 | method Action deq if(full[1]); 133 | full[1] <= False; 134 | endmethod 135 | 136 | method t first if(full[1]); 137 | return data[1]; 138 | endmethod 139 | 140 | method Action clear; 141 | full[2] <= False; 142 | endmethod 143 | endmodule 144 | */ 145 | // A Conflict free implementation of n element FIFO 146 | // {notEmpty, first} < deq < clear < canonicalize 147 | // notFull < enq < clear < canonicalize 148 | // deq conflict free with enq 149 | // canonicalize has no effect after clear anyway 150 | 151 | module mkCFFifo(Fifo#(n, t)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 152 | Integer ni = valueOf(n); 153 | Bit#(sz1) nb = fromInteger(ni); 154 | Bit#(sz1) n2 = 2*nb; 155 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 156 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 157 | CReg#(3, Bit#(sz1)) deqP <- mkCReg(0); 158 | CReg#(3, Bool) enqEn <- mkCReg(True); 159 | CReg#(3, Bool) deqEn <- mkCReg(False); 160 | CReg#(2, t) tempData <- mkCReg(?); 161 | CReg#(2, Maybe#(Bit#(sz1))) tempEnqP <- mkCReg(Invalid); 162 | 163 | rule canonicalize; 164 | Bit#(sz1) cnt = enqP[2] >= deqP[2]? enqP[2] - deqP[2]: 165 | (enqP[2]%nb + nb) - deqP[2]%nb; 166 | if(!enqEn[2] && cnt != nb) enqEn[2] <= True; 167 | if(!deqEn[2] && cnt != 0) deqEn[2] <= True; 168 | 169 | if(isValid(tempEnqP[1])) 170 | begin 171 | data[validValue(tempEnqP[1])] <= tempData[1]; 172 | tempEnqP[1] <= Invalid; 173 | end 174 | endrule 175 | 176 | method Bool notFull = enqEn[0]; 177 | 178 | method Action enq(t x) if(enqEn[0]); 179 | tempData[0] <= x; 180 | tempEnqP[0] <= Valid (enqP[0]%nb); 181 | enqP[0] <= (enqP[0] + 1)%n2; 182 | enqEn[0] <= False; 183 | endmethod 184 | 185 | method Bool notEmpty = deqEn[0]; 186 | 187 | method Action deq if(deqEn[0]); 188 | deqP[0] <= (deqP[0] + 1)%n2; 189 | deqEn[0] <= False; 190 | endmethod 191 | 192 | method t first if(deqEn[0]); 193 | return data[deqP[0]%nb]; 194 | endmethod 195 | 196 | method Action clear; 197 | enqP[1] <= 0; 198 | deqP[1] <= 0; 199 | enqEn[1] <= True; 200 | deqEn[1] <= False; 201 | endmethod 202 | endmodule 203 | 204 | // A pipelined implementation of n element FIFO 205 | // {notEmpty, first} < deq < notFull < enq < clear 206 | 207 | module mkPipelineFifo(Fifo#(n, t)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 208 | Integer ni = valueOf(n); 209 | Bit#(sz1) nb = fromInteger(ni); 210 | Bit#(sz1) n2 = 2*nb; 211 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 212 | CReg#(2, Bit#(sz1)) enqP <- mkCReg(0); 213 | CReg#(2, Bit#(sz1)) deqP <- mkCReg(0); 214 | 215 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 216 | (enqP[0]%nb + nb) - deqP[0]%nb; 217 | Bit#(sz1) cnt1 = enqP[0] >= deqP[1]? enqP[0] - deqP[1]: 218 | (enqP[0]%nb + nb) - deqP[1]%nb; 219 | 220 | method Bool notFull = cnt1 < nb; 221 | 222 | method Action enq(t x) if(cnt1 < nb); 223 | enqP[0] <= (enqP[0] + 1)%n2; 224 | data[enqP[0]%nb] <= x; 225 | endmethod 226 | 227 | method Bool notEmpty = cnt0 != 0; 228 | 229 | method Action deq if(cnt0 != 0); 230 | deqP[0] <= (deqP[0] + 1)%n2; 231 | endmethod 232 | 233 | method t first if(cnt0 != 0); 234 | return data[deqP[0]%nb]; 235 | endmethod 236 | 237 | method Action clear; 238 | enqP[1] <= 0; 239 | deqP[1] <= 0; 240 | endmethod 241 | endmodule 242 | 243 | // A Bypass implementation of n element FIFO 244 | // notFull < enq < {notEmpty, first} < deq < clear 245 | 246 | module mkBypassFifo(Fifo#(n, t)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 247 | Integer ni = valueOf(n); 248 | Bit#(sz1) nb = fromInteger(ni); 249 | Bit#(sz1) n2 = 2*nb; 250 | Vector#(n, CReg#(2, t)) data <- replicateM(mkCReg(?)); 251 | CReg#(2, Bit#(sz1)) enqP <- mkCReg(0); 252 | CReg#(2, Bit#(sz1)) deqP <- mkCReg(0); 253 | 254 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 255 | (enqP[0]%nb + nb) - deqP[0]%nb; 256 | Bit#(sz1) cnt1 = enqP[1] >= deqP[0]? enqP[1] - deqP[0]: 257 | (enqP[1]%nb + nb) - deqP[0]%nb; 258 | 259 | method Bool notFull = cnt0 < nb; 260 | 261 | method Action enq(t x) if(cnt0 < nb); 262 | enqP[0] <= (enqP[0] + 1)%n2; 263 | data[enqP[0]%nb][0] <= x; 264 | endmethod 265 | 266 | method Bool notEmpty = cnt1 != 0; 267 | 268 | method Action deq if(cnt1 != 0); 269 | deqP[0] <= (deqP[0] + 1)%n2; 270 | endmethod 271 | 272 | method t first if(cnt1 != 0); 273 | return data[deqP[0]%nb][1]; 274 | endmethod 275 | 276 | method Action clear; 277 | enqP[1] <= 0; 278 | deqP[1] <= 0; 279 | endmethod 280 | endmodule 281 | 282 | 283 | 284 | // Searchable FIFO has an extra search method 285 | interface SFifo#(numeric type n, type t, type st); 286 | method Bool notFull; 287 | method Action enq(t x); 288 | method Bool notEmpty; 289 | method Action deq; 290 | method Bool search(st s); 291 | method t first; 292 | method Action clear; 293 | endinterface 294 | 295 | // search is conflict-free with {enq, deq, first, notFull, notEmpty} 296 | // search < clear < canonicalize 297 | module mkCFSFifo#(function Bool isFound(t v, st k))(SFifo#(n, t, st)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 298 | Integer ni = valueOf(n); 299 | Bit#(sz1) nb = fromInteger(ni); 300 | Bit#(sz1) n2 = 2*nb; 301 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 302 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 303 | CReg#(3, Bit#(sz1)) deqP <- mkCReg(0); 304 | CReg#(3, Bool) enqEn <- mkCReg(True); 305 | CReg#(3, Bool) deqEn <- mkCReg(False); 306 | CReg#(2, t) tempData <- mkCReg(?); 307 | CReg#(2, Maybe#(Bit#(sz1))) tempEnqP <- mkCReg(Invalid); 308 | CReg#(2, Maybe#(Bit#(sz1))) tempDeqP <- mkCReg(Invalid); 309 | 310 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 311 | (enqP[0]%nb + nb) - deqP[0]%nb; 312 | Bit#(sz1) cnt2 = enqP[2] >= deqP[2]? enqP[2] - deqP[2]: 313 | (enqP[2]%nb + nb) - deqP[2]%nb; 314 | rule canonicalize; 315 | if(!enqEn[2] && cnt2 != nb) enqEn[2] <= True; 316 | if(!deqEn[2] && cnt2 != 0) deqEn[2] <= True; 317 | 318 | if(isValid(tempEnqP[1])) 319 | begin 320 | data[validValue(tempEnqP[1])] <= tempData[1]; 321 | tempEnqP[1] <= Invalid; 322 | end 323 | 324 | if(isValid(tempDeqP[1])) 325 | begin 326 | deqP[0] <= validValue(tempDeqP[1]); 327 | tempDeqP[1] <= Invalid; 328 | end 329 | endrule 330 | 331 | method Bool notFull = enqEn[0]; 332 | 333 | method Action enq(t x) if(enqEn[0]); 334 | tempData[0] <= x; 335 | tempEnqP[0] <= Valid (enqP[0]%nb); 336 | enqP[0] <= (enqP[0] + 1)%n2; 337 | enqEn[0] <= False; 338 | endmethod 339 | 340 | method Bool notEmpty = deqEn[0]; 341 | 342 | method Action deq if(deqEn[0]); 343 | tempDeqP[0] <= Valid ((deqP[0] + 1)%n2); 344 | deqEn[0] <= False; 345 | endmethod 346 | 347 | method t first if(deqEn[0]); 348 | return data[deqP[0]%nb]; 349 | endmethod 350 | 351 | method Bool search(st s); 352 | Bool ret = False; 353 | for(Bit#(sz1) i = 0; i < nb; i = i + 1) 354 | begin 355 | let ptr = (deqP[0] + i)%nb; 356 | if(isFound(data[ptr], s) && i < cnt0) 357 | ret = True; 358 | end 359 | return ret; 360 | endmethod 361 | 362 | method Action clear; 363 | enqP[1] <= 0; 364 | deqP[1] <= 0; 365 | enqEn[1] <= True; 366 | deqEn[1] <= False; 367 | endmethod 368 | endmodule 369 | 370 | // {notEmpty, first} < deq < search 371 | // search CF {enq, notFull} 372 | // search < clear 373 | module mkPipelineSFifo#(function Bool isFound(t v, st k))(SFifo#(n, t, st)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1), Bits#(st, stz)); 374 | Integer ni = valueOf(n); 375 | Bit#(sz1) nb = fromInteger(ni); 376 | Bit#(sz1) n2 = 2*nb; 377 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 378 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 379 | CReg#(2, Bit#(sz1)) deqP <- mkCReg(0); 380 | 381 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 382 | (enqP[0]%nb + nb) - deqP[0]%nb; 383 | Bit#(sz1) cnt1 = enqP[0] >= deqP[1]? enqP[0] - deqP[1]: 384 | (enqP[0]%nb + nb) - deqP[1]%nb; 385 | 386 | method Bool notFull = cnt1 < nb; 387 | 388 | method Action enq(t x) if(cnt1 < nb); 389 | enqP[0] <= (enqP[0] + 1)%n2; 390 | data[enqP[0]%nb] <= x; 391 | endmethod 392 | 393 | method Bool notEmpty = cnt0 != 0; 394 | 395 | method Action deq if(cnt0 != 0); 396 | deqP[0] <= (deqP[0] + 1)%n2; 397 | endmethod 398 | 399 | method t first if(cnt0 != 0); 400 | return data[deqP[0]%nb]; 401 | endmethod 402 | 403 | method Bool search(st s); 404 | Bool ret = False; 405 | for(Bit#(sz1) i = 0; i < nb; i = i + 1) 406 | begin 407 | let ptr = (deqP[1] + i)%nb; 408 | if(isFound(data[ptr], s) && i < cnt1) 409 | ret = True; 410 | end 411 | return ret; 412 | endmethod 413 | 414 | method Action clear; 415 | enqP[2] <= 0; 416 | deqP[1] <= 0; 417 | endmethod 418 | endmodule 419 | 420 | // Searchable Count FIFO has an extra search method which returns the count of the number of elements found 421 | interface SCountFifo#(numeric type n, type t, type st); 422 | method Bool notFull; 423 | method Action enq(t x); 424 | method Bool notEmpty; 425 | method Action deq; 426 | method Bit#(TLog#(TAdd#(n, 1))) search(st s); 427 | method t first; 428 | method Action clear; 429 | endinterface 430 | 431 | // search is conflict-free with {enq, deq, first, notFull, notEmpty} 432 | // search < clear < canonicalize 433 | module mkCFSCountFifo#(function Bool isFound(t v, st k))(SCountFifo#(n, t, st)) provisos(Bits#(t, tSz), Add#(n, 1, n1), Log#(n1, sz), Add#(sz, 1, sz1)); 434 | Integer ni = valueOf(n); 435 | Bit#(sz1) nb = fromInteger(ni); 436 | Bit#(sz1) n2 = 2*nb; 437 | Vector#(n, Reg#(t)) data <- replicateM(mkRegU); 438 | CReg#(3, Bit#(sz1)) enqP <- mkCReg(0); 439 | CReg#(3, Bit#(sz1)) deqP <- mkCReg(0); 440 | CReg#(3, Bool) enqEn <- mkCReg(True); 441 | CReg#(3, Bool) deqEn <- mkCReg(False); 442 | CReg#(2, t) tempData <- mkCReg(?); 443 | CReg#(2, Maybe#(Bit#(sz1))) tempEnqP <- mkCReg(Invalid); 444 | CReg#(2, Maybe#(Bit#(sz1))) tempDeqP <- mkCReg(Invalid); 445 | 446 | Bit#(sz1) cnt0 = enqP[0] >= deqP[0]? enqP[0] - deqP[0]: 447 | (enqP[0]%nb + nb) - deqP[0]%nb; 448 | Bit#(sz1) cnt2 = enqP[2] >= deqP[2]? enqP[2] - deqP[2]: 449 | (enqP[2]%nb + nb) - deqP[2]%nb; 450 | rule canonicalize; 451 | if(!enqEn[2] && cnt2 != nb) enqEn[2] <= True; 452 | if(!deqEn[2] && cnt2 != 0) deqEn[2] <= True; 453 | 454 | if(isValid(tempEnqP[1])) 455 | begin 456 | data[validValue(tempEnqP[1])] <= tempData[1]; 457 | tempEnqP[1] <= Invalid; 458 | end 459 | 460 | if(isValid(tempDeqP[1])) 461 | begin 462 | deqP[0] <= validValue(tempDeqP[1]); 463 | tempDeqP[1] <= Invalid; 464 | end 465 | endrule 466 | 467 | method Bool notFull = enqEn[0]; 468 | 469 | method Action enq(t x) if(enqEn[0]); 470 | tempData[0] <= x; 471 | tempEnqP[0] <= Valid (enqP[0]%nb); 472 | enqP[0] <= (enqP[0] + 1)%n2; 473 | enqEn[0] <= False; 474 | endmethod 475 | 476 | method Bool notEmpty = deqEn[0]; 477 | 478 | method Action deq if(deqEn[0]); 479 | tempDeqP[0] <= Valid ((deqP[0] + 1)%n2); 480 | deqEn[0] <= False; 481 | endmethod 482 | 483 | method t first if(deqEn[0]); 484 | return data[deqP[0]%nb]; 485 | endmethod 486 | 487 | method Bit#(TLog#(TAdd#(n, 1))) search(st s); 488 | Bit#(TLog#(TAdd#(n, 1))) ret = 0; 489 | for(Bit#(sz1) i = 0; i < nb; i = i + 1) 490 | begin 491 | let ptr = (deqP[0] + i)%nb; 492 | if(isFound(data[ptr], s) && i < cnt0) 493 | ret = ret + 1; 494 | end 495 | return ret; 496 | endmethod 497 | 498 | method Action clear; 499 | enqP[1] <= 0; 500 | deqP[1] <= 0; 501 | enqEn[1] <= True; 502 | deqEn[1] <= False; 503 | endmethod 504 | endmodule 505 | 506 | -------------------------------------------------------------------------------- /Day2/scripts/compile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Copyright (c) 2017 3 | #Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | #Permission is hereby granted, free of charge, to any person obtaining a copy 6 | #of this software and associated documentation files (the "Software"), to deal 7 | #in the Software without restriction, including without limitation the rights 8 | #to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | #copies of the Software, and to permit persons to whom the Software is 10 | #furnished to do so, subject to the following conditions: 11 | 12 | #The above copyright notice and this permission notice shall be included in all 13 | #copies or substantial portions of the Software. 14 | 15 | #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | #SOFTWARE. 22 | 23 | SRCPATH=./ 24 | LOGDIR=./Log 25 | BUILDDIR=./build 26 | CXXFLAGS="-Wall -Wno-unused -O0 -g -D_FILE_OFFSET_BITS=64 -j 2" 27 | 28 | SRCDIR="./src" 29 | LIBDIR="./lib" 30 | TBDIR="$SRCDIR/Testbenches" 31 | 32 | INCLUDE="$LIBDIR:$SRCDIR" 33 | 34 | DEBUGFLAGS=' 35 | -D DUMMY 36 | ' 37 | 38 | function clean { 39 | rm -rf $BUILDDIR 40 | rm -rf $LOGDIR 41 | rm -rf Verilog 42 | rm -rf *.v 43 | rm -rf ./bdir 44 | rm -rf ./build 45 | rm -f ./sim.so 46 | rm -f ./sim 47 | } 48 | 49 | 50 | function compile_arg { 51 | mkdir -p $BUILDDIR 52 | mkdir -p $BUILDDIR/bdir 53 | bsc -u -D $2 $DEBUGFLAGS -sim +RTS -K1024M -RTS -aggressive-conditions -no-warn-action-shadowing -parallel-sim-link 2 -warn-scheduler-effort -simdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -bdir $BUILDDIR/bdir -p +:$INCLUDE $TBDIR/$1 54 | bsc -u -D $2 $DEBUGFLAGS -sim -e mkTestbench +RTS -K1024M -RTS -bdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -simdir $BUILDDIR/bdir -warn-scheduler-effort -parallel-sim-link 2 -Xc++ -O0 -o sim 55 | mv sim $BUILDDIR/bdir 56 | mv sim.so $BUILDDIR/bdir 57 | } 58 | 59 | function run_test { 60 | ./$BUILDDIR/bdir/sim 61 | } 62 | 63 | case "$1" in 64 | -c) 65 | echo "Compiling Testbench: $2"; 66 | compile_arg $2 $3;; 67 | -clean) clean;; 68 | -r) run_test;; 69 | -h|--help|*) echo " "; 70 | echo "Usage : $0 (flag) (routing)"; 71 | echo "flag list: [-c : compile all] [-clean : cleanup build files] [ -r : run test ] "; 72 | echo " ";; 73 | esac 74 | -------------------------------------------------------------------------------- /Day2/src/DataReplicator.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import Fifo::*; 25 | 26 | typedef Bit#(16) RepData; 27 | typedef Bit#(16) RepIdx; 28 | 29 | interface DataReplicator; 30 | method Action putData(RepData value, RepIdx numRepeats); 31 | method ActionValue#(RepData) getData; 32 | endinterface 33 | 34 | 35 | (* synthesize *) 36 | module mkDataReplicator(DataReplicator); 37 | Fifo#(1, RepData) inputFifo <- mkPipelineFifo; 38 | Fifo#(1, RepData) outputFifo <- mkBypassFifo; 39 | 40 | Reg#(RepIdx) repCounts <- mkReg(0); 41 | 42 | 43 | rule sendRepData(repCounts != 0); 44 | //TODO: 45 | // 1) store the value stored in inputFifo to output Fifo 46 | // 2) decrement repCounts 47 | // 3) if you finished repeats, deque inputFifo. (inputFifo.deq) 48 | endrule 49 | 50 | method Action putData(RepData value, RepIdx numRepeats) if(repCounts == 0); 51 | //TODO: 52 | // 1) store value to inputFifo using enq method 53 | // 2) store numRepeats to register repCounts 54 | endmethod 55 | 56 | method ActionValue#(RepData) getData; 57 | //TODO: 58 | // 1) dequeue outputFifo 59 | // 2) return outputFifo's first element 60 | outputFifo.deq; 61 | return outputFifo.first; 62 | endmethod 63 | 64 | endmodule 65 | -------------------------------------------------------------------------------- /Day2/src/FixedAdder.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | import Fifo::*; 27 | import FixedTypes::*; 28 | 29 | (* synthesize *) 30 | module mkFixedAdder(FixedALU); 31 | //TODO 32 | // 1) instantiate two input FIFOs for two operands 33 | // 2) instantiate an output FIFO for the results 34 | 35 | rule doAddition; 36 | noAction(); 37 | //TODO: 38 | // 1) Implement fixed point addition using two operands stored in your input FIFOs 39 | // (use pipelineFifo ; e.g., Fifo#(1, FixedPoint) exFifo <- mkPipelineFifo) 40 | // 2) Store the addition results to your output FIFO 41 | // (use bypassFifo ; e.g., Fifo#(1, FixedPoint) exFifo <- mkBypassFifo) 42 | endrule 43 | 44 | method Action putArgA(FixedPoint newArg); 45 | noAction(); 46 | //TODO: store newArg to one of your input FIFO 47 | endmethod 48 | 49 | method Action putArgB(FixedPoint newArg); 50 | noAction(); 51 | //TODO: store newArg to one of your input FIFO 52 | endmethod 53 | 54 | method ActionValue#(FixedPoint) getRes; 55 | //TODO: dequeue your output FIFO and return the first value of your output FIFO 56 | return ?; 57 | endmethod 58 | 59 | endmodule 60 | -------------------------------------------------------------------------------- /Day2/src/FixedMultiplier.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | import Fifo::*; 27 | import FixedTypes::*; 28 | 29 | (* synthesize *) 30 | module mkFixedMultiplier(FixedALU); 31 | //TODO 32 | // 1) instantiate two input FIFOs for two operands 33 | // 2) instantiate an output FIFO for the results 34 | 35 | rule doMultiplication; 36 | noAction(); 37 | //TODO: 38 | // 1) Implement fixed point multiplication using two operands stored in your input FIFOs 39 | // (use pipelineFifo ; e.g., Fifo#(1, FixedPoint) exFifo <- mkPipelineFifo) 40 | // 2) Store the addition results to your output FIFO 41 | // (use bypassFifo ; e.g., Fifo#(1, FixedPoint) exFifo <- mkBypassFifo) 42 | // * Please note that our FixedPoint is Bit#(16) 43 | endrule 44 | 45 | method Action putArgA(FixedPoint newArg); 46 | noAction(); 47 | //TODO: store newArg to one of your input FIFO 48 | endmethod 49 | 50 | method Action putArgB(FixedPoint newArg); 51 | noAction(); 52 | //TODO: store newArg to one of your input FIFO 53 | endmethod 54 | 55 | method ActionValue#(FixedPoint) getRes; 56 | //TODO: dequeue your output FIFO and return the first value of your output FIFO 57 | return ?; 58 | endmethod 59 | 60 | endmodule 61 | -------------------------------------------------------------------------------- /Day2/src/FixedTypes.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | 25 | 26 | typedef 16 FixedPointSz; 27 | typedef Bit#(FixedPointSz) FixedPoint; 28 | 29 | interface FixedALU; 30 | method Action putArgA(FixedPoint newArg); 31 | method Action putArgB(FixedPoint newArg); 32 | method ActionValue#(FixedPoint) getRes; 33 | endinterface 34 | 35 | -------------------------------------------------------------------------------- /Day2/src/Testbenches/AdderTestbench.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import Fifo::*; 25 | import FixedTypes::*; 26 | import FixedAdder::*; 27 | 28 | 29 | (* synthesize *) 30 | module mkTestbench(); 31 | 32 | Reg#(Bit#(32)) cycleReg <- mkReg(0); 33 | 34 | FixedALU adder <- mkFixedAdder; 35 | 36 | Fifo#(5, FixedPoint) correctAnswers <- mkPipelineFifo; 37 | 38 | rule proceedTest; 39 | if(cycleReg < 10) begin 40 | cycleReg <= cycleReg + 1; 41 | end 42 | else begin 43 | $finish; 44 | end 45 | 46 | endrule 47 | 48 | rule genTestPattern; 49 | if(cycleReg == 0) begin 50 | $display("request 1.5 + (-3.65)"); 51 | adder.putArgA(16'b0001100000000000); //1.5 52 | adder.putArgB(16'b1100010110011001); //-3.65 53 | correctAnswers.enq(16'b1101110110011001); //-2.15 54 | end 55 | else if (cycleReg == 1) begin 56 | $display("request 1.732 + 0.512"); 57 | adder.putArgA(16'b0001101110110110); //1.732 58 | adder.putArgB(16'b0000100000110001); //0.512 59 | correctAnswers.enq(16'b0010001111100111); //2.244 60 | end 61 | else if (cycleReg == 2) begin 62 | $display("request (-0.0312) + (-1.329)"); 63 | adder.putArgA(16'b1111111110000000); //-0.0312 64 | adder.putArgB(16'b1110101010111100); //-1.329 65 | correctAnswers.enq(16'b1110101000111100); //-1.3602 66 | end 67 | else if (cycleReg == 3) begin 68 | $display("request (-1.215523) + 2.5321"); 69 | adder.putArgA(16'b1110110010001101); //-1.215523 70 | adder.putArgB(16'b0010101000011101); //2.6321 71 | correctAnswers.enq(16'b0001011010101010); //1.416577 72 | end 73 | endrule 74 | 75 | rule checkResults; 76 | let res <- adder.getRes; 77 | let answer = correctAnswers.first; 78 | correctAnswers.deq; 79 | 80 | $display("Cycle %d", cycleReg); 81 | 82 | if(res == answer) begin 83 | $display("Correct Answer"); 84 | end 85 | else begin 86 | $display("Warning! wrong answer! Result: %b, Answer: %b",res, answer); 87 | end 88 | endrule 89 | 90 | 91 | endmodule 92 | -------------------------------------------------------------------------------- /Day2/src/Testbenches/MultiplierTestbench.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import Fifo::*; 25 | import FixedTypes::*; 26 | import FixedMultiplier::*; 27 | 28 | 29 | (* synthesize *) 30 | module mkTestbench(); 31 | 32 | Reg#(Bit#(32)) cycleReg <- mkReg(0); 33 | 34 | FixedALU multiplier <- mkFixedMultiplier; 35 | 36 | Fifo#(5, FixedPoint) correctAnswers <- mkPipelineFifo; 37 | 38 | rule proceedTest; 39 | if(cycleReg < 10) begin 40 | cycleReg <= cycleReg + 1; 41 | end 42 | else begin 43 | $finish; 44 | end 45 | 46 | endrule 47 | 48 | rule genTestPattern; 49 | if(cycleReg == 0) begin 50 | $display("request 1.5 x (-0.1234)"); 51 | multiplier.putArgA(16'b0001100000000000); //1.5 52 | multiplier.putArgB(16'b1111111000000110); //-0.1234 53 | correctAnswers.enq(16'b1111110100001001); //-0.1851 54 | end 55 | else if (cycleReg == 1) begin 56 | $display("request 1.732 x 0.512"); 57 | multiplier.putArgA(16'b0001101110110110); //1.732 58 | multiplier.putArgB(16'b0000100000110001); //0.512 59 | correctAnswers.enq(16'b0000111000101111); //0.886784 60 | end 61 | else if (cycleReg == 2) begin 62 | $display("request (-0.0312) x (-1.329)"); 63 | multiplier.putArgA(16'b1111111110000000); //-0.0312 64 | multiplier.putArgB(16'b1110101010111100); //-1.329 65 | correctAnswers.enq(16'b0000000010101010); //0.0414648 66 | end 67 | else if (cycleReg == 3) begin 68 | $display("request (-1.215523) x 2.6321"); 69 | multiplier.putArgA(16'b1110110010001101); //-1.215523 70 | multiplier.putArgB(16'b0010101000011101); //2.6321 71 | correctAnswers.enq(16'b1100110011001110); //-3.199378088 72 | end 73 | else if (cycleReg == 4) begin 74 | $display("request (-0.25) x 0.875"); 75 | multiplier.putArgA(16'b1111110000000000); //-0.25 76 | multiplier.putArgB(16'b0000111000000000); //0.875 77 | correctAnswers.enq(16'b1111110010000000); //-0.21875 78 | end 79 | 80 | endrule 81 | 82 | rule checkResults; 83 | let res <- multiplier.getRes; 84 | let answer = correctAnswers.first; 85 | correctAnswers.deq; 86 | 87 | $display("Cycle %d", cycleReg); 88 | 89 | if(res == answer) begin 90 | $display("Correct Answer"); 91 | end 92 | else begin 93 | $display("Warning! wrong answer! Result: %b, Answer: %b",res, answer); 94 | end 95 | endrule 96 | 97 | 98 | endmodule 99 | -------------------------------------------------------------------------------- /Day2/src/Testbenches/ReplicatorTestbench.bsv: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2017 3 | Hyoukjun Kwon (hyoukjun@gatech.edu) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | */ 23 | 24 | import Fifo::*; 25 | import FixedTypes::*; 26 | import DataReplicator::*; 27 | 28 | 29 | (* synthesize *) 30 | module mkTestbench(); 31 | 32 | Reg#(Bit#(32)) cycleReg <- mkReg(0); 33 | 34 | DataReplicator replicator <- mkDataReplicator; 35 | 36 | rule proceedTest; 37 | if(cycleReg < 50) begin 38 | cycleReg <= cycleReg + 1; 39 | end 40 | else begin 41 | $finish; 42 | end 43 | 44 | endrule 45 | 46 | rule genTestPattern; 47 | if(cycleReg == 0) begin 48 | $display("@Cycle %d, Request to repeat 15 three times", cycleReg); 49 | replicator.putData(15, 3); 50 | end 51 | else if (cycleReg == 10) begin 52 | $display("@Cycle %d, Request to repeat 21 five times", cycleReg); 53 | replicator.putData(21, 5); 54 | end 55 | else if (cycleReg == 20) begin 56 | $display("@Cycle %d, Request to repeat 17 ten times", cycleReg); 57 | replicator.putData(17, 10); 58 | end 59 | endrule 60 | 61 | rule checkResults; 62 | let outData <- replicator.getData; 63 | 64 | $display("\n@Cycle %d, received %d", cycleReg, outData); 65 | 66 | endrule 67 | 68 | 69 | endmodule 70 | -------------------------------------------------------------------------------- /Day3/FixedAdder.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | import Fifo::*; 27 | import FixedTypes::*; 28 | 29 | (* synthesize *) 30 | module mkFixedAdder(FixedALU); 31 | Fifo#(1, FixedPoint) argA <- mkPipelineFifo; 32 | Fifo#(1, FixedPoint) argB <- mkPipelineFifo; 33 | 34 | Fifo#(1, FixedPoint) res <- mkBypassFifo; 35 | 36 | rule doAddition; 37 | let operandA = argA.first; 38 | let operandB = argB.first; 39 | argA.deq; 40 | argB.deq; 41 | 42 | res.enq(argA.first + argB.first); 43 | endrule 44 | 45 | method Action putArgA(FixedPoint newArg); 46 | argA.enq(newArg); 47 | endmethod 48 | 49 | method Action putArgB(FixedPoint newArg); 50 | argB.enq(newArg); 51 | endmethod 52 | 53 | method ActionValue#(FixedPoint) getRes; 54 | res.deq; 55 | return res.first; 56 | endmethod 57 | 58 | endmodule 59 | -------------------------------------------------------------------------------- /Day3/FixedMultiplier.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | import Fifo::*; 27 | import FixedTypes::*; 28 | 29 | (* synthesize *) 30 | module mkFixedMultiplier(FixedALU); 31 | Fifo#(1, FixedPoint) argA <- mkPipelineFifo; 32 | Fifo#(1, FixedPoint) argB <- mkPipelineFifo; 33 | 34 | Fifo#(1, FixedPoint) res <- mkBypassFifo; 35 | 36 | rule doMultiplication; 37 | let operandA = argA.first; 38 | let operandB = argB.first; 39 | argA.deq; 40 | argB.deq; 41 | 42 | Bit#(32) extendedA = signExtend(operandA); 43 | Bit#(32) extendedB = signExtend(operandB); 44 | 45 | Bit#(32) extendedRes = extendedA * extendedB; 46 | 47 | FixedPoint resValue = {extendedRes[31], extendedRes[26:24], extendedRes[23:12]}; 48 | 49 | res.enq(resValue); 50 | endrule 51 | 52 | method Action putArgA(FixedPoint newArg); 53 | argA.enq(newArg); 54 | endmethod 55 | 56 | method Action putArgB(FixedPoint newArg); 57 | argB.enq(newArg); 58 | endmethod 59 | 60 | method ActionValue#(FixedPoint) getRes; 61 | res.deq; 62 | return res.first; 63 | endmethod 64 | 65 | endmodule 66 | -------------------------------------------------------------------------------- /Day3/FixedTypes.bsv: -------------------------------------------------------------------------------- 1 | 2 | typedef 16 FixedPointSz; 3 | typedef Bit#(FixedPointSz) FixedPoint; 4 | 5 | interface FixedALU; 6 | method Action putArgA(FixedPoint newArg); 7 | method Action putArgB(FixedPoint newArg); 8 | method ActionValue#(FixedPoint) getRes; 9 | endinterface 10 | 11 | -------------------------------------------------------------------------------- /Day3/Makefile: -------------------------------------------------------------------------------- 1 | 2 | SCRIPT_DIR:=./scripts 3 | BUILD_DIR:=./build 4 | 5 | CompileModule: 6 | $(SCRIPT_DIR)/compile -ms 7 | 8 | run: 9 | $(SCRIPT_DIR)/compile -r 10 | 11 | clean: 12 | $(SCRIPT_DIR)/compile -clean 13 | 14 | -------------------------------------------------------------------------------- /Day3/NeuralNetworkConfig.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /*************** User-defined Neural Network Configuration **************/ 27 | 28 | /* Data type */ 29 | typedef 16 PixelBitSz; 30 | 31 | /* PE configurations */ 32 | //You need to make the number of PEs to be the power of 2 to get microswitch network work 33 | typedef 16 NumPERows; 34 | typedef 8 NumPEColumns; //For RS, NumPEColumns should be greater or equal than the FilterSz. 35 | 36 | typedef 1 PEDelay; 37 | 38 | /* CNN configurations */ 39 | 40 | // Experimental small size 41 | typedef 3 NumChannels; //C 42 | typedef 8 NumFilters; //M, Indicates the number of 3D filters 43 | typedef 1 NumIfMaps; //N 44 | typedef 3 FilterSz; // 'R' in Eyeriss paper 45 | typedef 100 IfMapSz; // 'H' in Eyeriss paper 46 | typedef 1 Stride; //U 47 | 48 | 49 | //Alexnet Conv1 50 | /* 51 | typedef 3 NumChannels; //C 52 | typedef 96 NumFilters; //M, Indicates the number of 3D filters 53 | typedef 1 NumIfMaps; //N 54 | typedef 11 FilterSz; // 'R' in Eyeriss paper 55 | typedef 227 IfMapSz; // 'H' in Eyeriss paper 56 | typedef 4 Stride; //U 57 | */ 58 | 59 | 60 | //Alexnet Conv2 61 | /* 62 | typedef 48 NumChannels; //C 63 | typedef 256 NumFilters; //M, Indicates the number of 3D filters 64 | typedef 1 NumIfMaps; //N 65 | typedef 5 FilterSz; // 'R' in Eyeriss paper 66 | typedef 31 IfMapSz; // 'H' in Eyeriss paper 67 | typedef 1 Stride; //U 68 | */ 69 | 70 | //VGGnet Conv 8 71 | /* 72 | typedef 512 NumChannels; //C 73 | typedef 512 NumFilters; //M, Indicates the number of 3D filters 74 | typedef 1 NumIfMaps; //N 75 | typedef 3 FilterSz; // 'R' in Eyeriss paper 76 | typedef 28 IfMapSz; // 'H' in Eyeriss paper 77 | typedef 1 Stride; //U 78 | */ 79 | //typedef 10 OFmapWidth; // 'E' in Eyeriss paper; will be automatically derived 80 | //typedef 10 OFmapHeight; 81 | 82 | 83 | typedef 1 NumBuffer2NetworkPorts; 84 | typedef 1 NumGlobalBufferPorts; 85 | -------------------------------------------------------------------------------- /Day3/NoCs/common/MatrixArbiter.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | 27 | /* Primitives */ 28 | import Vector::*; 29 | import Fifo::*; 30 | 31 | module mkMatrixArbiter#(Integer numReq)(NtkArbiter#(num)); 32 | 33 | Reg#(Bool) inited <- mkReg(False); 34 | Vector#(num, Vector#(num, Reg#(Bit#(1)))) priorityBits <- replicateM(replicateM(mkReg(1))); 35 | 36 | function Action updatePriorityBits(Integer target); 37 | action 38 | /* 1. Clear the row */ 39 | for(Integer j=0; jidx)? ~priorityBits[idx][i] : priorityBits[i][idx]; 60 | // priBits[i] = (i != idx)? priorityBits[i][idx] : 0; 61 | end 62 | 63 | //Check if any entity 1)has higher priority than me and 2) it requested the resource 64 | priTest = priBits & reqVec; 65 | 66 | return (priTest == 0); 67 | endactionvalue 68 | endfunction 69 | 70 | function ActionValue#(Integer) getGrantIdx(Bit#(num) reqVec); 71 | actionvalue 72 | Integer ret = ?; 73 | 74 | for(Integer i=0; i peID) begin 94 | deqBits[2][1] <= 1; 95 | end 96 | endrule 97 | 98 | rule deqLocalFifos; 99 | for(Integer prt = 0; prt<3; prt=prt+1) 100 | begin 101 | if(deqBits[prt][2] == 1) begin 102 | localFlitInFifos[prt].deq; 103 | deqBits[prt][2] <= 0; 104 | end 105 | end 106 | endrule 107 | 108 | /* LocalFlit traverse */ 109 | rule selectHostPortWinner; 110 | if(localFlitInFifos[0].notEmpty && localFlitInFifos[0].first.localDest == peID) begin 111 | `ifdef DEBUG_BOTTOMSWITCH 112 | $display("[BottomSwitch[%d]] local flit port %d -> %d", peID, 0, 2); 113 | `endif 114 | localFlitOutFifos[2].enq(localFlitInFifos[0].first); 115 | end 116 | else if(localFlitInFifos[1].notEmpty && localFlitInFifos[1].first.localDest == peID) begin 117 | `ifdef DEBUG_BOTTOMSWITCH 118 | $display("[BottomSwitch[%d]] local flit in port %d -> %d", peID, 1, 2); 119 | `endif 120 | localFlitOutFifos[2].enq(localFlitInFifos[1].first); 121 | end 122 | endrule 123 | 124 | rule selectLocalPortWinner0; 125 | if(localFlitInFifos[0].notEmpty && localFlitInFifos[0].first.localDest != peID) begin 126 | `ifdef DEBUG_BOTTOMSWITCH 127 | $display("[BottomSwitch[%d]] local flit in port %d -> %d", peID, 0, 0); 128 | `endif 129 | localFlitOutFifos[0].enq(localFlitInFifos[0].first); 130 | end 131 | else if(localFlitInFifos[2].notEmpty && localFlitInFifos[2].first.localDest < peID) begin 132 | `ifdef DEBUG_BOTTOMSWITCH 133 | $display("[BottomSwitch[%d]] local flit in port %d -> %d", peID, 2, 0); 134 | `endif 135 | localFlitOutFifos[0].enq(localFlitInFifos[2].first); 136 | end 137 | endrule 138 | 139 | rule selectLocalPortWinner1; 140 | if(localFlitInFifos[1].notEmpty && localFlitInFifos[1].first.localDest != peID) begin 141 | `ifdef DEBUG_BOTTOMSWITCH 142 | $display("[BottomSwitch[%d]] local flit in port %d -> %d", peID, 1, 1); 143 | `endif 144 | localFlitOutFifos[1].enq(localFlitInFifos[1].first); 145 | end 146 | else if(localFlitInFifos[2].notEmpty && localFlitInFifos[2].first.localDest > peID) begin 147 | `ifdef DEBUG_BOTTOMSWITCH 148 | $display("[BottomSwitch[%d]] local flit in port %d -> %d", peID, 2, 1); 149 | `endif 150 | localFlitOutFifos[1].enq(localFlitInFifos[2].first); 151 | end 152 | endrule 153 | 154 | Vector#(3, SwitchInPort) interPEInPortDummy; 155 | Vector#(3, SwitchOutPort) interPEOutPortDummy; 156 | for(Integer dirn = 0; dirn < 3 ; dirn = dirn+1) 157 | begin 158 | interPEInPortDummy[dirn] = 159 | interface SwitchInPort 160 | method Action putFlit(Flit flit) if(inited); 161 | `ifdef DEBUG_BOTTOMSWITCH 162 | $display("[BottomSwitch[%d]] Received a local flit in %d", peID, dirn); 163 | `endif 164 | 165 | localFlitInFifos[dirn].enq(flit); 166 | //TODO Need to arbitrate with broadcast; add another buffer to control this and give priority 167 | endmethod 168 | endinterface; 169 | 170 | interPEOutPortDummy[dirn] = 171 | interface SwitchOutPort 172 | method ActionValue#(Flit) getFlit if(inited); 173 | `ifdef DEBUG_BOTTOMSWITCH 174 | $display("[BottomSwitch[%d]] Sending a local flit to %d", peID, dirn); 175 | `endif 176 | localFlitOutFifos[dirn].deq; 177 | return localFlitOutFifos[dirn].first; 178 | endmethod 179 | endinterface; 180 | end 181 | interface interPEInPort = interPEInPortDummy; 182 | interface interPEOutPort = interPEOutPortDummy; 183 | 184 | interface SwitchInPort gatherInPort; 185 | method Action putFlit(Flit flit) if(inited); 186 | `ifdef DEBUG_BOTTOMSWITCH 187 | $display("[BottomSwitch[%d]] Received a gather flit", peID); 188 | `endif 189 | gatherFlitFifo.enq(flit); 190 | endmethod 191 | endinterface 192 | 193 | interface SwitchOutPort gatherOutPort; 194 | method ActionValue#(Flit) getFlit if(inited); 195 | `ifdef DEBUG_BOTTOMSWITCH 196 | $display("[BottomSwitch[%d]] Sending a gather flit", peID); 197 | `endif 198 | gatherFlitFifo.deq; 199 | return gatherFlitFifo.first; 200 | endmethod 201 | endinterface 202 | 203 | interface SwitchInPort scatterInPort; 204 | method Action putFlit(Flit flit) if(inited); 205 | `ifdef DEBUG_BOTTOMSWITCH 206 | $display("[BottomSwitch[%d]] Received a scatter flit", peID); 207 | `endif 208 | scatterFlitFifo.enq(flit); 209 | endmethod 210 | endinterface 211 | 212 | interface SwitchOutPort scatterOutPort; 213 | method ActionValue#(Flit) getFlit if(inited && (scatterFlitFifo.notEmpty || localFlitOutFifos[2].notEmpty)); 214 | //Prioritize scatter Flits 215 | if(scatterFlitFifo.notEmpty) begin 216 | `ifdef DEBUG_BOTTOMSWITCH 217 | $display("[BottomSwitch[%d]] Delivered the scatter flit to PE", peID); 218 | `endif 219 | // isScatterSent[0] <= True; 220 | return scatterFlitFifo.first; 221 | end 222 | else begin 223 | localFlitOutFifos[2].deq; 224 | return localFlitOutFifos[2].first; 225 | end 226 | endmethod 227 | endinterface 228 | 229 | method Action initialize(NumPEsBit initPEID) if(!inited); 230 | peID <= initPEID; 231 | inited <= True; 232 | endmethod 233 | 234 | endmodule 235 | -------------------------------------------------------------------------------- /Day3/NoCs/microswitch/MicroswitchController.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | import Fifo::*; 29 | 30 | /* NoC types */ 31 | import MicroswitchTypes::*; 32 | import MicroswitchMessageTypes::*; 33 | import MicroswitchNetworkTypes::*; 34 | 35 | /* Neural network types */ 36 | import NeuralNetworkTypes::*; 37 | import NeuralNetworkConfig::*; 38 | 39 | interface MicroswitchController; 40 | method MS_ScatterSetupSignal getScatterControlSignal(MS_DestBits destBits); 41 | endinterface 42 | 43 | (* synthesize *) 44 | module mkMicroswitchController(MicroswitchController); 45 | let targ_branchNodes = valueOf(MS_NumLowestBranchNodes); // First targets: NumPEs/2 branch nodes in the lowest level. 46 | let targ_width = 2; 47 | 48 | function MS_ScatterSetupSignal calculateScatterControlSignal(MS_DestBits destBits); 49 | 50 | Vector#(MS_NumMicroswitchLevels, Integer) baseIdx = newVector; 51 | 52 | baseIdx[0] = valueOf(MS_NumBranchNodes) - 1;// - valueOf(MS_NumLowestBranchNodes); 53 | for(Integer idx = 1; idx < valueOf(MS_NumMicroswitchLevels); idx = idx+1) begin 54 | baseIdx[idx] = baseIdx[idx-1] - 2**(valueOf(MS_NumMicroswitchLevels)-idx); 55 | end 56 | 57 | MS_ScatterSetupSignal results = newVector; 58 | 59 | //First level 60 | for(Integer j=0; j PE connection 120 | // Interconnect (1) peArray.pePorts[rowID][columnID].putFlit 121 | // and (2) network.peDataPorts[rowID * valueOf(NumPEColumns) + columnID].getFlit 122 | // 123 | // 2. PE -> NoC connection 124 | // Interconnect (1) peArray.pePorts[rowID][columnID].getFlit 125 | // and (2) network.peDataPorts[rowID * valueOf(NumPEColumns) + columnID].putFlit 126 | // 127 | // * Hints: you will need to use a nested for-loop; replafce "rowID" and "columnID" 128 | // with your for-loop iteration value 129 | 130 | 131 | //Implement here 132 | 133 | 134 | 135 | 136 | /***************************************************************************/ 137 | 138 | //Global buffer - network connection 139 | mkConnection(globalBuffer.ntkPorts[0].putFlit, network.hostDataPort.getFlit); 140 | mkConnection(globalBuffer.ntkPorts[0].getFlit, network.hostDataPort.putFlit); 141 | 142 | mkConnection(globalBuffer.getSetupSignal, network.controlPort.setSwitches); 143 | 144 | endmodule 145 | -------------------------------------------------------------------------------- /Day3/WS_PE.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Fifo::*; 28 | import CReg::*; 29 | import Vector::*; 30 | 31 | /* Neural network types */ 32 | import NeuralNetworkConfig::*; 33 | import NeuralNetworkTypes::*; 34 | import DerivedNeuralNetworkConfig::*; 35 | import WeightStationaryPE_Types::*; 36 | 37 | /* Submodules */ 38 | import FixedTypes::*; 39 | import FixedMultiplier::*; 40 | 41 | /***************************************************************************** 42 | A weight-statinary processing element 43 | ******************************************************************************/ 44 | 45 | (* synthesize *) 46 | module mkWS_ProcessingElement(ProcessingElement); 47 | 48 | /* Input Queues */ 49 | Fifo#(WeightFifoDepth, Pixel) weightFifo <- mkPipelineFifo; 50 | Fifo#(IfMapFifoDepth, Pixel) ifMapFifo <- mkPipelineFifo; 51 | 52 | /* Output Queues */ 53 | Fifo#(PSumFifoDepth, Pixel) pSumFifo <- mkBypassFifo; 54 | 55 | CReg#(2, NumPixelsBit) ifMapCount <- mkCReg(0); 56 | 57 | //TODO Instantiate a fixed mutiplier 58 | 59 | rule requestMult(weightFifo.notEmpty && ifMapFifo.notEmpty); 60 | // Do not touch the following statement 61 | ifMapCount[0] <= ifMapCount[0] + 1; 62 | 63 | /**************************************************************************/ 64 | //TODO: using putArgA and putArgB methods of your fixed point multiplier, 65 | // put weightFifo.first and ifMapFifo.first to request multiplicaiton 66 | // * Note that both Pixel and FixedPoint are Bit#(16), which means 67 | // you can regard type Pixel and FixedPoint are the same type 68 | // * You need to dequeue ifMapFifo to keep weight and iterate over ifMaps 69 | 70 | // Implement here 71 | 72 | /**************************************************************************/ 73 | endrule 74 | 75 | 76 | rule calculatePSum; 77 | /**************************************************************************/ 78 | //TODO: replace the following multipication using your fixed point multiplier 79 | // (use getRes method) 80 | // * To receive a return value of an ActionValue, you need to use "<-" 81 | // ex) let ret <- multiplier.getRes; 82 | 83 | // Implement here 84 | let pixel = ?; 85 | let res = zeroExtend(weightFifo.first) * pixel; //Dummy Multiplication 86 | 87 | /**************************************************************************/ 88 | 89 | pSumFifo.enq(res); //Store result to the output Fifo results 90 | 91 | // Dataflow control; if 92 | if(ifMapCount[1] >= fromInteger(valueOf(NumIfMapPixels)) ) begin 93 | `ifdef DEBUG_WS_PE_WEIGHT 94 | $display("[WS_PE]Deque a weight"); 95 | `endif 96 | ifMapCount[1] <= 0; 97 | weightFifo.deq; 98 | end 99 | endrule 100 | 101 | method Action enqWeight(Pixel weight); 102 | `ifdef DEBUG_WS_PE_WEIGHT 103 | $display("[WS_PE]Received a Weight"); 104 | `endif 105 | weightFifo.enq(weight); 106 | endmethod 107 | 108 | method Action enqIfMap(Pixel ifPixel); 109 | `ifdef DEBUG_WS_PE 110 | $display("[WS_PE]Received an IfMap"); 111 | `endif 112 | ifMapFifo.enq(ifPixel); 113 | endmethod 114 | 115 | method ActionValue#(Pixel) deqPSum; 116 | `ifdef DEBUG_WS_PE 117 | $display("[WS_PE]Sending a PSum"); 118 | `endif 119 | pSumFifo.deq; 120 | return pSumFifo.first; 121 | endmethod 122 | 123 | method Action enqPSum(Pixel pSum); 124 | `ifdef DEBUG_WS_PE 125 | $display("[WS_PE]Received an IfMap"); 126 | `endif 127 | noAction; 128 | endmethod 129 | 130 | endmodule 131 | -------------------------------------------------------------------------------- /Day3/WS_PE_Array.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | 29 | /* NoC types */ 30 | import MicroswitchTypes::*; 31 | import MicroswitchMessageTypes::*; 32 | import MicroswitchNetworkTypes::*; 33 | 34 | /* Neural network types */ 35 | import NeuralNetworkConfig::*; 36 | import NeuralNetworkTypes::*; 37 | import WeightStationaryPE_Types::*; 38 | 39 | /* Neural network modules */ 40 | import WS_PE_Unit::*; 41 | import WS_MicroswitchNIC::*; 42 | 43 | (* synthesize *) 44 | module mkPE_Array(ProcessingElementArray); 45 | Reg#(Bool) inited <- mkReg(False); 46 | /**************************************************************************/ 47 | //TODO: Initialize a PE array using name "peArray". The size of peArray (number of PEs in the array) is NumPERows x NumPEColumns 48 | // To instantiate a PE, sytax is as the following: ProcessingElementUnit singlePE <- mkWS_ProcessingElementUnit; 49 | // * You will need to use a nested Vector. 50 | 51 | // Implement here 52 | 53 | 54 | /**************************************************************************/ 55 | 56 | rule doInitialize(!inited); 57 | $display("[WS_PE_Array]Initialize"); 58 | inited <= True; 59 | for(Integer i = 0; i= fromInteger(valueOf(NumPEs))) begin 103 | numReceivedPSums[1] <= 0; 104 | 105 | `ifdef DEBUG_GLOBALBUFFER 106 | $display("numSentIfmaps: %d (Max: %d)", numSentIfMaps, valueOf(NumIfMapPixels)); 107 | `endif 108 | if(numSentIfMaps >= fromInteger(valueOf(NumIfMapPixels))) begin 109 | 110 | `ifdef DEBUG_GLOBALBUFFER 111 | $display("to weight braodcast"); 112 | `endif 113 | numSentIfMaps <= 0; 114 | bufferState <= WeightSend; 115 | end 116 | else begin 117 | `ifdef DEBUG_GLOBALBUFFER 118 | $display("to input feature map broadcast"); 119 | `endif 120 | bufferState <= IfMapSend; 121 | end 122 | 123 | if(lastWeight) begin 124 | isFinishedReg <= True; 125 | end 126 | end 127 | end 128 | endcase 129 | 130 | endrule 131 | 132 | interface GlobalBufferPort bufferPort; 133 | method Action enqMsg(GlobalBufferMsg msg); 134 | `ifdef DEBUG_GLOBALBUFFER 135 | $display("[GlobalBuffer]: Received a PSUM"); 136 | `endif 137 | numReceivedPSums[0] <= numReceivedPSums[0] + 1; 138 | endmethod 139 | 140 | method ActionValue#(GlobalBufferMsg) deqMsg; 141 | `ifdef DEBUG_GLOBALBUFFER 142 | $display("[GlobalBuffer]: Sending a message"); 143 | `endif 144 | let flit = outFifo.first; 145 | outFifo.deq; 146 | return flit; 147 | endmethod 148 | endinterface 149 | 150 | method Bool isFinished; 151 | return isFinishedReg; 152 | endmethod 153 | 154 | endmodule 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /Day3/accelerator/global_buffer/GlobalBufferMicroswitchNIC.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | import Fifo::*; 29 | import CReg::*; 30 | import Randomizable::*; 31 | 32 | /* NoC types */ 33 | import MicroswitchTypes::*; 34 | import MicroswitchMessageTypes::*; 35 | import MicroswitchNetworkTypes::*; 36 | 37 | /* Neural network types */ 38 | import NeuralNetworkConfig::*; 39 | import NeuralNetworkTypes::*; 40 | import GlobalBufferTypes::*; 41 | 42 | /* NoC modules */ 43 | import MicroswitchController::*; 44 | 45 | /* Neural network modules */ 46 | import GlobalBuffer::*; 47 | 48 | (* synthesize *) 49 | module mkGlobalBufferMicroswitchNIC(GlobalBufferNIC); 50 | 51 | function Flit globalBufferMsg2Flit(GlobalBufferMsg msg); 52 | Flit flit = ?; 53 | flit.msgType = msg.dataType; 54 | flit.dests = msg.dests; 55 | flit.flitData = msg.pixelData; 56 | return flit; 57 | endfunction 58 | 59 | Reg#(Maybe#(GlobalBufferMsg)) currMsg <- mkReg(Invalid); 60 | CReg#(2, Bool) injectionSuccess <- mkCReg(False); 61 | 62 | /* For broadcasting */ 63 | Reg#(RowID) currRowID <- mkReg(0); 64 | Reg#(ColID) currColID <- mkReg(0); 65 | 66 | Reg#(Bool) inited <- mkReg(False); 67 | 68 | Fifo#(1, GlobalBufferMsg) outMsgFifo <- mkBypassFifo; 69 | 70 | Randomize#(Data) recvRand <- mkConstrainedRandomizer(0, 99); 71 | Randomize#(Data) delayRand <- mkConstrainedRandomizer(1,3); 72 | Reg#(Data) delayReg <- mkReg(0); 73 | 74 | MicroswitchController msController <- mkMicroswitchController; 75 | 76 | 77 | Fifo#(2, MS_ScatterSetupSignal) controlSignalOutFifo <- mkBypassFifo; 78 | Fifo#(2, Flit) flitOutFifo <- mkPipelineFifo; 79 | Fifo#(1, Flit) flitInFifo <- mkPipelineFifo; 80 | 81 | let runningBroadcast = isValid(currMsg) 82 | && (validValue(currMsg).msgType == Broadcast); 83 | 84 | let runningMulticast = isValid(currMsg) 85 | && (validValue(currMsg).msgType == Multicast); 86 | 87 | rule doInit(!inited); 88 | inited <= True; 89 | delayRand.cntrl.init; 90 | recvRand.cntrl.init; 91 | endrule 92 | 93 | 94 | rule do_Broadcast(runningBroadcast); 95 | Flit newFlit = ?; 96 | newFlit.msgType = validValue(currMsg).dataType; 97 | //Destination 98 | MS_DestBits dest = 0; 99 | for(Integer targ = 0; targ < valueOf(NumPEs); targ = targ+1) begin 100 | dest[targ] = 1; 101 | end 102 | newFlit.dests = dest; 103 | newFlit.flitData = validValue(currMsg).pixelData; 104 | 105 | `ifdef DEBUG_GLOBALBUFFERNIC 106 | $display("[GlobalBufferNIC] Broadcast. Destination encoding: %b", dest); 107 | `endif 108 | 109 | let controlSignal = msController.getScatterControlSignal(dest); 110 | controlSignalOutFifo.enq(controlSignal); 111 | flitOutFifo.enq(newFlit); 112 | currMsg <= Invalid; 113 | endrule 114 | 115 | rule do_MulticastControl(runningMulticast && injectionSuccess[1] == True); 116 | //Check Finish broadcasting 117 | `ifdef DEBUG_GLOBALBUFFERNIC 118 | $display("[GlobalBufferNIC]Multicasting, current target: (%d, %d)", currRowID, currColID); 119 | `endif 120 | if((currRowID == fromInteger(valueOf(NumPERows))-1) 121 | && (currColID == fromInteger(valueOf(NumPEColumns))-1) 122 | ) begin 123 | `ifdef DEBUG_GLOBALBUFFERNIC 124 | $display("[GlobalBufferNIC]Finished multicasting. Invalidate current message"); 125 | `endif 126 | currRowID <= 0; 127 | currColID <= 0; 128 | currMsg <= Invalid; 129 | end 130 | else if(currColID == fromInteger(valueOf(NumPEColumns))-1) begin 131 | currRowID <= currRowID +1; 132 | currColID <= 0; 133 | end 134 | else begin 135 | currColID <= currColID + 1; 136 | end 137 | injectionSuccess[1] <= False; 138 | endrule 139 | 140 | rule do_receiveFlits; 141 | let recvFlit = flitInFifo.first; 142 | flitInFifo.deq; 143 | GlobalBufferMsg outMsg = GlobalBufferMsg{msgType: Gather, dataType: ?, dests: 0, pixelData:1}; 144 | outMsgFifo.enq(outMsg); 145 | endrule 146 | 147 | rule do_multicastFlitInjection(runningMulticast); 148 | Flit newFlit = ?; 149 | newFlit.msgType = validValue(currMsg).dataType; 150 | //Destination 151 | MS_DestBits dest = 0; 152 | Data targIdx = zeroExtend(currRowID) * fromInteger(valueOf(NumPEColumns)) + zeroExtend(currColID); 153 | dest[targIdx] = 1; 154 | newFlit.dests = dest; 155 | 156 | newFlit.flitData = validValue(currMsg).pixelData; 157 | 158 | `ifdef DEBUG_GLOBALBUFFERNIC 159 | $display("[GlobalBufferNIC] currRowID, currColID = (%d, %d) ", currRowID, currColID); 160 | $display("[GlobalBufferNIC] Destination: %d Destination encoding: %b", targIdx, dest); 161 | `endif 162 | 163 | let controlSignal = msController.getScatterControlSignal(dest); 164 | controlSignalOutFifo.enq(controlSignal); 165 | 166 | flitOutFifo.enq(newFlit); 167 | injectionSuccess[0] <= True; 168 | endrule 169 | 170 | Vector#(NumBuffer2NetworkPorts, NetworkExternalInterface) ntkPortsDummy; 171 | for(Integer prt = 0; prt < valueOf(NumBuffer2NetworkPorts); prt = prt+1) begin 172 | ntkPortsDummy[prt] = 173 | interface NetworkExternalInterface 174 | method Action putFlit(Flit flit); 175 | `ifdef DEBUG_GLOBALBUFFERNIC 176 | $display("[GlobalBufferNIC] port[%d]: receiving a flit", prt); 177 | `endif 178 | flitInFifo.enq(flit); 179 | endmethod 180 | 181 | method ActionValue#(Flit) getFlit; 182 | `ifdef DEBUG_GLOBALBUFFERNIC 183 | $display("[GlobalBufferNIC] port[%d]: sending a flit", prt); 184 | `endif 185 | flitOutFifo.deq; 186 | let flit = flitOutFifo.first; 187 | return flit; 188 | endmethod 189 | 190 | endinterface; 191 | end 192 | interface ntkPorts = ntkPortsDummy; 193 | 194 | interface GlobalBufferPort bufferPort; 195 | method Action enqMsg(GlobalBufferMsg msg) if(!isValid(currMsg)); 196 | currMsg <= Valid(msg); 197 | endmethod 198 | 199 | method ActionValue#(GlobalBufferMsg) deqMsg; 200 | outMsgFifo.deq; 201 | return outMsgFifo.first; 202 | endmethod 203 | endinterface 204 | 205 | method ActionValue#(MS_ScatterSetupSignal) getSetupSignal; 206 | `ifdef DEBUG_GLOBALBUFFERNIC 207 | $display("[GlobalBufferNIC] sending a control signal"); 208 | `endif 209 | 210 | controlSignalOutFifo.deq; 211 | let controlSignal = controlSignalOutFifo.first; 212 | return controlSignal; 213 | endmethod 214 | 215 | endmodule 216 | -------------------------------------------------------------------------------- /Day3/accelerator/global_buffer/GlobalBufferUnit.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | import Fifo::*; 29 | import Connectable::*; 30 | 31 | /* NoC Types */ 32 | import MicroswitchTypes::*; 33 | import MicroswitchMessageTypes::*; 34 | import MicroswitchNetworkTypes::*; 35 | 36 | /* Neuralnetwork Types */ 37 | import NeuralNetworkConfig::*; 38 | import NeuralNetworkTypes::*; 39 | import DerivedNeuralNetworkConfig::*; 40 | import GlobalBufferTypes::*; 41 | 42 | /* Neuralnetwork Modules */ 43 | `ifdef RS 44 | import RS_GlobalBuffer::*; 45 | import RS_GlobalBufferMicroswitchNIC::*; 46 | `else 47 | import GlobalBuffer::*; 48 | import GlobalBufferMicroswitchNIC::*; 49 | `endif 50 | 51 | 52 | 53 | function Data countOnes(DestBits dest); 54 | Data oneCount = 0; 55 | for(Integer d = 0; d 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | 11 | */ 12 | 13 | 14 | /* 15 | Comments: This EHR design generates the following scheduling constraints (forall i): 16 | forall j >= i, r[i] < w[j] 17 | forall j < i, r[i] > w[j] 18 | forall j > i, w[i] < w[j] 19 | w[i] conflicts with w[i] 20 | forall j, r[i] is conflict free with r[j] 21 | */ 22 | 23 | import Vector::*; 24 | import RWire::*; 25 | 26 | typedef Vector#(n, Reg#(t)) CReg#(numeric type n, type t); 27 | 28 | module mkCReg#(t init)(CReg#(n, t)) provisos(Bits#(t, tSz)); 29 | Vector#(n, RWire#(t)) lat <- replicateM(mkUnsafeRWire); 30 | 31 | Vector#(n, Vector#(n, RWire#(Maybe#(t)))) dummy <- replicateM(replicateM(mkUnsafeRWire)); 32 | Vector#(n, Reg#(Bool)) dummy2 <- replicateM(mkReg(True)); 33 | 34 | Reg#(t) rl <- mkReg(init); 35 | 36 | CReg#(n, t) r = newVector; 37 | 38 | rule canon; 39 | t upd = rl; 40 | for(Integer i = 0; i < valueOf(n); i = i + 1) 41 | if(lat[i].wget matches tagged Valid .x) 42 | upd = x; 43 | rl <= upd; 44 | endrule 45 | 46 | for(Integer i = 0; i < valueOf(n); i = i + 1) 47 | r[i] = (interface Reg; 48 | method Action _write(t x); 49 | lat[i].wset(x); 50 | dummy2[i] <= True; 51 | for(Integer j = 0; j < i; j = j + 1) 52 | dummy[i][j].wset(lat[j].wget); 53 | endmethod 54 | 55 | method t _read; 56 | t upd = rl; 57 | Bool yes = True; 58 | for(Integer j = i; j < valueOf(n); j = j + 1) 59 | yes = yes && dummy2[j]; 60 | for(Integer j = 0; j < i; j = j + 1) 61 | begin 62 | if(lat[j].wget matches tagged Valid .x) 63 | upd = x; 64 | end 65 | return yes? upd : ?; 66 | endmethod 67 | endinterface); 68 | 69 | return r; 70 | endmodule 71 | 72 | -------------------------------------------------------------------------------- /Day3/configs/microswitch_types/MicroswitchMessageTypes.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* NoC types */ 27 | import MicroswitchTypes::*; 28 | /* Neural network types */ 29 | import NeuralNetworkTypes::*; 30 | 31 | typedef NeuralNetworkFlitType MsgType; // enum {Weight, IfMap, PSum, OfMap} 32 | typedef enum {Head, Body, Tail, HeadTail} FlitType deriving(Bits, Eq); 33 | 34 | typedef Pixel FlitData; 35 | 36 | // Flit 37 | typedef struct { 38 | MsgType msgType; // {Weight, IfMap, PSum, OfMap} 39 | DestBits dests; 40 | NumPEsBit localDest; 41 | FlitData flitData; 42 | } Flit deriving (Bits, Eq); 43 | 44 | 45 | interface SwitchInPort; 46 | method Action putFlit(Flit flit); 47 | endinterface 48 | 49 | interface SwitchOutPort; 50 | method ActionValue#(Flit) getFlit; 51 | endinterface 52 | 53 | -------------------------------------------------------------------------------- /Day3/configs/microswitch_types/MicroswitchNetworkTypes.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | 29 | /* Microswitch types */ 30 | import MicroswitchTypes::*; 31 | import MicroswitchMessageTypes::*; 32 | 33 | /* Neural network types */ 34 | import NeuralNetworkConfig::*; 35 | import NeuralNetworkTypes::*; 36 | 37 | //Assumption: NumPEs = 2^n 38 | typedef TLog#(NumPEs) MS_NumMicroswitchLevels; 39 | typedef MS_NumMicroswitchLevels MS_NumMiddleSwitchLevels; 40 | typedef TMul#(MS_NumMicroswitchLevels, NumPEs) MS_NumSwitches; // N log(N) 41 | typedef TDiv#(NumPEs, 2) MS_NumLowestBranchNodes; 42 | typedef TSub#(NumPEs, 1) MS_NumBranchNodes; // N-1 43 | 44 | typedef TDiv#(NumPEs, 2) MS_RootTopSwitchID; 45 | 46 | interface NetworkExternalInterface; 47 | method Action putFlit(Flit req); 48 | method ActionValue#(Flit) getFlit; 49 | endinterface 50 | 51 | typedef Vector#(MS_NumBranchNodes, MS_SetupSignal) MS_ScatterSetupSignal; 52 | -------------------------------------------------------------------------------- /Day3/configs/microswitch_types/MicroswitchTypes.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Neural network types */ 27 | import NeuralNetworkConfig::*; 28 | import NeuralNetworkTypes::*; 29 | 30 | typedef 32 DataSz; 31 | typedef Bit#(DataSz) Data; 32 | 33 | typedef Bit#(2) MS_SetupSignal; 34 | typedef Bit#(TAdd#(NumPEs,1)) MS_DestBits; 35 | 36 | typedef 2 MS_GatherFifoDepth; 37 | 38 | interface NtkArbiter#(numeric type numRequesters); 39 | method Action initialize; 40 | method ActionValue#(Bit#(numRequesters)) getArbit(Bit#(numRequesters) reqBit); 41 | endinterface 42 | 43 | 44 | typedef 100 RecvRate; 45 | 46 | -------------------------------------------------------------------------------- /Day3/configs/neuralnetwork_types/.gitignore: -------------------------------------------------------------------------------- 1 | benchmarks/ 2 | -------------------------------------------------------------------------------- /Day3/configs/neuralnetwork_types/DerivedNeuralNetworkConfig.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | import NeuralNetworkConfig::*; 27 | 28 | /* Filter Dimensions */ 29 | typedef TMul#(FilterSz, FilterSz) NumPixelsPerFilterPlane; 30 | typedef TMul#(NumChannels, NumPixelsPerFilterPlane) NumPixelsPerFilter; 31 | typedef TMul#(NumFilters, NumPixelsPerFilter) NumFilterWeights; 32 | 33 | /* Ifmap Dimensions */ 34 | typedef TMul#(NumChannels, TMul#(IfMapSz, IfMapSz)) NumPixelsPerIfMap; 35 | typedef TMul#(NumIfMaps, NumPixelsPerIfMap) NumIfMapPixels; 36 | 37 | /* Ofmap Dimensions */ 38 | typedef TDiv#(TSub#(IfMapSz, TSub#(FilterSz, Stride)), Stride) OfMapSz; 39 | typedef TMul#(OfMapSz, OfMapSz) NumPixelsPerOfMapPlane; 40 | typedef TMul#(NumPixelsPerOfMapPlane, NumFilters) NumPixelsPerOfMap; 41 | typedef TMul#(NumIfMaps, NumPixelsPerOfMap) NumOfMapPixels; 42 | 43 | //For RS 44 | //typedef TDiv#(NumOfMapPixels, NumPERows) NumPSumsRS; //Assumption: NumPERows == FilterSz 45 | typedef TMul#(NumOfMapPixels, FilterSz) NumPSumsRS; 46 | typedef TDiv#(OfMapSz, NumPEColumns) NumNormalColumnIteration; 47 | 48 | /* Effective IfMap Dimensions */ 49 | 50 | typedef TMul#(NumPixelsPerFilterPlane, NumPixelsPerOfMapPlane) NumEffectiveIfMapPixelsPlane; 51 | 52 | typedef TMul#(NumIfMaps, 53 | TMul#(NumPixelsPerFilterPlane, 54 | NumPixelsPerOfMapPlane)) 55 | NumEffectiveIfMapPixelsPerChannel; 56 | 57 | 58 | typedef TMul#(NumChannels, NumEffectiveIfMapPixelsPerChannel) NumEffectiveIfMapPixels; 59 | 60 | -------------------------------------------------------------------------------- /Day3/configs/neuralnetwork_types/GlobalBufferTypes.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | 29 | /* NoC types */ 30 | import MicroswitchTypes::*; 31 | import MicroswitchMessageTypes::*; 32 | import MicroswitchNetworkTypes::*; 33 | 34 | /* Neural network Types */ 35 | import NeuralNetworkConfig::*; 36 | import NeuralNetworkTypes::*; 37 | 38 | 39 | 40 | 41 | typedef enum {Idle, WeightSend, IfMapSend, PSumGather} GlobalBufferState deriving(Bits, Eq); 42 | 43 | typedef enum {Broadcast, Multicast, Gather, Point2Point} GlobalBufferMessageType deriving(Bits, Eq); 44 | 45 | typedef NeuralNetworkFlitType GlobalBufferDataType; 46 | 47 | typedef struct { 48 | GlobalBufferMessageType msgType; 49 | GlobalBufferDataType dataType; 50 | DestBits dests; 51 | Pixel pixelData; 52 | } GlobalBufferMsg deriving(Bits, Eq); 53 | 54 | interface GlobalBufferPort; 55 | method Action enqMsg(GlobalBufferMsg msg); 56 | method ActionValue#(GlobalBufferMsg) deqMsg; 57 | endinterface 58 | 59 | interface GlobalBuffer; 60 | method Bool isFinished; 61 | interface GlobalBufferPort bufferPort; 62 | endinterface 63 | 64 | interface GlobalBufferNIC; 65 | interface Vector#(NumBuffer2NetworkPorts, NetworkExternalInterface) ntkPorts; 66 | interface GlobalBufferPort bufferPort; 67 | method ActionValue#(MS_ScatterSetupSignal) getSetupSignal; 68 | endinterface 69 | 70 | interface GlobalBufferStat; 71 | method Data getNumWeights; 72 | method Data getNumIfMaps; 73 | method Data getNumPSums; 74 | endinterface 75 | 76 | interface GlobalBufferUnit; 77 | method Bool isFinished; 78 | interface GlobalBufferStat stats; 79 | interface Vector#(NumBuffer2NetworkPorts, NetworkExternalInterface) ntkPorts; 80 | method ActionValue#(MS_ScatterSetupSignal) getSetupSignal; 81 | endinterface 82 | 83 | -------------------------------------------------------------------------------- /Day3/configs/neuralnetwork_types/NeuralNetworkTypes.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | import NeuralNetworkConfig::*; 27 | import DerivedNeuralNetworkConfig::*; 28 | 29 | /********** Derived parameters ************/ 30 | 31 | /* Pixel */ 32 | typedef Bit#(PixelBitSz) Pixel; 33 | 34 | /* PE Dimensions */ 35 | typedef TAdd#(1, TLog#(NumPERows)) RowIDBitSz; 36 | typedef TAdd#(1, TLog#(NumPEColumns)) ColIDBitSz; 37 | 38 | typedef Bit#(RowIDBitSz) RowID; 39 | typedef Bit#(ColIDBitSz) ColID; 40 | 41 | typedef TMul#(NumPERows, NumPEColumns) NumPEs; 42 | 43 | typedef TAdd#(TLog#(NumPEs), 1) NumPEsBitSz; 44 | typedef Bit#(NumPEsBitSz) NumPEsBit; 45 | 46 | typedef Bit#(TAdd#(NumPEs, 1)) DestBits; 47 | 48 | /* Foldings */ 49 | typedef TDiv#(IfMapSz, NumPEs) RowFoldings; 50 | typedef TDiv#(IfMapSz, NumPEs) ColumnFoldings; 51 | 52 | /* IF dimensions */ 53 | typedef TAdd#( TLog#(NumIfMapPixels), 1) NumPixelsBitSz; 54 | typedef Bit#(NumPixelsBitSz) NumPixelsBit; 55 | 56 | typedef TAdd#(TLog#(FilterSz), 1) WeightBitSize; 57 | typedef Bit#(WeightBitSize) Weight; 58 | 59 | typedef Bit#(TAdd#(TLog#(PEDelay), 1)) PEDelayBit; 60 | 61 | typedef enum {Idle, LoadWeight, Calculate} WS_Status deriving(Bits, Eq); 62 | 63 | typedef enum {Weight, IfMap, PSum, OfMap, RecurrWeight} NeuralNetworkFlitType deriving(Bits, Eq); 64 | 65 | -------------------------------------------------------------------------------- /Day3/configs/neuralnetwork_types/RowStationaryPE_Types.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | 29 | /* Neural network types */ 30 | import NeuralNetworkTypes::*; 31 | import NeuralNetworkConfig::*; 32 | 33 | /* NoC Types */ 34 | import MicroswitchTypes::*; 35 | import MicroswitchMessageTypes::*; 36 | import MicroswitchNetworkTypes::*; 37 | 38 | typedef 3 PEFifoDepth; 39 | 40 | interface ProcessingElementArray; 41 | interface Vector#(NumPERows, Vector#(NumPEColumns, NetworkExternalInterface)) pePorts; 42 | endinterface 43 | 44 | interface ProcessingElementUnit; 45 | method Action initialize(RowID rID, ColID cID); 46 | interface NetworkExternalInterface ntkPort; 47 | endinterface 48 | 49 | interface ProcessingElementNIC; 50 | method Action initialize(RowID rID, ColID cID); 51 | method ActionValue#(Pixel) getWeight; 52 | method ActionValue#(Pixel) getIfMap; 53 | method Action putPSum(Pixel pSum); 54 | method Action enqFlit(Flit flit); 55 | method ActionValue#(Flit) deqFlit; 56 | endinterface 57 | 58 | interface ProcessingElement; 59 | 60 | method Action enqWeight(Pixel weight); 61 | method Action enqIfMap(Pixel ifPixel); 62 | method Action enqPSum(Pixel pSum); 63 | 64 | method ActionValue#(Pixel) deqPSum; 65 | endinterface 66 | -------------------------------------------------------------------------------- /Day3/configs/neuralnetwork_types/WeightStationaryPE_Types.bsv: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | Copyright (c) 2017 Georgia Instititue of Technology 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | 24 | *******************************************************************************/ 25 | 26 | /* Primitives */ 27 | import Vector::*; 28 | 29 | /* Neural network types */ 30 | import NeuralNetworkTypes::*; 31 | import NeuralNetworkConfig::*; 32 | 33 | /* NoC Types */ 34 | import MicroswitchTypes::*; 35 | import MicroswitchMessageTypes::*; 36 | import MicroswitchNetworkTypes::*; 37 | 38 | typedef 1 WeightFifoDepth; 39 | typedef 3 IfMapFifoDepth; 40 | typedef 1 PSumFifoDepth; 41 | 42 | interface ProcessingElementArray; 43 | interface Vector#(NumPERows, Vector#(NumPEColumns, NetworkExternalInterface)) pePorts; 44 | endinterface 45 | 46 | interface ProcessingElementUnit; 47 | method Action initialize(RowID rID, ColID cID); 48 | interface NetworkExternalInterface ntkPort; 49 | endinterface 50 | 51 | interface ProcessingElementNIC; 52 | method Action initialize(RowID rID, ColID cID); 53 | method ActionValue#(Pixel) getWeight; 54 | method ActionValue#(Pixel) getIfMap; 55 | method Action putPSum(Pixel pSum); 56 | method Action enqFlit(Flit flit); 57 | method ActionValue#(Flit) deqFlit; 58 | endinterface 59 | 60 | interface ProcessingElement; 61 | 62 | method Action enqWeight(Pixel weight); 63 | method Action enqIfMap(Pixel ifPixel); 64 | method Action enqPSum(Pixel pSum); 65 | 66 | method ActionValue#(Pixel) deqPSum; 67 | endinterface 68 | -------------------------------------------------------------------------------- /Day3/scripts/compile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SRCPATH=./ 4 | LOGDIR=./Log 5 | BUILDDIR=./build 6 | CXXFLAGS="-Wall -Wno-unused -O0 -g -D_FILE_OFFSET_BITS=64 -j 4" 7 | 8 | MS_INCLUDE="accelerator/global_buffer:accelerator/processing_element/WS:accelerator/processing_element/RS:NoCs/microswitch/:NoCs/common/:common_lib:configs/microswitch_types:configs/neuralnetwork_types" 9 | 10 | DEBUGFLAGS=' 11 | -D DUMMY 12 | ' 13 | # -D DEBUG_WS_PE_WEIGHT 14 | # -D DEBUG_GLOBALBUFFER 15 | # -D DEBUG_GLOBALBUFFERUNIT 16 | # -D DEBUG_GLOBALBUFFERNIC 17 | # -D DEBUG_WS_MESHNIC 18 | # -D DEBUG_WS_PE 19 | # -D DEBUG_WS_PE_UNIT 20 | # -D DEBUG_WS_PE_ARRAY 21 | # -D Debug_RS_MSNIC 22 | # -D DEBUG_BUS 23 | # -D DEBUG_TOPSWITCH 24 | # -D DEBUG_MIDDLESWITCH 25 | # -D DEBUG_BOTTOMSWITCH 26 | # -D DEBUG_MICROSWITCHNETWORK 27 | 28 | function clean { 29 | rm -rf $BUILDDIR 30 | rm -rf $LOGDIR 31 | rm -rf Verilog 32 | rm -rf *.v 33 | rm -rf ./bdir 34 | rm -rf ./build 35 | rm -f ./sim.so 36 | rm -f ./sim 37 | } 38 | 39 | function compile_ms_sim { 40 | mkdir -p $BUILDDIR 41 | mkdir -p $BUILDDIR/bdir 42 | bsc -u -sim +RTS -K1024M -RTS -aggressive-conditions -no-warn-action-shadowing -parallel-sim-link 4 -warn-scheduler-effort -D MS -D $1 -simdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -bdir $BUILDDIR/bdir $DEBUGFLAGS -p +:$MS_INCLUDE ./TopModule.bsv 43 | bsc -u -sim -e mkTopModule +RTS -K1024M -RTS -D MS -D $1 -bdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -simdir $BUILDDIR/bdir $DEBUGFLAGS -warn-scheduler-effort -parallel-sim-link 4 -Xc++ -O0 -o sim 44 | mv sim $BUILDDIR/bdir 45 | mv sim.so $BUILDDIR/bdir 46 | } 47 | 48 | function compile_ms_verilog { 49 | mkdir -p $BUILDDIR 50 | mkdir -p $BUILDDIR/bdir 51 | bsc -verilog -g mkMicroswitchNetwork +RTS -K1024M -RTS -aggressive-conditions -no-warn-action-shadowing -simdir $BUILDDIR/bdir -info-dir $BUILDDIR/bdir -bdir $BUILDDIR/bdir -D MS -p +:$MS_INCLUDE -u ./NoCs/microswitch/MicroswitchNetwork.bsv 52 | mkdir -p MSVerilog 53 | mv NoCs/microswitch/*.v ./MSVerilog/ 54 | } 55 | 56 | 57 | 58 | function run_test { 59 | ./$BUILDDIR/bdir/sim 60 | } 61 | 62 | case "$1" in 63 | -ms) compile_ms_sim WS;; 64 | -rms) compile_ms_sim RS;; 65 | -msv) compile_ms_verilog;; 66 | -clean) clean;; 67 | -r) run_test;; 68 | -h|--help|*) echo " "; 69 | echo "Usage : $0 (flag)"; 70 | echo "flag list: [-ms : microswitch simulation (WS)] [-rms: microswitch simulation (RS)] [-msv: generate Verilog RTL] [-clean : delete build files] [ -r : run test ] "; 71 | echo " ";; 72 | esac 73 | -------------------------------------------------------------------------------- /Documents/BSV_Manuals/bsv-reference-card.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyoukjun/DesignCNNAccelerators/e757f65294096fe4b7661ea63ed37fce074f9c5f/Documents/BSV_Manuals/bsv-reference-card.pdf -------------------------------------------------------------------------------- /Documents/BSV_Manuals/bsv-reference-guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyoukjun/DesignCNNAccelerators/e757f65294096fe4b7661ea63ed37fce074f9c5f/Documents/BSV_Manuals/bsv-reference-guide.pdf -------------------------------------------------------------------------------- /Documents/BSV_Manuals/bsv_by_example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyoukjun/DesignCNNAccelerators/e757f65294096fe4b7661ea63ed37fce074f9c5f/Documents/BSV_Manuals/bsv_by_example.pdf -------------------------------------------------------------------------------- /Documents/Designing_CNN_Acclerator_Day1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyoukjun/DesignCNNAccelerators/e757f65294096fe4b7661ea63ed37fce074f9c5f/Documents/Designing_CNN_Acclerator_Day1.pdf -------------------------------------------------------------------------------- /Documents/Designing_CNN_Acclerator_Day2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyoukjun/DesignCNNAccelerators/e757f65294096fe4b7661ea63ed37fce074f9c5f/Documents/Designing_CNN_Acclerator_Day2.pdf -------------------------------------------------------------------------------- /Documents/Designing_CNN_Acclerator_Day3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyoukjun/DesignCNNAccelerators/e757f65294096fe4b7661ea63ed37fce074f9c5f/Documents/Designing_CNN_Acclerator_Day3.pdf -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Lab assignment code for three-day lecture, "Designing CNN Accelerators using Bluespec System Verilog", given in Seoul National University in December 2017. 2 | Author: Hyoukjun Kwon (hyoukjun@gatech.edu) 3 | 4 | For lab assignment descriptions, please refer to slides in /documents directory. 5 | 6 | * These lab assignements are based on Bluespec System Verilog (http://bluespec.com). 7 | You need Bluespec compiler license to run simulations for lab assignments. 8 | Bluespec offers university program: please refer to the website (http://bluespec.com/university/) 9 | 10 | * Compiling code 11 | In each lab, I added a make file that launches compilation script with right option. 12 | > make : Compile Blue-sim cycle accurate simulation 13 | > make run : Run the compiled simulation 14 | > make clean : Clean up build files 15 | 16 | * How to add vim syntax? 17 | > mkdir ~/.vim 18 | > cp -r vim_syntax/* ~/.vim 19 | -------------------------------------------------------------------------------- /vim_syntax/README: -------------------------------------------------------------------------------- 1 | A basic BSV syntax highlighing mode for the vi clone VIM 2 | (http://www.vim.org). The mode is mostly written from scratch, with 3 | two regexps copied from VIM's Verilog mode. 4 | 5 | To use, create a ~/.vim directory for your vim settings, with 6 | subdirectories ~/.vim/ftdetect , ~/.vim/indent and ~/.vim/syntax. 7 | Then copy the files from ftdetect/ , indent/ and syntax/ to 8 | ~/.vim/ftdetect/ , ~/.vim/indent and ~/.vim/syntax/ respectively. 9 | 10 | Or in unix terms tcsh: 11 | 12 | > mkdir -p ~/.vim/ftdetect 13 | > mkdir -p ~/.vim/indent 14 | > mkdir -p ~/.vim/syntax 15 | > (cd $BLUESPECDIR/../util/vim; tar cf - *) | (cd ~/.vim; tar xvf -) 16 | 17 | in your .tcshrc you may need to set the environment variable VIMRUNTIME 18 | 19 | setenv VIMRUNTIME /usr/share/vim/vim71 20 | 21 | or in bash 22 | 23 | VIMRUNTIME=/usr/share/vim/vim71 24 | 25 | verify this exists: older versions may have /usr/shar/vim/vim61 26 | 27 | You may need to run " :syn on " once vim is running to enable syntax coloring 28 | 29 | In order to enable BSV indenting, it is recommended to add the 30 | following to your .vimrc file: 31 | 32 | if has("autocmd") 33 | " Enabled file type detection 34 | " Enabled file language-dependent indenting 35 | filetype plugin on 36 | filetype indent on 37 | endif " has ("autocmd") 38 | let b:verilog_indent_modules = 1 39 | 40 | -------------------------------------------------------------------------------- /vim_syntax/ftdetect/bsv.vim: -------------------------------------------------------------------------------- 1 | au BufNewFile,BufRead *.bsv set filetype=bsv 2 | -------------------------------------------------------------------------------- /vim_syntax/indent/bsv.vim: -------------------------------------------------------------------------------- 1 | " Language: Bluespec System Verilog (BSV) 2 | " Maintainer: Hadar Agam 3 | " Last Change: Fri Oct 27 12:09:48 EST 2006 4 | " 5 | " Credits: 6 | " Originally created by 7 | " Chih-Tsun Huang 8 | " http://larc.ee.nthu.edu.tw/~cthuang/vim/indent/verilog.vim 9 | " 10 | " Buffer Variables: 11 | " b:verilog_indent_modules : indenting after the declaration 12 | " of module blocks 13 | " b:verilog_indent_width : indenting width 14 | " b:verilog_indent_verbose : verbose to each indenting 15 | " 16 | 17 | " Only load this indent file when no other was loaded. 18 | if exists("b:did_indent") 19 | finish 20 | endif 21 | let b:did_indent = 1 22 | 23 | setlocal indentexpr=GetBSVIndent() 24 | setlocal indentkeys=!^F,o,O,0),0},=begin,=end,=join,=endcase,=join_any,=join_none 25 | setlocal indentkeys+==endmodule,=endfunction,=endtask,=endspecify 26 | setlocal indentkeys+==endclass,=endpackage,=endsequence,=endclocking,=endrule 27 | setlocal indentkeys+==endmethod,=endinterface,=endgroup,=endprogram,=endproperty 28 | setlocal indentkeys+==`else,=`endif 29 | 30 | " Only define the function once. 31 | if exists("*GetBSVIndent") 32 | finish 33 | endif 34 | 35 | set cpo-=C 36 | 37 | function GetBSVIndent() 38 | 39 | if exists('b:verilog_indent_width') 40 | let offset = b:verilog_indent_width 41 | else 42 | let offset = &sw 43 | endif 44 | if exists('b:verilog_indent_modules') 45 | let indent_modules = offset 46 | else 47 | let indent_modules = 0 48 | endif 49 | 50 | " Find a non-blank line above the current line. 51 | let lnum = prevnonblank(v:lnum - 1) 52 | 53 | " At the start of the file use zero indent. 54 | if lnum == 0 55 | return 0 56 | endif 57 | 58 | let lnum2 = prevnonblank(lnum - 1) 59 | let curr_line = getline(v:lnum) 60 | let last_line = getline(lnum) 61 | let last_line2 = getline(lnum2) 62 | let ind = indent(lnum) 63 | let ind2 = indent(lnum - 1) 64 | let offset_comment1 = 1 65 | " Define the condition of an open statement 66 | " Exclude the match of //, /* or */ 67 | let vlog_openstat = '\(\\|\([*/]\)\@<+-/%^&|!=?:]\([*/]\)\@!\)' 68 | " Define the condition when the statement ends with a one-line comment 69 | let vlog_comment = '\(//.*\|/\*.*\*/\s*\)' 70 | if exists('b:verilog_indent_verbose') 71 | let vverb_str = 'INDENT VERBOSE:' 72 | let vverb = 1 73 | else 74 | let vverb = 0 75 | endif 76 | 77 | " Indent accoding to last line 78 | " End of multiple-line comment 79 | if last_line =~ '\*/\s*$' && last_line !~ '/\*.\{-}\*/' 80 | let ind = ind - offset_comment1 81 | if vverb 82 | echo vverb_str "De-indent after a multiple-line comment." 83 | endif 84 | 85 | " Indent after if/else/for/case/always/initial/specify/fork blocks 86 | elseif last_line =~ '`\@' || 87 | \ last_line =~ '^\s*\<\(for\|case\%[[zx]]\|do\|foreach\|randcase\)\>' || 88 | \ last_line =~ '^\s*\<\(always\|always_comb\|always_ff\|always_latch\)\>' || 89 | \ last_line =~ '^\s*\<\(initial\|specify\|fork\|final\)\>' 90 | if last_line !~ '\(;\|\\)\s*' . vlog_comment . '*$' || 91 | \ last_line =~ '\(//\|/\*\).*\(;\|\\)\s*' . vlog_comment . '*$' 92 | let ind = ind + offset 93 | if vverb | echo vverb_str "Indent after a block statement." | endif 94 | endif 95 | " Indent after function/task/class/package/sequence/clocking/ 96 | " rule/method/interface/covergroup/property/program blocks 97 | elseif last_line =~ '^\s*\<\(function\|task\|class\|package\)\>' || 98 | \ last_line =~ '^\s*\<\(sequence\|clocking\|rule\|method\|interface\)\>' || 99 | \ last_line =~ '^\s*\(\w\+\s*:\)\=\s*\' || 100 | \ last_line =~ '^\s*\<\(property\|program\)\>' 101 | if last_line !~ '\\s*' . vlog_comment . '*$' || 102 | \ last_line =~ '\(//\|/\*\).*\(;\|\\)\s*' . vlog_comment . '*$' 103 | let ind = ind + offset 104 | if vverb 105 | echo vverb_str "Indent after function/task/class block statement." 106 | endif 107 | endif 108 | 109 | " Indent after module/function/task/specify/fork blocks 110 | elseif last_line =~ '^\s*\(\\s*\)\=\' 111 | let ind = ind + indent_modules 112 | if vverb && indent_modules 113 | echo vverb_str "Indent after module statement." 114 | endif 115 | if last_line =~ '[(,]\s*' . vlog_comment . '*$' && 116 | \ last_line !~ '\(//\|/\*\).*[(,]\s*' . vlog_comment . '*$' 117 | let ind = ind + offset 118 | if vverb 119 | echo vverb_str "Indent after a multiple-line module statement." 120 | endif 121 | endif 122 | 123 | " Indent after a 'begin' statement 124 | elseif last_line =~ '\(\\)\(\s*:\s*\w\+\)*' . vlog_comment . '*$' && 125 | \ last_line !~ '\(//\|/\*\).*\(\\)' && 126 | \ ( last_line2 !~ vlog_openstat . '\s*' . vlog_comment . '*$' || 127 | \ last_line2 =~ '^\s*[^=!]\+\s*:\s*' . vlog_comment . '*$' ) 128 | let ind = ind + offset 129 | if vverb | echo vverb_str "Indent after begin statement." | endif 130 | 131 | " Indent after a '{' or a '(' 132 | elseif last_line =~ '[{(]' . vlog_comment . '*$' && 133 | \ last_line !~ '\(//\|/\*\).*[{(]' && 134 | \ ( last_line2 !~ vlog_openstat . '\s*' . vlog_comment . '*$' || 135 | \ last_line2 =~ '^\s*[^=!]\+\s*:\s*' . vlog_comment . '*$' ) 136 | let ind = ind + offset 137 | if vverb | echo vverb_str "Indent after begin statement." | endif 138 | 139 | " De-indent for the end of one-line block 140 | elseif ( last_line !~ '\' || 141 | \ last_line =~ '\(//\|/\*\).*\' ) && 142 | \ last_line2 =~ '\<\(`\@.*' . 143 | \ vlog_comment . '*$' && 144 | \ last_line2 !~ 145 | \ 146 | '\(//\|/\*\).*\<\(`\@' && 147 | \ last_line2 !~ vlog_openstat . '\s*' . vlog_comment . '*$' && 148 | \ ( last_line2 !~ '\' || 149 | \ last_line2 =~ '\(//\|/\*\).*\' ) 150 | let ind = ind - offset 151 | if vverb 152 | echo vverb_str "De-indent after the end of one-line statement." 153 | endif 154 | 155 | " Multiple-line statement (including case statement) 156 | " Open statement 157 | " Ident the first open line 158 | elseif last_line =~ vlog_openstat . '\s*' . vlog_comment . '*$' && 159 | \ last_line !~ '\(//\|/\*\).*' . vlog_openstat . '\s*$' && 160 | \ last_line2 !~ vlog_openstat . '\s*' . vlog_comment . '*$' 161 | let ind = ind + offset 162 | if vverb | echo vverb_str "Indent after an open statement." | endif 163 | 164 | " Close statement 165 | " De-indent for an optional close parenthesis and a semicolon, and only 166 | " if there exists precedent non-whitespace char 167 | elseif last_line =~ ')*\s*;\s*' . vlog_comment . '*$' && 168 | \ last_line !~ '^\s*)*\s*;\s*' . vlog_comment . '*$' && 169 | \ last_line !~ '\(//\|/\*\).*\S)*\s*;\s*' . vlog_comment . '*$' && 170 | \ ( last_line2 =~ vlog_openstat . '\s*' . vlog_comment . '*$' && 171 | \ last_line2 !~ ';\s*//.*$') && 172 | \ last_line2 !~ '^\s*' . vlog_comment . '$' 173 | let ind = ind - offset 174 | if vverb | echo vverb_str "De-indent after a close statement." | endif 175 | 176 | " `ifdef and `else 177 | elseif last_line =~ '^\s*`\<\(ifdef\|else\)\>' 178 | let ind = ind + offset 179 | if vverb 180 | echo vverb_str "Indent after a `ifdef or `else statement." 181 | endif 182 | 183 | endif 184 | 185 | " Re-indent current line 186 | 187 | " De-indent on the end of the block 188 | " join/end/endcase/endfunction/endtask/endspecify 189 | if curr_line =~ '^\s*\<\(join\|join_any\|join_none\|\|end\|endcase\|while\)\>' || 190 | \ curr_line =~ '^\s*\<\(endfunction\|endtask\|endspecify\|endclass\)\>' || 191 | \ curr_line =~ '^\s*\<\(endpackage\|endsequence\|endclocking\|endrule\|endmethod\|endinterface\)\>' || 192 | \ curr_line =~ '^\s*\<\(endgroup\|endproperty\|endprogram\)\>' || 193 | \ curr_line =~ '^\s*}' 194 | let ind = ind - offset 195 | if vverb | echo vverb_str "De-indent the end of a block." | endif 196 | elseif curr_line =~ '^\s*\' 197 | let ind = ind - indent_modules 198 | if vverb && indent_modules 199 | echo vverb_str "De-indent the end of a module." 200 | endif 201 | 202 | " De-indent on a stand-alone 'begin' 203 | elseif curr_line =~ '^\s*\' 204 | if last_line !~ '^\s*\<\(function\|task\|specify\|module\|class\|package\)\>' || 205 | \ last_line !~ '^\s*\<\(sequence\|clocking\|rule\|method\|interface\|covergroup\)\>' || 206 | \ last_line !~ '^\s*\<\(property\|program\)\>' && 207 | \ last_line !~ '^\s*\()*\s*;\|)\+\)\s*' . vlog_comment . '*$' && 208 | \ ( last_line =~ 209 | \ '\<\(`\@' || 210 | \ last_line =~ ')\s*' . vlog_comment . '*$' || 211 | \ last_line =~ vlog_openstat . '\s*' . vlog_comment . '*$' ) 212 | let ind = ind - offset 213 | if vverb 214 | echo vverb_str "De-indent a stand alone begin statement." 215 | endif 216 | endif 217 | 218 | " De-indent after the end of multiple-line statement 219 | elseif curr_line =~ '^\s*)' && 220 | \ ( last_line =~ vlog_openstat . '\s*' . vlog_comment . '*$' || 221 | \ last_line !~ vlog_openstat . '\s*' . vlog_comment . '*$' && 222 | \ last_line2 =~ vlog_openstat . '\s*' . vlog_comment . '*$' ) 223 | let ind = ind - offset 224 | if vverb 225 | echo vverb_str "De-indent the end of a multiple statement." 226 | endif 227 | 228 | " De-indent `else and `endif 229 | elseif curr_line =~ '^\s*`\<\(else\|endif\)\>' 230 | let ind = ind - offset 231 | if vverb | echo vverb_str "De-indent `else and `endif statement." | endif 232 | 233 | endif 234 | 235 | " Return the indention 236 | return ind 237 | endfunction 238 | 239 | " vim:sw=2 240 | -------------------------------------------------------------------------------- /vim_syntax/syntax/bsv.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Bluespec System Verilog (BSV) 3 | " Maintainer: Hadar Agam -- hadar at bluespec dot com 4 | " Last Change: Oct 24 2006 5 | " License: Proprietary 6 | 7 | " work with vim < 6.0 8 | if version < 600 9 | syntax clear 10 | elseif exists("b:current_syntax") 11 | finish 12 | endif 13 | 14 | " BSV is case-sensitive 15 | syntax case match 16 | 17 | " SV operators (XXX stolen from verilog.vim) 18 | syntax match bsv_op "[&|~>" 22 | 23 | " comments (must be before operators, or else / gets marked as an operator) 24 | syntax keyword bsv_todo XXX FIXME TODO 25 | syntax region bsv_comment start="//" end=/$/ contains=bsv_todo 26 | syntax region bsv_comment start="/\*" end="\*/" contains=bsv_todo 27 | 28 | " numeric literals (XXX stolen from verilog.vim) 29 | syntax match bsv_number "\(\<\d\+\|\)'[bB]\s*[0-1_xXzZ?]\+\>" 30 | syntax match bsv_number "\(\<\d\+\|\)'[oO]\s*[0-7_xXzZ?]\+\>" 31 | syntax match bsv_number "\(\<\d\+\|\)'[dD]\s*[0-9_xXzZ?]\+\>" 32 | syntax match bsv_number "\(\<\d\+\|\)'[hH]\s*[0-9a-fA-F_xXzZ?]\+\>" 33 | syntax match bsv_number "\<[+-]\=[0-9_]\+\(\.[0-9_]*\|\)\(e[0-9_]*\|\)\>" 34 | 35 | " strings 36 | syntax region bsv_string start=/"/ skip=/\\"/ end=/"/ 37 | 38 | " SV keywords 39 | syntax keyword bsv_statement alias 40 | syntax keyword bsv_statement always 41 | syntax keyword bsv_statement always_comb 42 | syntax keyword bsv_statement always_ff 43 | syntax keyword bsv_statement always_latch 44 | syntax keyword bsv_statement and 45 | syntax keyword bsv_statement assert 46 | syntax keyword bsv_statement assert_strobe 47 | syntax keyword bsv_statement assign 48 | syntax keyword bsv_statement assume 49 | syntax keyword bsv_statement automatic 50 | syntax keyword bsv_statement before 51 | syntax keyword bsv_statement begin 52 | syntax keyword bsv_statement bind 53 | syntax keyword bsv_statement bins 54 | syntax keyword bsv_statement binsof 55 | syntax match bsv_type "bit\(\[.*\]\)\?" 56 | syntax keyword bsv_statement break 57 | syntax keyword bsv_statement buf 58 | syntax keyword bsv_statement bufif0 59 | syntax keyword bsv_statement bufif1 60 | syntax keyword bsv_statement byte 61 | syntax keyword bsv_conditional case 62 | syntax keyword bsv_conditional casex 63 | syntax keyword bsv_conditional casez 64 | syntax keyword bsv_statement cell 65 | syntax keyword bsv_statement chandle 66 | syntax keyword bsv_statement class 67 | syntax keyword bsv_statement clocking 68 | syntax keyword bsv_statement cmos 69 | syntax keyword bsv_statement config 70 | syntax keyword bsv_statement const 71 | syntax keyword bsv_statement constraint 72 | syntax keyword bsv_statement context 73 | syntax keyword bsv_statement continue 74 | syntax keyword bsv_statement cover 75 | syntax keyword bsv_statement covergroup 76 | syntax keyword bsv_statement coverpoint 77 | syntax keyword bsv_statement cross 78 | syntax keyword bsv_statement deassign 79 | syntax keyword bsv_statement default 80 | syntax keyword bsv_statement defparam 81 | syntax keyword bsv_statement design 82 | syntax keyword bsv_statement disable 83 | syntax keyword bsv_statement dist 84 | syntax keyword bsv_statement do 85 | syntax keyword bsv_statement edge 86 | syntax keyword bsv_conditional else 87 | syntax keyword bsv_statement end 88 | syntax keyword bsv_statement endcase 89 | syntax keyword bsv_statement endclass 90 | syntax keyword bsv_statement endclocking 91 | syntax keyword bsv_statement endconfig 92 | syntax keyword bsv_statement endfunction 93 | syntax keyword bsv_statement endgenerate 94 | syntax keyword bsv_statement endgroup 95 | syntax keyword bsv_typedef endinterface 96 | syntax keyword bsv_statement endmodule 97 | syntax keyword bsv_statement endpackage 98 | syntax keyword bsv_statement endprimitive 99 | syntax keyword bsv_statement endprogram 100 | syntax keyword bsv_statement endproperty 101 | syntax keyword bsv_statement endspecify 102 | syntax keyword bsv_statement endsequence 103 | syntax keyword bsv_statement endtable 104 | syntax keyword bsv_statement endtask 105 | syntax keyword bsv_structure enum 106 | syntax keyword bsv_statement event 107 | syntax keyword bsv_statement expect 108 | syntax keyword bsv_statement export 109 | syntax keyword bsv_statement extends 110 | syntax keyword bsv_statement extern 111 | syntax keyword bsv_statement final 112 | syntax keyword bsv_statement first_match 113 | syntax keyword bsv_loop for 114 | syntax keyword bsv_statement force 115 | syntax keyword bsv_statement foreach 116 | syntax keyword bsv_statement forever 117 | syntax keyword bsv_statement fork 118 | syntax keyword bsv_statement forkjoin 119 | syntax keyword bsv_statement function 120 | syntax keyword bsv_statement generate 121 | syntax keyword bsv_statement genvar 122 | syntax keyword bsv_statement highz0 123 | syntax keyword bsv_statement highz1 124 | syntax keyword bsv_conditional if 125 | syntax keyword bsv_statement iff 126 | syntax keyword bsv_statement ifnone 127 | syntax keyword bsv_statement ignore_bins 128 | syntax keyword bsv_statement illegal_bins 129 | syntax keyword bsv_statement import 130 | syntax keyword bsv_statement incdir 131 | syntax keyword bsv_statement include 132 | syntax keyword bsv_statement initial 133 | syntax keyword bsv_statement inout 134 | syntax keyword bsv_statement input 135 | syntax keyword bsv_statement inside 136 | syntax keyword bsv_statement instance 137 | syntax keyword bsv_type int 138 | syntax keyword bsv_type integer 139 | syntax keyword bsv_typedef interface 140 | syntax keyword bsv_statement intersect 141 | syntax keyword bsv_statement join 142 | syntax keyword bsv_statement join_any 143 | syntax keyword bsv_statement join_none 144 | syntax keyword bsv_statement large 145 | syntax keyword bsv_statement liblist 146 | syntax keyword bsv_statement library 147 | syntax keyword bsv_statement local 148 | syntax keyword bsv_statement localparam 149 | syntax keyword bsv_statement logic 150 | syntax keyword bsv_type longint 151 | syntax keyword bsv_statement macromodule 152 | syntax keyword bsv_conditional matches 153 | syntax keyword bsv_statement medium 154 | syntax keyword bsv_statement modport 155 | syntax keyword bsv_statement module 156 | syntax keyword bsv_statement nand 157 | syntax keyword bsv_statement negedge 158 | syntax keyword bsv_statement new 159 | syntax keyword bsv_statement nmos 160 | syntax keyword bsv_statement nor 161 | syntax keyword bsv_statement noshowcancelled 162 | syntax keyword bsv_statement not 163 | syntax keyword bsv_statement notif0 164 | syntax keyword bsv_statement notif1 165 | syntax keyword bsv_statement null 166 | syntax keyword bsv_statement or 167 | syntax keyword bsv_statement output 168 | syntax keyword bsv_statement package 169 | syntax keyword bsv_statement packed 170 | syntax keyword bsv_statement parameter 171 | syntax keyword bsv_statement pmos 172 | syntax keyword bsv_statement posedge 173 | syntax keyword bsv_statement primitive 174 | syntax keyword bsv_statement priority 175 | syntax keyword bsv_statement program 176 | syntax keyword bsv_statement property 177 | syntax keyword bsv_statement protected 178 | syntax keyword bsv_statement pull0 179 | syntax keyword bsv_statement pull1 180 | syntax keyword bsv_statement pulldown 181 | syntax keyword bsv_statement pullup 182 | syntax keyword bsv_statement pulsestyle_onevent 183 | syntax keyword bsv_statement pulsestyle_ondetect 184 | syntax keyword bsv_statement pure 185 | syntax keyword bsv_statement rand 186 | syntax keyword bsv_statement randc 187 | syntax keyword bsv_statement randcase 188 | syntax keyword bsv_statement randsequence 189 | syntax keyword bsv_statement rcmos 190 | syntax keyword bsv_type real 191 | syntax keyword bsv_type realtime 192 | syntax keyword bsv_statement ref 193 | syntax keyword bsv_type reg 194 | syntax keyword bsv_statement release 195 | syntax keyword bsv_statement repeat 196 | syntax keyword bsv_statement return 197 | syntax keyword bsv_statement rnmos 198 | syntax keyword bsv_statement rpmos 199 | syntax keyword bsv_statement rtran 200 | syntax keyword bsv_statement rtranif0 201 | syntax keyword bsv_statement rtranif1 202 | syntax keyword bsv_statement scalared 203 | syntax keyword bsv_statement sequence 204 | syntax keyword bsv_type shortint 205 | syntax keyword bsv_type shortreal 206 | syntax keyword bsv_statement showcancelled 207 | syntax keyword bsv_statement signed 208 | syntax keyword bsv_statement small 209 | syntax keyword bsv_statement solve 210 | syntax keyword bsv_statement specify 211 | syntax keyword bsv_statement specparam 212 | syntax keyword bsv_statement static 213 | syntax keyword bsv_statement string 214 | syntax keyword bsv_statement strong0 215 | syntax keyword bsv_statement strong1 216 | syntax keyword bsv_structure struct 217 | syntax keyword bsv_statement super 218 | syntax keyword bsv_statement supply0 219 | syntax keyword bsv_statement supply1 220 | syntax keyword bsv_statement table 221 | syntax keyword bsv_structure tagged 222 | syntax keyword bsv_statement task 223 | syntax keyword bsv_statement this 224 | syntax keyword bsv_statement throughout 225 | syntax keyword bsv_type time 226 | syntax keyword bsv_statement timeprecision 227 | syntax keyword bsv_statement timeunit 228 | syntax keyword bsv_statement tran 229 | syntax keyword bsv_statement tranif0 230 | syntax keyword bsv_statement tranif1 231 | syntax keyword bsv_statement tri 232 | syntax keyword bsv_statement tri0 233 | syntax keyword bsv_statement tri1 234 | syntax keyword bsv_statement triand 235 | syntax keyword bsv_statement trior 236 | syntax keyword bsv_statement trireg 237 | syntax keyword bsv_statement type 238 | syntax keyword bsv_typedef typedef 239 | syntax keyword bsv_structure union 240 | syntax keyword bsv_statement unique 241 | syntax keyword bsv_statement unsigned 242 | syntax keyword bsv_statement use 243 | syntax keyword bsv_statement var 244 | syntax keyword bsv_statement vectored 245 | syntax keyword bsv_statement virtual 246 | syntax keyword bsv_type void 247 | syntax keyword bsv_statement wait 248 | syntax keyword bsv_statement wait_order 249 | syntax keyword bsv_statement wand 250 | syntax keyword bsv_statement weak0 251 | syntax keyword bsv_statement weak1 252 | syntax keyword bsv_loop while 253 | syntax keyword bsv_statement wildcard 254 | syntax keyword bsv_type wire 255 | syntax keyword bsv_statement with 256 | syntax keyword bsv_statement within 257 | syntax keyword bsv_statement wor 258 | syntax keyword bsv_statement xnor 259 | syntax keyword bsv_statement xor 260 | " BSV keywords 261 | syntax keyword bsv_statement action 262 | syntax keyword bsv_statement endaction 263 | syntax keyword bsv_statement actionvalue 264 | syntax keyword bsv_statement endactionvalue 265 | syntax keyword bsv_statement ancestor 266 | syntax keyword bsv_statement deriving 267 | syntax keyword bsv_statement endinstance 268 | syntax keyword bsv_statement let 269 | syntax keyword bsv_statement match 270 | syntax keyword bsv_statement method 271 | syntax keyword bsv_statement endmethod 272 | syntax keyword bsv_statement par 273 | syntax keyword bsv_statement endpar 274 | syntax keyword bsv_statement powered_by 275 | syntax keyword bsv_statement provisos 276 | syntax keyword bsv_statement rule 277 | syntax keyword bsv_statement endrule 278 | syntax keyword bsv_statement rules 279 | syntax keyword bsv_statement endrules 280 | syntax keyword bsv_statement seq 281 | syntax keyword bsv_statement endseq 282 | syntax keyword bsv_statement schedule 283 | syntax keyword bsv_statement typeclass 284 | syntax keyword bsv_statement endtypeclass 285 | syntax keyword bsv_statement clock 286 | syntax keyword bsv_statement reset 287 | syntax keyword bsv_statement noreset 288 | syntax keyword bsv_statement no_reset 289 | syntax keyword bsv_statement valueof 290 | syntax keyword bsv_statement valueOf 291 | syntax keyword bsv_statement clocked_by 292 | syntax keyword bsv_statement reset_by 293 | syntax keyword bsv_statement default_clock 294 | syntax keyword bsv_statement default_reset 295 | syntax keyword bsv_statement output_clock 296 | syntax keyword bsv_statement output_reset 297 | syntax keyword bsv_statement input_clock 298 | syntax keyword bsv_statement input_reset 299 | syntax keyword bsv_statement same_family 300 | 301 | 302 | " frequently used predefined types 303 | syntax keyword bsv_type Action 304 | syntax keyword bsv_type ActionValue 305 | syntax keyword bsv_type Integer 306 | syntax keyword bsv_type Nat 307 | syntax keyword bsv_type Bit 308 | syntax keyword bsv_type UInt 309 | syntax keyword bsv_type Int 310 | syntax keyword bsv_type Bool 311 | syntax keyword bsv_type Maybe 312 | syntax keyword bsv_type String 313 | syntax keyword bsv_type Either 314 | syntax keyword bsv_type Rules 315 | syntax keyword bsv_type Module 316 | syntax keyword bsv_type Clock 317 | syntax keyword bsv_type Reset 318 | syntax keyword bsv_type Power 319 | syntax keyword bsv_type TAdd TSub TMul TDiv TLog TExp 320 | 321 | syntax keyword bsv_interface Empty 322 | syntax keyword bsv_interface Reg 323 | syntax keyword bsv_interface RWire Wire BypassWire PulseWire 324 | syntax keyword bsv_interface RegFile 325 | syntax keyword bsv_interface Vector 326 | syntax keyword bsv_interface FIFO FIFOF 327 | 328 | syntax keyword bsv_typeclass Bits Eq Ord Bounded 329 | syntax keyword bsv_typeclass Arith Literal Bitwise BitReduction BitExtend 330 | syntax keyword bsv_typeclass IsModule 331 | syntax keyword bsv_typeclass Add Max Log 332 | 333 | " frequently used expressions 334 | syntax keyword bsv_bool True 335 | syntax keyword bsv_bool False 336 | syntax keyword bsv_function mkReg mkRegU mkRegA mkRWire mkWire mkFIFO mkFIFO1 337 | syntax keyword bsv_function mkBypassWire mkDWire mkPulseWire 338 | syntax keyword bsv_function pack unpack zeroExtend signExtend truncate 339 | syntax keyword bsv_function fromInteger inLiteralRange negate 340 | syntax keyword bsv_function minBound maxBound 341 | syntax keyword bsv_function signedShiftRight div mod exp log2 add abs max min quot rem 342 | syntax keyword bsv_function fromMaybe isValid noAction 343 | syntax keyword bsv_function error warning message messageM 344 | syntax keyword bsv_function nosplit emptyRules addRules rJoin rJoinPreempts rJoinDescendingUrgency 345 | 346 | " system tasks 347 | syntax match bsv_system_task "\$display" 348 | syntax match bsv_system_task "\$displayb" 349 | syntax match bsv_system_task "\$displayh" 350 | syntax match bsv_system_task "\$displayo" 351 | syntax match bsv_system_task "\$write" 352 | syntax match bsv_system_task "\$writeb" 353 | syntax match bsv_system_task "\$writeh" 354 | syntax match bsv_system_task "\$writeo" 355 | syntax match bsv_system_task "\$fopen" 356 | syntax match bsv_system_task "\$fclose" 357 | syntax match bsv_system_task "\$fgetc" 358 | syntax match bsv_system_task "\$ungetc" 359 | syntax match bsv_system_task "\$fflush" 360 | syntax match bsv_system_task "\$fdisplay" 361 | syntax match bsv_system_task "\$fdisplayb" 362 | syntax match bsv_system_task "\$fdisplayh" 363 | syntax match bsv_system_task "\$fdisplayo" 364 | syntax match bsv_system_task "\$fwrite" 365 | syntax match bsv_system_task "\$fwriteb" 366 | syntax match bsv_system_task "\$fwriteh" 367 | syntax match bsv_system_task "\$fwriteo" 368 | syntax match bsv_system_task "\$stop" 369 | syntax match bsv_system_task "\$finish" 370 | syntax match bsv_system_task "\$dumpon" 371 | syntax match bsv_system_task "\$dumpoff" 372 | syntax match bsv_system_task "\$dumpvars" 373 | syntax match bsv_system_task "\$dumpfile" 374 | syntax match bsv_system_task "\$dumpflush" 375 | syntax match bsv_system_task "\$time" 376 | syntax match bsv_system_task "\$stime" 377 | syntax match bsv_system_task "\$signed" 378 | syntax match bsv_system_task "\$unsigned" 379 | syntax match bsv_system_task "\$test$plusargs" 380 | 381 | " attributes 382 | syntax keyword bsv_attribute synthesize noinline doc options 383 | syntax keyword bsv_attribute always_ready always_enabled 384 | syntax keyword bsv_attribute ready enable result prefix port 385 | syntax keyword bsv_attribute fire_when_enabled no_implicit_conditions 386 | syntax keyword bsv_attribute bit_blast scan_insert 387 | syntax keyword bsv_attribute descending_urgency preempts 388 | syntax keyword bsv_attribute internal_scheduling method_scheduling 389 | syntax keyword bsv_attribute CLK RST_N RSTN ungated_clock 390 | syntax region bsv_attributes start="(\*" end="\*)" contains=bsv_attribute 391 | 392 | " link classes to vim colors 393 | highlight link bsv_statement Keyword 394 | highlight link bsv_typedef Typedef 395 | highlight link bsv_type Type 396 | highlight link bsv_interface Type 397 | highlight link bsv_typeclass Type 398 | highlight link bsv_structure Structure 399 | highlight link bsv_conditional Conditional 400 | highlight link bsv_loop Repeat 401 | highlight link bsv_comment Comment 402 | highlight link bsv_op Operator 403 | highlight link bsv_string String 404 | highlight link bsv_bool Boolean 405 | highlight link bsv_number Number 406 | " highlighting identifiers gets a bit garish 407 | " highlight link bsv_identifier Identifier 408 | highlight link bsv_function Function 409 | highlight link bsv_system_task Function 410 | highlight link bsv_todo Todo 411 | highlight link bsv_attributes SpecialComment 412 | highlight link bsv_attribute Keyword 413 | 414 | let b:current_syntax="bsv" 415 | 416 | --------------------------------------------------------------------------------