source: icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp @ 5259

Last change on this file since 5259 was 5259, checked in by cameron, 2 years ago

Fix mmap kernel producer position calculation

File size: 3.4 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#include <kernels/mmap_kernel.h>
6#include <IR_Gen/idisa_builder.h>
7
8namespace kernel {
9           
10void MMapSourceKernel::generateDoSegmentMethod() const {
11    auto savePoint = iBuilder->saveIP();
12    Module * m = iBuilder->getModule();
13    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
14   
15    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
16    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
17    BasicBlock * mmapSourceExit = BasicBlock::Create(iBuilder->getContext(), "mmapSourceExit", doSegmentFunction, 0);
18    Constant * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
19   
20   
21    Function::arg_iterator args = doSegmentFunction->arg_begin();
22    Value * self = &*(args);
23   
24    Value * fileItems = getScalarField(self, "fileSize");
25    if (mCodeUnitWidth > 8) {
26        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth/8));
27    }
28    Value * produced = getProducedItemCount(self, "sourceBuffer");
29    Value * itemsAvail = iBuilder->CreateSub(fileItems, produced);
30    Value * lessThanFullSegment = iBuilder->CreateICmpULT(itemsAvail, segmentItems);
31    Value * itemsToDo = iBuilder->CreateSelect(lessThanFullSegment, itemsAvail, segmentItems);
32    produced = iBuilder->CreateAdd(produced, itemsToDo);
33    setProducedItemCount(self, "sourceBuffer", produced);
34   
35    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
36    iBuilder->SetInsertPoint(setTermination);
37    setTerminationSignal(self);
38    iBuilder->CreateBr(mmapSourceExit);
39    iBuilder->SetInsertPoint(mmapSourceExit);
40    Value * ssStructPtr = getStreamSetStructPtr(self, "sourceBuffer");
41    Value * producerPosPtr = mStreamSetOutputBuffers[0]->getProducerPosPtr(ssStructPtr);
42    iBuilder->CreateAtomicStoreRelease(produced, producerPosPtr);
43   
44    iBuilder->CreateRetVoid();
45    iBuilder->restoreIP(savePoint);
46}
47
48void MMapSourceKernel::generateFinalSegmentMethod() const {
49    auto savePoint = iBuilder->saveIP();
50    Module * m = iBuilder->getModule();
51    Function * finalSegmentFunction = m->getFunction(mKernelName + finalSegment_suffix);
52    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", finalSegmentFunction, 0));
53       
54    Function::arg_iterator args = finalSegmentFunction->arg_begin();
55    Value * self = &*(args++);
56    Value * blocksToDo = &*(args);
57   
58    createDoSegmentCall(self, blocksToDo);
59
60    iBuilder->CreateRetVoid();
61    iBuilder->restoreIP(savePoint);
62}
63
64
65// The doBlock method is deprecated.   But in case it is used, just call doSegment with
66// 1 as the number of blocks to do.
67void MMapSourceKernel::generateDoBlockMethod() const {
68    auto savePoint = iBuilder->saveIP();
69    Module * m = iBuilder->getModule();
70    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
71    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
72    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
73    Value * self = getParameter(doBlockFunction, "self");
74    iBuilder->CreateCall(doSegmentFunction, {self, iBuilder->getSize(1)});
75    iBuilder->CreateRetVoid();
76    iBuilder->restoreIP(savePoint);
77}
78   
79}
Note: See TracBrowser for help on using the repository browser.