Ignore:
Timestamp:
Jan 14, 2017, 3:49:56 PM (2 years ago)
Author:
nmedfort
Message:

Changes working towards simplifying accessing stream elements + some modifications to simplify include / forward declarations within the CodeGen? library.

File:
1 edited

Legend:

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

    r5247 r5260  
    44 */
    55
    6 #include <kernels/kernel.h>
    7 #include <kernels/deletion.h>
     6#include "deletion.h"
    87#include <IR_Gen/idisa_builder.h>
    98#include <llvm/IR/Value.h>
     9#include <llvm/IR/Module.h>
    1010
    11 std::vector<Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * iBuilder, unsigned fw, Value * del_mask) {
     11using namespace llvm;
     12
     13namespace kernel {
     14
     15inline std::vector<Value *> parallel_prefix_deletion_masks(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * del_mask) {
    1216    Value * m = iBuilder->simd_not(del_mask);
    1317    Value * mk = iBuilder->simd_slli(fw, del_mask, 1);
     
    2630}
    2731
    28 Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * iBuilder, unsigned fw, Value * del_mask, std::vector<Value *> mv, Value * strm) {
     32inline Value * apply_parallel_prefix_deletion(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * del_mask, const std::vector<Value *> & mv, Value * strm) {
    2933    Value * s = iBuilder->simd_and(strm, iBuilder->simd_not(del_mask));
    3034    for (unsigned i = 0; i < mv.size(); i++) {
     
    3640}
    3741
    38 Value * partial_sum_popcount(IDISA::IDISA_Builder * iBuilder, unsigned fw, Value * mask) {
    39     Value * per_field = iBuilder->simd_popcount(fw, mask);
    40     for (unsigned move = 1; move < iBuilder->getBitBlockWidth()/fw; move *= 2) {
    41         per_field = iBuilder->simd_add(fw, per_field, iBuilder->mvmd_slli(fw, per_field, move));
     42inline Value * partial_sum_popcount(IDISA::IDISA_Builder * iBuilder, const unsigned fw, Value * mask) {
     43    Value * field = iBuilder->simd_popcount(fw, mask);
     44    const auto count = iBuilder->getBitBlockWidth() / fw;
     45    for (unsigned move = 1; move < count; move *= 2) {
     46        field = iBuilder->simd_add(fw, field, iBuilder->mvmd_slli(fw, field, move));
    4247    }
    43     return per_field;
     48    return field;
    4449}
    4550
     
    4853// Outputs: the deleted streams, plus a partial sum popcount
    4954
    50 namespace kernel {
     55void DeletionKernel::generateDoBlockMethod() const {
    5156
    52 void DeletionKernel::generateDoBlockMethod() const {
    5357    auto savePoint = iBuilder->saveIP();
    5458    Module * m = iBuilder->getModule();
     
    6266    Value * blockNo = getScalarField(self, blockNoScalar);
    6367
    64     Value * inputStreamPtr = getStreamSetBlockPtr(self, "inputStreamSet", blockNo);
    65 
    66     Value * delMaskPtr = getStreamSetBlockPtr(self, "delMaskSet", blockNo);
    67 
    68     Value * outputStreamPtr = getStreamSetBlockPtr(self, "outputStreamSet", blockNo);
    69 
    70     Value * delCountPtr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
    71 
    72     Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     68    Value * delMaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
     69    Value * delMask = iBuilder->CreateBlockAlignedLoad(delMaskPtr);
    7370
    7471    std::vector<Value *> move_masks = parallel_prefix_deletion_masks(iBuilder, mDeletionFieldWidth, delMask);
    7572
    7673    for (unsigned j = 0; j < mStreamCount; ++j) {
    77         Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     74        Value * inputStreamPtr = getStream(self, "inputStreamSet", blockNo, iBuilder->getInt32(j));
     75        Value * input = iBuilder->CreateBlockAlignedLoad(inputStreamPtr);
     76
    7877        Value * output = apply_parallel_prefix_deletion(iBuilder, mDeletionFieldWidth, delMask, move_masks, input);
    79         iBuilder->CreateBlockAlignedStore(output, outputStreamPtr, {iBuilder->getInt32(0), iBuilder->getInt32(j)});
     78
     79        Value * outputStreamPtr = getStream(self, "outputStreamSet", blockNo, iBuilder->getInt32(j));
     80        iBuilder->CreateBlockAlignedStore(output, outputStreamPtr);
    8081    }
    81     Value * counts = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(delMask));
    82     iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(counts), delCountPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     82    Value * delCount = partial_sum_popcount(iBuilder, mDeletionFieldWidth, iBuilder->simd_not(delMask));
     83    Value * delCountPtr = getStream(self, "deletionCounts", blockNo, iBuilder->getInt32(0));
     84    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(delCount), delCountPtr);
    8385    /* Stream deletion has only been applied within fields; the actual number of data items
    8486     * has not yet changed.   */
     
    103105    Value * self = getParameter(finalBlockFunction, "self");
    104106    Value * blockNo = getScalarField(self, blockNoScalar);
    105     Value * delMaskBlock = getStreamSetBlockPtr(self, "delMaskSet", blockNo);
    106107    Value * remaining = iBuilder->CreateZExt(remainingBytes, iBuilder->getIntNTy(blockSize));
    107108    Value * EOF_del = iBuilder->bitCast(iBuilder->CreateShl(Constant::getAllOnesValue(iBuilder->getIntNTy(blockSize)), remaining));
    108     Value * const delmaskPtr = iBuilder->CreateGEP(delMaskBlock, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     109    Value * const delmaskPtr = getStream(self, "delMaskSet", blockNo, iBuilder->getInt32(0));
    109110    Value * const delmaskVal = iBuilder->CreateBlockAlignedLoad(delmaskPtr);
    110111    iBuilder->CreateBlockAlignedStore(iBuilder->CreateOr(EOF_del, delmaskVal), delmaskPtr);
     
    121122}
    122123
     124DeletionKernel::DeletionKernel(IDISA::IDISA_Builder * iBuilder, unsigned fw, unsigned streamCount) :
     125KernelBuilder(iBuilder, "del",
     126              {Binding{iBuilder->getStreamSetTy(streamCount), "inputStreamSet"},
     127               Binding{iBuilder->getStreamSetTy(), "delMaskSet"}},
     128              {Binding{iBuilder->getStreamSetTy(streamCount), "outputStreamSet"},
     129               Binding{iBuilder->getStreamSetTy(), "deletionCounts"}},
     130              {}, {}, {}),
     131mDeletionFieldWidth(fw),
     132mStreamCount(streamCount) {
     133
    123134}
     135
     136}
Note: See TracChangeset for help on using the changeset viewer.