Ignore:
Timestamp:
May 31, 2017, 4:25:33 PM (2 years ago)
Author:
nmedfort
Message:

Initial attempt to improve debugging capabilities with compilation stack traces on error.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

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

    r5479 r5486  
    656656    const unsigned totalSetCount = inputSetCount + outputSetCount;
    657657    bool isDerived[totalSetCount];
    658     int itemsPerPrincipalBlock[totalSetCount];
     658    unsigned itemsPerPrincipalBlock[totalSetCount];
    659659   
    660660    for (unsigned i = 0; i < inputSetCount; i++) {
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5479 r5486  
    3333
    3434Value * StreamSetBuffer::getStreamBlockPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
    35     iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(iBuilder, self)), "StreamSetBuffer: out-of-bounds stream access");
     35    if (codegen::EnableAsserts) {
     36        Value * const count = getStreamSetCount(iBuilder, self);
     37        Value * const index = iBuilder->CreateZExtOrTrunc(streamIndex, count->getType());
     38        Value * const cond = iBuilder->CreateICmpULT(index, count);
     39        iBuilder->CreateAssert(cond, "StreamSetBuffer: out-of-bounds stream access");
     40    }
    3641    return iBuilder->CreateGEP(getStreamSetBlockPtr(iBuilder, self, blockIndex), {iBuilder->getInt32(0), streamIndex});
    3742}
    3843
    3944Value * StreamSetBuffer::getStreamPackPtr(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
    40     iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(iBuilder, self)), "StreamSetBuffer: out-of-bounds stream access");
     45    if (codegen::EnableAsserts) {
     46        Value * const count = getStreamSetCount(iBuilder, self);
     47        Value * const index = iBuilder->CreateZExtOrTrunc(streamIndex, count->getType());
     48        Value * const cond = iBuilder->CreateICmpULT(index, count);
     49        iBuilder->CreateAssert(cond, "StreamSetBuffer: out-of-bounds stream access");
     50    }
    4151    return iBuilder->CreateGEP(getStreamSetBlockPtr(iBuilder, self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
    4252}
     
    140150    Type * i8ptr = iBuilder->getInt8PtrTy();
    141151    unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    142     Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    143152    unsigned numStreams = getType()->getArrayNumElements();
    144153    auto elemTy = getType()->getArrayElementType();
     
    149158
    150159void StreamSetBuffer::createBlockAlignedCopy(IDISA::IDISA_Builder * const iBuilder, Value * targetBlockPtr, Value * sourceBlockPtr, Value * itemsToCopy) const {
    151     Type * i8ptr = iBuilder->getInt8PtrTy();
    152     unsigned alignment = iBuilder->getBitBlockWidth() / 8;
    153     Constant * blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
    154     unsigned numStreams = getType()->getArrayNumElements();
    155     auto elemTy = getType()->getArrayElementType();
    156     unsigned fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
     160    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
     161    const unsigned alignment = iBuilder->getBitBlockWidth() / 8;
     162    Constant * const blockSize = iBuilder->getSize(iBuilder->getBitBlockWidth());
     163    const unsigned numStreams = getType()->getArrayNumElements();
     164    const auto elemTy = getType()->getArrayElementType();
     165    const auto fieldWidth = isa<ArrayType>(elemTy) ? elemTy->getArrayNumElements() : 1;
    157166    if (numStreams == 1) {
    158167        Value * copyBits = iBuilder->CreateMul(itemsToCopy, iBuilder->getSize(fieldWidth));
    159168        Value * copyBytes = iBuilder->CreateLShr(iBuilder->CreateAdd(copyBits, iBuilder->getSize(7)), iBuilder->getSize(3));
    160         iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, i8ptr), iBuilder->CreateBitCast(sourceBlockPtr, i8ptr), copyBytes, alignment);
    161         return;
    162     }
    163     Value * blocksToCopy = iBuilder->CreateUDiv(itemsToCopy, blockSize);
    164     Value * partialItems = iBuilder->CreateURem(itemsToCopy, blockSize);
    165     Value * partialBlockTargetPtr = iBuilder->CreateGEP(targetBlockPtr, blocksToCopy);
    166     Value * partialBlockSourcePtr = iBuilder->CreateGEP(sourceBlockPtr, blocksToCopy);
    167     Value * blockCopyBytes = iBuilder->CreateMul(blocksToCopy, iBuilder->getSize(iBuilder->getBitBlockWidth() * numStreams * fieldWidth/8));
    168     iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, i8ptr), iBuilder->CreateBitCast(sourceBlockPtr, i8ptr), blockCopyBytes, alignment);
    169     Value * partialCopyBitsPerStream = iBuilder->CreateMul(partialItems, iBuilder->getSize(fieldWidth));
    170     Value * partialCopyBytesPerStream = iBuilder->CreateLShr(iBuilder->CreateAdd(partialCopyBitsPerStream, iBuilder->getSize(7)), iBuilder->getSize(3));
    171     for (unsigned strm = 0; strm < numStreams; strm++) {
    172         Value * strmTargetPtr = iBuilder->CreateGEP(partialBlockTargetPtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
    173         Value * strmSourcePtr = iBuilder->CreateGEP(partialBlockSourcePtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
    174         iBuilder->CreateMemMove(iBuilder->CreateBitCast(strmTargetPtr, i8ptr), iBuilder->CreateBitCast(strmSourcePtr, i8ptr), partialCopyBytesPerStream, alignment);
    175     }
    176 }
    177 
    178 
     169        iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, int8PtrTy), iBuilder->CreateBitCast(sourceBlockPtr, int8PtrTy), copyBytes, alignment);
     170    } else {
     171        Value * blocksToCopy = iBuilder->CreateUDiv(itemsToCopy, blockSize);
     172        Value * partialItems = iBuilder->CreateURem(itemsToCopy, blockSize);
     173        Value * partialBlockTargetPtr = iBuilder->CreateGEP(targetBlockPtr, blocksToCopy);
     174        Value * partialBlockSourcePtr = iBuilder->CreateGEP(sourceBlockPtr, blocksToCopy);
     175        Value * blockCopyBytes = iBuilder->CreateMul(blocksToCopy, iBuilder->getSize(iBuilder->getBitBlockWidth() * numStreams * fieldWidth/8));
     176        iBuilder->CreateMemMove(iBuilder->CreateBitCast(targetBlockPtr, int8PtrTy), iBuilder->CreateBitCast(sourceBlockPtr, int8PtrTy), blockCopyBytes, alignment);
     177        Value * partialCopyBitsPerStream = iBuilder->CreateMul(partialItems, iBuilder->getSize(fieldWidth));
     178        Value * partialCopyBytesPerStream = iBuilder->CreateLShr(iBuilder->CreateAdd(partialCopyBitsPerStream, iBuilder->getSize(7)), iBuilder->getSize(3));
     179        for (unsigned strm = 0; strm < numStreams; strm++) {
     180            Value * strmTargetPtr = iBuilder->CreateGEP(partialBlockTargetPtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
     181            Value * strmSourcePtr = iBuilder->CreateGEP(partialBlockSourcePtr, {iBuilder->getInt32(0), iBuilder->getInt32(strm)});
     182            strmTargetPtr = iBuilder->CreateBitCast(strmTargetPtr, int8PtrTy);
     183            strmSourcePtr = iBuilder->CreateBitCast(strmSourcePtr, int8PtrTy);
     184            iBuilder->CreateMemMove(strmTargetPtr, strmSourcePtr, partialCopyBytesPerStream, alignment);
     185        }
     186    }
     187}
    179188
    180189// Source File Buffer
     
    398407        Value * size = iBuilder->CreateMul(newCapacity, iBuilder->getSize(mBufferBlocks));
    399408        const auto memAlign = std::max(iBuilder->getCacheAlignment(), iBuilder->getBitBlockWidth() / 8);
     409
    400410        Value * newStreamSet = iBuilder->CreatePointerCast(iBuilder->CreateAlignedMalloc(iBuilder->CreateMul(size, vectorWidth), memAlign), elementType->getPointerTo());
    401411        Value * const diffCapacity = iBuilder->CreateMul(iBuilder->CreateSub(newCapacity, capacity), vectorWidth);
Note: See TracChangeset for help on using the changeset viewer.