source: icGREP/icgrep-devel/icgrep/idisa_test.cpp @ 6053

Last change on this file since 6053 was 6052, checked in by cameron, 15 months ago

IDISA test checking, more test operations, IDISA fixes

File size: 21.6 KB
Line 
1/*
2 *  Copyright (c) 2018 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include <vector>
8#include <string>
9#include <toolchain/toolchain.h>
10#include <llvm/IR/Function.h>
11#include <llvm/IR/Module.h>
12#include <llvm/Support/CommandLine.h>
13#include <llvm/Support/raw_ostream.h>
14#include <kernels/kernel_builder.h>
15#include <IR_Gen/idisa_target.h>
16#include <kernels/interface.h>
17#include <kernels/streamset.h>
18#include <kernels/source_kernel.h>
19#include <kernels/hex_convert.h>
20#include <kernels/s2p_kernel.h>
21#include <kernels/stdout_kernel.h>
22#include <toolchain/toolchain.h>
23#include <toolchain/cpudriver.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <boost/filesystem.hpp>
27namespace fs = boost::filesystem;
28
29using namespace llvm;
30
31static cl::OptionCategory testFlags("Command Flags", "test options");
32
33static cl::opt<std::string> TestOperation(cl::Positional, cl::desc("Operation to test"), cl::Required, cl::cat(testFlags));
34
35static cl::opt<int> TestFieldWidth(cl::Positional, cl::desc("Test field width (default 64)."), cl::init(64), cl::Required, cl::cat(testFlags));
36
37static cl::opt<std::string> Operand1TestFile(cl::Positional, cl::desc("Operand 1 data file."), cl::Required, cl::cat(testFlags));
38static cl::opt<std::string> Operand2TestFile(cl::Positional, cl::desc("Operand 2 data file."), cl::Required, cl::cat(testFlags));
39static cl::opt<std::string> TestOutputFile("o", cl::desc("Test output file."), cl::cat(testFlags));
40
41static cl::opt<int> ShiftLimit("ShiftLimit", cl::desc("Upper limit for the shift operand (2nd operand) of sllv, srlv, srav."), cl::init(0));
42
43class ShiftLimitKernel : public kernel::BlockOrientedKernel {
44public:
45    ShiftLimitKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned limit);
46    bool isCachable() const override { return true; }
47    bool hasSignature() const override { return false; }
48protected:
49    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & kb) override;
50private:
51    const unsigned mTestFw;
52    const unsigned mShiftLimit;
53};
54
55ShiftLimitKernel::ShiftLimitKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw, unsigned limit)
56: kernel::BlockOrientedKernel("shiftLimit" + std::to_string(fw) + "_" + std::to_string(limit),
57                              {kernel::Binding{b->getStreamSetTy(1, fw), "shiftOperand"}},
58                              {kernel::Binding{b->getStreamSetTy(1, fw), "limitedShift"}},
59                              {}, {}, {}),
60mTestFw(fw), mShiftLimit(limit) {}
61
62void ShiftLimitKernel::generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & kb) {
63    Type * fwTy = kb->getIntNTy(mTestFw);
64    Constant * const ZeroConst = kb->getSize(0);
65    Value * shiftOperand = kb->loadInputStreamBlock("shiftOperand", ZeroConst);
66    unsigned fieldCount = kb->getBitBlockWidth()/mTestFw;
67    Value * limited = kb->simd_umin(mTestFw, shiftOperand, ConstantVector::getSplat(fieldCount, ConstantInt::get(fwTy, mShiftLimit)));
68    kb->storeOutputStreamBlock("limitedShift", ZeroConst, limited);
69}
70
71class IdisaBinaryOpTestKernel : public kernel::MultiBlockKernel {
72public:
73    IdisaBinaryOpTestKernel(const std::unique_ptr<kernel::KernelBuilder> & b, std::string idisa_op, unsigned fw);
74    bool isCachable() const override { return true; }
75    bool hasSignature() const override { return false; }
76protected:
77    void generateMultiBlockLogic(const std::unique_ptr<kernel::KernelBuilder> & kb, llvm::Value * const numOfStrides) override;
78private:
79    const std::string mIdisaOperation;
80    const unsigned mTestFw;
81};
82
83IdisaBinaryOpTestKernel::IdisaBinaryOpTestKernel(const std::unique_ptr<kernel::KernelBuilder> & b, std::string idisa_op, unsigned fw)
84: kernel::MultiBlockKernel(idisa_op + std::to_string(fw) + "_test",
85     {kernel::Binding{b->getStreamSetTy(1, 1), "operand1"}, kernel::Binding{b->getStreamSetTy(1, 1), "operand2"}},
86     {kernel::Binding{b->getStreamSetTy(1, 1), "result"}},
87     {}, {}, {}),
88mIdisaOperation(idisa_op), mTestFw(fw) {}
89
90void IdisaBinaryOpTestKernel::generateMultiBlockLogic(const std::unique_ptr<kernel::KernelBuilder> & kb, llvm::Value * const numOfBlocks) {
91    BasicBlock * entry = kb->GetInsertBlock();
92    BasicBlock * processBlock = kb->CreateBasicBlock("processBlock");
93    BasicBlock * done = kb->CreateBasicBlock("done");
94    Constant * const ZeroConst = kb->getSize(0);
95    kb->CreateBr(processBlock);
96    kb->SetInsertPoint(processBlock);
97    PHINode * blockOffsetPhi = kb->CreatePHI(kb->getSizeTy(), 2);
98    blockOffsetPhi->addIncoming(ZeroConst, entry);
99    Value * operand1 = kb->loadInputStreamBlock("operand1", ZeroConst, blockOffsetPhi);
100    Value * operand2 = kb->loadInputStreamBlock("operand2", ZeroConst, blockOffsetPhi);
101    Value * result = nullptr;
102    if (mIdisaOperation == "simd_add") {
103        result = kb->simd_add(mTestFw, operand1, operand2);
104    } else if (mIdisaOperation == "simd_sub") {
105        result = kb->simd_sub(mTestFw, operand1, operand2);
106    } else if (mIdisaOperation == "simd_mult") {
107        result = kb->simd_mult(mTestFw, operand1, operand2);
108    } else if (mIdisaOperation == "simd_eq") {
109        result = kb->simd_eq(mTestFw, operand1, operand2);
110    } else if (mIdisaOperation == "simd_gt") {
111        result = kb->simd_gt(mTestFw, operand1, operand2);
112    } else if (mIdisaOperation == "simd_ugt") {
113        result = kb->simd_ugt(mTestFw, operand1, operand2);
114    } else if (mIdisaOperation == "simd_uge") {
115        result = kb->simd_uge(mTestFw, operand1, operand2);
116    } else if (mIdisaOperation == "simd_lt") {
117        result = kb->simd_lt(mTestFw, operand1, operand2);
118    } else if (mIdisaOperation == "simd_ult") {
119        result = kb->simd_ult(mTestFw, operand1, operand2);
120    } else if (mIdisaOperation == "simd_ule") {
121        result = kb->simd_ule(mTestFw, operand1, operand2);
122    } else if (mIdisaOperation == "simd_max") {
123        result = kb->simd_max(mTestFw, operand1, operand2);
124    } else if (mIdisaOperation == "simd_min") {
125        result = kb->simd_min(mTestFw, operand1, operand2);
126    } else if (mIdisaOperation == "simd_umax") {
127        result = kb->simd_umax(mTestFw, operand1, operand2);
128    } else if (mIdisaOperation == "simd_umin") {
129        result = kb->simd_umin(mTestFw, operand1, operand2);
130    } else if (mIdisaOperation == "simd_sllv") {
131        result = kb->simd_sllv(mTestFw, operand1, operand2);
132    } else if (mIdisaOperation == "simd_srlv") {
133        result = kb->simd_srlv(mTestFw, operand1, operand2);
134    } else if (mIdisaOperation == "simd_pext") {
135        result = kb->simd_pext(mTestFw, operand1, operand2);
136    } else if (mIdisaOperation == "simd_pdep") {
137        result = kb->simd_pdep(mTestFw, operand1, operand2);
138    } else if (mIdisaOperation == "hsimd_packh") {
139        result = kb->hsimd_packh(mTestFw, operand1, operand2);
140    } else if (mIdisaOperation == "hsimd_packl") {
141        result = kb->hsimd_packl(mTestFw, operand1, operand2);
142    } else if (mIdisaOperation == "esimd_mergeh") {
143        result = kb->esimd_mergeh(mTestFw, operand1, operand2);
144    } else if (mIdisaOperation == "esimd_mergel") {
145        result = kb->esimd_mergel(mTestFw, operand1, operand2);
146    } else if (mIdisaOperation == "mvmd_shuffle") {
147        result = kb->mvmd_shuffle(mTestFw, operand1, operand2);
148    } else if (mIdisaOperation == "mvmd_compress") {
149        result = kb->mvmd_compress(mTestFw, operand1, operand2);
150    } else {
151        llvm::report_fatal_error("Binary operation " + mIdisaOperation + " is unknown to the IdisaBinaryOpTestKernel kernel.");
152    }
153    kb->storeOutputStreamBlock("result", ZeroConst, blockOffsetPhi, kb->bitCast(result));
154    Value * nextBlk = kb->CreateAdd(blockOffsetPhi, kb->getSize(1));
155    blockOffsetPhi->addIncoming(nextBlk, processBlock);
156    Value * moreToDo = kb->CreateICmpNE(nextBlk, numOfBlocks);
157    kb->CreateCondBr(moreToDo, processBlock, done);
158    kb->SetInsertPoint(done);
159}
160
161class IdisaBinaryOpCheckKernel : public kernel::BlockOrientedKernel {
162public:
163    IdisaBinaryOpCheckKernel(const std::unique_ptr<kernel::KernelBuilder> & b, std::string idisa_op, unsigned fw);
164    bool isCachable() const override { return true; }
165    bool hasSignature() const override { return false; }
166protected:
167    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & kb) override;
168private:
169    const std::string mIdisaOperation;
170    const unsigned mTestFw;
171};
172
173IdisaBinaryOpCheckKernel::IdisaBinaryOpCheckKernel(const std::unique_ptr<kernel::KernelBuilder> & b, std::string idisa_op, unsigned fw)
174: kernel::BlockOrientedKernel(idisa_op + std::to_string(fw) + "_check",
175                           {kernel::Binding{b->getStreamSetTy(1, 1), "operand1"},
176                            kernel::Binding{b->getStreamSetTy(1, 1), "operand2"},
177                            kernel::Binding{b->getStreamSetTy(1, 1), "test_result"}},
178                           {kernel::Binding{b->getStreamSetTy(1, 1), "expected_result"}},
179                           {}, {}, {}),
180mIdisaOperation(idisa_op), mTestFw(fw) {}
181
182void IdisaBinaryOpCheckKernel::generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & kb) {
183    Type * fwTy = kb->getIntNTy(mTestFw);
184    BasicBlock * reportFailure = kb->CreateBasicBlock("reportFailure");
185    BasicBlock * continueTest = kb->CreateBasicBlock("continueTest");
186    Constant * const ZeroConst = kb->getSize(0);
187    Value * operand1Block = kb->loadInputStreamBlock("operand1", ZeroConst);
188    Value * operand2Block = kb->loadInputStreamBlock("operand2", ZeroConst);
189    Value * resultBlock = kb->loadInputStreamBlock("test_result", ZeroConst);
190    unsigned fieldCount = kb->getBitBlockWidth()/mTestFw;
191    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);
240                }
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));
253                }
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));
277            }
278        }
279    }
280    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);
290}
291
292// Open a file and return its file desciptor.
293int32_t openFile(const std::string & fileName, llvm::raw_ostream & msgstrm) {
294    if (fileName == "-") {
295        return STDIN_FILENO;
296    }
297    else {
298        struct stat sb;
299        int32_t fileDescriptor = open(fileName.c_str(), O_RDONLY);
300        if (LLVM_UNLIKELY(fileDescriptor == -1)) {
301            if (errno == EACCES) {
302                msgstrm << "idisa_test: " << fileName << ": Permission denied.\n";
303            }
304            else if (errno == ENOENT) {
305                msgstrm << "idisa_test: " << fileName << ": No such file.\n";
306            }
307            else {
308                msgstrm << "idisa_test: " << fileName << ": Failed.\n";
309            }
310            return fileDescriptor;
311        }
312        if (stat(fileName.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
313            msgstrm << "idisa_test: " << fileName << ": Is a directory.\n";
314            close(fileDescriptor);
315            return -1;
316        }
317        return fileDescriptor;
318    }
319}
320
321typedef void (*IDISAtestFunctionType)(int32_t fd1, int32_t fd2);
322
323using namespace parabix;
324
325void pipelineGen(ParabixDriver & pxDriver) {
326
327    auto & idb = pxDriver.getBuilder();
328    Module * m = idb->getModule();
329    Value * useMMap = idb->CreateZExt(idb->getTrue(), idb->getInt8Ty());
330    const auto bufferSize = codegen::SegmentSize * codegen::BufferSegments;
331   
332    Type * const int32Ty = idb->getInt32Ty();
333    Type * const voidTy = idb->getVoidTy();
334
335    FunctionType * const mainType = FunctionType::get(voidTy, {int32Ty, int32Ty}, false);
336    Function * const main = cast<Function>(m->getOrInsertFunction("Main", mainType));
337    main->setCallingConv(CallingConv::C);
338    Function::arg_iterator args = main->arg_begin();   
339    Value * const fileDecriptor1 = &*(args++);
340    fileDecriptor1->setName("operand1FileDecriptor");
341    Value * const fileDecriptor2 = &*(args++);
342    fileDecriptor2->setName("operand2FileDecriptor");
343
344    idb->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry", main,0));
345
346    StreamSetBuffer * Operand1HexStream = pxDriver.addBuffer<ExternalBuffer>(idb, idb->getStreamSetTy(1, 8));
347    kernel::Kernel * sourceK1 = pxDriver.addKernelInstance<kernel::FDSourceKernel>(idb);
348    sourceK1->setInitialArguments({useMMap, fileDecriptor1});
349    pxDriver.makeKernelCall(sourceK1, {}, {Operand1HexStream});
350   
351    StreamSetBuffer * Operand1BitStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 1), bufferSize);
352    kernel::Kernel * hexbinK = pxDriver.addKernelInstance<kernel::HexToBinary>(idb);
353    pxDriver.makeKernelCall(hexbinK, {Operand1HexStream}, {Operand1BitStream});
354   
355    StreamSetBuffer * Operand2HexStream = pxDriver.addBuffer<ExternalBuffer>(idb, idb->getStreamSetTy(1, 8));
356    kernel::Kernel * sourceK2 = pxDriver.addKernelInstance<kernel::FDSourceKernel>(idb);
357    sourceK2->setInitialArguments({useMMap, fileDecriptor2});
358    pxDriver.makeKernelCall(sourceK2, {}, {Operand2HexStream});
359   
360    StreamSetBuffer * Operand2BitStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 1), bufferSize);
361    kernel::Kernel * hexbinK2 = pxDriver.addKernelInstance<kernel::HexToBinary>(idb);
362    pxDriver.makeKernelCall(hexbinK2, {Operand2HexStream}, {Operand2BitStream});
363   
364    if (ShiftLimit > 0) {
365        StreamSetBuffer * PreLimitBitStream = Operand2BitStream;
366        Operand2BitStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 1), bufferSize);
367        kernel::Kernel * limitK = pxDriver.addKernelInstance<ShiftLimitKernel>(idb, TestFieldWidth, ShiftLimit);
368        pxDriver.makeKernelCall(limitK, {PreLimitBitStream}, {Operand2BitStream});
369    }
370
371    StreamSetBuffer * ResultBitStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 1), bufferSize);
372    kernel::Kernel * testK = pxDriver.addKernelInstance<IdisaBinaryOpTestKernel>(idb, TestOperation, TestFieldWidth);
373    pxDriver.makeKernelCall(testK, {Operand1BitStream, Operand2BitStream}, {ResultBitStream});
374   
375    StreamSetBuffer * ExpectedResultBitStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 1), bufferSize);
376    kernel::Kernel * checkK = pxDriver.addKernelInstance<IdisaBinaryOpCheckKernel>(idb, TestOperation, TestFieldWidth);
377    pxDriver.makeKernelCall(checkK, {Operand1BitStream, Operand2BitStream, ResultBitStream}, {ExpectedResultBitStream});
378
379    if (!TestOutputFile.empty()) {
380        StreamSetBuffer * ResultHexStream = pxDriver.addBuffer<StaticBuffer>(idb, idb->getStreamSetTy(1, 8), bufferSize);
381        kernel::Kernel * binhexK = pxDriver.addKernelInstance<kernel::BinaryToHex>(idb);
382        pxDriver.makeKernelCall(binhexK, {ResultBitStream}, {ResultHexStream});
383        kernel::Kernel * outK = pxDriver.addKernelInstance<kernel::FileSink>(idb, 8);
384        Value * fName = idb->CreatePointerCast(idb->GetString(TestOutputFile.c_str()), idb->getInt8PtrTy());
385        outK->setInitialArguments({fName});
386        pxDriver.makeKernelCall(outK, {ResultHexStream}, {});
387   }
388   
389    pxDriver.generatePipelineIR();
390    pxDriver.deallocateBuffers();
391    idb->CreateRetVoid();
392    pxDriver.finalizeObject();
393}
394
395int main(int argc, char *argv[]) {
396    cl::ParseCommandLineOptions(argc, argv);
397    //codegen::SegmentSize = 1;
398    ParabixDriver pxDriver("idisa_test");
399    pipelineGen(pxDriver);
400   
401    int32_t fd1 = openFile(Operand1TestFile, llvm::outs());
402    int32_t fd2 = openFile(Operand2TestFile, llvm::outs());
403   
404    auto idisaTestFunction = reinterpret_cast<IDISAtestFunctionType>(pxDriver.getMain());
405    idisaTestFunction(fd1, fd2);
406    close(fd1);
407    close(fd2);
408    return 0;
409}
Note: See TracBrowser for help on using the repository browser.