Ignore:
Timestamp:
Aug 16, 2015, 3:55:50 PM (4 years ago)
Author:
cameron
Message:

Embed carry data in compiled LLVM module; eliminate passing of carry data pointers/size

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4722 r4726  
    1414#include <iostream>
    1515#include <llvm/Support/CommandLine.h>
     16#include <llvm/IR/BasicBlock.h>
     17#include <llvm/IR/CallingConv.h>
     18#include <llvm/IR/Function.h>
     19
    1620
    1721static cl::opt<CarryManagerStrategy> Strategy(cl::desc("Choose carry management strategy:"),
     
    3943    }
    4044
    41 unsigned CarryManager::initialize(PabloBlock * pb, Value * carryPtr) {
     45void CarryManager::initialize(Module * m, PabloBlock * pb) {
    4246    mPabloRoot = pb;
     47    unsigned scopeCount = doScopeCount(pb);
     48    mCarryInfoVector.resize(scopeCount);
     49    unsigned totalCarryDataSize = enumerate(pb, 0, 0);
     50   
     51    unsigned totalPackCount = (totalCarryDataSize + mITEMS_PER_PACK - 1)/mITEMS_PER_PACK;
     52
     53    mCarryPackPtr.resize(totalPackCount);
     54    mCarryInPack.resize(totalPackCount);
     55    mCarryOutPack.resize(totalPackCount);
     56    for (auto i = 0; i < totalPackCount; i++) mCarryInPack[i]=nullptr;
     57
    4358    if (Strategy == SequentialFullyPackedStrategy) {
    4459        mPACK_SIZE = 64;
    4560        mITEMS_PER_PACK = 64;
    4661        mCarryPackType = mBuilder->getIntNTy(mPACK_SIZE);
    47         mCarryPackBasePtr = mBuilder->CreateBitCast(carryPtr, Type::getInt64PtrTy(mBuilder->getContext()));
    48         mCarryBitBlockPtr = carryPtr;
    4962        mZeroInitializer = mBuilder->getInt64(0);
    5063        mOneInitializer = mBuilder->getInt64(-1);
    51     }
    52     else { // if Strategy == BitBlockStrategy
     64        mTotalCarryDataBitBlocks = (totalCarryDataSize + BLOCK_SIZE - 1)/BLOCK_SIZE;
     65       
     66    }
     67    else {
    5368        mPACK_SIZE = BLOCK_SIZE;
    5469        mITEMS_PER_PACK = 1;
    5570        mCarryPackType = mBitBlockType;
    56         mCarryPackBasePtr = carryPtr;
    57         mCarryBitBlockPtr = mCarryPackBasePtr;
    58     }
    59     unsigned scopeCount = doScopeCount(pb);
    60     mCarryInfoVector.resize(scopeCount);
    61     unsigned totalCarryDataSize = enumerate(pb, 0, 0);
    62    
    63     unsigned totalPackCount = (totalCarryDataSize + mITEMS_PER_PACK - 1)/mITEMS_PER_PACK;
    64 
    65     mCarryPackPtr.resize(totalPackCount);
    66     mCarryInPack.resize(totalPackCount);
    67     mCarryOutPack.resize(totalPackCount);
    68     for (auto i = 0; i < totalPackCount; i++) mCarryInPack[i]=nullptr;
    69 
    70     if (Strategy == SequentialFullyPackedStrategy) {
    71         mTotalCarryDataBitBlocks = (totalCarryDataSize + BLOCK_SIZE - 1)/BLOCK_SIZE;
    72     }
    73     else {
    7471        mTotalCarryDataBitBlocks = totalCarryDataSize;
    7572    }
     73   
     74    ArrayType* cdArrayTy = ArrayType::get(mBitBlockType, mTotalCarryDataBitBlocks);
     75    GlobalVariable* cdArray = new GlobalVariable(*m, cdArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, /*Initializer=*/0, "process_block_carry_data");
     76    cdArray->setAlignment(BLOCK_SIZE/8);
     77    ConstantAggregateZero* cdInitData = ConstantAggregateZero::get(cdArrayTy);
     78    cdArray->setInitializer(cdInitData);
     79   
     80    mCarryPackBasePtr = mBuilder->CreateBitCast(cdArray, PointerType::get(mCarryPackType, 0));
     81    mCarryBitBlockPtr = mBuilder->CreateBitCast(cdArray, PointerType::get(mBitBlockType, 0));
     82   
    7683    // Popcount data is stored after all the carry data.
    7784    if (mPabloCountCount > 0) {
    78         mPopcountBasePtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(carryPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks)), Type::getInt64PtrTy(mBuilder->getContext()));
    79         mTotalCarryDataBitBlocks += (mPabloCountCount + BLOCK_SIZE/64 - 1) * 64/BLOCK_SIZE;
     85        ArrayType* pcArrayTy = ArrayType::get(mBuilder->getIntNTy(64), mPabloCountCount);
     86        GlobalVariable* pcArray = new GlobalVariable(*m, pcArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "popcount_data");
     87        cdArray->setAlignment(BLOCK_SIZE/8);
     88        ConstantAggregateZero* pcInitData = ConstantAggregateZero::get(pcArrayTy);
     89        pcArray->setInitializer(pcInitData);
     90        mPopcountBasePtr = mBuilder->CreateBitCast(pcArray, Type::getInt64PtrTy(mBuilder->getContext()));
    8091    }
    8192    // Carry Data area will have one extra bit block to store the block number.
    82     mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(carryPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks)), Type::getInt64PtrTy(mBuilder->getContext()));
     93    GlobalVariable* blkNo = new GlobalVariable(*m, mBuilder->getIntNTy(64), /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "blockNo");
     94    blkNo->setAlignment(8);
     95    blkNo->setInitializer(mBuilder->getInt64(0));
     96    mBlockNoPtr = blkNo;
    8397    mBlockNo = mBuilder->CreateLoad(mBlockNoPtr);
    8498    /*  Set the current scope to PabloRoot */
     
    86100    mCurrentFrameIndex = 0;
    87101    mCarryInfo = mCarryInfoVector[0];
    88     return mTotalCarryDataBitBlocks + 1; // One extra element for the block no.
    89102}
    90103   
     
    681694    return mBuilder->CreateBitCast(mBuilder->CreateZExt(countSoFar, mBuilder->getIntNTy(BLOCK_SIZE)), mBitBlockType);
    682695}
    683    
     696
    684697CarryManager::~CarryManager() {
    685698    for (auto * cd : mCarryInfoVector) {
Note: See TracChangeset for help on using the changeset viewer.