Skip to content

Commit

Permalink
fixed strange bug with sort reduce dram output
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwoojun committed Sep 17, 2019
1 parent f9e52aa commit 17f9962
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions examples/sortreduce/SortReduceSingle.bsv
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ module mkSortReduceSingle (SortReduceSingleIfc);
let d <- srSer.get;
let l = srLastSer.first;
srLastSer.deq;
//$display( "input skipping %d", i );
if ( l ) begin
skippingStream <= False;
//$display( "input skip done %d", i );
end
endrule
rule flushLastR (flushLast);
Expand Down Expand Up @@ -103,10 +105,14 @@ module mkSortReduceSingle (SortReduceSingleIfc);
let ld = fromMaybe(?,staggerInBuffer);
sortreducer.enq[i].enq(tpl_1(ld), tpl_2(ld), False);
staggerInBuffer <= tagged Valid tuple2(key,val);
//$display( "input replace stagger %d", i );
if ( l ) begin
flushLast <= True;
end
end else staggerInBuffer <= tagged Valid tuple2(key,val);
end else begin
staggerInBuffer <= tagged Valid tuple2(key,val);
//$display( "input stagger %d", i );
end

endrule
end
Expand All @@ -123,7 +129,7 @@ module mkSortReduceSingle (SortReduceSingleIfc);
Reg#(Bit#(3)) desPadIdx <- mkReg(0);
rule padOutputDes (desPadIdx > 0);
outDes.put({32'hffffffff,32'hffffffff});
desPadIdx <= desIdx + 1;
desPadIdx <= desPadIdx + 1;
endrule
rule appendNullOutR (appendNullOut && desPadIdx == 0);
outDes.put({32'hffffffff,32'hffffffff});
Expand Down Expand Up @@ -157,7 +163,7 @@ module mkSortReduceSingle (SortReduceSingleIfc);
dramArbiter.eps[16].burstWrite(curStripeBase+outWriteOff,truncate(writeIn-writeOut));
outWriteOff <= 0;
curStripeBase <= curStripeBase + outStripeSz;
$display( "Skipping block since we encountered a null -> %x", curStripeBase + outStripeSz);
$display( "Skipping block since we encountered a null -> %x %d", curStripeBase + outStripeSz, outWriteOff);
endrule
rule genDramBurstRegR (genDramBurstReq == True);
genDramBurstReq <= False;
Expand All @@ -176,21 +182,24 @@ module mkSortReduceSingle (SortReduceSingleIfc);
let o <- outDes.get;
if ( curStripeBase >= outDramLimit ) begin
overflowQ.enq(o);
//$display("Entering overflow!" );
$display("Entering overflow!" );
end else if ( writeIn+1 - writeOut >= 1024*2/64 ) begin
outBufferQ.enq(o);
genDramBurstReq <= True;
writeIn <= writeIn + 1;
$display( "Generating burst write req" );
end else if ( o[511:512-64] == 64'hffffffffffffffff ) begin
//if MSB is h32'hffffffff, 32'hffffffff, send partial write and then skip to next block
if (outWriteOff > 0 ) begin // if there was no reduction, null is at beginning of stripe...
outBufferQ.enq(o);
writeIn <= writeIn + 1;
skipToNextOutStripe <= True;
end
$display( "delimeter output at %d", outWriteOff );
end else begin
outBufferQ.enq(o);
writeIn <= writeIn + 1;
$display("outBufferQ %d", writeIn-writeOut);
end
endrule

Expand Down
4 changes: 2 additions & 2 deletions examples/sortreduce/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ int main(int argc, char** argv) {

//uint32_t istripe = (1024*1024*256/16)/64;
//uint32_t bufferwords = (1024*1024*256)/64; // 256MB scratchpad
uint32_t buffermb = 2;
uint32_t buffermb = 256;
uint32_t outstripemb = 1;
uint32_t bufferwords = (1024*1024*buffermb)/64; // 256MB scratchpad
uint32_t istripe = (1024*1024*outstripemb)/16/64; // each output stripe adding up to ...
Expand All @@ -43,7 +43,7 @@ int main(int argc, char** argv) {
buffer[i] = rand() % (1<<24);
}
//std::sort(buffer, buffer+kvcnt);
//buffer[kvcnt/2] = 0xffffffff;
buffer[kvcnt/2] = 0xffffffff;

for ( int i = 0; i < kvcnt; i++ ){
if ( buffer[i] == 0xffffffff ) {
Expand Down

0 comments on commit 17f9962

Please sign in to comment.