Changeset 5861 for icGREP


Ignore:
Timestamp:
Feb 3, 2018, 12:02:14 PM (13 months ago)
Author:
cameron
Message:

Using DirectCC builder updates; speedup wc -l

Location:
icGREP/icgrep-devel/icgrep
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5832 r5861  
    1616namespace IDISA {
    1717
     18   
     19inline bool isStreamTy(llvm::Type * t) {
     20    return t->isVectorTy() && (t->getVectorNumElements() == 0);
     21}
     22
     23inline bool isStreamSetTy(llvm::Type * t) {
     24    return t->isArrayTy() && (isStreamTy(t->getArrayElementType()));
     25}
     26
     27inline unsigned getNumOfStreams (llvm::Type * t) {
     28    if (isStreamTy(t)) return 1;
     29    assert(isStreamSetTy(t));
     30    return t->getArrayNumElements();
     31}
     32
     33inline unsigned getStreamFieldWidth (llvm::Type * t) {
     34    if (isStreamTy(t)) return t->getScalarSizeInBits();
     35    assert(isStreamSetTy(t));
     36    return t->getArrayElementType()->getScalarSizeInBits();
     37}
     38
     39   
    1840class IDISA_Builder : public CBuilder {
    1941
     
    168190        return getStreamSetTy(getContext(), NumElements, FieldWidth);
    169191    }
    170 
     192   
    171193    void CallPrintRegister(const std::string & regName, llvm::Value * const value);
    172194
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5860 r5861  
    4949using namespace llvm;
    5050using namespace cc;
     51using namespace kernel;
    5152
    5253static cl::opt<int> Threads("t", cl::desc("Total number of threads."), cl::init(2));
     
    116117
    117118    #ifdef USE_DIRECT_LF_BUILDER
    118     kernel::Kernel * linefeedK = mGrepDriver->addKernelInstance<kernel::LineFeedKernelBuilder>(idb, encodingBits);
     119    kernel::Kernel * linefeedK = mGrepDriver->addKernelInstance<kernel::LineFeedKernelBuilder>(idb, Binding{idb->getStreamSetTy(1, 8), "byteStream", FixedRate(), Principal()});
    119120    mGrepDriver->makeKernelCall(linefeedK, {ByteStream}, {LineFeedStream});
    120121    #endif
     
    131132
    132133    #ifndef USE_DIRECT_LF_BUILDER
    133     kernel::Kernel * linefeedK = mGrepDriver->addKernelInstance<kernel::LineFeedKernelBuilder>(idb, encodingBits);
     134    kernel::Kernel * linefeedK = mGrepDriver->addKernelInstance<kernel::LineFeedKernelBuilder>(idb, Binding{idb->getStreamSetTy(8), "basis", FixedRate(), Principal()});
    134135    mGrepDriver->makeKernelCall(linefeedK, {BasisBits}, {LineFeedStream});
    135136    #endif
  • icGREP/icgrep-devel/icgrep/kernels/charclasses.cpp

    r5854 r5861  
    7878void CharClassesKernel::generatePabloMethod() {
    7979    PabloBuilder pb(getEntryScope());
    80     CC_Compiler * ccc;
     80    std::unique_ptr<CC_Compiler> ccc;
    8181    if (mUseDirectCC) {
    82         ccc = new Direct_CC_Compiler(this, pb.createExtract(getInputStreamVar("byteData"), pb.getInteger(0)));
     82        ccc = make_unique<cc::Direct_CC_Compiler>(this, pb.createExtract(getInput(0), pb.getInteger(0)));
     83    } else {
     84        ccc = make_unique<cc::Parabix_CC_Compiler>(this, getInputStreamSet("basis"));
    8385    }
    84     else {
    85         ccc = new Parabix_CC_Compiler(this, getInputStreamSet("basis"));
    86     }
    87 
    8886    unsigned n = mCCs.size();
    8987
     
    9694    }
    9795
    98     UCD::UCDCompiler ucdCompiler(*ccc);
     96    UCD::UCDCompiler ucdCompiler(*ccc.get());
    9997    if (LLVM_UNLIKELY(AlgorithmOptionIsSet(DisableIfHierarchy))) {
    10098        ucdCompiler.generateWithoutIfHierarchy(nameMap, pb);
     
    114112        }
    115113    }
    116     delete ccc;
    117114}
    118115
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.cpp

    r5856 r5861  
    11/*
    2  *  Copyright (c) 2016 International Characters.
     2 *  Copyright (c) 2018 International Characters.
    33 *  This software is licensed to the public under the Open Software License 3.0.
    44 */
     
    1212#include <cc/cc_compiler.h>
    1313#include <pablo/builder.hpp>
     14#include <IR_Gen/idisa_builder.h>
    1415#include <kernels/kernel_builder.h>
    1516
     
    2122using namespace re;
    2223using namespace llvm;
     24using namespace IDISA;
    2325
    24 LineFeedKernelBuilder::LineFeedKernelBuilder(const std::unique_ptr<kernel::KernelBuilder> & b, const unsigned codeUnitWidth)
    25 : PabloKernel(b, "lf" + std::to_string(codeUnitWidth),
     26LineFeedKernelBuilder::LineFeedKernelBuilder(const std::unique_ptr<kernel::KernelBuilder> & b, Binding && inputStreamSet)
     27: PabloKernel(b, "lf" + std::to_string(getNumOfStreams(inputStreamSet.getType())) + "x" + std::to_string(getStreamFieldWidth(inputStreamSet.getType())),
    2628// input
    27 #ifdef USE_DIRECT_LF_BUILDER
    28 {Binding{b->getStreamSetTy(1, codeUnitWidth), "byteStream", FixedRate(), Principal()}},
    29 #else
    30 {Binding{b->getStreamSetTy(codeUnitWidth), "basis", FixedRate(), Principal()}},
    31 #endif
    32 // output
    33 {Binding{b->getStreamSetTy(1), "lf"}}) {
    34 
     29{inputStreamSet},
     30{Binding{b->getStreamSetTy(1), "lf"}}),
     31    mNumOfStreams(getNumOfStreams(inputStreamSet.getType())),
     32    mStreamFieldWidth(getStreamFieldWidth(inputStreamSet.getType()))
     33{
    3534}
    3635
    3736void LineFeedKernelBuilder::generatePabloMethod() {
    3837    PabloBuilder pb(getEntryScope());
    39     #ifdef USE_DIRECT_LF_BUILDER
    40     cc::Direct_CC_Compiler ccc(this, pb.createExtract(getInputStreamVar("byteStream"), pb.getInteger(0)));
    41     #else
    42     cc::Parabix_CC_Compiler ccc(this, getInputStreamSet("basis"));
    43     #endif
    44     PabloAST * LF = ccc.compileCC("LF", makeByte(0x0A), pb);
     38    std::unique_ptr<CC_Compiler> ccc;
     39    if (mNumOfStreams == 1) {
     40        ccc = make_unique<cc::Direct_CC_Compiler>(this, pb.createExtract(getInput(0), pb.getInteger(0)));
     41    } else {
     42        ccc = make_unique<cc::Parabix_CC_Compiler>(this, getInputStreamSet("basis"));
     43    }
     44    PabloAST * LF = ccc->compileCC("LF", makeByte(0x0A), pb);
    4545    pb.createAssign(pb.createExtract(getOutput(0), 0), LF);
    4646}
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.h

    r5859 r5861  
    1111
    1212namespace kernel {
    13 //#define USE_DIRECT_LF_BUILDER
     13#define USE_DIRECT_LF_BUILDER
    1414
    1515class LineFeedKernelBuilder final : public pablo::PabloKernel {
    1616public:
    17     LineFeedKernelBuilder(const std::unique_ptr<KernelBuilder> & b, unsigned codeUnitWidth = 8);
     17    LineFeedKernelBuilder(const std::unique_ptr<KernelBuilder> & b, kernel::Binding && inputStreamSet);
    1818    bool isCachable() const override { return true; }
    1919    bool hasSignature() const override { return false; }
    2020protected:
    2121    void generatePabloMethod() override;
     22    unsigned mNumOfStreams;
     23    unsigned mStreamFieldWidth;
    2224};
    2325
  • icGREP/icgrep-devel/icgrep/toolchain/grep_pipeline.cpp

    r5856 r5861  
    2626using namespace parabix;
    2727using namespace llvm;
     28using namespace kernel;
    2829
    2930namespace grep {
     
    6465    StreamSetBuffer * LineFeedStream = pxDriver.addBuffer<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize);
    6566    #ifdef USE_DIRECT_LF_BUILDER
    66     kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, 8);
     67    kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, Binding{idb->getStreamSetTy(1, 8), "byteStream", FixedRate(), Principal()});
    6768    pxDriver.makeKernelCall(linefeedK, {ByteStream}, {LineFeedStream});
    6869    #endif
     
    7374
    7475    #ifndef USE_DIRECT_LF_BUILDER
    75     kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, 8);
     76    kernel::Kernel * linefeedK = pxDriver.addKernelInstance<kernel::LineFeedKernelBuilder>(idb, Binding{idb->getStreamSetTy(8), "basis", FixedRate(), Principal()});
    7677    pxDriver.makeKernelCall(linefeedK, {BasisBits}, {LineFeedStream});
    7778    #endif
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5847 r5861  
    4242             CL_ENUM_VAL_SENTINEL), cl::cat(wcFlags), cl::Grouping);
    4343                                                 
    44 
     44static std::string wc_modes = "";
    4545
    4646static int defaultFieldWidth = 7;  // default field width
     
    8383class WordCountKernel final: public pablo::PabloKernel {
    8484public:
    85     WordCountKernel(const std::unique_ptr<kernel::KernelBuilder> & b);
     85    WordCountKernel(const std::unique_ptr<kernel::KernelBuilder> & b, Binding && inputStreamSet);
    8686    bool isCachable() const override { return true; }
    8787    bool hasSignature() const override { return false; }
     
    9090};
    9191
    92 WordCountKernel::WordCountKernel (const std::unique_ptr<kernel::KernelBuilder> & b)
    93 : PabloKernel(b, "wc",
    94     {Binding{b->getStreamSetTy(8, 1), "u8bit"}},
     92WordCountKernel::WordCountKernel (const std::unique_ptr<kernel::KernelBuilder> & b, Binding && inputStreamSet)
     93: PabloKernel(b, "wc_" + wc_modes,
     94    {inputStreamSet},
    9595    {},
    9696    {},
     
    101101void WordCountKernel::generatePabloMethod() {
    102102    PabloBuilder pb(getEntryScope());
    103     //  input: 8 basis bit streams
    104     std::vector<PabloAST *> u8_bits = getInputStreamSet("u8bit");
     103    std::unique_ptr<cc::CC_Compiler> ccc;
     104    if (CountWords || CountChars) {
     105        ccc = make_unique<cc::Parabix_CC_Compiler>(this, getInputStreamSet("u8bit"));
     106    } else {
     107        ccc = make_unique<cc::Direct_CC_Compiler>(this, pb.createExtract(getInput(0), pb.getInteger(0)));
     108    }
     109
    105110    //  output: 3 counters
    106 
    107     cc::Parabix_CC_Compiler ccc(this, u8_bits);
    108 
    109111    Var * lc = getOutputScalarVar("lineCount");
    110112    Var * wc = getOutputScalarVar("wordCount");
     
    112114
    113115    if (CountLines) {
    114         PabloAST * LF = ccc.compileCC(re::makeCC(0x0A));
     116        PabloAST * LF = ccc->compileCC(re::makeByte(0x0A));
    115117        pb.createAssign(lc, pb.createCount(LF));
    116118    }
    117119    if (CountWords) {
    118         PabloAST * WS = ccc.compileCC(re::makeCC(re::makeCC(0x09, 0x0D), re::makeCC(0x20)));
     120        PabloAST * WS = ccc->compileCC(re::makeCC(re::makeByte(0x09, 0x0D), re::makeByte(0x20)));
    119121        PabloAST * wordChar = pb.createNot(WS);
    120122        // WS_follow_or_start = 1 past WS or at start of file
     
    128130        // not UTF-8, or is not valid?
    129131        //
    130         PabloAST * u8Begin = ccc.compileCC(re::makeCC(re::makeCC(0, 0x7F), re::makeCC(0xC2, 0xF4)));
     132        PabloAST * u8Begin = ccc->compileCC(re::makeCC(re::makeByte(0, 0x7F), re::makeByte(0xC2, 0xF4)));
    131133        pb.createAssign(cc, pb.createCount(u8Begin));
    132134    }
     
    163165    StreamSetBuffer * const ByteStream = pxDriver.addBuffer<SourceBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8));
    164166
    165     StreamSetBuffer * const BasisBits = pxDriver.addBuffer<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments);
    166167
    167168    Kernel * mmapK = pxDriver.addKernelInstance<MMapSourceKernel>(iBuilder);
    168169    mmapK->setInitialArguments({fileDecriptor});
    169170    pxDriver.makeKernelCall(mmapK, {}, {ByteStream});
    170 
    171     Kernel * s2pk = pxDriver.addKernelInstance<S2PKernel>(iBuilder);
    172     pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    173    
    174     Kernel * wck = pxDriver.addKernelInstance<WordCountKernel>(iBuilder);
    175     pxDriver.makeKernelCall(wck, {BasisBits}, {});
     171   
     172    Kernel * wck  = nullptr;
     173    if (CountWords || CountChars) {
     174        StreamSetBuffer * const BasisBits = pxDriver.addBuffer<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments);
     175        Kernel * s2pk = pxDriver.addKernelInstance<S2PKernel>(iBuilder);
     176        pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
     177       
     178        wck = pxDriver.addKernelInstance<WordCountKernel>(iBuilder, Binding{iBuilder->getStreamSetTy(8, 1), "u8bit"});
     179        pxDriver.makeKernelCall(wck, {BasisBits}, {});
     180
     181
     182    } else {
     183        wck = pxDriver.addKernelInstance<WordCountKernel>(iBuilder, Binding{iBuilder->getStreamSetTy(1, 8), "u8byte"});
     184        pxDriver.makeKernelCall(wck, {ByteStream}, {});
     185    }
    176186
    177187    pxDriver.generatePipelineIR();
     
    217227                case WordOption: CountWords = true; break;
    218228                case LineOption: CountLines = true; break;
    219                 case CharOption: CountBytes = true; CountChars = false; break;
    220                 case ByteOption: CountChars = true; CountBytes = false; break;
     229                case CharOption: CountChars = true; CountBytes = false; break;
     230                case ByteOption: CountBytes = true; CountChars = false; break;
    221231            }
    222232        }
    223233    }
    224    
     234    if (CountLines) wc_modes += "l";
     235    if (CountWords) wc_modes += "w";
     236    if (CountChars) wc_modes += "m";
     237    if (CountBytes) wc_modes += "c";
     238
    225239    ParabixDriver pxDriver("wc");
    226240    wcPipelineGen(pxDriver);
     
    243257    if (CountBytes) maxCount = TotalBytes;
    244258   
     259   
     260   
    245261    int fieldWidth = std::to_string(maxCount).size() + 1;
    246262    if (fieldWidth < defaultFieldWidth) fieldWidth = defaultFieldWidth;
Note: See TracChangeset for help on using the changeset viewer.