Ignore:
Timestamp:
May 22, 2017, 12:14:19 PM (2 years ago)
Author:
nmedfort
Message:

Restructuring work for the Driver classes. Start of work to eliminate the memory leaks with the ExecutionEngine?. Replaced custom AlignedMalloc? with backend call to std::aligned_malloc. Salvaged some work on DistributionPass? for reevaluation.

File:
1 edited

Legend:

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

    r5454 r5464  
    160160void ReadSourceKernel::generateInitializeMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    161161    ConstantInt * const bufferSize = iBuilder->getSize(64 * getpagesize());
    162     Value * const buffer = iBuilder->CreateAlignedMalloc(bufferSize, iBuilder->getCacheAlignment());
     162    Value * const buffer = iBuilder->CreateCacheAlignedMalloc(bufferSize);
    163163    iBuilder->setScalarField("buffer", buffer);
    164164    iBuilder->setScalarField("capacity", bufferSize);
     
    179179    assert(iBuilder->getKernel() == this);
    180180
    181     // The ReadSourceKernel begins by checking whether it needs to read another page of data
     181    // Check whether we need to read another page of data
    182182    ConstantInt * const segmentSize = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    183183    Value * bufferedSize = iBuilder->getBufferedSize("sourceBuffer");
     
    203203    inputStream = iBuilder->CreatePointerCast(inputStream, codeUnitPtrTy);
    204204    Value * const originalPtr = iBuilder->CreateGEP(inputStream, produced);
     205
    205206    Value * const buffer = iBuilder->CreatePointerCast(iBuilder->getScalarField("buffer"), codeUnitPtrTy);
    206207    Value * const capacity = iBuilder->getScalarField("capacity");
    207     Value * const canAppend = iBuilder->CreateICmpULT(iBuilder->CreateGEP(originalPtr, pageSize), iBuilder->CreateGEP(buffer, capacity));
     208
     209    Value * L = iBuilder->CreateGEP(originalPtr, pageSize);
     210
     211//    iBuilder->CallPrintInt("L", L);
     212
     213    Value * B = iBuilder->CreateGEP(buffer, capacity);
     214
     215//    iBuilder->CallPrintInt("B", B);
     216
     217    Value * const canAppend = iBuilder->CreateICmpULT(L, B);
    208218    iBuilder->CreateLikelyCondBr(canAppend, readData, waitOnConsumers);
    209219
     
    211221    iBuilder->SetInsertPoint(waitOnConsumers);
    212222    iBuilder->CreateConsumerWait();
     223
    213224    // Then determine how much data has been consumed and how much needs to be copied back, noting
    214225    // that our "unproduced" data must be block aligned.
    215     const auto alignment = iBuilder->getBitBlockWidth() / 8;
    216     Constant * const alignmentMask = ConstantExpr::getNeg(iBuilder->getSize(alignment));
     226    const auto blockAlignment = iBuilder->getBitBlockWidth() / 8;
     227    Constant * const alignmentMask = ConstantExpr::getNot(iBuilder->getSize(blockAlignment - 1));
    217228    Value * const consumed = iBuilder->CreateAnd(iBuilder->getConsumedItemCount("sourceBuffer"), alignmentMask);
    218229    Value * const remaining = iBuilder->CreateSub(bufferedSize, consumed);
    219230    Value * const unconsumedPtr = iBuilder->CreateGEP(inputStream, consumed);
    220231    Value * const consumedMajority = iBuilder->CreateICmpULT(iBuilder->CreateGEP(buffer, remaining), unconsumedPtr);
     232
     233//    iBuilder->CallPrintInt("consumedMajority", consumedMajority);
     234
    221235    BasicBlock * const copyBack = iBuilder->CreateBasicBlock("CopyBack");
    222236    BasicBlock * const expandAndCopyBack = iBuilder->CreateBasicBlock("ExpandAndCopyBack");
     
    227241    iBuilder->SetInsertPoint(copyBack);
    228242    // If so, just copy the data ...
    229     iBuilder->CreateMemCpy(buffer, unconsumedPtr, remaining, alignment);
     243    iBuilder->CreateMemCpy(buffer, unconsumedPtr, remaining, blockAlignment);
    230244    iBuilder->CreateBr(calculateLogicalAddress);
    231245    // Otherwise, allocate a buffer with twice the capacity and copy the unconsumed data back into it
    232246    iBuilder->SetInsertPoint(expandAndCopyBack);
    233247    Value * const expandedCapacity = iBuilder->CreateShl(capacity, 1);
    234     Value * const expandedBuffer = iBuilder->CreateAlignedMalloc(expandedCapacity, iBuilder->getCacheAlignment());
     248    Value * const expandedBuffer = iBuilder->CreateCacheAlignedMalloc(expandedCapacity);
    235249    Value * const expandedPtr = iBuilder->CreatePointerCast(expandedBuffer, codeUnitPtrTy);
    236     iBuilder->CreateMemCpy(expandedPtr, unconsumedPtr, remaining, alignment);
    237     iBuilder->CreateAlignedFree(buffer);
     250    iBuilder->CreateMemCpy(expandedPtr, unconsumedPtr, remaining, blockAlignment);
     251    iBuilder->CreateFree(buffer);
    238252    iBuilder->setScalarField("buffer", expandedBuffer);
    239253    iBuilder->setScalarField("capacity", expandedCapacity);
     
    285299
    286300void ReadSourceKernel::generateFinalizeMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    287     iBuilder->CreateAlignedFree(iBuilder->getScalarField("buffer"));
     301    iBuilder->CreateFree(iBuilder->getScalarField("buffer"));
    288302}
    289303
Note: See TracChangeset for help on using the changeset viewer.