MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
occa.cpp
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#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
21namespace mfem
22{
23
24// This variable is defined in device.cpp:
25namespace internal { extern occa::device occaDevice; }
26
27occa::device &OccaDev() { return internal::occaDevice; }
28
29occa::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
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:259
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
@ OCCA_CUDA
[device] OCCA CUDA backend. Enabled when MFEM_USE_OCCA = YES and MFEM_USE_CUDA = YES.
Definition device.hpp:60