Ignore:
Timestamp:
Jan 14, 2017, 3:49:56 PM (3 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/radix64.cpp

    r5247 r5260  
    77#include <kernels/kernel.h>
    88#include <IR_Gen/idisa_builder.h>
     9#include <llvm/IR/Module.h>
    910#include <llvm/Support/raw_ostream.h>
    1011
     12using namespace llvm;
     13
    1114namespace kernel {
    12 using namespace llvm;
    1315
    1416// This kernel produces an expanded input stream by duplicating every third byte.
     
    8688    Constant * packSize = iBuilder->getSize(PACK_SIZE);
    8789    Constant * loopItemCount = iBuilder->getSize(3 * PACK_SIZE); // 3 packs per loop.
    88     UndefValue * undefPack = UndefValue::get(iBuilder->fwVectorType(parabix::i8));
     90    UndefValue * undefPack = UndefValue::get(iBuilder->fwVectorType(8));
    8991   
    9092    const unsigned packAlign = iBuilder->getBitBlockWidth()/8;
     
    114116    Value * blockNo = getScalarField(self, blockNoScalar);
    115117
    116     Value * sourceBlockPtr = getStreamSetBlockPtr(self, "sourceStream", blockNo);
     118    // A block is made up of 8 packs.  Get the pointer to the first pack (changes the type of the pointer only).
     119    Value * sourcePackPtr = getStream(self, "sourceStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
    117120
    118121    Value * outputGenerated = getProducedItemCount(self, "expandedStream"); // bytes previously generated to output
    119122    Value * outputBlockNo = iBuilder->CreateUDiv(outputGenerated, stride);
    120 
    121     Value * outputBlockPtr = getStreamSetBlockPtr(self, "expandedStream", outputBlockNo);
    122 
    123     // A block is made up of 8 packs.  Get the pointer to the first pack (changes the type of the pointer only).
    124     Value * sourcePackPtr = iBuilder->CreateGEP(sourceBlockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(0)});
    125     Value * outputPackPtr = iBuilder->CreateGEP(outputBlockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(0)});
     123    Value * outputPackPtr = getStream(self, "expandedStream", outputBlockNo, iBuilder->getInt32(0), iBuilder->getInt32(0));
     124
    126125    Value * hasFullLoop = iBuilder->CreateICmpUGE(itemsToDo, loopItemCount);
    127126
     
    307306//    xwvuts|  nlkjzy|  barqpm|  hgfedc    Target
    308307void radix64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    309     Value * expandedStream = getStreamSetBlockPtr(self, "expandedStream", blockNo);
    310     Value * radix64stream = getStreamSetBlockPtr(self, "radix64stream",blockNo);
    311308
    312309    Value * step_right_6 = iBuilder->simd_fill(32, ConstantInt::get(iBuilder->getInt32Ty(), 0x00C00000));
     
    318315   
    319316    for (unsigned i = 0; i < 8; i++) {
    320         Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStream, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     317        Value * expandedStream = getStream(self, "expandedStream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     318        Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStream);
    321319
    322320        Value * right_6_result = iBuilder->simd_srli(32, iBuilder->simd_and(bytepack, step_right_6), 6);
     
    335333        Value * radix64pack = iBuilder->bitCast(mid);
    336334
    337         iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     335        Value * radix64stream = getStream(self, "radix64stream",blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     336        iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream);
    338337    }
    339338    Value * produced = getProducedItemCount(self, "radix64stream");
     
    363362    Constant * packSize = iBuilder->getSize(PACK_SIZE);
    364363    Value * blockNo = getScalarField(self, blockNoScalar);
    365     Value * expandedstream_ptr = getStreamSetBlockPtr(self, "expandedStream", blockNo);
    366     Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    367364
    368365    Value * step_right_6 = iBuilder->simd_fill(32, iBuilder->getInt32(0x00C00000));
     
    383380    loopRemain->addIncoming(remainingBytes, radix64_fb_entry);
    384381
    385     Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedstream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     382    Value * expandedStreamLoopPtr = getStream(self, "expandedStream", blockNo, iBuilder->getInt32(0), idx);
     383    Value * bytepack = iBuilder->CreateBlockAlignedLoad(expandedStreamLoopPtr);
    386384    Value * right_6_result = iBuilder->simd_srli(32, iBuilder->simd_and(bytepack, step_right_6), 6);
    387385    Value * right_4_result = iBuilder->simd_srli(32, iBuilder->simd_and(bytepack, step_right_4), 4);
     
    399397    Value * radix64pack = iBuilder->bitCast(mid);
    400398
    401     iBuilder->CreateBlockAlignedStore(radix64pack, radix64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     399    Value * radix64streamPtr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), idx);
     400    iBuilder->CreateBlockAlignedStore(radix64pack, radix64streamPtr);
    402401
    403402    Value* nextIdx = iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1));
     
    414413    iBuilder->SetInsertPoint(handleRemainFirstByte);
    415414    // At least one padding byte required.
    416 
    417     Value * i8output_ptr = iBuilder->CreatePointerCast(radix64stream_ptr, iBuilder->getInt8PtrTy());
    418     Value * i8input_ptr = iBuilder->CreatePointerCast(expandedstream_ptr, iBuilder->getInt8PtrTy());
     415    Value * i8input_ptr = getStreamView(iBuilder->getInt8PtrTy(), self, "expandedStream", blockNo, iBuilder->getInt32(0));
    419416    Value * remainOutputStart = iBuilder->CreateSub(remainingBytes, remainMod4);
    420417
    421     Value * firstRemainByte = iBuilder->CreateLoad(iBuilder->CreateGEP(i8input_ptr, iBuilder->getInt32(0)));
     418    Value * firstRemainByte = iBuilder->CreateLoad(i8input_ptr);
    422419
    423420    Value * first_move_right_2_mask = ConstantInt::get(iBuilder->getInt8Ty(), 0xFC);
     
    427424    Value * first_move_left_4_byte = iBuilder->CreateShl(iBuilder->CreateAnd(firstRemainByte, first_move_left_4_mask), 4);
    428425
    429     iBuilder->CreateStore(first_output_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(0))));
    430 
     426
     427    Value * i8OutPtr0 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, remainOutputStart);
     428
     429    iBuilder->CreateStore(first_output_byte, i8OutPtr0);
    431430
    432431    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(1)), handleNoRemainSecondByte, handleRemainSecondByte);
     
    437436    Value * second_move_right_4_byte = iBuilder->CreateLShr(iBuilder->CreateAnd(secondRemainByte, second_move_right_4_mask), 4);
    438437    Value * second_output_byte = iBuilder->CreateOr(first_move_left_4_byte, second_move_right_4_byte);
    439     iBuilder->CreateStore(second_output_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1))));
     438
     439    Value * i8OutPtr1 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1)));
     440
     441    iBuilder->CreateStore(second_output_byte, i8OutPtr1);
    440442
    441443    Value * second_move_left_2_mask = ConstantInt::get(iBuilder->getInt8Ty(), 0x0F);
    442444    Value * second_move_left_2_byte = iBuilder->CreateShl(iBuilder->CreateAnd(secondRemainByte, second_move_left_2_mask), 2);
    443     iBuilder->CreateStore(second_move_left_2_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(2))));
     445
     446    Value * i8OutPtr2 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(2)));
     447
     448    iBuilder->CreateStore(second_move_left_2_byte, i8OutPtr2);
    444449    iBuilder->CreateBr(fbExit);
    445450
    446451    iBuilder->SetInsertPoint(handleNoRemainSecondByte);
    447     iBuilder->CreateStore(first_move_left_4_byte, iBuilder->CreateGEP(i8output_ptr, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1))));
     452
     453    i8OutPtr1 = getStreamView(iBuilder->getInt8PtrTy(), self, "radix64stream", blockNo, iBuilder->CreateAdd(remainOutputStart, iBuilder->getInt64(1)));
     454
     455    iBuilder->CreateStore(first_move_left_4_byte, i8OutPtr1);
    448456    iBuilder->CreateBr(fbExit);
    449457
     
    474482
    475483
    476 void base64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {
    477     Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    478     Value * base64stream_ptr = getStreamSetBlockPtr(self, "base64stream", blockNo);   
     484void base64Kernel::generateDoBlockLogic(Value * self, Value * blockNo) const {       
    479485    for (unsigned i = 0; i < 8; i++) {
    480         Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     486        Value * radix64stream_ptr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     487        Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr);
    481488        Value * mask_gt_25 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(25)));
    482489        Value * mask_gt_51 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(51)));
     
    494501        Value * t0_62 = iBuilder->simd_sub(8, t0_61, iBuilder->simd_and(mask_eq_62, iBuilder->simd_fill(8, iBuilder->getInt8(15))));
    495502        Value * base64pack = iBuilder->simd_sub(8, t0_62, iBuilder->simd_and(mask_eq_63, iBuilder->simd_fill(8, iBuilder->getInt8(2))));
    496         iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i)});
     503        Value * base64stream_ptr = getStream(self, "base64stream", blockNo, iBuilder->getInt32(0), iBuilder->getInt32(i));
     504        iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr);
    497505    }
    498506    Value * produced = getProducedItemCount(self, "base64stream");
     
    526534    Constant * packSize = iBuilder->getSize(iBuilder->getStride() / 8);
    527535    Value * blockNo = getScalarField(self, blockNoScalar);
    528     Value * radix64stream_ptr = getStreamSetBlockPtr(self, "radix64stream", blockNo);
    529     Value * base64stream_ptr = getStreamSetBlockPtr(self, "base64stream", blockNo);
    530    
     536
    531537    // Enter the loop only if there is at least one byte remaining to process.
    532538    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0)), fbExit, base64_loop);
     
    537543    idx->addIncoming(ConstantInt::getNullValue(iBuilder->getInt32Ty()), base64_fb_entry);
    538544    loopRemain->addIncoming(remainingBytes, base64_fb_entry);
    539     Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     545    Value * radix64streamPtr = getStream(self, "radix64stream", blockNo, iBuilder->getInt32(0), idx);
     546    Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64streamPtr);
    540547    Value * mask_gt_25 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(25)));
    541548    Value * mask_gt_51 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(51)));
     
    547554    Value * t0_62 = iBuilder->simd_sub(8, t0_61, iBuilder->simd_and(mask_eq_62, iBuilder->simd_fill(8, iBuilder->getInt8(15))));
    548555    Value * base64pack = iBuilder->simd_sub(8, t0_62, iBuilder->simd_and(mask_eq_63, iBuilder->simd_fill(8, iBuilder->getInt8(2))));
    549     iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64stream_ptr, {iBuilder->getInt32(0), iBuilder->getInt32(0), idx});
     556    Value * base64streamPtr = getStream(self, "base64stream", blockNo, iBuilder->getInt32(0), idx);
     557    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64streamPtr);
    550558    idx->addIncoming(iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1)), base64_loop);
    551559    Value* remainAfterLoop = iBuilder->CreateSub(loopRemain, packSize);
     
    557565    iBuilder->SetInsertPoint(loopExit);
    558566    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(padBytes, iBuilder->getSize(0)), fbExit, doPadding);
     567
    559568    iBuilder->SetInsertPoint(doPadding);
    560     Value * i8output_ptr = iBuilder->CreatePointerCast(base64stream_ptr, iBuilder->getInt8PtrTy());
     569    Value * i8output_ptr = getStreamView(iBuilder->getInt8PtrTy(), self, "base64stream", blockNo, iBuilder->getInt32(0));
    561570    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), '='), iBuilder->CreateGEP(i8output_ptr, remainingBytes));
    562571    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(3)), fbExit, doPadding2);
Note: See TracChangeset for help on using the changeset viewer.