Ignore:
Timestamp:
Aug 29, 2016, 1:53:08 PM (3 years ago)
Author:
lindanl
Message:

Add pipeline parallel strategy to the framework.

File:
1 edited

Legend:

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

    r5125 r5135  
    1313using namespace parabix;
    1414
     15enum SS_struct_index {iProducer_pos = 0, iConsumer_pos = 1, iEnd_of_input = 2, iBuffer_ptr = 3};
     16
    1517llvm::Type * StreamSetType::getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder) {
    1618    llvm::Type * streamType = mFieldWidth == 1 ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), mFieldWidth);
     
    2224}
    2325
     26llvm::PointerType * StreamSetBuffer::getStreamSetStructPointerType() {
     27    return PointerType::get(mStreamSetStructType, 0);
     28}
     29
     30llvm::Value * StreamSetBuffer::getProducerPosPtr(Value * ptr) {
     31    return iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)});
     32}
     33
     34void StreamSetBuffer::setProducerPos(Value * ptr, llvm::Value * pos){
     35    iBuilder->CreateStore(pos, iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     36}
     37
     38llvm::Value * StreamSetBuffer::getComsumerPosPtr(Value * ptr) {
     39    return iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)});
     40}
     41
     42void StreamSetBuffer::setConsumerPos(Value * ptr, Value * pos){
     43    iBuilder->CreateStore(pos, iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     44}
     45
     46llvm::Value * StreamSetBuffer::hasEndOfInputPtr(Value * ptr) {
     47    return iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)});
     48}
     49
     50void StreamSetBuffer::setEndOfInput(Value * ptr){
     51    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), 1), iBuilder->CreateGEP(ptr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
     52}
     53
     54llvm::Value * StreamSetBuffer::getStreamSetStructPtr(){
     55    return mStreamSetStructPtr;
     56}
    2457// Single Block Buffer
    2558
     
    2962
    3063llvm::Value * SingleBlockBuffer::allocateBuffer() {
    31     mStreamSetBufferPtr = iBuilder->CreateAlloca(mStreamSetType.getStreamSetBlockType(iBuilder));
     64    Type * const int64ty = iBuilder->getInt64Ty();
     65    Type * const int8ty = iBuilder->getInt8Ty();
     66    mStreamSetStructPtr = iBuilder->CreateAlloca(mStreamSetStructType);
     67    iBuilder->CreateStore(ConstantInt::get(int64ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     68    iBuilder->CreateStore(ConstantInt::get(int64ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     69    iBuilder->CreateStore(ConstantInt::get(int8ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
     70    mStreamSetBufferPtr = iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    3271    return mStreamSetBufferPtr;
    3372}
    3473
    3574// For a single block buffer, the block pointer is always the buffer base pointer.
    36 llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
    37     return bufferBasePtr;
     75llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * basePtr, llvm::Value * blockNo) {
     76    return iBuilder->CreateGEP(mStreamSetType.getStreamSetBlockType(iBuilder), basePtr, {iBuilder->getInt32(0), iBuilder->getInt32(3)});
    3877}
    3978
     
    4685
    4786void ExternalUnboundedBuffer::setStreamSetBuffer(llvm::Value * ptr) {
    48     PointerType * t = PointerType::get(mStreamSetType.getStreamSetBlockType(iBuilder), mAddrSpace);
    49    
     87
     88    Type * const int64ty = iBuilder->getInt64Ty();
     89    Type * const int8ty = iBuilder->getInt8Ty();
     90
     91    PointerType * t = getStreamBufferPointerType();   
    5092    mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, t);
     93
     94    mStreamSetStructPtr = iBuilder->CreateAlloca(mStreamSetStructType);
     95    iBuilder->CreateStore(ConstantInt::get(int64ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     96    iBuilder->CreateStore(ConstantInt::get(int64ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     97    iBuilder->CreateStore(ConstantInt::get(int8ty, 1), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
     98    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
     99
    51100}
    52101
     
    55104}
    56105
    57 llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
     106llvm::Value * ExternalUnboundedBuffer::allocateBuffer() { 
    58107    throw std::runtime_error("External buffers cannot be allocated.");
    59108}
    60109
    61 llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
    62     PointerType * t = getStreamBufferPointerType();
    63     return iBuilder->CreateGEP(iBuilder->CreatePointerBitCastOrAddrSpaceCast(bufferBasePtr, t), {blockNo});
     110llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * basePtr, llvm::Value * blockNo) {
     111    Value * handle = iBuilder->CreateGEP(basePtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     112    return iBuilder->CreateGEP(iBuilder->CreateLoad(handle), {blockNo});
    64113}
    65114
     
    72121
    73122llvm::Value * CircularBuffer::allocateBuffer() {
     123    Type * const int64ty = iBuilder->getInt64Ty();
     124    Type * const int8ty = iBuilder->getInt8Ty();
    74125    mStreamSetBufferPtr = iBuilder->CreateAlloca(mStreamSetType.getStreamSetBlockType(iBuilder), ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
     126    mStreamSetStructPtr = iBuilder->CreateAlloca(mStreamSetStructType);
     127    iBuilder->CreateStore(ConstantInt::get(int64ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     128    iBuilder->CreateStore(ConstantInt::get(int64ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     129    iBuilder->CreateStore(ConstantInt::get(int8ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
     130    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
     131
    75132    return mStreamSetBufferPtr;
    76133}
    77134
    78 llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
    79     return iBuilder->CreateGEP(mStreamSetType.getStreamSetBlockType(iBuilder), bufferBasePtr, {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
     135llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * basePtr, llvm::Value * blockNo) {
     136    Value * handle = iBuilder->CreateGEP(basePtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
     137    return iBuilder->CreateGEP(iBuilder->CreateLoad(handle), {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
    80138}
    81139
Note: See TracChangeset for help on using the changeset viewer.