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

Last change on this file since 5756 was 5756, checked in by cameron, 16 months ago

idisa_target bug fix, eliminate braces around scalar initializer warning, disable lz4d_test

File size: 2.4 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 <llvm/Support/raw_ostream.h>
16#include <kernels/kernel_builder.h>
17
18using namespace kernel;
19using namespace llvm;
20
21struct Features {
22    bool hasAVX;
23    bool hasAVX2;
24    Features() : hasAVX(0), hasAVX2(0) { }
25};
26
27Features getHostCPUFeatures() {
28    Features hostCPUFeatures;
29    StringMap<bool> features;
30    if (sys::getHostCPUFeatures(features)) {
31        hostCPUFeatures.hasAVX = features.lookup("avx");
32        hostCPUFeatures.hasAVX2 = features.lookup("avx2");
33    }
34    return hostCPUFeatures;
35}
36
37bool AVX2_available() {
38    StringMap<bool> features;
39    if (sys::getHostCPUFeatures(features)) {
40        return features.lookup("avx2");
41    }
42    return false;
43}
44
45namespace IDISA {
46   
47KernelBuilder * GetIDISA_Builder(llvm::LLVMContext & C) {
48    const auto hostCPUFeatures = getHostCPUFeatures();
49    if (LLVM_LIKELY(codegen::BlockSize == 0)) {  // No BlockSize override: use processor SIMD width
50       
51        codegen::BlockSize = hostCPUFeatures.hasAVX2 ? 256 : 128;
52    }
53    else if (((codegen::BlockSize & (codegen::BlockSize - 1)) != 0) || (codegen::BlockSize < 64)) {
54        llvm::report_fatal_error("BlockSize must be a power of 2 and >=64");
55    }
56    if (codegen::BlockSize >= 256) {
57        // AVX2 or AVX builders can only be used for BlockSize multiples of 256
58        if (hostCPUFeatures.hasAVX2) {
59            return new KernelBuilderImpl<IDISA_AVX2_Builder>(C, codegen::BlockSize, codegen::BlockSize);
60        } else if (hostCPUFeatures.hasAVX) {
61            return new KernelBuilderImpl<IDISA_AVX_Builder>(C, codegen::BlockSize, codegen::BlockSize);
62        }
63    } else if (codegen::BlockSize == 64) {
64        return new KernelBuilderImpl<IDISA_I64_Builder>(C, codegen::BlockSize, codegen::BlockSize);
65    }
66    return new KernelBuilderImpl<IDISA_SSE2_Builder>(C, codegen::BlockSize, codegen::BlockSize);
67}
68#ifdef CUDA_ENABLED
69KernelBuilder * GetIDISA_GPU_Builder(llvm::LLVMContext & C) {
70    return new KernelBuilderImpl<IDISA_NVPTX20_Builder>(C, 64, 64 * 64);
71}
72#endif
73}
Note: See TracBrowser for help on using the repository browser.