Ignore:
Timestamp:
Mar 11, 2016, 4:44:53 PM (3 years ago)
Author:
nmedfort
Message:

Added ability to name internal state types; removed unnecessary predefined states. Some progress towards supporting segment size > 1

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r4968 r4970  
    1212using namespace pablo;
    1313
    14 static cl::opt<unsigned> SegmentSize("segment-size", cl::desc("Segment Size"), cl::value_desc("LLVM IR file"), cl::init(1));
     14static cl::opt<unsigned> SegmentSize("segment-size", cl::desc("Segment Size"), cl::value_desc("positive integer"), cl::init(1));
    1515
    1616inline bool isPowerOfTwo(const unsigned x) {
     
    2828, mCircularBufferModulo(1)
    2929, mSegmentIndex(0)
    30 , mStartIndex(0) {
     30, mBlockIndex(0) {
    3131    assert (mBlocksPerSegment > 0);
    32     addInternalStateType(b->getInt64Ty());
    33     addInternalStateType(b->getInt64Ty());
    34     addInternalStateType(b->getInt64Ty());
    35     addInternalStateType(b->getInt64Ty());
    36 }
    37 
    38 /** ------------------------------------------------------------------------------------------------------------- *
    39  * @brief addInternalStateType
    40  ** ------------------------------------------------------------------------------------------------------------- */
    41 unsigned KernelBuilder::addInternalStateType(Type * const type) {
     32    mBlockIndex = addInternalState(b->getInt64Ty(), "BlockNo");
     33}
     34
     35/** ------------------------------------------------------------------------------------------------------------- *
     36 * @brief addInternalState
     37 ** ------------------------------------------------------------------------------------------------------------- */
     38unsigned KernelBuilder::addInternalState(Type * const type) {
    4239    assert (type);
    4340    const unsigned index = mStates.size();
     
    4643}
    4744
     45unsigned KernelBuilder::addInternalState(llvm::Type * const type, std::string name) {
     46    if (LLVM_UNLIKELY(mStateNameMap.count(name) != 0)) {
     47        throw std::runtime_error("Kernel already contains internal state " + name);
     48    }
     49    const unsigned index = addInternalState(type);
     50    mStateNameMap.emplace(name, index);
     51    return index;
     52}
     53
    4854/** ------------------------------------------------------------------------------------------------------------- *
    4955 * @brief addOutputStream
     
    5561
    5662/** ------------------------------------------------------------------------------------------------------------- *
    57  * @brief addOutputAccum
    58  ** ------------------------------------------------------------------------------------------------------------- */
    59 void KernelBuilder::addOutputAccum(Type * const type) {
     63 * @brief addOutputScalar
     64 ** ------------------------------------------------------------------------------------------------------------- */
     65void KernelBuilder::addOutputScalar(Type * const type) {
    6066    assert (type);
    61     mOutputAccums.push_back(type);
     67    mOutputScalar.push_back(type);
    6268}
    6369
     
    6672 ** ------------------------------------------------------------------------------------------------------------- */
    6773void KernelBuilder::addInputStream(const unsigned fields, std::string name) {
    68     assert (fields > 0);
    69     if (name.empty())
    70         mInputStreamNames.push_back(mKernelName + "_inputstream_" + std::to_string(mInputStreams.size()));
    71     else
    72         mInputStreamNames.push_back(name);
    73 
     74    assert (fields > 0 && !name.empty());
     75    mInputStreamNames.push_back(name);
    7476    if (fields == 1){
    7577        mInputStreams.push_back(mBitBlockType);
     
    7981}
    8082
     83void KernelBuilder::addInputStream(const unsigned fields) {
     84    addInputStream(fields, std::move(mKernelName + "_inputstream_" + std::to_string(mInputStreams.size())));
     85}
     86
     87
     88/** ------------------------------------------------------------------------------------------------------------- *
     89 * @brief getInputStream
     90 ** ------------------------------------------------------------------------------------------------------------- */
     91Value * KernelBuilder::getInputStream(const unsigned index, const unsigned streamOffset) {
     92    Value * const indices[] = {getOffset(streamOffset), iBuilder->getInt32(index)};
     93    return iBuilder->CreateGEP(mInputParam, indices);
     94}
     95
     96/** ------------------------------------------------------------------------------------------------------------- *
     97 * @brief getInputScalar
     98 ** ------------------------------------------------------------------------------------------------------------- */
     99Value * KernelBuilder::getInputScalar(const unsigned) {
     100    throw std::runtime_error("currently not supported!");
     101}
     102
     103/** ------------------------------------------------------------------------------------------------------------- *
     104 * @brief getOutputStream
     105 ** ------------------------------------------------------------------------------------------------------------- */
     106Value * KernelBuilder::getOutputStream(const unsigned index, const unsigned streamOffset) {
     107    Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(1), getOffset(streamOffset), iBuilder->getInt32(index)};
     108    return iBuilder->CreateGEP(mKernelParam, indices);
     109}
     110
     111/** ------------------------------------------------------------------------------------------------------------- *
     112 * @brief getOutputScalar
     113 ** ------------------------------------------------------------------------------------------------------------- */
     114Value * KernelBuilder::getOutputScalar(const unsigned) {
     115    throw std::runtime_error("currently not supported!");
     116}
     117
     118/** ------------------------------------------------------------------------------------------------------------- *
     119 * @brief getInternalState
     120 ** ------------------------------------------------------------------------------------------------------------- */
     121Value * KernelBuilder::getInternalState(const unsigned index, Value * const inputStruct) {
     122    Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(index)};
     123    return iBuilder->CreateGEP(inputStruct ? inputStruct : mKernelParam, indices);
     124}
     125
     126Value * KernelBuilder::getInternalState(const std::string & name, Value * const inputStruct) {
     127    const auto f = mStateNameMap.find(name);
     128    if (LLVM_UNLIKELY(f == mStateNameMap.end())) {
     129        throw std::runtime_error("Kernel does not contain internal state " + name);
     130    }
     131    return getInternalState(f->second, inputStruct);
     132}
     133
     134/** ------------------------------------------------------------------------------------------------------------- *
     135 * @brief setInternalState
     136 ** ------------------------------------------------------------------------------------------------------------- */
     137void KernelBuilder::setInternalState(const unsigned index, Value * const value) {
     138    Value * ptr = getInternalState(index);
     139    assert (ptr->getType()->getPointerElementType() == value->getType());
     140    if (value->getType() == iBuilder->getBitBlockType()) {
     141        iBuilder->CreateBlockAlignedStore(value, ptr);
     142    } else {
     143        iBuilder->CreateStore(value, ptr);
     144    }
     145}
     146
    81147/** ------------------------------------------------------------------------------------------------------------- *
    82148 * @brief addInputScalar
    83149 ** ------------------------------------------------------------------------------------------------------------- */
    84150void KernelBuilder::addInputScalar(Type * const type, std::string name) {
    85     if (name.empty())
    86         mInputScalarNames.push_back(mKernelName + "_inputscalar_" + std::to_string(mInputScalars.size()));
    87     else
    88         mInputScalarNames.push_back(name);
    89 
     151    assert (type && !name.empty());
     152    mInputScalarNames.push_back(name);
    90153    mInputScalars.push_back(type);
     154}
     155
     156void KernelBuilder::addInputScalar(Type * const type) {
     157    addInputScalar(type, std::move(mKernelName + "_inputscalar_" + std::to_string(mInputScalars.size())));
    91158}
    92159
     
    96163Function * KernelBuilder::prepareFunction() {   
    97164    if (mCircularBufferModulo > 1) {
    98         mStartIndex = addInternalStateType(iBuilder->getInt32Ty());
     165        mBlockIndex = addInternalState(iBuilder->getInt32Ty());
    99166    }
    100167    const unsigned capacity = mBlocksPerSegment + mCircularBufferModulo - 1;
     
    103170    mInputScalarType = PointerType::get(StructType::get(mMod->getContext(), mInputScalars), 0);
    104171    Type * outputStreamType = ArrayType::get(StructType::get(mMod->getContext(), mOutputStreams), capacity);
    105     Type * outputAccumType = StructType::get(mMod->getContext(), mOutputAccums);
     172    Type * outputAccumType = StructType::get(mMod->getContext(), mOutputScalar);
    106173    Type * internalStateType = StructType::create(mMod->getContext(), mStates, mKernelName);
    107174    mKernelStructType = StructType::create(mMod->getContext(),std::vector<Type *>({internalStateType, outputStreamType, outputAccumType}), "KernelStruct_"+ mKernelName);
     
    116183    mKernelParam = args++;
    117184    mKernelParam->setName("this");
    118 
    119185    mInputParam = args++;
    120186    mInputParam->setName("input_stream");
     
    131197 ** ------------------------------------------------------------------------------------------------------------- */
    132198void KernelBuilder::finalize() {
     199
    133200    // Finish the actual function
    134     if (mCircularBufferModulo > 1) {
    135         Value * startIdx = getInternalState(mStartIndex);
    136         Value * value = iBuilder->CreateBlockAlignedLoad(startIdx);
    137         value = iBuilder->CreateAdd(value, iBuilder->getInt32(1));
    138         iBuilder->CreateBlockAlignedStore(value, startIdx);
    139     }
     201    Value * startIdx = getInternalState(mBlockIndex);
     202    Value * value = iBuilder->CreateBlockAlignedLoad(startIdx);
     203    value = iBuilder->CreateAdd(value, ConstantInt::get(value->getType(), 1));
     204    iBuilder->CreateBlockAlignedStore(value, startIdx);
    140205    iBuilder->CreateRetVoid();
    141 
    142206
    143207    // Generate the zero initializer
     
    145209    initializer->setCallingConv(CallingConv::C);
    146210    Function::arg_iterator args = initializer->arg_begin();
    147 
    148211    mKernelParam = args++;
    149212    mKernelParam->setName("this");
     
    176239    mKernelParam->setName("this");
    177240
    178     Value* block_size_param = args++;
    179     block_size_param->setName("block_size");
    180     Value* seg_size_param = args++;
    181     seg_size_param->setName("seg_size");
    182241    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mConstructor, 0));
    183     setInternalState(0, block_size_param);
    184     setInternalState(1, seg_size_param);
    185242    iBuilder->CreateCall(initializer, mKernelParam);
    186243    iBuilder->CreateRetVoid();
     
    199256
    200257/** ------------------------------------------------------------------------------------------------------------- *
    201  * @brief getInputStream
    202  ** ------------------------------------------------------------------------------------------------------------- */
    203 Value * KernelBuilder::getInputStream(const unsigned index, const unsigned streamOffset) {
    204     Value * const indices[] = {getOffset(streamOffset), iBuilder->getInt32(index)};
    205     return iBuilder->CreateGEP(mInputParam, indices);
    206 }
    207 
    208 /** ------------------------------------------------------------------------------------------------------------- *
    209  * @brief getInputScalar
    210  ** ------------------------------------------------------------------------------------------------------------- */
    211 Value * KernelBuilder::getInputScalar(const unsigned index) {
    212     throw std::runtime_error("currently not supported!");
    213 }
    214 
    215 /** ------------------------------------------------------------------------------------------------------------- *
    216  * @brief getKernelState
    217  ** ------------------------------------------------------------------------------------------------------------- */
    218 Value * KernelBuilder::getKernelState(const unsigned index, const unsigned streamOffset) {
    219     Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(0), getOffset(streamOffset), iBuilder->getInt32(index)};
    220     return iBuilder->CreateGEP(mKernelParam, indices);
    221 }
    222 
    223 /** ------------------------------------------------------------------------------------------------------------- *
    224  * @brief getOutputStream
    225  ** ------------------------------------------------------------------------------------------------------------- */
    226 Value * KernelBuilder::getOutputStream(const unsigned index, const unsigned streamOffset) {
    227     Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(1), getOffset(streamOffset), iBuilder->getInt32(index)};
    228     return iBuilder->CreateGEP(mKernelParam, indices);
    229 }
    230 
    231 /** ------------------------------------------------------------------------------------------------------------- *
    232  * @brief getOutputScalar
    233  ** ------------------------------------------------------------------------------------------------------------- */
    234 Value * KernelBuilder::getOutputScalar(const unsigned index) {
    235 //    Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(2), getOffset(0), iBuilder->getInt32(index)};
    236 //    return iBuilder->CreateGEP(mKernelParam, indices);
    237     throw std::runtime_error("currently not supported!");
    238 }
    239 
    240 /** ------------------------------------------------------------------------------------------------------------- *
    241  * @brief getInternalState
    242  ** ------------------------------------------------------------------------------------------------------------- */
    243 Value * KernelBuilder::getInternalState(const unsigned index){
    244     Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(index)};
    245     return iBuilder->CreateGEP(mKernelParam, indices);
    246 }
    247 
    248 /** ------------------------------------------------------------------------------------------------------------- *
    249  * @brief setInternalState
    250  ** ------------------------------------------------------------------------------------------------------------- */
    251 void KernelBuilder::setInternalState(const unsigned index, Value * const value) {
    252     Value * ptr = getInternalState(index);
    253     assert (ptr->getType()->getPointerElementType() == value->getType());
    254     if (value->getType() == iBuilder->getBitBlockType()) {
    255         iBuilder->CreateBlockAlignedStore(value, ptr);
    256     } else {
    257         iBuilder->CreateStore(value, ptr);
    258     }
    259 }
    260 
    261 /** ------------------------------------------------------------------------------------------------------------- *
    262258 * @brief generateDoBlockCall
    263259 ** ------------------------------------------------------------------------------------------------------------- */
     
    283279    const unsigned adjustedOffset = (mSegmentIndex + value);
    284280    Value * offset = iBuilder->getInt32(adjustedOffset);
    285     if (mStartIndex) {
    286         Value * index = iBuilder->CreateBlockAlignedLoad(getInternalState(mStartIndex));
     281    if (mBlockIndex) {
     282        Value * index = iBuilder->CreateBlockAlignedLoad(getInternalState(mBlockIndex));
    287283        if (adjustedOffset) {
    288284            index = iBuilder->CreateAdd(index, offset);
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r4968 r4970  
    88#include <string>
    99#include <vector>
     10#include <boost/container/flat_map.hpp>
    1011
    1112namespace llvm {
     
    3233
    3334class KernelBuilder {
    34 
     35    using NameMap = boost::container::flat_map<std::string, unsigned>;
    3536public:
    3637    // sets name & sets internal state to the kernel superclass state
    3738    KernelBuilder(std::string name, llvm::Module * m, IDISA::IDISA_Builder * b);
    3839
    39     unsigned addInternalStateType(llvm::Type * const type);
     40    unsigned addInternalState(llvm::Type * const type);
     41    unsigned addInternalState(llvm::Type * const type, std::string name);
     42
     43    void addInputStream(const unsigned fields);
     44    void addInputStream(const unsigned fields, std::string name);
     45
     46    void addInputScalar(llvm::Type * const type);
     47    void addInputScalar(llvm::Type * const type, std::string name);
     48
     49
    4050    void addOutputStream(const unsigned fields);
    41     void addOutputAccum(llvm::Type * const type);
    42     void addInputStream(const unsigned fields, std::string name);
    43     void addInputScalar(llvm::Type * const type, std::string name);
     51    void addOutputScalar(llvm::Type * const type);
    4452
    4553    llvm::Function * prepareFunction();
    4654
    4755    void increment();
    48     void incrementCircularBuffer();
    4956
    5057    llvm::Value * getInputStream(const unsigned index, const unsigned streamOffset = 0);
     58
    5159    llvm::Value * getInputScalar(const unsigned index);
    52     llvm::Value * getKernelState(const unsigned index, const unsigned streamOffset = 0);
     60
     61    llvm::Value * getInternalState(const std::string & name, llvm::Value * const inputStruct = nullptr);
     62
     63    llvm::Value * getInternalState(const unsigned index, llvm::Value * const inputStruct = nullptr);
     64
    5365    llvm::Value * getOutputStream(const unsigned index, const unsigned streamOffset = 0);
     66
    5467    llvm::Value * getOutputScalar(const unsigned index);
    5568
     
    6982
    7083    void setInternalState(const unsigned index, llvm::Value * const value);
    71     llvm::Value * getInternalState(const unsigned index);
     84
     85    llvm::Value * getBlockIndexScalar();
    7286
    7387protected:
     
    8498    std::vector<llvm::Type *>           mOutputStreams;
    8599    std::vector<llvm::Type *>           mInputScalars;
    86     std::vector<llvm::Type *>           mOutputAccums;
     100    std::vector<llvm::Type *>           mOutputScalar;
    87101    std::vector<std::string>            mInputStreamNames;
    88102    std::vector<std::string>            mInputScalarNames;
     
    100114    llvm::Value *                       mKernelParam;
    101115    unsigned                            mSegmentIndex;
    102     unsigned                            mStartIndex;
     116    unsigned                            mBlockIndex;
     117
     118
     119    NameMap                             mStateNameMap;
     120
    103121};
    104122
     
    127145}
    128146
     147inline llvm::Value * KernelBuilder::getBlockIndexScalar() {
     148    return getInternalState(mBlockIndex);
     149}
     150
    129151#endif // KERNEL_H
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r4968 r4970  
    1919: mMod(m)
    2020, iBuilder(b)
    21 , mFileBufIdx(7)
    22 , mFileSizeIdx(8)
    23 , mFileNameIdx(9)
    2421, mBitBlockType(b->getBitBlockType())
    2522, mBlockSize(b->getBitBlockWidth()){
     
    3936
    4037    generateS2PKernel(mMod, iBuilder, mS2PKernel);
     38
    4139    generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel, isNameExpression);
    4240
     
    5755}
    5856
    59 void PipelineBuilder::ExecuteKernels(){
     57void PipelineBuilder::ExecuteKernels() {
    6058    Type * T = iBuilder->getIntNTy(64);   
    6159    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
     
    9189
    9290
    93     Value * gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(mFileBufIdx)});
     91    Value * gep = mScanMatchKernel->getInternalState("FileBuf", scanMatchKernelStruct);
    9492    Value * filebuf = iBuilder->CreateBitCast(input_param, S);
    9593    iBuilder->CreateStore(filebuf, gep);
    9694
    97     gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(mFileSizeIdx)});
     95
     96    gep = mScanMatchKernel->getInternalState("FileSize", scanMatchKernelStruct);
    9897    iBuilder->CreateStore(buffersize_param, gep);
    9998
    10099
    101     gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(mFileNameIdx)});
     100    gep = mScanMatchKernel->getInternalState("FileName", scanMatchKernelStruct);
    102101    iBuilder->CreateStore(filename_param, gep);
    103102
     
    113112    blkNo_phi->addIncoming(iBuilder->getInt64(0), entry_block);
    114113
    115     Value * final_block_cond = iBuilder->CreateICmpSLT(remaining_phi, ConstantInt::get(T, mBlockSize));
     114    Constant * step = ConstantInt::get(T, mBlockSize * mS2PKernel->getSegmentBlocks());
     115
     116    Value * final_block_cond = iBuilder->CreateICmpSLT(remaining_phi, step);
    116117    iBuilder->CreateCondBr(final_block_cond, pipeline_final_block, pipeline_do_block);
    117118
     
    126127    mScanMatchKernel->generateDoBlockCall(results);
    127128
    128     Value * update_remaining = iBuilder->CreateSub(remaining_phi, iBuilder->getInt64(mBlockSize));
     129    Value * update_remaining = iBuilder->CreateSub(remaining_phi, step);
    129130    remaining_phi->addIncoming(update_remaining, pipeline_do_block);
    130131    iBuilder->CreateBr(pipeline_test_block);
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r4959 r4970  
    4343    KernelBuilder *                     mICgrepKernel;   
    4444    KernelBuilder *                     mScanMatchKernel;
    45     int                                 mFileBufIdx;
    46     int                                 mFileSizeIdx;
    47     int                                 mFileNameIdx;
    4845    Type*                               mBitBlockType;
    4946    int                                 mBlockSize;
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r4959 r4970  
    3737}
    3838
    39 Function * generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanwordBitWidth, Type * kernelStuctType, bool isNameExpression) {
     39Function * generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanwordBitWidth, KernelBuilder * const kBuilder, bool isNameExpression) {
    4040
    4141    Function * function = m->getFunction("scan_matches_in_scanword");
     
    4848    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
    4949    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    50     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({kernelStuctType, T, T, T, T, T}), false);
     50    FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({PointerType::get(kBuilder->getKernelStructType(), 0), T, T, T, T, T}), false);
    5151
    5252    SmallVector<AttributeSet, 6> Attrs;
     
    7777    Value * recordNum_input_parm = args++;
    7878    recordNum_input_parm->setName("lineNum");
     79
    7980    Constant * matchProcessor;
    80     if(isNameExpression)
     81    if (isNameExpression) {
    8182        matchProcessor = m->getOrInsertFunction("insert_codepoints", Type::getVoidTy(ctxt), T, T, T, S, nullptr);
    82     else
     83    } else {
    8384        matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, S, T, S, nullptr);
    84 
     85    }
    8586    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", function,0));
    8687
     
    147148    matchRecordNum_phi->addIncoming(matchRecordNum, prior_breaks_block);
    148149    matchRecordStart_phi->addIncoming(recordStart_phi, process_matches_loop_entry);
    149     matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);
     150    matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);   
    150151    Value * matchRecordEnd = iBuilder->CreateAdd(scanwordPos, generateCountForwardZeroes(iBuilder, matches_phi));
    151152
    152     Value* filebuf_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
     153    Value* filebuf_gep = kBuilder->getInternalState("FileBuf", this_input_parm);
    153154    Value* filebufptr = iBuilder->CreateLoad(filebuf_gep, "filebuf");
    154155
    155     Value* filesize_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
    156     Value* filesize = iBuilder->CreateLoad(filesize_gep, "filensize");
    157 
    158     Value* filename_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
    159     Value* filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
    160 
    161     if(isNameExpression)
     156    if (isNameExpression) {
    162157        iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr}));
    163     else
     158    } else {
     159        Value * filesize_gep = kBuilder->getInternalState("FileSize", this_input_parm);
     160        Value * filesize = iBuilder->CreateLoad(filesize_gep, "filesize");
     161
     162        Value * filename_gep = kBuilder->getInternalState("FileName", this_input_parm);
     163        Value * filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
     164
    164165        iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr, filesize, filenameptr}));
     166    }
     167
    165168    Value * remaining_matches = generateResetLowestBit(iBuilder, matches_phi);
    166169    Value * remaining_breaks = iBuilder->CreateXor(record_breaks_phi, prior_breaks);
     
    203206
    204207
    205 void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanWordBitWidth, KernelBuilder * kBuilder, bool isNameExpression){
     208void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, unsigned scanWordBitWidth, KernelBuilder * kBuilder, bool isNameExpression) {
    206209
    207210
     
    214217    kBuilder->addInputStream(1, "breaks");
    215218    //use index
    216     unsigned blockPosIdx = kBuilder->addInternalStateType(T);
    217     unsigned lineStartIdx = kBuilder->addInternalStateType(T);
    218     unsigned lineNumIdx = kBuilder->addInternalStateType(T);
    219     kBuilder->addInternalStateType(S);
    220     kBuilder->addInternalStateType(T);
    221     kBuilder->addInternalStateType(S);
     219    const unsigned lineStart = kBuilder->addInternalState(T, "LineStart");
     220    const unsigned lineNum = kBuilder->addInternalState(T, "LineNum");
     221    kBuilder->addInternalState(S, "FileBuf");
     222    kBuilder->addInternalState(T, "FileSize");
     223    kBuilder->addInternalState(S, "FileName");
    222224
    223225    Function * function = kBuilder->prepareFunction();
    224226
    225     Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
    226 
    227     Function * scanWordFunction = generateScanWordRoutine(m, iBuilder, scanWordBitWidth, kernelStuctType, isNameExpression);
     227    // Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
     228
     229    Function * scanWordFunction = generateScanWordRoutine(m, iBuilder, scanWordBitWidth, kBuilder, isNameExpression);
    228230
    229231    iBuilder->SetInsertPoint(&function->getEntryBlock());
     
    231233    Value * kernelStuctParam = kBuilder->getKernelStructParam();
    232234
    233     Value * scanwordPos = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(blockPosIdx));
    234     Value * recordStart = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineStartIdx));
    235     Value * recordNum = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineNumIdx));
     235    Value * scanwordPos = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState("BlockNo"));
     236    scanwordPos = iBuilder->CreateMul(scanwordPos, ConstantInt::get(scanwordPos->getType(), iBuilder->getBitBlockWidth()));
     237
     238    Value * recordStart = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineStart));
     239    Value * recordNum = iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(lineNum));
     240
    236241    Value * wordResult = nullptr;
    237242
    238243    const unsigned segmentBlocks = kBuilder->getSegmentBlocks();
    239244    const unsigned scanWordBlocks =  segmentBlocks * fieldCount;
    240 
    241245    for(unsigned j = 0; j < segmentBlocks; ++j) {
    242 
    243246        Value * matchWordVector = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(kBuilder->getInputStream(0)), scanwordVectorType);
    244247        Value * breakWordVector = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(kBuilder->getInputStream(1)), scanwordVectorType);
    245 
    246248        for(unsigned i = 0; i < scanWordBlocks; ++i){
    247249            Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
     
    254256        kBuilder->increment();
    255257    }
    256 
    257     kBuilder->setInternalState(blockPosIdx, scanwordPos);
    258     kBuilder->setInternalState(lineStartIdx, recordStart);
    259     kBuilder->setInternalState(lineNumIdx, recordNum);
    260 
     258    kBuilder->setInternalState(lineStart, recordStart);
     259    kBuilder->setInternalState(lineNum, recordNum);
    261260    kBuilder->finalize();
    262261}
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r4959 r4970  
    55#ifndef SCANMATCHGEN_H
    66#define SCANMATCHGEN_H
     7
     8#include <tuple>
    79
    810class KernelBuilder;
Note: See TracChangeset for help on using the changeset viewer.