MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
enzyme.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, 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 "../config/config.hpp"
13
14#ifndef MFEM_ENZYME_HPP
15#define MFEM_ENZYME_HPP
16
17#ifdef MFEM_USE_ENZYME
18/*
19 * Variables prefixed with enzyme_* or function types prefixed with __enzyme_*,
20 * are variables which will get preprocessed in the LLVM intermediate
21 * representation when the Enzyme LLVM plugin is loaded. See the Enzyme
22 * documentation (https://enzyme.mit.edu) for more information.
23 */
24
25extern int enzyme_dup;
26extern int enzyme_dupnoneed;
27extern int enzyme_out;
28extern int enzyme_const;
29extern int enzyme_interleave;
30
31#if defined(MFEM_USE_CUDA) || defined(MFEM_USE_HIP)
32#define MFEM_DEVICE_EXTERN_STMT(name) extern __device__ int name;
33#else
34#define MFEM_DEVICE_EXTERN_STMT(name)
35#endif
36
42
43// warning: if inlined, triggers function '__enzyme_autodiff' is not defined
44template <typename return_type, typename... Args>
45MFEM_HOST_DEVICE
46return_type __enzyme_autodiff(Args...);
47
48// warning: if inlined, triggers function '__enzyme_fwddiff' is not defined
49template <typename return_type, typename... Args>
50MFEM_HOST_DEVICE
51return_type __enzyme_fwddiff(Args...);
52
53#define MFEM_ENZYME_INACTIVENOFREE __attribute__((enzyme_inactive, enzyme_nofree))
54#define MFEM_ENZYME_INACTIVE __attribute__((enzyme_inactive))
55#define MFEM_ENZYME_FN_LIKE(x) __attribute__((enzyme_function_like(#x)))
56
57#else
58#define MFEM_ENZYME_INACTIVENOFREE
59#define MFEM_ENZYME_INACTIVE
60#define MFEM_ENZYME_FN_LIKE(x)
61#endif
62
63#define MFEM_ENZYME_FN_LIKE_FREE MFEM_ENZYME_FN_LIKE(free)
64#define MFEM_ENZYME_FN_LIKE_DYNCAST MFEM_ENZYME_FN_LIKE(__dynamic_cast)
65
66#endif
int enzyme_dup
MFEM_DEVICE_EXTERN_STMT(enzyme_dup) MFEM_DEVICE_EXTERN_STMT(enzyme_dupnoneed) MFEM_DEVICE_EXTERN_STMT(enzyme_out) MFEM_DEVICE_EXTERN_STMT(enzyme_const) MFEM_DEVICE_EXTERN_STMT(enzyme_interleave) template< typename return_type
int enzyme_dupnoneed
int enzyme_out
int enzyme_interleave
typename Args MFEM_HOST_DEVICE return_type __enzyme_autodiff(Args...)
MFEM_HOST_DEVICE return_type __enzyme_fwddiff(Args...)
int enzyme_const