| 34 | } // namespace |
| 35 | |
| 36 | Status KernelAttrsMatch(const KernelDef& kernel_def, AttrSlice attrs, |
| 37 | bool* match) { |
| 38 | *match = false; |
| 39 | for (const auto& constraint : kernel_def.constraint()) { |
| 40 | if (constraint.allowed_values().list().type_size() == 0) { |
| 41 | return errors::Unimplemented( |
| 42 | "KernelDef '", ProtoShortDebugString(kernel_def), |
| 43 | " has constraint on attr '", constraint.name(), |
| 44 | "' with unsupported type: ", |
| 45 | SummarizeAttrValue(constraint.allowed_values())); |
| 46 | } |
| 47 | |
| 48 | const AttrValue* found = attrs.Find(constraint.name()); |
| 49 | if (found) { |
| 50 | if (found->type() != DT_INVALID) { |
| 51 | if (!InTypeList(found->type(), constraint.allowed_values())) { |
| 52 | return Status::OK(); |
| 53 | } |
| 54 | } else { |
| 55 | if (!AttrValueHasType(*found, "list(type)").ok()) { |
| 56 | return errors::InvalidArgument( |
| 57 | "KernelDef '", ProtoShortDebugString(kernel_def), |
| 58 | "' has constraint on attr '", constraint.name(), |
| 59 | "' that has value '", SummarizeAttrValue(*found), |
| 60 | "' that does not have type 'type' or 'list(type)' in NodeDef " |
| 61 | "'", |
| 62 | attrs.SummarizeNode(), "'"); |
| 63 | } |
| 64 | |
| 65 | for (int t : found->list().type()) { |
| 66 | if (!InTypeList(static_cast<DataType>(t), |
| 67 | constraint.allowed_values())) { |
| 68 | return Status::OK(); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } else { |
| 73 | return errors::InvalidArgument( |
| 74 | "OpKernel '", kernel_def.op(), "' has constraint on attr '", |
| 75 | constraint.name(), "' not in NodeDef '", attrs.SummarizeNode(), |
| 76 | "', KernelDef: '", ProtoShortDebugString(kernel_def), "'"); |
| 77 | } |
| 78 | } |
| 79 | *match = true; |
| 80 | return Status::OK(); |
| 81 | } |
| 82 | |
| 83 | } // namespace tensorflow |