| 98 | }; |
| 99 | |
| 100 | struct KernelKeyParser : ArgsIterator<KernelKeyParser> { |
| 101 | KernelKeySet key_set; |
| 102 | bool disable_gpudnn = false; |
| 103 | // this dtype_set is used for cache multi-inputs dtype and used for |
| 104 | // data_promote |
| 105 | DataTypeSet dtype_set{DataType::UNDEFINED}; |
| 106 | |
| 107 | inline void AssignKernelKeySet(const phi::TensorBase& tensor) { |
| 108 | // assign Backend |
| 109 | BackendSet tensor_backend_set = detail::GetTensorBackendSet(tensor); |
| 110 | key_set.backend_set = key_set.backend_set | tensor_backend_set; |
| 111 | // tensor's attribute use_gpudnn=False, explicitly disable gpudnn kernel |
| 112 | if (tensor_backend_set == |
| 113 | BackendSet(paddle::experimental::get_accelerat_backend()) || |
| 114 | disable_gpudnn) { |
| 115 | disable_gpudnn = true; |
| 116 | key_set.backend_set = key_set.backend_set - BackendSet(Backend::GPUDNN); |
| 117 | VLOG(8) << "Disable kernel backend: GPUDNN"; |
| 118 | } |
| 119 | // assign DataLayout |
| 120 | phi::DataLayout tensor_layout = tensor.layout(); |
| 121 | key_set.layout = |
| 122 | tensor_layout > key_set.layout ? tensor_layout : key_set.layout; |
| 123 | // assign DataType |
| 124 | key_set.dtype = tensor.dtype(); |
| 125 | dtype_set = dtype_set | DataTypeSet(key_set.dtype); |
| 126 | auto promote_result = PromoteTypes(dtype_set); |
| 127 | if (promote_result != DataType::UNDEFINED) { |
| 128 | key_set.dtype = promote_result; |
| 129 | VLOG(8) << "promote kernel DataType:" << promote_result; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void operator()(const Tensor& x) { |
| 134 | const auto* tensor = x.impl().get(); |
| 135 | if (tensor) { |
| 136 | AssignKernelKeySet(*tensor); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | void operator()(const std::vector<Tensor>& x) { |
| 141 | if (!x.empty()) { |
| 142 | const phi::TensorBase& tensor = *x.at(0).impl(); |
| 143 | AssignKernelKeySet(tensor); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void operator()(const paddle::optional<Tensor>& x) { |
| 148 | if (x) { |
| 149 | const phi::TensorBase& tensor = *(x.get_ptr()->impl()); |
| 150 | AssignKernelKeySet(tensor); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | // skip other type args, these args don't used in kernel selection |
| 155 | template <typename T> |
| 156 | void operator()(const T& x) { |
| 157 | // do nothing |
no outgoing calls
no test coverage detected