Ignore:
Timestamp:
May 31, 2017, 4:25:33 PM (2 years ago)
Author:
nmedfort
Message:

Initial attempt to improve debugging capabilities with compilation stack traces on error.

Location:
icGREP/icgrep-devel/icgrep/toolchain
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/toolchain/cpudriver.cpp

    r5474 r5486  
    7171    mTarget = builder.selectTarget();
    7272    if (LLVM_LIKELY(codegen::EnableObjectCache)) {
    73         if (codegen::ObjectCacheDir.empty()) {
     73        if (codegen::ObjectCacheDir) {
     74            mCache = new ParabixObjectCache(codegen::ObjectCacheDir);
     75        } else {
    7476            mCache = new ParabixObjectCache();
    75         } else {
    76             mCache = new ParabixObjectCache(codegen::ObjectCacheDir);
    7777        }
    7878        mEngine->setObjectCache(mCache);
     
    117117        k->initializeInstance(iBuilder);
    118118    }
    119     if (codegen::pipelineParallel) {
     119    if (codegen::PipelineParallel) {
    120120        generateParallelPipeline(iBuilder, mPipeline);
    121     } else if (codegen::segmentPipelineParallel) {
     121    } else if (codegen::SegmentPipelineParallel) {
    122122        generateSegmentParallelPipeline(iBuilder, mPipeline);
    123123    } else {
    124         codegen::ThreadNum = 1;
    125124        generatePipelineLoop(iBuilder, mPipeline);
    126125    }
     
    132131Function * ParabixDriver::addLinkFunction(Module * mod, llvm::StringRef name, FunctionType * type, void * functionPtr) const {
    133132    assert ("addKernelCall or makeKernelCall must be called before LinkFunction" && (mod != nullptr));
    134     Function * const f = cast<Function>(mod->getOrInsertFunction(name, type));
    135     mEngine->addGlobalMapping(f, functionPtr);
     133    Function * f = mod->getFunction(name);
     134    if (LLVM_UNLIKELY(f == nullptr)) {
     135        f = Function::Create(type, Function::ExternalLinkage, name, mod);
     136        mEngine->addGlobalMapping(f, functionPtr);
     137    } else if (LLVM_UNLIKELY(f->getType() != type->getPointerTo())) {
     138        report_fatal_error("Cannot link " + name + ": a function with a differing signature already exists with that name in " + mod->getName());
     139    }
    136140    return f;
    137141}
     
    142146    std::unique_ptr<raw_fd_ostream> IROutputStream(nullptr);
    143147    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowUnoptimizedIR))) {
    144         if (codegen::IROutputFilename.empty()) {
    145             IROutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    146         } else {
     148        if (codegen::IROutputFilename) {
    147149            std::error_code error;
    148150            IROutputStream.reset(new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None));
     151        } else {
     152            IROutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    149153        }
    150154        PM.add(createPrintModulePass(*IROutputStream));
     
    161165    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowIR))) {
    162166        if (LLVM_LIKELY(IROutputStream == nullptr)) {
    163             if (codegen::IROutputFilename.empty()) {
    164                 IROutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    165             } else {
     167            if (codegen::IROutputFilename) {
    166168                std::error_code error;
    167169                IROutputStream.reset(new raw_fd_ostream(codegen::IROutputFilename, error, sys::fs::OpenFlags::F_None));
     170            } else {
     171                IROutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    168172            }
    169173        }
     
    174178    std::unique_ptr<raw_fd_ostream> ASMOutputStream(nullptr);
    175179    if (LLVM_UNLIKELY(codegen::DebugOptionIsSet(codegen::ShowASM))) {
    176         if (codegen::ASMOutputFilename.empty()) {
    177             ASMOutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    178         } else {
     180        if (codegen::ASMOutputFilename) {
    179181            std::error_code error;
    180182            ASMOutputStream.reset(new raw_fd_ostream(codegen::ASMOutputFilename, error, sys::fs::OpenFlags::F_None));
     183        } else {
     184            ASMOutputStream.reset(new raw_fd_ostream(STDERR_FILENO, false, false));
    181185        }
    182186        if (LLVM_UNLIKELY(mTarget->addPassesToEmitFile(PM, *ASMOutputStream, TargetMachine::CGFT_AssemblyFile))) {
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.cpp

    r5474 r5486  
    1111#include <boost/container/flat_set.hpp>
    1212#include <boost/container/flat_map.hpp>
     13#include <llvm/Support/CommandLine.h>
    1314#include <kernels/kernel_builder.h>
    1415
     
    1920using namespace llvm;
    2021
     22// static cl::opt<bool> UseYield("yield", cl::desc("yield after waiting"), cl::init(false));
    2123
    2224template <typename Value>
     
    105107
    106108        BasicBlock * const segmentWait = BasicBlock::Create(iBuilder->getContext(), kernel->getName() + "Wait", threadFunc);
     109
     110        BasicBlock * segmentYield = segmentWait;
     111//        if (UseYield) {
     112//            segmentYield = BasicBlock::Create(iBuilder->getContext(), kernel->getName() + "Yield", threadFunc);
     113//        }
     114
    107115        iBuilder->CreateBr(segmentWait);
    108116
     
    120128
    121129        if (kernel->hasNoTerminateAttribute()) {
    122             iBuilder->CreateCondBr(ready, segmentLoopBody, segmentWait);
     130            iBuilder->CreateCondBr(ready, segmentLoopBody, segmentYield);
    123131        } else { // If the kernel was terminated in a previous segment then the pipeline is done.
    124132            BasicBlock * completionTest = BasicBlock::Create(iBuilder->getContext(), kernel->getName() + "Completed", threadFunc, 0);
    125133            BasicBlock * exitBlock = BasicBlock::Create(iBuilder->getContext(), kernel->getName() + "Exit", threadFunc, 0);
    126             iBuilder->CreateCondBr(ready, completionTest, segmentWait);
     134            iBuilder->CreateCondBr(ready, completionTest, segmentYield);
    127135
    128136            iBuilder->SetInsertPoint(completionTest);
     
    134142            iBuilder->CreateBr(exitThreadBlock);
    135143        }
     144
     145//        if (UseYield) {
     146//            // Yield the thread after waiting
     147//            iBuilder->SetInsertPoint(segmentYield);
     148//            iBuilder->CreatePThreadYield();
     149//            iBuilder->CreateBr(segmentWait);
     150//        }
    136151
    137152        // Execute the kernel segment
     
    171186        if (codegen::EnableCycleCounter) {
    172187            cycleCountEnd = iBuilder->CreateReadCycleCounter();
    173             //Value * counterPtr = iBuilder->CreateGEP(mCycleCounts, {iBuilder->getInt32(0), iBuilder->getInt32(k)});
    174188            Value * counterPtr = iBuilder->getScalarFieldPtr(Kernel::CYCLECOUNT_SCALAR);
    175189            iBuilder->CreateStore(iBuilder->CreateAdd(iBuilder->CreateLoad(counterPtr), iBuilder->CreateSub(cycleCountEnd, cycleCountStart)), counterPtr);
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5473 r5486  
    3131                        clEnumValEnd), cl::cat(CodeGenOptions));
    3232
    33 static cl::opt<std::string> IROutputFilenameOption("dump-generated-IR-output", cl::init(""),
     33static cl::opt<const char *> IROutputFilenameOption("dump-generated-IR-output", cl::init(nullptr),
    3434                                                       cl::desc("output IR filename"), cl::cat(CodeGenOptions));
    3535
    3636#ifndef USE_LLVM_3_6
    37 static cl::opt<std::string> ASMOutputFilenameOption("asm-output", cl::init(""),
     37static cl::opt<const char *> ASMOutputFilenameOption("asm-output", cl::init(nullptr),
    3838                                                    cl::desc("output ASM filename"), cl::cat(CodeGenOptions));
    3939
     
    4646
    4747
    48 static cl::opt<bool> EnableObjectCacheOption("enable-object-cache",
    49                                              cl::init(true), cl::desc("Enable object caching"), cl::cat(CodeGenOptions));
    50 
    51 static cl::opt<std::string> ObjectCacheDirOption("object-cache-dir",
    52                                                  cl::init(""), cl::desc("Path to the object cache diretory"), cl::cat(CodeGenOptions));
     48static cl::opt<bool, true> EnableObjectCacheOption("enable-object-cache", cl::location(EnableObjectCache), cl::init(true),
     49                                                   cl::desc("Enable object caching"), cl::cat(CodeGenOptions));
     50
     51static cl::opt<const char *> ObjectCacheDirOption("object-cache-dir", cl::init(nullptr),
     52                                                 cl::desc("Path to the object cache diretory"), cl::cat(CodeGenOptions));
    5353
    5454
     
    5757
    5858
    59 static cl::opt<int, true> SegmentSizeOption("segment-size", cl::location(SegmentSize),
    60                                             cl::desc("Segment Size"), cl::value_desc("positive integer"), cl::init(1));
     59static cl::opt<int, true> SegmentSizeOption("segment-size", cl::location(SegmentSize), cl::init(1),
     60                                            cl::desc("Segment Size"), cl::value_desc("positive integer"));
    6161
    6262static cl::opt<int, true> BufferSegmentsOption("buffer-segments", cl::location(BufferSegments), cl::init(1),
     
    6464
    6565
    66 static cl::opt<int, true> ThreadNumOption("thread-num", cl::location(ThreadNum), cl::init(2),
     66static cl::opt<int> ThreadNumOption("thread-num", cl::init(2),
    6767                                          cl::desc("Number of threads used for segment pipeline parallel"), cl::value_desc("positive integer"));
    6868
    6969
    7070static cl::opt<bool, true> EnableAssertsOption("ea", cl::location(EnableAsserts), cl::init(IN_DEBUG_MODE),
    71                                                cl::desc("Enable Asserts"));
     71                                               cl::desc("Enable Asserts"), cl::cat(CodeGenOptions));
    7272
    7373static cl::opt<bool, true> EnableCycleCountOption("ShowKernelCycles", cl::location(EnableCycleCounter), cl::init(false),
    74                                                   cl::desc("Count and report CPU cycles per kernel"), cl::cat(CodeGenOptions));
    75 
    76 static cl::opt<bool, true> pipelineParallelOption("enable-pipeline-parallel", cl::location(pipelineParallel),
     74                                             cl::desc("Count and report CPU cycles per kernel"), cl::cat(CodeGenOptions));
     75
     76static cl::opt<bool, true> pipelineParallelOption("enable-pipeline-parallel", cl::location(PipelineParallel), cl::init(false),
    7777                                                  cl::desc("Enable multithreading with pipeline parallelism."), cl::cat(CodeGenOptions));
    7878   
    79 static cl::opt<bool, true> segmentPipelineParallelOption("enable-segment-pipeline-parallel", cl::location(segmentPipelineParallel),
     79static cl::opt<bool, true> segmentPipelineParallelOption("enable-segment-pipeline-parallel", cl::location(SegmentPipelineParallel),
    8080                                                         cl::desc("Enable multithreading with segment pipeline parallelism."), cl::cat(CodeGenOptions));
    8181
    82 static cl::opt<bool> USENVPTX("NVPTX", cl::init(false),
    83                               cl::desc("Run on GPU only."));
     82static cl::opt<bool, true> NVPTXOption("NVPTX", cl::location(NVPTX), cl::init(false),
     83                                 cl::desc("Run on GPU only."), cl::cat(CodeGenOptions));
    8484
    8585static cl::opt<int, true> GroupNumOption("group-num", cl::location(GroupNum), cl::init(256),
    86                                          cl::desc("NUmber of groups declared on GPU"), cl::value_desc("positive integer"));
    87 
    88 
    89 const CodeGenOpt::Level OptLevel = [](const char optLevel) {
    90     switch (optLevel) {
    91         case '0': return CodeGenOpt::None;
    92         case '1': return CodeGenOpt::Less;
    93         case '2': return CodeGenOpt::Default;
    94         case '3': return CodeGenOpt::Aggressive;
    95         default: report_fatal_error(std::string(1,optLevel) + " is an invalid optimization level.");
    96     }
    97 }(OptLevelOption);
    98 
    99 bool pipelineParallel;
    100 bool segmentPipelineParallel;
    101 const std::string ASMOutputFilename = ASMOutputFilenameOption;
    102 const std::string IROutputFilename = IROutputFilenameOption;
    103 const std::string ObjectCacheDir = ObjectCacheDirOption;
     86                                         cl::desc("NUmber of groups declared on GPU"), cl::value_desc("positive integer"), cl::cat(CodeGenOptions));
     87
     88CodeGenOpt::Level OptLevel;
     89
     90bool PipelineParallel;
     91
     92bool SegmentPipelineParallel;
     93
     94const char * ASMOutputFilename;
     95
     96const char * IROutputFilename;
     97
     98const char * ObjectCacheDir;
     99
    104100int BlockSize;
     101
    105102int SegmentSize;
     103
    106104int BufferSegments;
     105
    107106int ThreadNum;
     107
    108108bool EnableAsserts;
     109
    109110bool EnableCycleCounter;
    110 const bool EnableObjectCache = EnableObjectCacheOption && (DebugOptions.getBits() == 0);
    111 bool NVPTX;
     111
     112bool EnableObjectCache;
     113
     114bool NVPTX = [](const bool nvptx) {
     115    #ifndef CUDA_ENABLED
     116    if (nvptx) {
     117        report_fatal_error("CUDA compiler is not supported.");
     118    }
     119    #endif
     120    return nvptx;
     121}(NVPTXOption);
     122
    112123int GroupNum;
    113124
    114125const llvm::Reloc::Model RelocModel = ::RelocModel;
     126
    115127const llvm::CodeModel::Model CMModel = ::CMModel;
     128
    116129const std::string MArch = ::MArch;
     130
    117131const std::string RunPass = ::RunPass;
     132
    118133const llvm::TargetMachine::CodeGenFileType FileType = ::FileType;
     134
    119135const std::string StopAfter = ::StopAfter;
     136
    120137const std::string StartAfter = ::StartAfter;
    121 #ifndef USE_LLVM_3_6
    122 const TargetOptions Options = [](const bool asmVerbose) {
    123     TargetOptions opt = InitTargetOptionsFromCodeGenFlags();
    124     opt.MCOptions.AsmVerbose = AsmVerbose;
    125     return opt;
    126 }(AsmVerbose);
    127 #else
    128 const TargetOptions Options = InitTargetOptionsFromCodeGenFlags();
    129 #endif
     138
     139TargetOptions Options;
    130140
    131141const cl::OptionCategory * codegen_flags() {
     
    149159}
    150160
    151 
    152 }
    153 
    154 void setNVPTXOption() {
    155     codegen::NVPTX = codegen::USENVPTX;
    156     if (codegen::NVPTX) {
    157         #ifndef CUDA_ENABLED
     161std::string ProgramName;
     162
     163void ParseCommandLineOptions(int argc, const char * const *argv, std::initializer_list<const cl::OptionCategory *> hiding) {
     164    AddParabixVersionPrinter();
     165    codegen::ProgramName = argv[0];
     166    #ifndef USE_LLVM_3_6
     167    if (hiding.size() != 0) {
     168        cl::HideUnrelatedOptions(ArrayRef<const cl::OptionCategory *>(hiding));
     169    }
     170    #endif
     171    cl::ParseCommandLineOptions(argc, argv);
     172    if (DebugOptions.getBits()) {
     173        EnableObjectCache = false;
     174    }
     175
     176    ThreadNum = (PipelineParallel || SegmentPipelineParallel) ? 2 : 1;
     177
     178    ObjectCacheDir = ObjectCacheDirOption;
     179    IROutputFilename = IROutputFilenameOption;
     180    ObjectCacheDir = ObjectCacheDirOption;
     181    Options = InitTargetOptionsFromCodeGenFlags();
     182    #ifndef USE_LLVM_3_6
     183    Options.MCOptions.AsmVerbose = AsmVerbose;
     184    #endif
     185    switch (OptLevelOption) {
     186        case '0': OptLevel = CodeGenOpt::None; break;
     187        case '1': OptLevel = CodeGenOpt::Less; break;
     188        case '2': OptLevel = CodeGenOpt::Default; break;
     189        case '3': OptLevel = CodeGenOpt::Aggressive; break;
     190        default: report_fatal_error(std::string(1, OptLevelOption) + " is an invalid optimization level.");
     191    }
     192    #ifndef CUDA_ENABLED
     193    if (NVPTX) {
    158194        report_fatal_error("CUDA compiler is not supported.");
    159         #endif
    160     }
     195    }
     196    #endif
     197}
     198
    161199}
    162200
    163201void printParabixVersion () {
    164     raw_ostream &OS = outs();
    165     OS << "Parabix (http://parabix.costar.sfu.ca/):\n  " << "Parabix revision " << PARABIX_VERSION << "\n";
     202    outs() << "Parabix (http://parabix.costar.sfu.ca/):\n  " << "Parabix revision " << PARABIX_VERSION << "\n";
    166203}
    167204
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.h

    r5464 r5486  
    3636bool DebugOptionIsSet(const DebugFlags flag);
    3737
    38 extern bool pipelineParallel;
    39 extern bool segmentPipelineParallel;
     38extern bool PipelineParallel;
     39extern bool SegmentPipelineParallel;
    4040#ifndef USE_LLVM_3_6
    41 extern const std::string ASMOutputFilename;
     41extern const char * ASMOutputFilename;
    4242#endif
    43 extern const std::string IROutputFilename;
    44 extern const std::string ObjectCacheDir;
    45 extern const llvm::CodeGenOpt::Level OptLevel;  // set from command line
     43extern const char * IROutputFilename;
     44extern const char * ObjectCacheDir;
     45extern llvm::CodeGenOpt::Level OptLevel;  // set from command line
    4646extern int BlockSize;  // set from command line
    4747extern int SegmentSize;  // set from command line
    4848extern int BufferSegments;
    4949extern int ThreadNum;
    50 extern const bool EnableObjectCache;
     50extern bool EnableObjectCache;
    5151extern bool EnableAsserts;
    5252extern bool EnableCycleCounter;
    5353extern bool NVPTX;
    5454extern int GroupNum;
    55 extern const llvm::TargetOptions Options;
     55extern std::string ProgramName;
     56extern llvm::TargetOptions Options;
    5657extern const llvm::Reloc::Model RelocModel;
    5758extern const llvm::CodeModel::Model CMModel;
     
    6667void setFunctionAttributes(llvm::StringRef CPU, llvm::StringRef Features, llvm::Module &M);
    6768
     69void ParseCommandLineOptions(int argc, const char *const *argv, std::initializer_list<const llvm::cl::OptionCategory *> hiding = {});
     70
    6871}
    69 
    70 
    71 void setNVPTXOption();
    7272
    7373void AddParabixVersionPrinter();
Note: See TracChangeset for help on using the changeset viewer.