Enzyme main
Loading...
Searching...
No Matches
GradientUtilsReverse.h
Go to the documentation of this file.
1//===- GradientUtilsReverse.h - Utilities for gradient interfaces -------* C++
2//-*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef ENZYME_MLIR_INTERFACES_GRADIENT_UTILS_REVERSE_H
11#define ENZYME_MLIR_INTERFACES_GRADIENT_UTILS_REVERSE_H
12
13#include "mlir/IR/IRMapping.h"
14#include "mlir/Interfaces/FunctionInterfaces.h"
15
17#include "CloneFunction.h"
18#include "EnzymeLogic.h"
19
20#include <functional>
21
22#include "GradientUtils.h"
23
24namespace mlir {
25namespace enzyme {
26
28public:
29 MGradientUtilsReverse(MEnzymeLogic &Logic, FunctionOpInterface newFunc_,
30 FunctionOpInterface oldFunc_, MTypeAnalysis &TA_,
31 IRMapping invertedPointers_,
32 const llvm::ArrayRef<bool> returnPrimals,
33 const llvm::ArrayRef<bool> returnShadows,
34 const SmallPtrSetImpl<mlir::Value> &constantvalues_,
35 const SmallPtrSetImpl<mlir::Value> &activevals_,
36 ArrayRef<DIFFE_TYPE> ReturnActivity,
37 ArrayRef<DIFFE_TYPE> ArgDiffeTypes_,
38 IRMapping &originalToNewFn_,
39 std::map<Operation *, Operation *> &originalToNewFnOps_,
40 DerivativeMode mode_, unsigned width, bool omp,
41 llvm::StringRef postpasses, bool verifyPostPasses,
42 bool strongZero);
43
45
46 void addToDiffe(mlir::Value oldGradient, mlir::Value addedGradient,
47 OpBuilder &builder);
48
49 Type getIndexType();
50 Value insertInit(Type t);
51
52 SmallVector<std::function<std::pair<Value, Value>(Type)>> cacheCreatorHook;
53 void
54 registerCacheCreatorHook(std::function<std::pair<Value, Value>(Type)> hook);
55 void
56 deregisterCacheCreatorHook(std::function<std::pair<Value, Value>(Type)> hook);
57 std::pair<Value, Value> getNewCache(Type t);
58
59 // Cache
60 Type getCacheType(Type t);
61 Type getIndexCacheType();
62 Value initAndPushCache(Value v, OpBuilder &builder);
63
64 Operation *cloneWithNewOperands(OpBuilder &B, Operation *op);
65
66 Value popCache(Value cache, OpBuilder &builder);
67
68 void createReverseModeBlocks(Region &oldFunc, Region &newFunc);
69
71 MEnzymeLogic &Logic, DerivativeMode mode_, unsigned width,
72 FunctionOpInterface todiff, MTypeAnalysis &TA, MFnTypeInfo &oldTypeInfo,
73 const ArrayRef<bool> returnPrimals, const ArrayRef<bool> returnShadows,
74 llvm::ArrayRef<DIFFE_TYPE> retType,
75 llvm::ArrayRef<DIFFE_TYPE> constant_args, mlir::Type additionalArg,
76 bool omp, llvm::StringRef postpasses, bool verifyPostPasses,
77 bool strongZero);
78};
79
80} // namespace enzyme
81} // namespace mlir
82
83#endif // ENZYME_MLIR_INTERFACES_GRADIENT_UTILS_REVERSE_H
DerivativeMode
Definition Utils.h:524
Value popCache(Value cache, OpBuilder &builder)
SmallVector< std::function< std::pair< Value, Value >(Type)> > cacheCreatorHook
Value initAndPushCache(Value v, OpBuilder &builder)
MGradientUtilsReverse(MEnzymeLogic &Logic, FunctionOpInterface newFunc_, FunctionOpInterface oldFunc_, MTypeAnalysis &TA_, IRMapping invertedPointers_, const llvm::ArrayRef< bool > returnPrimals, const llvm::ArrayRef< bool > returnShadows, const SmallPtrSetImpl< mlir::Value > &constantvalues_, const SmallPtrSetImpl< mlir::Value > &activevals_, ArrayRef< DIFFE_TYPE > ReturnActivity, ArrayRef< DIFFE_TYPE > ArgDiffeTypes_, IRMapping &originalToNewFn_, std::map< Operation *, Operation * > &originalToNewFnOps_, DerivativeMode mode_, unsigned width, bool omp, llvm::StringRef postpasses, bool verifyPostPasses, bool strongZero)
void createReverseModeBlocks(Region &oldFunc, Region &newFunc)
void deregisterCacheCreatorHook(std::function< std::pair< Value, Value >(Type)> hook)
void registerCacheCreatorHook(std::function< std::pair< Value, Value >(Type)> hook)
void addToDiffe(mlir::Value oldGradient, mlir::Value addedGradient, OpBuilder &builder)
static MGradientUtilsReverse * CreateFromClone(MEnzymeLogic &Logic, DerivativeMode mode_, unsigned width, FunctionOpInterface todiff, MTypeAnalysis &TA, MFnTypeInfo &oldTypeInfo, const ArrayRef< bool > returnPrimals, const ArrayRef< bool > returnShadows, llvm::ArrayRef< DIFFE_TYPE > retType, llvm::ArrayRef< DIFFE_TYPE > constant_args, mlir::Type additionalArg, bool omp, llvm::StringRef postpasses, bool verifyPostPasses, bool strongZero)
std::pair< Value, Value > getNewCache(Type t)
Operation * cloneWithNewOperands(OpBuilder &B, Operation *op)
const llvm::ArrayRef< bool > returnShadows
const llvm::ArrayRef< bool > returnPrimals
FunctionOpInterface oldFunc
FunctionOpInterface newFunc