Ignore:
Timestamp:
Dec 4, 2018, 1:48:37 PM (6 months ago)
Author:
cameron
Message:

Abort on null: DirectCharacterClassKernel?, on by default

File:
1 edited

Legend:

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

    r6184 r6216  
    1919
    2020DirectCharacterClassKernelBuilder::DirectCharacterClassKernelBuilder(
    21         const std::unique_ptr<kernel::KernelBuilder> & b, std::string ccSetName, std::vector<re::CC *> charClasses, StreamSet * byteStream, StreamSet * ccStream)
    22 : PabloKernel(b, ccSetName +"_direct",
     21        const std::unique_ptr<kernel::KernelBuilder> & b, std::string ccSetName, std::vector<re::CC *> charClasses, StreamSet * byteStream, StreamSet * ccStream, Scalar * signalNullObject)
     22: PabloKernel(b, ccSetName + (signalNullObject ? "_direct_abort_on_null" : "_direct"),
    2323// input
    2424{Binding{"byteStream", byteStream}},
    2525// output
    26 {Binding{"ccStream", ccStream}})
    27 , mCharClasses(std::move(charClasses)) {
     26{Binding{"ccStream", ccStream}},
     27makeInputScalarBindings(signalNullObject),
     28{}), mCharClasses(std::move(charClasses)), mAbortOnNull(signalNullObject != nullptr) {
    2829    if (LLVM_UNLIKELY(ccStream->getNumElements() != mCharClasses.size())) {
    2930        report_fatal_error("cc streamset must have " + std::to_string(mCharClasses.size()) + " streams");
     31    }
     32    if (mAbortOnNull) {
     33        addAttribute(CanTerminateEarly());
     34    }
     35}
     36
     37Bindings DirectCharacterClassKernelBuilder::makeInputScalarBindings(Scalar * signalNullObject) {
     38    if (signalNullObject) {
     39        return {Binding{"handler_address", signalNullObject}};
     40    } else {
     41        return {};
    3042    }
    3143}
     
    3547    cc::Direct_CC_Compiler ccc(getEntryScope(), getInputStreamSet("byteStream")[0]);
    3648    Var * outputVar = getOutputStreamVar("ccStream");
     49    PabloAST * nonNull = nullptr;
     50    if (mAbortOnNull) {
     51        PabloAST * nullCC = pb.createTerminateAt(ccc.compileCC(makeCC(0, &cc::Byte)), pb.getInteger(0));
     52        nonNull = pb.createNot(nullCC);
     53    }
    3754    for (unsigned i = 0; i < mCharClasses.size(); ++i) {
    38         pb.createAssign(pb.createExtract(outputVar, i), ccc.compileCC(mCharClasses[i]));
     55        PabloAST * cc = ccc.compileCC(mCharClasses[i]);
     56        if (mAbortOnNull) {
     57            cc = pb.createAnd(nonNull, cc);
     58        }
     59        pb.createAssign(pb.createExtract(outputVar, i), cc);
    3960    }
    4061}
Note: See TracChangeset for help on using the changeset viewer.