Ignore:
Timestamp:
Dec 3, 2017, 12:40:40 PM (21 months ago)
Author:
nmedfort
Message:

Bug fixes and simplified MultiBlockKernel? logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.cpp

    r5734 r5755  
    1616
    1717using namespace kernel;
     18using namespace llvm;
     19
     20struct Features {
     21    bool hasAVX;
     22    bool hasAVX2;
     23    Features() : hasAVX(0), hasAVX2(0) { }
     24};
     25
     26Features getHostCPUFeatures() {
     27    Features hostCPUFeatures;
     28    StringMap<bool> features;
     29    if (sys::getHostCPUFeatures(features)) {
     30        hostCPUFeatures.hasAVX = features.count("avx");
     31        hostCPUFeatures.hasAVX2 = features.count("avx2");
     32    }
     33    return hostCPUFeatures;
     34}
     35
     36bool AVX2_available() {
     37    StringMap<bool> features;
     38    if (sys::getHostCPUFeatures(features)) {
     39        return features.count("avx2");
     40    }
     41    return false;
     42}
    1843
    1944namespace IDISA {
    2045   
    2146KernelBuilder * GetIDISA_Builder(llvm::LLVMContext & C) {
    22     const bool hasAVX2 = AVX2_available();
     47    const auto hostCPUFeatures = getHostCPUFeatures();
    2348    if (LLVM_LIKELY(codegen::BlockSize == 0)) {  // No BlockSize override: use processor SIMD width
    24         codegen::BlockSize = hasAVX2 ? 256 : 128;
     49        codegen::BlockSize = hostCPUFeatures.hasAVX2 ? 256 : 128;
    2550    }
    2651    else if (((codegen::BlockSize & (codegen::BlockSize - 1)) != 0) || (codegen::BlockSize < 64)) {
    2752        llvm::report_fatal_error("BlockSize must be a power of 2 and >=64");
    2853    }
    29     if (codegen::BlockSize >= 256) {
    30         if (hasAVX2) {
     54    if (codegen::BlockSize >= 128) {
     55        if (hostCPUFeatures.hasAVX2) {
    3156            return new KernelBuilderImpl<IDISA_AVX2_Builder>(C, codegen::BlockSize, codegen::BlockSize);
     57        } else if (hostCPUFeatures.hasAVX) {
     58            return new KernelBuilderImpl<IDISA_AVX_Builder>(C, codegen::BlockSize, codegen::BlockSize);
    3259        }
    3360    } else if (codegen::BlockSize == 64) {
Note: See TracChangeset for help on using the changeset viewer.