1 /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 // This is the side effect definition file for TensorFlow. 17 #ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_IR_TF_SIDE_EFFECTS_H_ 18 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_IR_TF_SIDE_EFFECTS_H_ 19 20 #include "mlir/Interfaces/SideEffectInterfaces.h" // from @llvm-project 21 22 namespace mlir { 23 namespace TF { 24 namespace ResourceEffects { 25 26 struct Variable : ::mlir::SideEffects::Resource::Base<Variable> { getNameVariable27 StringRef getName() final { return "Variable"; } 28 }; 29 30 struct Stack : ::mlir::SideEffects::Resource::Base<Stack> { getNameStack31 StringRef getName() final { return "Stack"; } 32 }; 33 34 struct TensorArray : ::mlir::SideEffects::Resource::Base<TensorArray> { getNameTensorArray35 StringRef getName() final { return "TensorArray"; } 36 }; 37 38 struct Summary : ::mlir::SideEffects::Resource::Base<Summary> { getNameSummary39 StringRef getName() final { return "Summary"; } 40 }; 41 42 struct LookupTable : ::mlir::SideEffects::Resource::Base<LookupTable> { getNameLookupTable43 StringRef getName() final { return "LookupTable"; } 44 }; 45 46 struct DatasetSeedGenerator 47 : ::mlir::SideEffects::Resource::Base<DatasetSeedGenerator> { getNameDatasetSeedGenerator48 StringRef getName() final { return "DatasetSeedGenerator"; } 49 }; 50 51 struct DatasetMemoryCache 52 : ::mlir::SideEffects::Resource::Base<DatasetMemoryCache> { getNameDatasetMemoryCache53 StringRef getName() final { return "DatasetMemoryCache"; } 54 }; 55 56 struct DatasetIterator : ::mlir::SideEffects::Resource::Base<DatasetIterator> { getNameDatasetIterator57 StringRef getName() final { return "DatasetIterator"; } 58 }; 59 60 // Special resource type to track TPU Embedding specific ops, which must execute 61 // but do not have side effects with one another or with resource variable ops. 62 struct TPUEmbedding : ::mlir::SideEffects::Resource::Base<TPUEmbedding> { getNameTPUEmbedding63 StringRef getName() final { return "TPUEmbedding"; } 64 }; 65 66 // Resource corresponding to GeneratorOp. 67 struct GeneratorOp : public ::mlir::SideEffects::Resource::Base<GeneratorOp> { getNameGeneratorOp68 StringRef getName() final { return "Generator"; } 69 }; 70 71 struct Send : public ::mlir::SideEffects::Resource::Base<Send> { getNameSend72 StringRef getName() final { return "Send"; } 73 }; 74 75 struct Recv : public ::mlir::SideEffects::Resource::Base<Recv> { getNameRecv76 StringRef getName() final { return "Recv"; } 77 }; 78 79 struct XlaHostCompute 80 : public ::mlir::SideEffects::Resource::Base<XlaHostCompute> { getNameXlaHostCompute81 StringRef getName() final { return "XlaHostCompute"; } 82 }; 83 84 struct RandomGenerator 85 : public ::mlir::SideEffects::Resource::Base<RandomGenerator> { getNameRandomGenerator86 StringRef getName() final { return "RandomGenerator"; } 87 }; 88 89 struct TPUExecute : public ::mlir::SideEffects::Resource::Base<TPUExecute> { getNameTPUExecute90 StringRef getName() final { return "TPUExecute"; } 91 }; 92 93 struct MustExecute : public ::mlir::SideEffects::Resource::Base<MustExecute> { getNameMustExecute94 StringRef getName() final { return "MustExecute"; } 95 }; 96 97 struct CollectiveReduceOrdering 98 : public ::mlir::SideEffects::Resource::Base<CollectiveReduceOrdering> { getNameCollectiveReduceOrdering99 StringRef getName() final { return "CollectiveReduceOrdering"; } 100 }; 101 102 // Returns true iff resource type with given ID is only self-dependent, i.e., 103 // there are no dependencies to other resource types (including unknown resource 104 // type). IsOnlySelfDependent(TypeID resource_type_id)105inline bool IsOnlySelfDependent(TypeID resource_type_id) { 106 return resource_type_id == ResourceEffects::Send::getResourceID() || 107 resource_type_id == ResourceEffects::Recv::getResourceID(); 108 } 109 110 } // namespace ResourceEffects 111 } // namespace TF 112 } // namespace mlir 113 114 #endif // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_IR_TF_SIDE_EFFECTS_H_ 115