Changeset 6054


Ignore:
Timestamp:
May 21, 2018, 8:15:50 AM (5 months ago)
Author:
cameron
Message:

IDISA testing: quiet mode, return code, pdep64 test case

Location:
icGREP/icgrep-devel
Files:
4 added
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r6050 r6054  
    282282  COMMAND python base64test.py ${CMAKE_BINARY_DIR}/base64)
    283283
     284add_test(
     285  NAME pdep64_test
     286  WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../QA/IDISA_test
     287  COMMAND ${CMAKE_BINARY_DIR}/idisa_test simd_pdep 64 randhex65536a randhex65536b)
     288
    284289#add_test(
    285290#  NAME character_deletion_test
  • icGREP/icgrep-devel/icgrep/idisa_test.cpp

    r6052 r6054  
    3838static cl::opt<std::string> Operand2TestFile(cl::Positional, cl::desc("Operand 2 data file."), cl::Required, cl::cat(testFlags));
    3939static cl::opt<std::string> TestOutputFile("o", cl::desc("Test output file."), cl::cat(testFlags));
    40 
     40static cl::opt<bool> QuietMode("q", cl::desc("Suppress output, set the return code only."), cl::cat(testFlags));
    4141static cl::opt<int> ShiftLimit("ShiftLimit", cl::desc("Upper limit for the shift operand (2nd operand) of sllv, srlv, srav."), cl::init(0));
    4242
     
    172172
    173173IdisaBinaryOpCheckKernel::IdisaBinaryOpCheckKernel(const std::unique_ptr<kernel::KernelBuilder> & b, std::string idisa_op, unsigned fw)
    174 : kernel::BlockOrientedKernel(idisa_op + std::to_string(fw) + "_check",
     174: kernel::BlockOrientedKernel(idisa_op + std::to_string(fw) + "_check" + std::to_string(QuietMode),
    175175                           {kernel::Binding{b->getStreamSetTy(1, 1), "operand1"},
    176176                            kernel::Binding{b->getStreamSetTy(1, 1), "operand2"},
    177177                            kernel::Binding{b->getStreamSetTy(1, 1), "test_result"}},
    178178                           {kernel::Binding{b->getStreamSetTy(1, 1), "expected_result"}},
    179                            {}, {}, {}),
     179                           {}, {kernel::Binding{b->getSizeTy(), "totalFailures"}}, {}),
    180180mIdisaOperation(idisa_op), mTestFw(fw) {}
    181181
     
    190190    unsigned fieldCount = kb->getBitBlockWidth()/mTestFw;
    191191    Value * expectedBlock = kb->allZeroes();
    192     for (unsigned i = 0; i < fieldCount; i++) {
    193         Value * operand1 = kb->mvmd_extract(mTestFw, operand1Block, i);
    194         Value * operand2 = kb->mvmd_extract(mTestFw, operand2Block, i);
    195         Value * expected = nullptr;
    196         if (mIdisaOperation.substr(0,5) == "simd_") {
    197             if (mIdisaOperation == "simd_add") {
    198                 expected = kb->CreateAdd(operand1, operand2);
    199             } else if (mIdisaOperation == "simd_sub") {
    200                 expected = kb->CreateSub(operand1, operand2);
    201             } else if (mIdisaOperation == "simd_mult") {
    202                 expected = kb->CreateMul(operand1, operand2);
    203             } else if (mIdisaOperation == "simd_eq") {
    204                 expected = kb->CreateSExt(kb->CreateICmpEQ(operand1, operand2), fwTy);
    205             } else if (mIdisaOperation == "simd_gt") {
    206                 expected = kb->CreateSExt(kb->CreateICmpSGT(operand1, operand2), fwTy);
    207             } else if (mIdisaOperation == "simd_ugt") {
    208                 expected = kb->CreateSExt(kb->CreateICmpUGT(operand1, operand2), fwTy);
    209             } else if (mIdisaOperation == "simd_uge") {
    210                 expected = kb->CreateSExt(kb->CreateICmpUGE(operand1, operand2), fwTy);
    211             } else if (mIdisaOperation == "simd_lt") {
    212                 expected = kb->CreateSExt(kb->CreateICmpSLT(operand1, operand2), fwTy);
    213             } else if (mIdisaOperation == "simd_ult") {
    214                 expected = kb->CreateSExt(kb->CreateICmpULT(operand1, operand2), fwTy);
    215             } else if (mIdisaOperation == "simd_ule") {
    216                 expected = kb->CreateSExt(kb->CreateICmpULE(operand1, operand2), fwTy);
    217             } else if (mIdisaOperation == "simd_max") {
    218                 expected = kb->CreateSelect(kb->CreateICmpSGT(operand1, operand2), operand1, operand2);
    219             } else if (mIdisaOperation == "simd_min") {
    220                 expected = kb->CreateSelect(kb->CreateICmpSLT(operand1, operand2), operand1, operand2);
    221             } else if (mIdisaOperation == "simd_umax") {
    222                 expected = kb->CreateSelect(kb->CreateICmpUGT(operand1, operand2), operand1, operand2);
    223             } else if (mIdisaOperation == "simd_umin") {
    224                 expected = kb->CreateSelect(kb->CreateICmpULT(operand1, operand2), operand1, operand2);
    225             } else if (mIdisaOperation == "simd_sllv") {
    226                 expected = kb->CreateShl(operand1, operand2);
    227             } else if (mIdisaOperation == "simd_srlv") {
    228                 expected = kb->CreateLShr(operand1, operand2);
    229             } else if (mIdisaOperation == "simd_pext") {
    230                 Constant * zeroConst = ConstantInt::getNullValue(fwTy);
    231                 Constant * oneConst = ConstantInt::get(fwTy, 1);
    232                 expected = zeroConst;
    233                 Value * out_bit = oneConst;
    234                 for (unsigned i = 0; i < mTestFw; i++) {
    235                     Value * i_bit = Constant::getIntegerValue(fwTy, APInt::getOneBitSet(mTestFw, i));
    236                     Value * operand_i_isSet = kb->CreateICmpEQ(kb->CreateAnd(operand1, i_bit), i_bit);
    237                     Value * mask_i_isSet = kb->CreateICmpEQ(kb->CreateAnd(operand2, i_bit), i_bit);
    238                     expected = kb->CreateSelect(kb->CreateAnd(operand_i_isSet, mask_i_isSet), kb->CreateOr(expected, out_bit), expected);
    239                     out_bit = kb->CreateSelect(mask_i_isSet, kb->CreateAdd(out_bit, out_bit), out_bit);
     192    if (mIdisaOperation == "mvmd_shuffle") {
     193        for (unsigned i = 0; i < mTestFw; i++) {
     194            Value * iConst = ConstantInt::get(kb->getInt32Ty(), i);
     195            Value * idx = kb->CreateExtractElement(operand2Block, iConst);
     196            expectedBlock = kb->CreateInsertElement(expectedBlock, kb->CreateExtractElement(operand1Block, idx), iConst);
     197        }
     198    } else {
     199        for (unsigned i = 0; i < fieldCount; i++) {
     200            Value * operand1 = kb->mvmd_extract(mTestFw, operand1Block, i);
     201            Value * operand2 = kb->mvmd_extract(mTestFw, operand2Block, i);
     202            Value * expected = nullptr;
     203            if (mIdisaOperation.substr(0,5) == "simd_") {
     204                if (mIdisaOperation == "simd_add") {
     205                    expected = kb->CreateAdd(operand1, operand2);
     206                } else if (mIdisaOperation == "simd_sub") {
     207                    expected = kb->CreateSub(operand1, operand2);
     208                } else if (mIdisaOperation == "simd_mult") {
     209                    expected = kb->CreateMul(operand1, operand2);
     210                } else if (mIdisaOperation == "simd_eq") {
     211                    expected = kb->CreateSExt(kb->CreateICmpEQ(operand1, operand2), fwTy);
     212                } else if (mIdisaOperation == "simd_gt") {
     213                    expected = kb->CreateSExt(kb->CreateICmpSGT(operand1, operand2), fwTy);
     214                } else if (mIdisaOperation == "simd_ugt") {
     215                    expected = kb->CreateSExt(kb->CreateICmpUGT(operand1, operand2), fwTy);
     216                } else if (mIdisaOperation == "simd_uge") {
     217                    expected = kb->CreateSExt(kb->CreateICmpUGE(operand1, operand2), fwTy);
     218                } else if (mIdisaOperation == "simd_lt") {
     219                    expected = kb->CreateSExt(kb->CreateICmpSLT(operand1, operand2), fwTy);
     220                } else if (mIdisaOperation == "simd_ult") {
     221                    expected = kb->CreateSExt(kb->CreateICmpULT(operand1, operand2), fwTy);
     222                } else if (mIdisaOperation == "simd_ule") {
     223                    expected = kb->CreateSExt(kb->CreateICmpULE(operand1, operand2), fwTy);
     224                } else if (mIdisaOperation == "simd_max") {
     225                    expected = kb->CreateSelect(kb->CreateICmpSGT(operand1, operand2), operand1, operand2);
     226                } else if (mIdisaOperation == "simd_min") {
     227                    expected = kb->CreateSelect(kb->CreateICmpSLT(operand1, operand2), operand1, operand2);
     228                } else if (mIdisaOperation == "simd_umax") {
     229                    expected = kb->CreateSelect(kb->CreateICmpUGT(operand1, operand2), operand1, operand2);
     230                } else if (mIdisaOperation == "simd_umin") {
     231                    expected = kb->CreateSelect(kb->CreateICmpULT(operand1, operand2), operand1, operand2);
     232                } else if (mIdisaOperation == "simd_sllv") {
     233                    expected = kb->CreateShl(operand1, operand2);
     234                } else if (mIdisaOperation == "simd_srlv") {
     235                    expected = kb->CreateLShr(operand1, operand2);
     236                } else if (mIdisaOperation == "simd_pext") {
     237                    Constant * zeroConst = ConstantInt::getNullValue(fwTy);
     238                    Constant * oneConst = ConstantInt::get(fwTy, 1);
     239                    expected = zeroConst;
     240                    Value * out_bit = oneConst;
     241                    for (unsigned i = 0; i < mTestFw; i++) {
     242                        Value * i_bit = Constant::getIntegerValue(fwTy, APInt::getOneBitSet(mTestFw, i));
     243                        Value * operand_i_isSet = kb->CreateICmpEQ(kb->CreateAnd(operand1, i_bit), i_bit);
     244                        Value * mask_i_isSet = kb->CreateICmpEQ(kb->CreateAnd(operand2, i_bit), i_bit);
     245                        expected = kb->CreateSelect(kb->CreateAnd(operand_i_isSet, mask_i_isSet), kb->CreateOr(expected, out_bit), expected);
     246                        out_bit = kb->CreateSelect(mask_i_isSet, kb->CreateAdd(out_bit, out_bit), out_bit);
     247                    }
     248                } else if (mIdisaOperation == "simd_pdep") {
     249                    Constant * zeroConst = ConstantInt::getNullValue(fwTy);
     250                    Constant * oneConst = ConstantInt::get(fwTy, 1);
     251                    expected = zeroConst;
     252                    Value * shft = zeroConst;
     253                    Value * select_bit = oneConst;
     254                    for (unsigned i = 0; i < mTestFw; i++) {
     255                        expected = kb->CreateOr(kb->CreateAnd(operand2, kb->CreateShl(kb->CreateAnd(operand1, select_bit), shft)), expected);
     256                        Value * i_bit = Constant::getIntegerValue(fwTy, APInt::getOneBitSet(mTestFw, i));
     257                        Value * mask_i_isSet = kb->CreateICmpEQ(kb->CreateAnd(operand2, i_bit), i_bit);
     258                        select_bit = kb->CreateSelect(mask_i_isSet, kb->CreateAdd(select_bit, select_bit), select_bit);
     259                        shft = kb->CreateSelect(mask_i_isSet, shft, kb->CreateAdd(shft, oneConst));
     260                    }
     261                } else {
     262                    llvm::report_fatal_error("Unknown SIMD vertical operation: " + mIdisaOperation);
    240263                }
    241             } else if (mIdisaOperation == "simd_pdep") {
    242                 Constant * zeroConst = ConstantInt::getNullValue(fwTy);
    243                 Constant * oneConst = ConstantInt::get(fwTy, 1);
    244                 expected = zeroConst;
    245                 Value * shft = zeroConst;
    246                 Value * select_bit = oneConst;
    247                 for (unsigned i = 0; i < mTestFw; i++) {
    248                     expected = kb->CreateOr(kb->CreateAnd(operand2, kb->CreateShl(kb->CreateAnd(operand1, select_bit), shft)), expected);
    249                     Value * i_bit = Constant::getIntegerValue(fwTy, APInt::getOneBitSet(mTestFw, i));
    250                     Value * mask_i_isSet = kb->CreateICmpEQ(kb->CreateAnd(operand2, i_bit), i_bit);
    251                     select_bit = kb->CreateSelect(mask_i_isSet, kb->CreateAdd(select_bit, select_bit), select_bit);
    252                     shft = kb->CreateSelect(mask_i_isSet, shft, kb->CreateAdd(shft, oneConst));
     264                expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw, expectedBlock, expected, i));
     265            } else if (mIdisaOperation == "hsimd_packh") {
     266                operand1 = kb->CreateTrunc(kb->CreateLShr(operand1, mTestFw/2), kb->getIntNTy(mTestFw/2));
     267                operand2 = kb->CreateTrunc(kb->CreateLShr(operand2, mTestFw/2), kb->getIntNTy(mTestFw/2));
     268                expectedBlock = kb->mvmd_insert(mTestFw/2, expectedBlock, operand1, i);
     269                expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw/2, expectedBlock, operand2, fieldCount + i));
     270            } else if (mIdisaOperation == "hsimd_packl") {
     271                operand1 = kb->CreateTrunc(operand1, kb->getIntNTy(mTestFw/2));
     272                operand2 = kb->CreateTrunc(operand2, kb->getIntNTy(mTestFw/2));
     273                expectedBlock = kb->mvmd_insert(mTestFw/2, expectedBlock, operand1, i);
     274                expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw/2, expectedBlock, operand2, fieldCount + i));
     275            } else if (mIdisaOperation == "esimd_mergeh") {
     276                if (i >= fieldCount/2) {
     277                    expectedBlock = kb->mvmd_insert(mTestFw, expectedBlock, operand1, 2*(i - fieldCount/2));
     278                    expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw, expectedBlock, operand2, 2*(i - fieldCount/2) + 1));
    253279                }
    254             } else {
    255                 llvm::report_fatal_error("Unknown SIMD vertical operation: " + mIdisaOperation);
    256             }
    257             expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw, expectedBlock, expected, i));
    258         } else if (mIdisaOperation == "hsimd_packh") {
    259             operand1 = kb->CreateTrunc(kb->CreateLShr(operand1, mTestFw/2), kb->getIntNTy(mTestFw/2));
    260             operand2 = kb->CreateTrunc(kb->CreateLShr(operand2, mTestFw/2), kb->getIntNTy(mTestFw/2));
    261             expectedBlock = kb->mvmd_insert(mTestFw/2, expectedBlock, operand1, i);
    262             expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw/2, expectedBlock, operand2, fieldCount + i));
    263         } else if (mIdisaOperation == "hsimd_packl") {
    264             operand1 = kb->CreateTrunc(operand1, kb->getIntNTy(mTestFw/2));
    265             operand2 = kb->CreateTrunc(operand2, kb->getIntNTy(mTestFw/2));
    266             expectedBlock = kb->mvmd_insert(mTestFw/2, expectedBlock, operand1, i);
    267             expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw/2, expectedBlock, operand2, fieldCount + i));
    268         } else if (mIdisaOperation == "esimd_mergeh") {
    269             if (i >= fieldCount/2) {
    270                 expectedBlock = kb->mvmd_insert(mTestFw, expectedBlock, operand1, 2*(i - fieldCount/2));
    271                 expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw, expectedBlock, operand2, 2*(i - fieldCount/2) + 1));
    272             }
    273         } else if (mIdisaOperation == "esimd_mergel") {
    274             if (i < fieldCount/2) {
    275                 expectedBlock = kb->mvmd_insert(mTestFw, expectedBlock, operand1, 2*i);
    276                 expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw, expectedBlock, operand2, 2*i + 1));
     280            } else if (mIdisaOperation == "esimd_mergel") {
     281                if (i < fieldCount/2) {
     282                    expectedBlock = kb->mvmd_insert(mTestFw, expectedBlock, operand1, 2*i);
     283                    expectedBlock = kb->bitCast(kb->mvmd_insert(mTestFw, expectedBlock, operand2, 2*i + 1));
     284                }
    277285            }
    278286        }
    279287    }
    280288    kb->storeOutputStreamBlock("expected_result", ZeroConst, expectedBlock);
    281     Value * failure = kb->bitblock_any(kb->CreateXor(resultBlock, expectedBlock));
    282     kb->CreateCondBr(failure, reportFailure, continueTest);
    283     kb->SetInsertPoint(reportFailure);
    284     kb->CallPrintRegister("operand1", kb->bitCast(operand1Block));
    285     kb->CallPrintRegister("operand2", kb->bitCast(operand2Block));
    286     kb->CallPrintRegister(mIdisaOperation + "(" + std::to_string(mTestFw) + ", operand1, operand2)", resultBlock);
    287     kb->CallPrintRegister("expecting", expectedBlock);
    288     kb->CreateBr(continueTest);
    289     kb->SetInsertPoint(continueTest);
     289    Value * failures = kb->simd_ugt(mTestFw, kb->CreateXor(resultBlock, expectedBlock), kb->allZeroes());
     290    Value * anyFailure = kb->bitblock_any(failures);
     291    Value * failure_count = kb->CreateUDiv(kb->bitblock_popcount(failures), kb->getSize(mTestFw));
     292    kb->setScalarField("totalFailures", kb->CreateAdd(kb->getScalarField("totalFailures"), failure_count));
     293    if (!QuietMode) {
     294        kb->CreateCondBr(anyFailure, reportFailure, continueTest);
     295        kb->SetInsertPoint(reportFailure);
     296        kb->CallPrintRegister("operand1", kb->bitCast(operand1Block));
     297        kb->CallPrintRegister("operand2", kb->bitCast(operand2Block));
     298        kb->CallPrintRegister(mIdisaOperation + "(" + std::to_string(mTestFw) + ", operand1, operand2)", resultBlock);
     299        kb->CallPrintRegister("expecting", expectedBlock);
     300        kb->CreateBr(continueTest);
     301        kb->SetInsertPoint(continueTest);
     302    }
    290303}
    291304
     
    319332}
    320333
    321 typedef void (*IDISAtestFunctionType)(int32_t fd1, int32_t fd2);
     334typedef size_t (*IDISAtestFunctionType)(int32_t fd1, int32_t fd2);
    322335
    323336using namespace parabix;
     
    331344   
    332345    Type * const int32Ty = idb->getInt32Ty();
    333     Type * const voidTy = idb->getVoidTy();
    334 
    335     FunctionType * const mainType = FunctionType::get(voidTy, {int32Ty, int32Ty}, false);
     346    Type * const sizeTy = idb->getSizeTy();
     347
     348    FunctionType * const mainType = FunctionType::get(sizeTy, {int32Ty, int32Ty}, false);
    336349    Function * const main = cast<Function>(m->getOrInsertFunction("Main", mainType));
    337350    main->setCallingConv(CallingConv::C);
     
    376389    kernel::Kernel * checkK = pxDriver.addKernelInstance<IdisaBinaryOpCheckKernel>(idb, TestOperation, TestFieldWidth);
    377390    pxDriver.makeKernelCall(checkK, {Operand1BitStream, Operand2BitStream, ResultBitStream}, {ExpectedResultBitStream});
    378 
     391   
    379392    if (!TestOutputFile.empty()) {
    380393        StreamSetBuffer * ResultHexStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 8), bufferSize);
     
    388401   
    389402    pxDriver.generatePipelineIR();
     403    idb->setKernel(checkK);
     404    Value * totalFailures = idb->getAccumulator("totalFailures");
     405   
    390406    pxDriver.deallocateBuffers();
    391     idb->CreateRetVoid();
     407    idb->CreateRet(totalFailures);
    392408    pxDriver.finalizeObject();
    393409}
     
    403419   
    404420    auto idisaTestFunction = reinterpret_cast<IDISAtestFunctionType>(pxDriver.getMain());
    405     idisaTestFunction(fd1, fd2);
     421    size_t failure_count = idisaTestFunction(fd1, fd2);
     422    if (!QuietMode) {
     423        if (failure_count == 0) {
     424            llvm::outs() << "Test success: " << TestOperation << "<" << TestFieldWidth << ">\n";
     425        } else {
     426            llvm::outs() << "Test failure: " << TestOperation << "<" << TestFieldWidth << "> failed " << failure_count << " tests!\n";
     427        }
     428    }
    406429    close(fd1);
    407430    close(fd2);
    408     return 0;
    409 }
     431    return failure_count > 0;
     432}
Note: See TracChangeset for help on using the changeset viewer.