Ignore:
Timestamp:
Dec 19, 2016, 2:39:35 PM (3 years ago)
Author:
nmedfort
Message:

Multi-threading support for PabloAST / PabloCompiler?. Requires unique LLVM Context / Module for each thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5227 r5230  
    3333#include <pablo/pablo_compiler.h>
    3434#include <pablo/pablo_toolchain.h>
    35 #include <pablo/printer_pablos.h>
     35
     36#include <kernels/stdout_kernel.h>
    3637
    3738#include <llvm/Support/raw_os_ostream.h>
     39
     40#include <pthread.h>
    3841
    3942using namespace pablo;
     
    6972Function * pipeline(IDISA::IDISA_Builder * iBuilder, const unsigned count = 10) {
    7073
    71     PabloKernel main(iBuilder, "wc");
     74    PabloKernel main(iBuilder, "at");
    7275    generate(&main, count);
    7376
    74     ExternalFileBuffer input(iBuilder, iBuilder->getStreamSetTy(count));
     77    SingleBlockBuffer input(iBuilder, iBuilder->getStreamSetTy(count));
    7578
    7679    SingleBlockBuffer output(iBuilder, iBuilder->getStreamSetTy(count));
     
    7881    main.generateKernel({&input}, {&output});
    7982
    80     return nullptr;
     83    Module * const mod = iBuilder->getModule();
     84
     85    Function * const f = cast<Function>(mod->getOrInsertFunction("main", iBuilder->getVoidTy(), nullptr));
     86    f->setCallingConv(CallingConv::C);
     87
     88    iBuilder->SetInsertPoint(BasicBlock::Create(mod->getContext(), "entry", f, 0));
     89    input.allocateBuffer();
     90    output.allocateBuffer();
     91    generatePipelineLoop(iBuilder, {&main});
     92    iBuilder->CreateRetVoid();
     93
     94    return f;
    8195}
    8296
     97typedef void (*AtFunctionType)();
    8398
    84 static ExecutionEngine * wcEngine = nullptr;
    85 
    86 void * arrayTest() {
    87     Module * M = new Module("wc", getGlobalContext());
     99void * arrayTest(void *) {
     100    LLVMContext ctx;
     101    Module * M = new Module("at", ctx);
    88102    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    89103
     
    92106    verifyModule(*M, &dbgs());
    93107
    94     wcEngine = JIT_to_ExecutionEngine(M);
     108    ExecutionEngine * wcEngine = JIT_to_ExecutionEngine(M);
    95109
    96110    wcEngine->finalizeObject();
    97111
    98112    delete idb;
    99 //    return wcEngine->getPointerToFunction(main_IR);
    100113
    101     return nullptr;
     114    return wcEngine->getPointerToFunction(main_IR);
    102115}
    103116
     
    106119    cl::ParseCommandLineOptions(argc, argv);
    107120
    108     arrayTest();
     121    pthread_t t1, t2;
     122
     123    pthread_create(&t1, nullptr, arrayTest, nullptr);
     124
     125    pthread_create(&t2, nullptr, arrayTest, nullptr);
     126
     127    void * r1, * r2;
     128
     129    pthread_join(t1, &r1);
     130
     131    pthread_join(t2, &r2);
    109132
    110133    return 0;
Note: See TracChangeset for help on using the changeset viewer.