MFEM  v4.3.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
backends.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2021, 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_BACKENDS_HPP
13 #define MFEM_BACKENDS_HPP
14 
15 #include "../config/config.hpp"
16 
17 #ifdef MFEM_USE_CUDA
18 #include <cusparse.h>
19 #include <library_types.h>
20 #include <cuda_runtime.h>
21 #include <cuda.h>
22 #endif
23 #include "cuda.hpp"
24 
25 #ifdef MFEM_USE_HIP
26 #include <hip/hip_runtime.h>
27 #endif
28 #include "hip.hpp"
29 
30 #ifdef MFEM_USE_OCCA
31 #include "occa.hpp"
32 #endif
33 
34 #ifdef MFEM_USE_RAJA
35 #include "RAJA/RAJA.hpp"
36 #if defined(RAJA_ENABLE_CUDA) && !defined(MFEM_USE_CUDA)
37 #error When RAJA is built with CUDA, MFEM_USE_CUDA=YES is required
38 #endif
39 #endif
40 
41 #if !(defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP))
42 #define MFEM_DEVICE
43 #define MFEM_LAMBDA
44 #define MFEM_HOST_DEVICE
45 // MFEM_DEVICE_SYNC is made available for debugging purposes
46 #define MFEM_DEVICE_SYNC
47 // MFEM_STREAM_SYNC is used for UVM and MPI GPU-Aware kernels
48 #define MFEM_STREAM_SYNC
49 #endif
50 
51 #if !((defined(MFEM_USE_CUDA) && defined(__CUDA_ARCH__)) || \
52  (defined(MFEM_USE_HIP) && defined(__HIP_DEVICE_COMPILE__)))
53 #define MFEM_SHARED
54 #define MFEM_SYNC_THREAD
55 #define MFEM_BLOCK_ID(k) 0
56 #define MFEM_THREAD_ID(k) 0
57 #define MFEM_THREAD_SIZE(k) 1
58 #define MFEM_FOREACH_THREAD(i,k,N) for(int i=0; i<N; i++)
59 #endif
60 
61 template <typename T>
62 MFEM_HOST_DEVICE T AtomicAdd(T &add, const T val)
63 {
64 #if ((defined(MFEM_USE_CUDA) && defined(__CUDA_ARCH__)) || \
65  (defined(MFEM_USE_HIP) && defined(__HIP_DEVICE_COMPILE__)))
66  return atomicAdd(&add,val);
67 #else
68  T old = add;
69  add += val;
70  return old;
71 #endif
72 }
73 
74 #endif // MFEM_BACKENDS_HPP
MFEM_HOST_DEVICE T AtomicAdd(T &add, const T val)
Definition: backends.hpp:62
void add(const Vector &v1, const Vector &v2, Vector &v)
Definition: vector.cpp:291