source: icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.cpp @ 5755

Last change on this file since 5755 was 5755, checked in by nmedfort, 16 months ago

Bug fixes and simplified MultiBlockKernel? logic

File size: 2.3 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5
6#include "idisa_target.h"
7#include <toolchain/toolchain.h>
8#include <IR_Gen/idisa_sse_builder.h>
9#include <IR_Gen/idisa_avx_builder.h>
10#include <IR_Gen/idisa_i64_builder.h>
11#include <IR_Gen/idisa_nvptx_builder.h>
12#include <llvm/IR/Module.h>
13#include <llvm/ADT/Triple.h>
14#include <llvm/Support/ErrorHandling.h>
15#include <kernels/kernel_builder.h>
16
17using 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}
43
44namespace IDISA {
45   
46KernelBuilder * GetIDISA_Builder(llvm::LLVMContext & C) {
47    const auto hostCPUFeatures = getHostCPUFeatures();
48    if (LLVM_LIKELY(codegen::BlockSize == 0)) {  // No BlockSize override: use processor SIMD width
49        codegen::BlockSize = hostCPUFeatures.hasAVX2 ? 256 : 128;
50    }
51    else if (((codegen::BlockSize & (codegen::BlockSize - 1)) != 0) || (codegen::BlockSize < 64)) {
52        llvm::report_fatal_error("BlockSize must be a power of 2 and >=64");
53    }
54    if (codegen::BlockSize >= 128) {
55        if (hostCPUFeatures.hasAVX2) {
56            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);
59        }
60    } else if (codegen::BlockSize == 64) {
61        return new KernelBuilderImpl<IDISA_I64_Builder>(C, codegen::BlockSize, codegen::BlockSize);
62    }
63    return new KernelBuilderImpl<IDISA_SSE2_Builder>(C, codegen::BlockSize, codegen::BlockSize);
64}
65#ifdef CUDA_ENABLED
66KernelBuilder * GetIDISA_GPU_Builder(llvm::LLVMContext & C) {
67    return new KernelBuilderImpl<IDISA_NVPTX20_Builder>(C, 64, 64 * 64);
68}
69#endif
70}
Note: See TracBrowser for help on using the repository browser.