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

Last change on this file since 5263 was 5263, checked in by cameron, 9 months ago

New doSegment partial progress

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