Ignore:
Timestamp:
May 7, 2017, 4:34:48 PM (2 years ago)
Author:
nmedfort
Message:

Continued refactoring work. PabloKernel? now abstract base type with a 'generatePabloMethod' hook to generate Pablo code.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5435 r5436  
    1616#include <pablo/pablo_compiler.h>
    1717#include <pablo/pablo_kernel.h>
    18 #include <IR_Gen/idisa_builder.h>
     18#include <kernels/kernel_builder.h>
    1919#include <IR_Gen/idisa_target.h>
    2020#include <kernels/streamset.h>
     
    158158}
    159159
    160 void buildPatternKernel(PabloKernel * const kernel, const std::vector<std::string> & patterns) {
    161     PabloBuilder entry(kernel->getEntryBlock());
    162 
    163     Var * pat = kernel->getInputStreamVar("pat");
    164 
     160class PatternKernel final: public pablo::PabloKernel {
     161public:
     162    PatternKernel(const std::unique_ptr<kernel::KernelBuilder> & b, const std::vector<std::string> & patterns);
     163    bool isCachable() const override { return true; }
     164protected:
     165    void generatePabloMethod() override;
     166private:
     167    const std::vector<std::string> & mPatterns;
     168};
     169
     170PatternKernel::PatternKernel(const std::unique_ptr<kernel::KernelBuilder> & b, const std::vector<std::string> & patterns)
     171: PabloKernel(b, "editd", {{b->getStreamSetTy(4), "pat"}}, {{b->getStreamSetTy(editDistance + 1), "E"}})
     172, mPatterns(patterns) {
     173}
     174
     175void PatternKernel::generatePabloMethod() {
     176    PabloBuilder entry(getEntryBlock());
     177    Var * const pat = getInputStreamVar("pat");
    165178    PabloAST * basisBits[4];
    166 
    167179    basisBits[0] = entry.createExtract(pat, 0, "A");
    168180    basisBits[1] = entry.createExtract(pat, 1, "C");
    169181    basisBits[2] = entry.createExtract(pat, 2, "T");
    170182    basisBits[3] = entry.createExtract(pat, 3, "G");
    171 
    172     re::Pattern_Compiler pattern_compiler(*kernel);
    173     pattern_compiler.compile(patterns, entry, basisBits, editDistance, optPosition, stepSize);
    174 
    175     pablo_function_passes(kernel);
     183    re::Pattern_Compiler pattern_compiler(*this);
     184    pattern_compiler.compile(mPatterns, entry, basisBits, editDistance, optPosition, stepSize);
    176185}
    177186
     
    217226    auto MatchResults = pxDriver.addBuffer(make_unique<SingleBlockBuffer>(idb, idb->getStreamSetTy(editDistance + 1)));
    218227
    219     auto editdk = pxDriver.addKernelInstance(make_unique<PabloKernel>(
    220         idb, "editd", std::vector<Binding>{{idb->getStreamSetTy(4), "pat"}}, std::vector<Binding>{{idb->getStreamSetTy(editDistance + 1), "E"}}
    221         ));
    222 
    223     editdk->setBuilder(idb.get());
    224     buildPatternKernel(reinterpret_cast<PabloKernel *>(editdk), patterns);
     228    auto editdk = pxDriver.addKernelInstance(make_unique<PatternKernel>(idb, patterns));
     229
    225230    pxDriver.makeKernelCall(editdk, {ChStream}, {MatchResults});
    226231
     
    235240}
    236241
    237 void buildPreprocessKernel(PabloKernel * const kernel) {
    238     assert (kernel->getBuilder());
    239     cc::CC_Compiler ccc(kernel, kernel->getInputStreamVar("basis"));
    240 
     242class PreprocessKernel final: public pablo::PabloKernel {
     243public:
     244    PreprocessKernel(const std::unique_ptr<kernel::KernelBuilder> & b);
     245    bool isCachable() const override { return true; }
     246protected:
     247    void generatePabloMethod() override;
     248};
     249
     250PreprocessKernel::PreprocessKernel(const std::unique_ptr<kernel::KernelBuilder> & b)
     251: PabloKernel(b, "ccc", {{b->getStreamSetTy(8), "basis"}}, {{b->getStreamSetTy(4), "pat"}}) {
     252
     253}
     254
     255void PreprocessKernel::generatePabloMethod() {
     256    cc::CC_Compiler ccc(this, getInputStreamVar("basis"));
    241257    PabloBuilder & pb = ccc.getBuilder();
    242 
    243258    PabloAST * A = ccc.compileCC(re::makeCC(re::makeCC(0x41), re::makeCC(0x61)), pb);
    244259    PabloAST * C = ccc.compileCC(re::makeCC(re::makeCC(0x43), re::makeCC(0x63)), pb);
    245260    PabloAST * T = ccc.compileCC(re::makeCC(re::makeCC(0x54), re::makeCC(0x74)), pb);
    246261    PabloAST * G = ccc.compileCC(re::makeCC(re::makeCC(0x47), re::makeCC(0x67)), pb);
    247 
    248     Var * const pat = kernel->getOutputStreamVar("pat");
    249 
     262    Var * const pat = getOutputStreamVar("pat");
    250263    pb.createAssign(pb.createExtract(pat, 0), A);
    251264    pb.createAssign(pb.createExtract(pat, 1), C);
    252265    pb.createAssign(pb.createExtract(pat, 2), T);
    253266    pb.createAssign(pb.createExtract(pat, 3), G);
    254 
    255     pablo_function_passes(kernel);
    256267}
    257268
     
    260271    auto & iBuilder = pxDriver.getBuilder();
    261272    Module * m = iBuilder->getModule();
    262     Type * mBitBlockType = iBuilder->getBitBlockType();
    263 
    264273
    265274    Type * const voidTy = iBuilder->getVoidTy();
    266275    Type * const int32Ty = iBuilder->getInt32Ty();
    267     Type * const outputType = PointerType::get(ArrayType::get(mBitBlockType, 4), 0);
     276    Type * const outputType = PointerType::get(ArrayType::get(iBuilder->getBitBlockType(), 4), 0);
    268277
    269278    Function * const main = cast<Function>(m->getOrInsertFunction("Main", voidTy, int32Ty, outputType, nullptr));
     
    286295    auto BasisBits = pxDriver.addBuffer(make_unique<SingleBlockBuffer>(iBuilder, iBuilder->getStreamSetTy(8)));
    287296    auto s2pk = pxDriver.addKernelInstance(make_unique<S2PKernel>(iBuilder));
     297
    288298    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    289299
    290300    auto CCResults = pxDriver.addExternalBuffer(make_unique<ExternalBuffer>(iBuilder, iBuilder->getStreamSetTy(4), outputStream));
    291301
    292     auto ccck = pxDriver.addKernelInstance(make_unique<PabloKernel>(
    293         iBuilder, "ccc", std::vector<Binding>{{iBuilder->getStreamSetTy(8), "basis"}}, std::vector<Binding>{{iBuilder->getStreamSetTy(4), "pat"}}
    294     ));
    295 
    296     ccck->setBuilder(iBuilder.get());
    297     buildPreprocessKernel(reinterpret_cast<PabloKernel *>(ccck));
     302    auto ccck = pxDriver.addKernelInstance(make_unique<PreprocessKernel>(iBuilder));
    298303
    299304    pxDriver.makeKernelCall(ccck, {BasisBits}, {CCResults});
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.cpp

    r5435 r5436  
    55
    66#include "editd_cpu_kernel.h"
    7 #include <IR_Gen/idisa_builder.h>
     7#include <kernels/kernel_builder.h>
    88#include <llvm/IR/Module.h>
    99
     
    8484}
    8585
    86 editdCPUKernel::editdCPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen) :
     86editdCPUKernel::editdCPUKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned dist, unsigned pattLen) :
    8787BlockOrientedKernel("editd_cpu",
    8888             {Binding{b->getStreamSetTy(4), "CCStream"}},
  • icGREP/icgrep-devel/icgrep/editd/editd_cpu_kernel.h

    r5435 r5436  
    1717public:
    1818
    19     editdCPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen);
     19    editdCPUKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned dist, unsigned pattLen);
    2020   
    2121
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.cpp

    r5435 r5436  
    44 */
    55#include "editd_gpu_kernel.h"
    6 #include <IR_Gen/idisa_builder.h>
     6#include <kernels/kernel_builder.h>
    77#include <llvm/IR/Module.h>
    88
     
    8080}
    8181
    82 editdGPUKernel::editdGPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen) :
     82editdGPUKernel::editdGPUKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned dist, unsigned pattLen) :
    8383BlockOrientedKernel("editd_gpu",
    8484              {Binding{b->getStreamSetTy(4), "CCStream"}},
  • icGREP/icgrep-devel/icgrep/editd/editd_gpu_kernel.h

    r5435 r5436  
    1717public:
    1818   
    19     editdGPUKernel(const std::unique_ptr<IDISA::IDISA_Builder> & b, unsigned dist, unsigned pattLen);
     19    editdGPUKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned dist, unsigned pattLen);
    2020   
    2121   
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5435 r5436  
    66
    77#include "editdscan_kernel.h"
    8 #include <IR_Gen/idisa_builder.h>
     8#include <kernels/kernel_builder.h>
    99#include <llvm/IR/Module.h>
    1010
     
    8787}
    8888
    89 editdScanKernel::editdScanKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned dist) :
     89editdScanKernel::editdScanKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned dist) :
    9090BlockOrientedKernel("scanMatch",
    9191              {Binding{iBuilder->getStreamSetTy(dist + 1), "matchResults"}},
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.h

    r5435 r5436  
    1515class editdScanKernel : public BlockOrientedKernel {
    1616public:
    17     editdScanKernel(const std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, unsigned dist);
     17    editdScanKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned dist);
    1818       
    1919private:
Note: See TracChangeset for help on using the changeset viewer.