Ignore:
Timestamp:
Feb 17, 2016, 11:36:17 AM (4 years ago)
Author:
lindanl
Message:

KernelBuilder? updates.

File:
1 edited

Legend:

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

    r4926 r4930  
    6363}
    6464
    65 Function* KernelBuilder::CreateDoBlockFunction(){
    66     Type * inputStreamType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), mInputStreams), mSegmentBlocks), 0);
    67     Type * inputScalarType = PointerType::get(StructType::get(mMod->getContext(), mInputScalars), 0);
     65void KernelBuilder::PrepareDoBlockFunction(){
     66    mInputStreamType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), mInputStreams), mSegmentBlocks), 0);
     67    mInputScalarType = PointerType::get(StructType::get(mMod->getContext(), mInputScalars), 0);
    6868    Type * outputStreamType = ArrayType::get(StructType::get(mMod->getContext(), mOutputStreams), mSegmentBlocks);
    6969    Type * outputAccumType = StructType::get(mMod->getContext(), mOutputAccums);
    7070    Type * stateType = StructType::create(mMod->getContext(), mStates, mKernelName);
    7171    mKernelStructType = StructType::create(mMod->getContext(),std::vector<Type *>({stateType, outputStreamType, outputAccumType}), "KernelStruct_"+mKernelName);
    72  
    73    
     72}
     73
     74struct Inputs KernelBuilder::openDoBlock(){
     75    // FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()),
     76    //     std::vector<Type *>({PointerType::get(mKernelStructType, 0), mInputStreamType, mInputScalarType}), false);
     77       
    7478    FunctionType * functionType = FunctionType::get(Type::getVoidTy(mMod->getContext()),
    75         std::vector<Type *>({PointerType::get(mKernelStructType, 0), inputStreamType, inputScalarType}), false);
    76        
     79        std::vector<Type *>({PointerType::get(mKernelStructType, 0), mInputStreamType}), false);
     80
    7781    mDoBlockFunction = Function::Create(functionType, GlobalValue::ExternalLinkage, mKernelName + "_DoBlock", mMod);
    7882    mDoBlockFunction->setCallingConv(CallingConv::C);
    79 
    80     return mDoBlockFunction;
    81 }
    82 
    83 //create doBlock method with empty body and load inputs
    84 struct Inputs KernelBuilder::openDoBlock(){
    8583   
    86 
    8784    Function::arg_iterator args = mDoBlockFunction->arg_begin();
    8885    mKernelStructParam = args++;
     
    9087    Value* input_stream_param = args++;
    9188    input_stream_param->setName("input_stream");
    92     Value* input_scalar_param = args++;
    93     input_scalar_param->setName("input_scalar");
     89    // Value* input_scalar_param = args++;
     90    // input_scalar_param->setName("input_scalar");
    9491
    9592    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mDoBlockFunction,0));
    9693
    97     // std::vector<std::vector<valptr>> inputs;
    9894    struct Inputs inputs;
    9995    for(int j = 0; j<mSegmentBlocks; j++){
     
    118114    }
    119115
    120     inputs.scalars.resize(mInputScalars.size());
    121     for(int i = 0; i<mInputScalars.size(); i++){
    122         Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
    123         Value * gep = iBuilder->CreateGEP(input_scalar_param, indices);
    124         inputs.scalars[i] = iBuilder->CreateAlignedLoad(gep, mBlockSize/8, false, mInputScalarNames.at(i));
    125     }
     116    // inputs.scalars.resize(mInputScalars.size());
     117    // for(int i = 0; i<mInputScalars.size(); i++){
     118    //     Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
     119    //     Value * gep = iBuilder->CreateGEP(input_scalar_param, indices);
     120    //     inputs.scalars[i] = iBuilder->CreateAlignedLoad(gep, mBlockSize/8, false, mInputScalarNames.at(i));
     121    // }
    126122
    127123    return inputs;
     
    186182    while(i < mStates.size()){
    187183        gep = iBuilder->CreateGEP(this_param, std::vector<Value *>({ iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(i++) }));
    188         // iBuilder->CreateStore(iBuilder->getInt64(0), gep);
    189         // std::cerr << "size = " << mMod->getDataLayout()->getTypeAllocSize(mStates[i]) << std::endl;
    190         // iBuilder->CreateMemSet(gep, iBuilder->getInt8(0), mMod->getDataLayout()->getTypeAllocSize(mStates[i]), 4);
     184        Value * gep_next = iBuilder->CreateGEP(gep, std::vector<Value *>({iBuilder->getInt32(1)}));
     185        Value * get_int = iBuilder->CreatePtrToInt(gep, T);
     186        Value * get_next_int = iBuilder->CreatePtrToInt(gep_next, T);
     187        Value * state_size = iBuilder->CreateSub(get_next_int, get_int);
     188        iBuilder->CreateMemSet(gep, iBuilder->getInt8(0), state_size, 4);
    191189    }
    192190
     
    194192
    195193    c = mMod->getOrInsertFunction(mKernelName+"_Create_Default", Type::getVoidTy(mMod->getContext()), PointerType::get(mKernelStructType, 0), T, T, NULL);
    196     Function* mConstructor = cast<Function>(c);
     194    mConstructor = cast<Function>(c);
    197195    mConstructor->setCallingConv(CallingConv::C);
    198196    args = mConstructor->arg_begin();
     
    204202    Value* seg_size_param = args++;
    205203    seg_size_param->setName("seg_size");
    206 
    207     //initialize blockz_size and seg_size in Constructor not in init function
    208     //allocate buffer
     204 
    209205    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mConstructor, 0));
    210206    gep = iBuilder->CreateGEP(this_param, std::vector<Value *>({ iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(0) }));
     
    217213
    218214}
    219 //alloc space & set buffer size
    220 void KernelBuilder::generateKernelInstance(int segmentBlocks = 1){
     215
     216Value * KernelBuilder::generateKernelInstance(){
    221217
    222218    mKernelStruct = iBuilder->CreateAlloca(mKernelStructType);
     
    224220        ConstantInt::get(iBuilder->getIntNTy(64), mBlockSize),
    225221        ConstantInt::get(iBuilder->getIntNTy(64), mBufferSize));
     222    return mKernelStruct;
    226223
    227224}
     
    230227}
    231228
    232 // Value * KernelBuilder::generateDoBlockCall(Value * inputBuffer){
    233 //     iBuilder->CreateCall3(mDoBlockFunction, mKernelStruct, inputBuffer, outputBuffer);
    234 //     return outputBuffer;
     229// void KernelBuilder::generateDoBlockCall(Value * inputStreams, Value * inputScalars){
     230//     iBuilder->CreateCall3(mDoBlockFunction, mKernelStruct, inputStreams, inputScalars);
    235231// }
     232void KernelBuilder::generateDoBlockCall(Value * inputStreams){
     233    iBuilder->CreateCall2(mDoBlockFunction, mKernelStruct, inputStreams);
     234}
    236235
    237236int KernelBuilder::getSegmentBlocks(){
     
    239238}
    240239
     240Function * KernelBuilder::getDoBlockFunction(){
     241    return mDoBlockFunction;
     242}
     243
     244Type * KernelBuilder::getKernelStructType(){
     245    return mKernelStructType;
     246}
     247
     248Value * KernelBuilder::getKernelStructParam(){
     249    return mKernelStructParam;
     250}
     251
Note: See TracChangeset for help on using the changeset viewer.