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