Ignore:
Timestamp:
Aug 29, 2016, 1:53:08 PM (3 years ago)
Author:
lindanl
Message:

Add pipeline parallel strategy to the framework.

File:
1 edited

Legend:

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

    r5126 r5135  
    1515#include <kernels/s2p_kernel.h>
    1616
     17#include <llvm/IR/TypeBuilder.h>
    1718
    1819using namespace kernel;
     20
     21void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, std::vector<Value *> instances) {
     22 
     23    Module * m = iBuilder->getModule();
     24
     25    Type * pthreadTy = iBuilder->getInt64Ty(); //Pthread Type for 64-bit machine.     
     26    Type * const voidPtrTy = TypeBuilder<void *, false>::get(m->getContext());
     27    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
     28
     29    Type * const pthreadsTy = ArrayType::get(pthreadTy, kernels.size());
     30    AllocaInst * const pthreads = iBuilder->CreateAlloca(pthreadsTy);
     31    std::vector<Value *> pthreadsPtrs;
     32    for (unsigned i = 0; i < kernels.size(); i++) {
     33        pthreadsPtrs.push_back(iBuilder->CreateGEP(pthreads, {iBuilder->getInt32(0), iBuilder->getInt32(i)}));
     34    }
     35    Value * nullVal = Constant::getNullValue(voidPtrTy);
     36    AllocaInst * const status = iBuilder->CreateAlloca(int8PtrTy);
     37
     38    std::vector<Function *> kernel_functions;
     39    const auto ip = iBuilder->saveIP();
     40    for (unsigned i = 0; i < kernels.size(); i++) {
     41        kernel_functions.push_back(kernels[i]->generateThreadFunction("k_"+std::to_string(i)));
     42    }
     43    iBuilder->restoreIP(ip);
     44
     45    Function * pthreadCreateFunc = m->getFunction("pthread_create");
     46    Function * pthreadJoinFunc = m->getFunction("pthread_join");
     47
     48    for (unsigned i = 0; i < kernels.size(); i++) {
     49        iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtrs[i], nullVal, kernel_functions[i], iBuilder->CreateBitCast(instances[i], int8PtrTy)}));
     50    }
     51
     52    std::vector<Value *> threadIDs;
     53    for (unsigned i = 0; i < kernels.size(); i++) {
     54        threadIDs.push_back(iBuilder->CreateLoad(pthreadsPtrs[i]));
     55    }
     56   
     57    for (unsigned i = 0; i < kernels.size(); i++) {
     58        iBuilder->CreateCall(pthreadJoinFunc, std::vector<Value *>({threadIDs[i], status}));
     59    }
     60}
    1961
    2062
Note: See TracChangeset for help on using the changeset viewer.