@@ -39,11 +39,7 @@ void CompilationConfigNode::VisitAttrs(AttrVisitor* v) {
3939}
4040
4141Target CompilationConfigNode::FindPrimitiveTargetOrFail (DLDeviceType device_type) const {
42- if (device_type < 0 && primitive_targets.size () == 1 ) {
43- // In the homogenous case don't be fussy with device types.
44- return primitive_targets.front ();
45- }
46- ICHECK_GT (device_type, 0 );
42+ ICHECK_GT (device_type, 0 ) << " Invalid device type" ;
4743 auto itr = std::find_if (
4844 primitive_targets.begin (), primitive_targets.end (),
4945 [device_type](const Target& target) { return target->kind ->device_type == device_type; });
@@ -144,6 +140,8 @@ void CompilationConfigNode::Init(const transform::PassContext& pass_ctx,
144140
145141 //
146142 // Check the primitive_targets are ordered correctly re Target::IsExternalCodegenFor.
143+ // Note we could just sort the list, but given all the implicit defaulting for backwards
144+ // compat it seems we should avoid making this any more magical than necessarny.
147145 //
148146 std::unordered_set<DLDeviceType> primitive_target_device_types;
149147 for (const auto & target : primitive_targets) {
@@ -157,13 +155,18 @@ void CompilationConfigNode::Init(const transform::PassContext& pass_ctx,
157155 }
158156 if (!first_primitive_target.defined ()) {
159157 first_primitive_target = current_primitive_target;
160- continue ;
158+ CHECK (!first_primitive_target.IsExternalCodegen ())
159+ << " The first given target for device type " << device_type
160+ << " must not be for an external codegen, however given "
161+ << first_primitive_target->ToDebugString ();
162+ } else {
163+ CHECK (current_primitive_target.IsExternalCodegenFor (first_primitive_target))
164+ << " When given multiple targets for the device type " << device_type
165+ << " the first must be for non external codegen, and all subsequent must be for "
166+ " external codegen. However have been given first "
167+ << first_primitive_target->ToDebugString () << " and subsequent "
168+ << current_primitive_target->ToDebugString ();
161169 }
162- CHECK (current_primitive_target.IsExternalCodegenFor (first_primitive_target))
163- << " The first given target for device type " << device_type << " is "
164- << first_primitive_target->ToDebugString () << " , however a later target "
165- << current_primitive_target->ToDebugString ()
166- << " for the same device type is not an external codegen target." ;
167170 }
168171 }
169172
0 commit comments