MFEM  v4.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, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
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
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
[device] OCCA CUDA backend. Enabled when MFEM_USE_OCCA = YES and MFEM_USE_CUDA = YES.
Definition: device.hpp:54
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:204