source: icGREP/icgrep-devel/icgrep/array-test.cpp @ 5227

Last change on this file since 5227 was 5227, checked in by nmedfort, 3 years ago

Rewrite of the CarryManager? to support non-carry-collapsing loops.

File size: 2.7 KB
Line 
1/*
2 *  Copyright (c) 2015 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 <string>
8#include <iostream>
9#include <iomanip>
10#include <fstream>
11#include <sstream>
12
13
14#include <toolchain.h>
15#include <pablo/pablo_toolchain.h>
16#include <llvm/IR/Function.h>
17#include <llvm/IR/Module.h>
18#include <llvm/ExecutionEngine/ExecutionEngine.h>
19#include <llvm/ExecutionEngine/MCJIT.h>
20#include "llvm/Linker/Linker.h"
21#include <llvm/IR/Verifier.h>
22#include <llvm/Support/CommandLine.h>
23#include <llvm/Support/raw_ostream.h>
24
25#include <pablo/pablo_kernel.h>
26#include <IDISA/idisa_builder.h>
27#include <IDISA/idisa_target.h>
28#include <kernels/streamset.h>
29#include <kernels/interface.h>
30#include <kernels/kernel.h>
31#include <kernels/pipeline.h>
32#include <pablo/builder.hpp>
33#include <pablo/pablo_compiler.h>
34#include <pablo/pablo_toolchain.h>
35#include <pablo/printer_pablos.h>
36
37#include <llvm/Support/raw_os_ostream.h>
38
39using namespace pablo;
40using namespace kernel;
41using namespace parabix;
42
43//
44//
45
46void generate(PabloKernel * kernel, const unsigned size) {
47
48    PabloBuilder pb(kernel->getEntryBlock());
49
50    Var * input = kernel->addInput("input", kernel->getStreamSetTy(size));
51    Var * output = kernel->addOutput("output", kernel->getStreamSetTy(size));
52    Var * index = pb.createVar("idx", pb.getInteger(0));
53
54    Integer * one = pb.getInteger(1);
55
56    PabloBuilder body = PabloBuilder::Create(pb);
57
58    pb.createWhile(pb.createLessThan(index, pb.getInteger(size)), body);
59
60        PabloAST * adv = body.createAdvance(body.createExtract(input, index), one, "adv");
61        body.createAssign(body.createExtract(output, index), adv);
62
63        body.createAssign(index, body.createAdd(index, one));
64
65
66
67}
68
69Function * pipeline(IDISA::IDISA_Builder * iBuilder, const unsigned count = 10) {
70
71    PabloKernel main(iBuilder, "wc");
72    generate(&main, count);
73
74    ExternalFileBuffer input(iBuilder, iBuilder->getStreamSetTy(count));
75
76    SingleBlockBuffer output(iBuilder, iBuilder->getStreamSetTy(count));
77
78    main.generateKernel({&input}, {&output});
79
80    return nullptr;
81}
82
83
84static ExecutionEngine * wcEngine = nullptr;
85
86void * arrayTest() {
87    Module * M = new Module("wc", getGlobalContext());
88    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
89
90    llvm::Function * main_IR = pipeline(idb);
91
92    verifyModule(*M, &dbgs());
93
94    wcEngine = JIT_to_ExecutionEngine(M);
95
96    wcEngine->finalizeObject();
97
98    delete idb;
99//    return wcEngine->getPointerToFunction(main_IR);
100
101    return nullptr;
102}
103
104int main(int argc, char *argv[]) {
105
106    cl::ParseCommandLineOptions(argc, argv);
107
108    arrayTest();
109
110    return 0;
111}
Note: See TracBrowser for help on using the repository browser.