Ignore:
Timestamp:
Dec 15, 2018, 3:43:59 PM (4 months ago)
Author:
nmedfort
Message:

Re-enabled segment pipeline parallelism; moved logical segment number into pipeline kernel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/pipeline/pipeline_logic.hpp

    r6233 r6237  
    1010 ** ------------------------------------------------------------------------------------------------------------- */
    1111void PipelineCompiler::generateSingleThreadKernelMethod(BuilderRef b) {
    12     Value * const localState = allocateThreadLocalSpace(b);
     12    StructType * const localStateType = getLocalStateType(b);
     13    Value * const localState = allocateThreadLocalSpace(b, localStateType);
    1314    setThreadLocalSpace(b, localState);
    1415    start(b, b->getSize(0));
     
    2021    deallocateThreadLocalSpace(b, localState);
    2122}
     23
     24
    2225
    2326/** ------------------------------------------------------------------------------------------------------------- *
     
    3437    assert (numOfThreads > 1);
    3538
     39
    3640    Module * const m = b->getModule();
    3741    IntegerType * const sizeTy = b->getSizeTy();
     
    4246    ConstantInt * const TWO = b->getInt32(2);
    4347
    44     // store where we'll resume compiling the DoSegment method
    45     const auto resumePoint = b->saveIP();
    4648    Value * const handle = mPipelineKernel->getHandle(); assert (handle);
    47     StructType * const threadStructType = StructType::get(m->getContext(), {handle->getType(), sizeTy, voidPtrTy});
    48     FunctionType * const threadFuncType = FunctionType::get(voidPtrTy, {voidPtrTy}, false);
     49    StructType * const localStateTy = getLocalStateType(b);
     50    PointerType * const localStatePtrTy = localStateTy->getPointerTo();
     51    StructType * const threadStructType = StructType::get(m->getContext(), {handle->getType(), sizeTy, localStatePtrTy});
     52    FunctionType * const threadFuncType = FunctionType::get(b->getVoidTy(), {voidPtrTy}, false);
    4953
    5054    const auto threadName = mPipelineKernel->getName() + "_DoSegmentThread";
     
    5357    auto args = threadFunc->arg_begin();
    5458    args->setName("kernelStateObject");
     59
     60    // store where we'll resume compiling the DoSegment method
     61    const auto resumePoint = b->saveIP();
    5562
    5663    // -------------------------------------------------------------------------------------------------------------------------
     
    6875        synchronize(b);
    6976        executeKernel(b);
     77        releaseCurrentSegment(b);
    7078    }
    7179    mKernel = nullptr;
     
    8189    b->CreateBr(exitFunction);
    8290    b->SetInsertPoint(exitFunction);
    83     b->CreateRet(nullVoidPtrVal);
     91    b->CreateRetVoid();
    8492
    8593    // -------------------------------------------------------------------------------------------------------------------------
    86     // MAKE PIPELINE DRIVER
     94    // MAKE PIPELINE DRIVER CONTINUED
    8795    // -------------------------------------------------------------------------------------------------------------------------
    8896    b->restoreIP(resumePoint);
     
    95103        threadIdPtr[i] = b->CreateGEP(pthreads, {ZERO, b->getInt32(i)});
    96104    }
     105
    97106    // use the process thread to handle the initial segment function after spawning
    98107    // (n - 1) threads to handle the subsequent offsets
    99     Value * localState[threads];
     108    std::vector<Value *> localState(numOfThreads);
    100109    for (unsigned i = 0; i < threads; ++i) {
    101110        AllocaInst * const threadState = b->CreateAlloca(threadStructType);
    102111        b->CreateStore(handle, b->CreateGEP(threadState, {ZERO, ZERO}));
    103112        b->CreateStore(b->getSize(i + 1), b->CreateGEP(threadState, {ZERO, ONE}));
    104         localState[i] = allocateThreadLocalSpace(b);
     113        localState[i] = allocateThreadLocalSpace(b, localStateTy);
    105114        b->CreateStore(localState[i], b->CreateGEP(threadState, {ZERO, TWO}));
    106115        b->CreatePThreadCreateCall(threadIdPtr[i], nullVoidPtrVal, threadFunc, threadState);
     
    119128    }
    120129
    121 
    122130}
    123131
     
    126134};
    127135
     136/** ------------------------------------------------------------------------------------------------------------- *
     137 * @brief getLocalStateType
     138 ** ------------------------------------------------------------------------------------------------------------- */
     139inline StructType * PipelineCompiler::getLocalStateType(BuilderRef b) {
     140    StructType * const popCountTy = getPopCountThreadLocalStateType(b);
     141    return StructType::get(popCountTy, nullptr);
     142}
    128143
    129144/** ------------------------------------------------------------------------------------------------------------- *
    130145 * @brief allocateThreadLocalSpace
    131146 ** ------------------------------------------------------------------------------------------------------------- */
    132 inline Value * PipelineCompiler::allocateThreadLocalSpace(BuilderRef b) {
    133     // malloc the local state object
    134     StructType * const popCountTy = getPopCountThreadLocalStateType(b);
    135     StructType * const localStateTy = StructType::get(popCountTy, nullptr);
    136     Value * const localState = b->CreateCacheAlignedAlloca(localStateTy);
    137     // and any pop count refs
     147inline Value * PipelineCompiler::allocateThreadLocalSpace(BuilderRef b, StructType * localStateType) {
     148    Value * const localState = b->CreateCacheAlignedAlloca(localStateType);
    138149    Constant * const ZERO = b->getInt32(0);
    139150    Constant * const POP_COUNT_STRUCT = b->getInt32(POP_COUNT_STRUCT_INDEX);
Note: See TracChangeset for help on using the changeset viewer.