Ignore:
Timestamp:
Mar 11, 2016, 4:44:53 PM (3 years ago)
Author:
nmedfort
Message:

Added ability to name internal state types; removed unnecessary predefined states. Some progress towards supporting segment size > 1

File:
1 edited

Legend:

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

    r4968 r4970  
    2828    const unsigned totalCarryDataSize = std::max<unsigned>(enumerate(mRootScope, 0, 0), 1);
    2929    mCarryPackPtr.resize(totalCarryDataSize, nullptr);
    30     mCarryInPack.resize(totalCarryDataSize, nullptr);
     30    mCarryInPack.resize(totalCarryDataSize);
    3131    mCarryOutPack.resize(totalCarryDataSize, nullptr);
    3232    mTotalCarryDataBitBlocks = totalCarryDataSize;
    3333    ArrayType* cdArrayTy = ArrayType::get(mBitBlockType, mTotalCarryDataBitBlocks);
    34     mCdArrayIdx = kBuilder->addInternalStateType(cdArrayTy);
     34    mCdArrayIdx = kBuilder->addInternalState(cdArrayTy);
    3535    if (mPabloCountCount > 0) {
    3636        ArrayType* pcArrayTy = ArrayType::get(iBuilder->getIntNTy(64), mPabloCountCount);
    37         mPcArrayIdx = kBuilder->addInternalStateType(pcArrayTy);
     37        mPcArrayIdx = kBuilder->addInternalState(pcArrayTy);
     38    }
     39    mKernelBuilder = kBuilder;
     40}
     41
     42/** ------------------------------------------------------------------------------------------------------------- *
     43 * @brief reset
     44 ** ------------------------------------------------------------------------------------------------------------- */
     45void CarryManager::reset() {
     46    Value * cdArrayPtr = mKernelBuilder->getInternalState(mCdArrayIdx);
     47    mCarryPackBasePtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mCarryPackType, 0));
     48    mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mBitBlockType, 0));
     49    if (mPabloCountCount > 0) {
     50        Value * pcArrayPtr = mKernelBuilder->getInternalState(mPcArrayIdx);
     51        mPopcountBasePtr = iBuilder->CreateBitCast(pcArrayPtr, Type::getInt64PtrTy(iBuilder->getContext()));
    3852    }
    3953    mCurrentScope = mRootScope;
     
    4155    mCarryInfo = mCarryInfoVector[0];
    4256    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
    43 }
    44 
    45 /** ------------------------------------------------------------------------------------------------------------- *
    46  * @brief initialize_setPtrs
    47  ** ------------------------------------------------------------------------------------------------------------- */
    48 void CarryManager::initialize_setPtrs(KernelBuilder * kBuilder) {
    49     Value * cdArrayPtr = kBuilder->getInternalState(mCdArrayIdx);
    50     mCarryPackBasePtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mCarryPackType, 0));
    51     mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mBitBlockType, 0));
    52     if (mPabloCountCount > 0) {
    53         Value * pcArrayPtr = kBuilder->getInternalState(mPcArrayIdx);
    54         mPopcountBasePtr = iBuilder->CreateBitCast(pcArrayPtr, Type::getInt64PtrTy(iBuilder->getContext()));
    55     }
    56     setBlockNo(kBuilder);
    57     mCurrentScope = mRootScope;
    58     mCurrentFrameIndex = 0;
    59     mCarryInfo = mCarryInfoVector[0];
    60     mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
    61 }
    62 
    63 /** ------------------------------------------------------------------------------------------------------------- *
    64  * @brief setBlockNo
    65  ** ------------------------------------------------------------------------------------------------------------- */
    66 void CarryManager::setBlockNo(KernelBuilder * kBuilder) {
    67     mBlockNo = iBuilder->CreateUDiv(iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(mFilePosIdx)), iBuilder->getInt64(mBitBlockWidth));
     57    assert (mCarrySummary.empty());
     58    std::fill(mCarryInPack.begin(), mCarryInPack.end(), nullptr);
    6859}
    6960
     
    205196    const unsigned bufsize = mCarryInfo->longAdvanceBufferSize(shiftAmount);
    206197    Value * indexMask = iBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
    207     Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(mBlockNo, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
    208     Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(mBlockNo, indexMask), advBaseIndex);
     198    Value * blockIndex = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getBlockIndexScalar());
     199    Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(blockIndex, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
     200    Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(blockIndex, indexMask), advBaseIndex);
    209201    Value * carry_block0 = iBuilder->CreateBlockAlignedLoad(iBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex0));
    210202    // If the long advance is an exact multiple of mBITBLOCK_WIDTH, we simply return the oldest
     
    215207    }
    216208    // Otherwise we need to combine data from the two oldest blocks.
    217     Value * loadIndex1 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(mBlockNo, iBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
     209    Value * loadIndex1 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(blockIndex, iBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
    218210    Value * carry_block1 = iBuilder->CreateBlockAlignedLoad(iBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex1));
    219211    Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carry_block0, iBuilder->getIntNTy(mBitBlockWidth)), mBitBlockWidth - block_shift);
Note: See TracChangeset for help on using the changeset viewer.