Ignore:
Timestamp:
Feb 20, 2016, 11:31:45 AM (3 years ago)
Author:
cameron
Message:

Bug fix; simplification

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

Legend:

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

    r4934 r4935  
    151151
    152152    Value * remaining = iBuilder->CreateZExt(remaining_phi, iBuilder->getIntNTy(128));
    153     Value * EOF_mask = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(128), 1), remaining);
    154     EOF_mask = iBuilder->CreateSub(EOF_mask, ConstantInt::get(iBuilder->getIntNTy(128), 1));
    155 
    156     Value * EOF_pos = iBuilder->CreateNeg(iBuilder->CreateOr(iBuilder->CreateShl(iBuilder->CreateNeg(EOF_mask), 1), EOF_mask));
     153    Value * EOF_pos = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(128), 1), remaining);
    157154    EOF_pos = iBuilder->CreateBitCast(EOF_pos, mBitBlockType);
    158155
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r4907 r4935  
    44 */
    55
    6 
     6#include "kernel.h"
    77#include "scanmatchgen.h"
    88#include <llvm/IR/Intrinsics.h>
     
    3232    return iBuilder->CreateAnd(bits_minus1, bits);
    3333}
    34 
    35 /*
    36        
    37 void write_matches_ending_in_segment(scanword_t matches, scanword_t lbreaks, ssize_t segmentPos, ssize_t & pendingLineStart, int & lineNum) {
    38     scanword_t remaining_matches = matches;
    39     scanword_t remaining_LBs = lbreaks;
    40     while (remaining_matches != 0) {
    41         // Find all the line marks prior to the match position
    42         scanword_t priorLineMarks = ForwardZeroesMask(remaining_matches) & remaining_LBs;
    43         if (priorLineMarks != 0) {
    44             int matchLineNum = lineNum + popcount(priorLineMarks);
    45             // The last of these line marks prior to the match position is the
    46             // starting positions of the matched line.
    47             matchLineStart = segmentPos + segmentBitWidth - CountReverseZeroes(priorLineMarks);
    48         }
    49         else {
    50             matchLineNum = lineNum;
    51             matchLineStart = pendingLineStart;
    52         }
    53         // The line end is marked by the match posiiton.
    54         matchLineEnd = segmentPos + CountForwardZeroes(remaining_matches);
    55         call write_match(matchLineNum, matchLineStart, matchLineEnd);
    56        
    57         remaining_matches = ResetLowestBit(remaining_matches);
    58         remaining_LBs = remaining_LBs ^ priorLineMarks;
    59         lineNum = matchLineNum;
    60     }
    61     if (remaining_LBs != 0) {
    62         lineNum += popcount(remaining_LBs);
    63         pendingLineStart = segmentPos + segmentBitWidth - CountReverseZeroes(remaining_LBs);
    64     }
    65 }   
    66         */
    67 
    68        
    69        
    70 void generateScanSegmentRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth) {
     34       
     35       
     36void generateScanWordRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int scanwordBitWidth, Type * kernelStuctType) {
    7137    LLVMContext & ctxt = m->getContext();
    72     Type * T = iBuilder->getIntNTy(segBitWidth);
     38    Type * T = iBuilder->getIntNTy(scanwordBitWidth);   
     39    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
    7340    Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    74     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({T, T, T, T, T}), false);
     41    FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({kernelStuctType, T, T, T, T, T}), false);
    7542    Function * sFunction;
    7643       
     
    8451    AttributeSet AttrSet = AttributeSet::get(ctxt, Attrs);
    8552   
    86     sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_segment", m);
     53    sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_scanword", m);
    8754    sFunction->setCallingConv(CallingConv::C);
    8855    sFunction->setAttributes(AttrSet);
    8956       
    9057    Function::arg_iterator args = sFunction->arg_begin();
     58    Value * this_input_parm = args++;
     59    this_input_parm->setName("this");
    9160    Value * matches_input_parm = args++;
    9261    matches_input_parm->setName("matches");
    9362    Value * record_breaks_input_parm = args++;
    9463    record_breaks_input_parm->setName("breaks");
    95     Value * segmentPos = args++;
    96     segmentPos->setName("segmentPos");
     64    Value * scanwordPos = args++;
     65    scanwordPos->setName("scanwordPos");
    9766    Value * recordStart_input_parm = args++;
    9867    recordStart_input_parm->setName("pendingLineStart");
     
    10069    recordNum_input_parm->setName("lineNum");
    10170   
    102     Constant * matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, NULL);
    103 
     71    Constant * matchProcessor = m->getOrInsertFunction("wrapped_report_match", Type::getVoidTy(ctxt), T, T, T, S, T, S, NULL);
    10472   
    10573    iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", sFunction,0));
     
    11684       
    11785    // The match scanner works with a loop involving four variables:
    118     // (a) the bit stream segment of matches marking the ends of selected records,
    119     // (b) the bit stream segment of record_breaks marking the ends of all records,
     86    // (a) the bit stream scanword of matches marking the ends of selected records,
     87    // (b) the bit stream scanword of record_breaks marking the ends of all records,
    12088    // (c) the integer lastRecordNum indicating the number of records processed so far,
    12189    // (d) the index lastRecordStart indicating the file position of the last record.
     
    154122    Value * matchRecordNum = iBuilder->CreateAdd(generatePopcount(iBuilder, prior_breaks), recordNum_phi);
    155123    Value * reverseDistance = generateCountReverseZeroes(iBuilder, prior_breaks);
    156     Value * width = ConstantInt::get(T, segBitWidth);
    157     Value * matchRecordStart = iBuilder->CreateAdd(segmentPos, iBuilder->CreateSub(width, reverseDistance));
     124    Value * width = ConstantInt::get(T, scanwordBitWidth);
     125    Value * matchRecordStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseDistance));
    158126    iBuilder->CreateBr(loop_final_block);
    159127   
     
    168136    matchRecordStart_phi->addIncoming(recordStart_phi, process_matches_loop_entry);
    169137    matchRecordStart_phi->addIncoming(matchRecordStart, prior_breaks_block);
    170     Value * matchRecordEnd = iBuilder->CreateAdd(segmentPos, generateCountForwardZeroes(iBuilder, matches_phi));
    171     iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd}));
     138    Value * matchRecordEnd = iBuilder->CreateAdd(scanwordPos, generateCountForwardZeroes(iBuilder, matches_phi));
     139
     140    Value* filebuf_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
     141    Value* filebufptr = iBuilder->CreateLoad(filebuf_gep, "filebuf");
     142
     143    Value* filesize_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
     144    Value* filesize = iBuilder->CreateLoad(filesize_gep, "filensize");
     145
     146    Value* filename_gep = iBuilder->CreateGEP(this_input_parm, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
     147    Value* filenameptr = iBuilder->CreateLoad(filename_gep, "filename");
     148
     149    iBuilder->CreateCall(matchProcessor, std::vector<Value *>({matchRecordNum_phi, matchRecordStart_phi, matchRecordEnd, filebufptr, filesize, filenameptr}));
    172150    Value * remaining_matches = generateResetLowestBit(iBuilder, matches_phi);
    173151    Value * remaining_breaks = iBuilder->CreateXor(record_breaks_phi, prior_breaks);
     
    190168    Value * final_record_num = iBuilder->CreateAdd(recordNum_phi, break_count);
    191169    Value * reverseZeroes = generateCountReverseZeroes(iBuilder, record_breaks_phi);
    192     Value * pendingLineStart = iBuilder->CreateAdd(segmentPos, iBuilder->CreateSub(width, reverseZeroes));
     170    Value * pendingLineStart = iBuilder->CreateAdd(scanwordPos, iBuilder->CreateSub(width, reverseZeroes));
    193171    iBuilder->CreateBr(return_block);
    194172   
     
    202180    finalRecordStart_phi->addIncoming(pendingLineStart, remaining_breaks_block);
    203181    Value * retVal = UndefValue::get(returnType);
    204     retVal = iBuilder->CreateInsertValue(retVal, finalRecordCount_phi, 0);
    205     retVal = iBuilder->CreateInsertValue(retVal, finalRecordStart_phi, 1);
     182    retVal = iBuilder->CreateInsertValue(retVal, finalRecordStart_phi, 0);
     183    retVal = iBuilder->CreateInsertValue(retVal, finalRecordCount_phi, 1);
    206184    iBuilder->CreateRet(retVal);
    207185   
     
    209187
    210188
    211 void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth) {
    212     LLVMContext & ctxt = m->getContext();
    213     Type * B = iBuilder->getBitBlockType();
    214     Type * T = iBuilder->getIntNTy(segBitWidth);
    215     generateScanSegmentRoutine(m, iBuilder, segBitWidth);
    216     int fieldCount = iBuilder->getBitBlockWidth()/segBitWidth;
    217     Type * segmentVectorType =  VectorType::get(T, fieldCount);
    218    
    219    
    220     Type * returnType = StructType::get(ctxt, std::vector<Type *>({T, T}));
    221     FunctionType * functionType = FunctionType::get(returnType, std::vector<Type *>({B, B, T, T, T}), false);
    222     Function * sFunction;
    223    
    224     SmallVector<AttributeSet, 6> Attrs;
    225     Attrs.push_back(AttributeSet::get(ctxt, ~0U, std::vector<Attribute::AttrKind>({ Attribute::NoUnwind, Attribute::UWTable })));
    226     Attrs.push_back(AttributeSet::get(ctxt, 1, std::vector<Attribute::AttrKind>({})));
    227     Attrs.push_back(AttributeSet::get(ctxt, 2, std::vector<Attribute::AttrKind>({})));
    228     Attrs.push_back(AttributeSet::get(ctxt, 3, std::vector<Attribute::AttrKind>({})));
    229     Attrs.push_back(AttributeSet::get(ctxt, 4, std::vector<Attribute::AttrKind>({})));
    230     Attrs.push_back(AttributeSet::get(ctxt, 5, std::vector<Attribute::AttrKind>({})));
    231     AttributeSet AttrSet = AttributeSet::get(ctxt, Attrs);
    232     sFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, "scan_matches_in_bitblock", m);
    233     sFunction->setCallingConv(CallingConv::C);
    234     sFunction->setAttributes(AttrSet);
    235    
    236    
    237    
    238     Function::arg_iterator args = sFunction->arg_begin();
    239     Value * matches_input_parm = args++;
    240     matches_input_parm->setName("matches");
    241     Value * record_breaks_input_parm = args++;
    242     record_breaks_input_parm->setName("breaks");
    243     Value * blockPos = args++;
    244     blockPos->setName("blockPos");
    245     Value * recordStart_input_parm = args++;
    246     recordStart_input_parm->setName("pendingLineStart");
    247     Value * recordNum_input_parm = args++;
    248     recordNum_input_parm->setName("lineNum");
    249    
    250     iBuilder->SetInsertPoint(BasicBlock::Create(ctxt, "entry", sFunction,0));
    251    
    252     Value * matchSegVector = iBuilder->CreateBitCast(matches_input_parm, segmentVectorType);
    253     Value * breakSegVector = iBuilder->CreateBitCast(record_breaks_input_parm, segmentVectorType);
    254     Value * segmentPos = blockPos;
    255     Value * recordStart = recordStart_input_parm;
    256     Value * recordNum = recordNum_input_parm;
    257     Value * segResult = nullptr;
    258     Function * segScanFcn = m->getFunction("scan_matches_in_segment");
    259     for (uint64_t i = 0; i < iBuilder->getBitBlockWidth()/segBitWidth; i++) {
    260         Value * matchSeg = iBuilder->CreateExtractElement(matchSegVector, ConstantInt::get(T, i));
    261         Value * recordBreaksSeg = iBuilder->CreateExtractElement(breakSegVector, ConstantInt::get(T, i));
    262         segResult = iBuilder->CreateCall(segScanFcn, std::vector<Value *>({matchSeg, recordBreaksSeg, segmentPos, recordStart, recordNum}));
    263         segmentPos = iBuilder->CreateAdd(segmentPos, ConstantInt::get(T, segBitWidth));
    264         recordStart = iBuilder->CreateExtractValue(segResult, std::vector<unsigned>({0}));
    265         recordNum = iBuilder->CreateExtractValue(segResult, std::vector<unsigned>({1}));
     189void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, int scanwordBitWidth, KernelBuilder * kBuilder){
     190   
     191   
     192    Type * T = iBuilder->getIntNTy(scanwordBitWidth);
     193    Type * S = PointerType::get(iBuilder->getIntNTy(8), 0);
     194    int fieldCount = iBuilder->getBitBlockWidth()/scanwordBitWidth;
     195    Type * scanwordVectorType =  VectorType::get(T, fieldCount);
     196
     197    kBuilder->addKernelInputStream(1, "matches");
     198    kBuilder->addKernelInputStream(1, "breaks");
     199    //use index
     200    int blockPosIdx = kBuilder->extendKernelInternalStateType(T);
     201    int lineStartIdx = kBuilder->extendKernelInternalStateType(T);
     202    int lineNumIdx = kBuilder->extendKernelInternalStateType(T);
     203    int fileBufIdx = kBuilder->extendKernelInternalStateType(S);
     204    int bufSizeIdx = kBuilder->extendKernelInternalStateType(T);
     205    int fileNameIdx = kBuilder->extendKernelInternalStateType(S);
     206
     207    int segBlocks = kBuilder->getSegmentBlocks();
     208
     209    kBuilder->PrepareDoBlockFunction();
     210
     211    Type * kernelStuctType = PointerType::get(kBuilder->getKernelStructType(), 0);
     212    generateScanWordRoutine(m, iBuilder, scanwordBitWidth, kernelStuctType);
     213
     214    struct Inputs inputs = kBuilder->openDoBlock();
     215    struct Outputs outputs;   
     216    Value * kernelStuctParam = kBuilder->getKernelStructParam();
     217   
     218    Value * scanwordPos = kBuilder->getKernelInternalState(blockPosIdx);
     219    Value * recordStart = kBuilder->getKernelInternalState(lineStartIdx);
     220    Value * recordNum = kBuilder->getKernelInternalState(lineNumIdx);
     221    Value * wordResult = nullptr;
     222
     223    Function * wordScanFcn = m->getFunction("scan_matches_in_scanword");
     224    for(int j=0; j<segBlocks; j++){
     225        Value * matchWordVector = iBuilder->CreateBitCast(inputs.streams[j][0], scanwordVectorType);
     226        Value * breakWordVector = iBuilder->CreateBitCast(inputs.streams[j][1], scanwordVectorType);
     227        for(int i=0; i<segBlocks*iBuilder->getBitBlockWidth()/scanwordBitWidth; i++){
     228
     229            Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
     230            Value * recordBreaksWord = iBuilder->CreateExtractElement(breakWordVector, ConstantInt::get(T, i));
     231            wordResult = iBuilder->CreateCall(wordScanFcn, std::vector<Value *>({kernelStuctParam, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum}));
     232            scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, scanwordBitWidth));
     233            recordStart = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({0}));
     234            recordNum = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({1}));
     235        }
    266236    }
    267     iBuilder->CreateRet(segResult);
    268 }
    269 
    270 
    271 
    272 
     237
     238    kBuilder->changeKernelInternalState(blockPosIdx, scanwordPos);
     239    kBuilder->changeKernelInternalState(lineStartIdx, recordStart);
     240    kBuilder->changeKernelInternalState(lineNumIdx, recordNum);
     241
     242    kBuilder->closeDoBlock(outputs);
     243
     244    kBuilder->finalizeMethods();
     245}
     246
     247
     248
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r4907 r4935  
    1111#include <llvm/IR/Module.h>
    1212       
    13 void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth);
     13void generateScanBitBlockRoutine(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth, Type * kernelStuctType);
     14
     15void generateScanMatch(Module * m, IDISA::IDISA_Builder * iBuilder, int segBitWidth, KernelBuilder * kBuilder);
    1416
    1517#endif // SCANMATCHGEN_H
Note: See TracChangeset for help on using the changeset viewer.