MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
simd.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef MFEM_SIMD_HPP
13 #define MFEM_SIMD_HPP
14 
15 #include "../config/tconfig.hpp"
16 
17 // --- AutoSIMD + specializations with intrinsics
18 #include "simd/auto.hpp"
19 #ifdef MFEM_USE_SIMD
20 #if defined(__VSX__)
21 #include "simd/vsx.hpp"
22 #elif defined (__bgq__)
23 #include "simd/qpx.hpp"
24 #elif defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86)
25 #include "simd/x86.hpp"
26 #elif !defined(_MSC_VER)
27 #warning Unknown SIMD architecture
28 #else
29 #pragma message("warning: Unknown SIMD architecture")
30 #endif
31 #endif
32 
33 // MFEM_SIMD_BYTES is the default SIMD size used by MFEM, see e.g. class
34 // TBilinearForm and the default traits class AutoSIMDTraits.
35 // MFEM_ALIGN_BYTES determines the padding used in TVector when its 'align'
36 // template parameter is set to true -- it ensues that the size of such TVector
37 // types is a multiple of MFEM_ALIGN_BYTES. MFEM_ALIGN_BYTES must be a multiple
38 // of MFEM_SIMD_BYTES.
39 #if !defined(MFEM_USE_SIMD)
40 #define MFEM_SIMD_BYTES 8
41 #define MFEM_ALIGN_BYTES 32
42 #elif defined(__AVX512F__)
43 #define MFEM_SIMD_BYTES 64
44 #define MFEM_ALIGN_BYTES 64
45 #elif defined(__AVX__) || defined(__VECTOR4DOUBLE__)
46 #define MFEM_SIMD_BYTES 32
47 #define MFEM_ALIGN_BYTES 32
48 #elif defined(__SSE2__) || defined(__VSX__)
49 #define MFEM_SIMD_BYTES 16
50 #define MFEM_ALIGN_BYTES 32
51 #else
52 #define MFEM_SIMD_BYTES 8
53 #define MFEM_ALIGN_BYTES 32
54 #endif
55 
56 // derived macros
57 #define MFEM_ROUNDUP(val,base) ((((val)+(base)-1)/(base))*(base))
58 #define MFEM_ALIGN_SIZE(size,type) \
59  MFEM_ROUNDUP(size,(MFEM_ALIGN_BYTES)/sizeof(type))
60 
61 namespace mfem
62 {
63 
64 template<typename complex_t, typename real_t>
66 {
67  static const int block_size = MFEM_TEMPLATE_BLOCK_SIZE;
68 
69  // Alignment for arrays of vcomplex_t and vreal_t
70  static const int align_bytes = MFEM_SIMD_BYTES;
71 
72  static const int batch_size = 1;
73 
74  static const int simd_size = MFEM_SIMD_BYTES/sizeof(real_t);
75 
76  typedef AutoSIMD<complex_t, simd_size, MFEM_SIMD_BYTES> vcomplex_t;
77  typedef AutoSIMD<real_t, simd_size, MFEM_SIMD_BYTES> vreal_t;
78  typedef AutoSIMD<int, simd_size, simd_size*sizeof(int)> vint_t;
79 };
80 
81 template<typename complex_t, typename real_t>
83 {
84  static const int block_size = MFEM_TEMPLATE_BLOCK_SIZE;
85 
86  // Alignment for arrays of vcomplex_t and vreal_t
87  static const int align_bytes = sizeof(real_t);
88 
89  static const int batch_size = 1;
90 
91  static const int simd_size = 1;
92 
93  typedef AutoSIMD<complex_t, simd_size, align_bytes> vcomplex_t;
94  typedef AutoSIMD<real_t, simd_size, align_bytes> vreal_t;
95  typedef AutoSIMD<int, simd_size, simd_size*sizeof(int)> vint_t;
96 };
97 
98 } // mfem namespace
99 
100 #endif // MFEM_SIMD_HPP
static const int simd_size
Definition: simd.hpp:91
AutoSIMD< complex_t, simd_size, align_bytes > vcomplex_t
Definition: simd.hpp:93
static const int batch_size
Definition: simd.hpp:89
static const int align_bytes
Definition: simd.hpp:70
AutoSIMD< real_t, simd_size, align_bytes > vreal_t
Definition: simd.hpp:94
static const int batch_size
Definition: simd.hpp:72
static const int block_size
Definition: simd.hpp:67
AutoSIMD< int, simd_size, simd_size *sizeof(int)> vint_t
Definition: simd.hpp:95
AutoSIMD< int, simd_size, simd_size *sizeof(int)> vint_t
Definition: simd.hpp:78
static const int block_size
Definition: simd.hpp:84
static const int simd_size
Definition: simd.hpp:74
AutoSIMD< real_t, simd_size, MFEM_SIMD_BYTES > vreal_t
Definition: simd.hpp:77
static const int align_bytes
Definition: simd.hpp:87
AutoSIMD< complex_t, simd_size, MFEM_SIMD_BYTES > vcomplex_t
Definition: simd.hpp:76