MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
simd.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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(__aarch64__) && defined(__ARM_FEATURE_SVE)
21#include "simd/sve.hpp"
22#elif defined(__VSX__)
23#include "simd/vsx.hpp"
24#elif defined (__bgq__)
25#include "simd/qpx.hpp"
26#elif defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86)
27#include "simd/x86.hpp"
28#elif !defined(_MSC_VER)
29#warning Unknown SIMD architecture
30#else
31#pragma message("warning: Unknown SIMD architecture")
32#endif
33#endif
34
35// MFEM_SIMD_BYTES is the default SIMD size used by MFEM, see e.g. class
36// TBilinearForm and the default traits class AutoSIMDTraits.
37// MFEM_ALIGN_BYTES determines the padding used in TVector when its 'align'
38// template parameter is set to true -- it ensures that the size of such TVector
39// types is a multiple of MFEM_ALIGN_BYTES. MFEM_ALIGN_BYTES must be a multiple
40// of MFEM_SIMD_BYTES.
41#if !defined(MFEM_USE_SIMD)
42#define MFEM_SIMD_BYTES 8
43#define MFEM_ALIGN_BYTES 32
44#elif defined(__AVX512F__)
45#define MFEM_SIMD_BYTES 64
46#define MFEM_ALIGN_BYTES 64
47#elif defined(__aarch64__) && defined(__ARM_FEATURE_SVE)
48#define MFEM_SIMD_BYTES 64
49#define MFEM_ALIGN_BYTES 64
50#elif defined(__AVX__) || defined(__VECTOR4DOUBLE__)
51#define MFEM_SIMD_BYTES 32
52#define MFEM_ALIGN_BYTES 32
53#elif defined(__SSE2__) || defined(__VSX__)
54#define MFEM_SIMD_BYTES 16
55#define MFEM_ALIGN_BYTES 32
56#else
57#define MFEM_SIMD_BYTES 8
58#define MFEM_ALIGN_BYTES 32
59#endif
60
61// derived macros
62#define MFEM_ROUNDUP(val,base) ((((val)+(base)-1)/(base))*(base))
63#define MFEM_ALIGN_SIZE(size,type) \
64 MFEM_ROUNDUP(size,(MFEM_ALIGN_BYTES)/sizeof(type))
65
66namespace mfem
67{
68
69template<typename complex_t, typename real_t>
71{
72 static const int block_size = MFEM_TEMPLATE_BLOCK_SIZE;
73
74 // Alignment for arrays of vcomplex_t and vreal_t
75 static const int align_bytes = MFEM_SIMD_BYTES;
76
77 static const int batch_size = 1;
78
79 static const int simd_size = MFEM_SIMD_BYTES/sizeof(real_t);
80
83 typedef AutoSIMD<int, simd_size, simd_size*sizeof(int)> vint_t;
84};
85
86template<typename complex_t, typename real_t>
88{
89 static const int block_size = MFEM_TEMPLATE_BLOCK_SIZE;
90
91 // Alignment for arrays of vcomplex_t and vreal_t
92 static const int align_bytes = sizeof(real_t);
93
94 static const int batch_size = 1;
95
96 static const int simd_size = 1;
97
100 typedef AutoSIMD<int, simd_size, simd_size*sizeof(int)> vint_t;
101};
102
103} // mfem namespace
104
105#endif // MFEM_SIMD_HPP
float real_t
Definition config.hpp:43
static const int align_bytes
Definition simd.hpp:75
static const int simd_size
Definition simd.hpp:79
AutoSIMD< complex_t, simd_size, MFEM_SIMD_BYTES > vcomplex_t
Definition simd.hpp:81
static const int block_size
Definition simd.hpp:72
static const int batch_size
Definition simd.hpp:77
AutoSIMD< real_t, simd_size, MFEM_SIMD_BYTES > vreal_t
Definition simd.hpp:82
static const int block_size
Definition simd.hpp:89
AutoSIMD< real_t, simd_size, align_bytes > vreal_t
Definition simd.hpp:99
static const int align_bytes
Definition simd.hpp:92
static const int simd_size
Definition simd.hpp:96
static const int batch_size
Definition simd.hpp:94
AutoSIMD< complex_t, simd_size, align_bytes > vcomplex_t
Definition simd.hpp:98