@@ -586,41 +586,49 @@ std::function<void(xir::OpDef&)> BroadcastOpDefGenerator(
586586 return [=](xir::OpDef& op_def) {
587587 auto input = xir::OpArgDef{" input" , OpArgDef::REQUIRED_AND_REPEATED, T,
588588 " The feature maps, can be x-dimension." };
589- op_def.add_input_arg (input).set_annotation (
590- " We support broadcasting operations:\n\n "
591- " \" add\" : input[0] + input[1]\n "
592- " \" sub\" : input[0] - input[1]\n "
593- " \" mul\" : input[0] * input[1]\n "
594- " \" div\" : input[0] / input[1]\n "
595- " \" min\" : min(input[0], input[1])\n "
596- " \" max\" : max(input[0], input[1])\n "
597- " What is broadcasting?\n\n "
598- " When operating on two arrays, we compare their shapes element-wise. \n "
599- " It starts with the trailing dimensions, and works its way forward.\n\n "
600- " Two dimensions are compatible when:\n\n "
601- " 1. they are equal, or\n "
602- " 2. one of them is 1\n "
603- " If these conditions are not met, a mismatch would be thrown, \n "
604- " indicating that the arrays have incompatible shapes. \n "
605- " The size of the resulting array is the maximum size \n "
606- " along each dimension of the input arrays.\n "
607- " For example,\n\n "
608- " (1). bias_add, which is a channel-wise operation:\n\n "
609- " input[0] (4d tensor): 1 x 112 x 112 x 64\n "
610- " input[1] (1d tensor): 64\n "
611- " result (4d tensor): 1 x 112 x 112 x 64\n "
612- " (2). element-wise add, which is an element-wise operation:\n\n "
613- " input[0] (3d tensor): 32 x 32 x 10\n "
614- " input[1] (3d tensor): 32 x 32 x 10\n "
615- " result (3d tensor): 32 x 32 x 10\n "
616- " (3). more examples:\n\n "
617- " input[0] (4d tensor): 1 x 32 x 32 x 10\n "
618- " input[1] (3d tensor): 32 x 1 x 1\n "
619- " result (4d tensor): 1 x 32 x 32 x 10\n "
620- " (4). mismatched examples:\n\n "
621- " input[0] (4d tensor): 1 x 32 x 32 x 10\n "
622- " input[1] (3d tensor): 1 x 32 x 2\n "
623- " result : mismatch\n " );
589+ op_def.add_input_arg (input)
590+ .set_annotation (
591+ " We support broadcasting operations:\n\n "
592+ " \" add\" : input[0] + input[1]\n "
593+ " \" sub\" : input[0] - input[1]\n "
594+ " \" mul\" : input[0] * input[1]\n "
595+ " \" div\" : input[0] / input[1]\n "
596+ " \" min\" : min(input[0], input[1])\n "
597+ " \" max\" : max(input[0], input[1])\n "
598+ " What is broadcasting?\n\n "
599+ " When operating on two arrays, we compare their shapes "
600+ " element-wise. \n "
601+ " It starts with the trailing dimensions, and works its way "
602+ " forward.\n\n "
603+ " Two dimensions are compatible when:\n\n "
604+ " 1. they are equal, or\n "
605+ " 2. one of them is 1\n "
606+ " If these conditions are not met, a mismatch would be thrown, \n "
607+ " indicating that the arrays have incompatible shapes. \n "
608+ " The size of the resulting array is the maximum size \n "
609+ " along each dimension of the input arrays.\n "
610+ " For example,\n\n "
611+ " (1). bias_add, which is a channel-wise operation:\n\n "
612+ " input[0] (4d tensor): 1 x 112 x 112 x 64\n "
613+ " input[1] (1d tensor): 64\n "
614+ " result (4d tensor): 1 x 112 x 112 x 64\n "
615+ " (2). element-wise add, which is an element-wise operation:\n\n "
616+ " input[0] (3d tensor): 32 x 32 x 10\n "
617+ " input[1] (3d tensor): 32 x 32 x 10\n "
618+ " result (3d tensor): 32 x 32 x 10\n "
619+ " (3). more examples:\n\n "
620+ " input[0] (4d tensor): 1 x 32 x 32 x 10\n "
621+ " input[1] (3d tensor): 32 x 1 x 1\n "
622+ " result (4d tensor): 1 x 32 x 32 x 10\n "
623+ " (4). mismatched examples:\n\n "
624+ " input[0] (4d tensor): 1 x 32 x 32 x 10\n "
625+ " input[1] (3d tensor): 1 x 32 x 2\n "
626+ " result : mismatch\n " )
627+ .add_constraint ([](xir::Op* op) {
628+ UNI_LOG_CHECK (op->get_input_num () > 1 , XIR_INVALID_ARG_OCCUR)
629+ << op->to_string () << " only has " << op->get_input_num ()
630+ << " input arguments, but it requires at least 2 inputs." ;
631+ });
624632 };
625633}
626634
@@ -1509,10 +1517,16 @@ auto eltwise_fix =
15091517 " The feature maps, can be x-dimension. "
15101518 " eltwise-fix operator implements element-wise add." })
15111519 .add_attr(xir::AttrDefBuilder<std::string>::build(
1512- " nonlinear" , AttrDef::REQUIRED ,
1520+ " nonlinear" , AttrDef::OPTIONAL ,
15131521 " `Datatype`: `string`\n\n "
15141522 " nonlinear type, \" NONE\" , \" RELU\" , \" PRELU\" , "
1515- " \" LEAKYRELU\" ,\" RELU6\" ." ))
1523+ " \" LEAKYRELU\" ,\" RELU6\" . Default is \" NONE\" " ,
1524+ " NONE" ))
1525+ .add_attr(xir::AttrDefBuilder<std::string>::build(
1526+ " type" , AttrDef::OPTIONAL,
1527+ " `Datatype`: `string`\n\n "
1528+ " eltwise type, \" ADD\" , \" MUL\" . Default is \" ADD\" " ,
1529+ " ADD" ))
15161530 .set_shape_infer(xir::shape_infer_eltwise_fix);
15171531
15181532XIR_REGISTER_BUILT_IN_OP (eltwise_fix);
0 commit comments