MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
occa.cpp
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 #include "occa.hpp"
13 
14 #ifdef MFEM_USE_OCCA
15 #include "device.hpp"
16 
17 #if defined(MFEM_USE_CUDA) && OCCA_CUDA_ENABLED
18 #include <occa/modes/cuda/utils.hpp>
19 #endif
20 
21 namespace mfem
22 {
23 
24 // This variable is defined in device.cpp:
25 namespace internal { extern occa::device occaDevice; }
26 
27 occa::device &OccaDev() { return internal::occaDevice; }
28 
29 occa::memory OccaMemoryWrap(void *ptr, std::size_t bytes)
30 {
31 #if defined(MFEM_USE_CUDA) && OCCA_CUDA_ENABLED
32  // If OCCA_CUDA is allowed, it will be used since it has the highest priority
34  {
35  return occa::cuda::wrapMemory(internal::occaDevice, ptr, bytes);
36  }
37 #endif // MFEM_USE_CUDA && OCCA_CUDA_ENABLED
38  // otherwise, fallback to occa::cpu address space
39  return occa::cpu::wrapMemory(internal::occaDevice, ptr, bytes);
40 }
41 
42 } // namespace mfem
43 
44 #endif // MFEM_USE_OCCA
[device] OCCA CUDA backend. Enabled when MFEM_USE_OCCA = YES and MFEM_USE_CUDA = YES.
Definition: device.hpp:56
occa::memory OccaMemoryWrap(void *ptr, std::size_t bytes)
Wrap a pointer as occa::memory with the default occa::device used by MFEM.
Definition: occa.cpp:29
occa::device & OccaDev()
Return the default occa::device used by MFEM.
Definition: occa.cpp:27
static bool Allows(unsigned long b_mask)
Return true if any of the backends in the backend mask, b_mask, are allowed.
Definition: device.hpp:246