| 167 | namespace { |
| 168 | |
| 169 | class UserOpExprInferContext : public user_op::InferContext { |
| 170 | public: |
| 171 | UserOpExprInferContext(const UserOpExpr* user_op_expr, const AttrMap& attrs, |
| 172 | const std::string& device_tag, |
| 173 | const std::function<const TensorMeta*(int32_t)>& TensorMeta4InputIndex, |
| 174 | const std::function<TensorMeta*(int32_t)>& TensorMeta4OutputIndex) |
| 175 | : user_op_expr_(user_op_expr), |
| 176 | composed_attrs_(attrs, user_op_expr->base_attrs()), |
| 177 | tensor_meta4input_index_(TensorMeta4InputIndex), |
| 178 | tensor_meta4output_index_(TensorMeta4OutputIndex) { |
| 179 | loc_ = DispatchFrame::get_str(); |
| 180 | } |
| 181 | virtual ~UserOpExprInferContext() override = default; |
| 182 | |
| 183 | const std::vector<std::pair<std::string, int32_t>>& inputs() const override { |
| 184 | return user_op_expr_->indexed_input_pairs(); |
| 185 | } |
| 186 | |
| 187 | const std::vector<std::pair<std::string, int32_t>>& outputs() const override { |
| 188 | return user_op_expr_->indexed_output_pairs(); |
| 189 | } |
| 190 | |
| 191 | const user_op::TensorDesc& InputTensorDesc(const std::string& arg_name, |
| 192 | int32_t index) const override { |
| 193 | return *TensorDesc4ArgNameAndIndex(arg_name, index); |
| 194 | } |
| 195 | const user_op::TensorDesc& OutputTensorDesc(const std::string& arg_name, |
| 196 | int32_t index) const override { |
| 197 | return *TensorDesc4ArgNameAndIndex(arg_name, index); |
| 198 | } |
| 199 | user_op::TensorDesc* MutOutputTensorDesc(const std::string& name, int32_t index) override { |
| 200 | return MutTensorDesc4ArgNameAndIndex(name, index); |
| 201 | } |
| 202 | |
| 203 | const user_op::TensorDesc* TensorDesc4ArgNameAndIndex(const std::string& name, |
| 204 | int32_t index) const { |
| 205 | { |
| 206 | const auto& arg_tuple = *user_op_expr_->output_arg_tuple(); |
| 207 | int32_t tuple_index = arg_tuple.TensorTupleIndex4ArgNameAndIndex(name, index); |
| 208 | if (tuple_index >= 0) { return tensor_meta4output_index_(tuple_index); } |
| 209 | } |
| 210 | { |
| 211 | const auto& arg_tuple = *user_op_expr_->input_arg_tuple(); |
| 212 | int32_t tuple_index = arg_tuple.TensorTupleIndex4ArgNameAndIndex(name, index); |
| 213 | if (tuple_index >= 0) { return tensor_meta4input_index_(tuple_index); } |
| 214 | } |
| 215 | return nullptr; |
| 216 | } |
| 217 | |
| 218 | user_op::TensorDesc* MutTensorDesc4ArgNameAndIndex(const std::string& name, int32_t index) { |
| 219 | { |
| 220 | const auto& arg_tuple = *user_op_expr_->output_arg_tuple(); |
| 221 | int32_t tuple_index = arg_tuple.TensorTupleIndex4ArgNameAndIndex(name, index); |
| 222 | if (tuple_index >= 0) { |
| 223 | TensorMeta* tensor_meta_ptr = tensor_meta4output_index_(tuple_index); |
| 224 | CHECK_NOTNULL(dynamic_cast<MutTensorMeta*>(tensor_meta_ptr)); |
| 225 | return tensor_meta_ptr; |
| 226 | } |
nothing calls this directly
no test coverage detected