You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ascend_control_parser.cc 39 kB

adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
5 years ago
5 years ago
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
5 years ago
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
adapte to remove inline merge me commit for remove inline deal witch multiple cases of switch in ConstructKernelGraph deal with switch and call cases in ConstructKernelGraph fix bug and rebase master ConstructKernelGraph adapte to remove inline fix InsertMultipleAssignToGraph bug add graph input to new graph which is created for switch input replace CreateNewParameterFromCNode to NewParameter in order to set new parameter's abstract and kernel_info avoids create a new switch repeatedly when the cnode is a call switch without real input null pointer check update frontend code Revert "update frontend code" This reverts commit ce1f600d1e9b4b47d9b81122f981bbbe505dd250. update frontend code PR_2948 fix bug of CheckLabalIndex handle switch_layer in ConstructKernelGraph add attr for assign node to avoid erasing by cse pass cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem rebase master Revert "cherry-pick ms commit[59b35f690ddcc94ff35a4f4eaf3816121b32235b]:temporary avoid list getitem problem" This reverts commit 74c258f94260ca0769a1ef69c6ef8e831c301dbf. Revert "handle switch_layer in ConstructKernelGraph" This reverts commit cb5367f02d69facbca8d39e9234c501608aee27f. Revert "update frontend code PR_2948" This reverts commit 234ac583400a96a8ddd641f7a722e1ccd5e056c6. Revert "merge me commit for remove inline" This reverts commit 55c0ebd42b6699c7686f5ce585e745f87dd42280. fix diff after rebase master doing remove inline in me overwrite FindNodePrimitive Revert "doing remove inline in me" This reverts commit b42e893125bc624d323e855ac6ae615333c06e65.
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "backend/session/ascend_control_parser.h"
  17. #include <utility>
  18. #include <memory>
  19. #include <algorithm>
  20. #include <string>
  21. #include "backend/session/anf_runtime_algorithm.h"
  22. #include "utils/union_find_set.h"
  23. #include "runtime/device/ascend/ascend_label_assign.h"
  24. #include "utils/ms_context.h"
  25. #include "debug/anf_ir_dump.h"
  26. static constexpr size_t kCNodePrim = 0;
  27. static constexpr size_t kCNodeCallArg = 1;
  28. static constexpr size_t kCNodeSwitchCond = 1;
  29. static constexpr size_t kCNodeSwitchTrue = 2;
  30. static constexpr size_t kCNodeSwitchFalse = 3;
  31. static constexpr size_t kCNodeSwitchLength = 4;
  32. static constexpr size_t kCNodePartialLength = 2;
  33. static constexpr size_t kCNodePartialFunc = 1;
  34. static constexpr size_t kCNodeSwitchLayerBranch = 2;
  35. static constexpr size_t kCNodeSwitchLayerLength = 3;
  36. static constexpr size_t kCNodeAssignTarget = 1;
  37. static constexpr size_t kCNodeAssignSource = 2;
  38. namespace mindspore {
  39. namespace session {
  40. static void RecursiveReplaceNode(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> main_parameter,
  41. const std::set<AnfNodePtr> &parameter_reuse_set,
  42. const NotNull<std::set<KernelGraphPtr> *> memo) {
  43. if (parameter_reuse_set.empty()) {
  44. MS_LOG(EXCEPTION) << "Parameter_reuse_set is empty.";
  45. }
  46. if (memo->find(kg.get()) != memo->end()) {
  47. return;
  48. }
  49. memo->insert(kg.get());
  50. for (auto &para : parameter_reuse_set) {
  51. if (para == main_parameter.get()) {
  52. continue;
  53. }
  54. MS_EXCEPTION_IF_NULL(para);
  55. MS_LOG(INFO) << "In " << kg->ToString() << " replace " << para->DebugString() << " of graph "
  56. << AnfAlgo::GetGraphId(para.get()) << " to " << main_parameter->DebugString() << " of graph "
  57. << AnfAlgo::GetGraphId(main_parameter.get().get());
  58. kg->ReplaceNode(NOT_NULL(para), main_parameter);
  59. }
  60. for (auto &child : kg->child_graph_order()) {
  61. RecursiveReplaceNode(NOT_NULL(child), main_parameter, parameter_reuse_set, memo);
  62. }
  63. }
  64. static AnfNodePtr GetMainParameter(NotNull<KernelGraphPtr> root_kg, const AnfNodePtr &key,
  65. const std::set<AnfNodePtr> &parameter_reuse_set) {
  66. AnfNodePtr main_parameter = key;
  67. std::set<AnfNodePtr> root_inputs_set;
  68. const auto &root_inputs_vector = root_kg->inputs();
  69. root_inputs_set.insert(root_inputs_vector.begin(), root_inputs_vector.end());
  70. for (auto &node : parameter_reuse_set) {
  71. if (root_inputs_set.find(node) != root_inputs_set.end()) {
  72. main_parameter = node;
  73. break;
  74. }
  75. }
  76. return main_parameter;
  77. }
  78. static void ReuseParameter(NotNull<KernelGraphPtr> root_kg,
  79. const std::vector<std::pair<AnfNodePtr, AnfNodePtr>> &link_list) {
  80. // make union find set
  81. UnionFindSet<AnfNodePtr> union_find_set;
  82. for (auto &[param, arg] : link_list) {
  83. union_find_set.Add(param);
  84. union_find_set.Add(arg);
  85. }
  86. for (auto &[param, arg] : link_list) {
  87. union_find_set.Union(param, arg);
  88. }
  89. auto parameter_reuse_sets = union_find_set.GetSets();
  90. for (auto &[key, parameter_reuse_set] : parameter_reuse_sets) {
  91. if (parameter_reuse_set.size() <= 1) {
  92. continue;
  93. }
  94. auto main_parameter = GetMainParameter(root_kg, key, parameter_reuse_set);
  95. std::set<KernelGraphPtr> memo;
  96. RecursiveReplaceNode(root_kg, NOT_NULL(main_parameter), parameter_reuse_set, NOT_NULL(&memo));
  97. }
  98. }
  99. static CNodePtr GetNextRealKernel(const std::vector<CNodePtr> &list, size_t start) {
  100. for (size_t i = start; i < list.size() - 1; ++i) {
  101. if (AnfAlgo::IsRealKernel(list[i])) {
  102. return list[i];
  103. }
  104. }
  105. return nullptr;
  106. }
  107. static void UpdateLabelIdToLabelSetMap(const std::vector<CNodePtr> &exec_order,
  108. const NotNull<std::map<uint32_t, CNodePtr> *> label_id_to_label_set) {
  109. for (auto &node : exec_order) {
  110. MS_EXCEPTION_IF_NULL(node);
  111. if (!IsPrimitiveCNode(node, prim::kPrimLabelSet)) {
  112. continue;
  113. }
  114. if (!AnfAlgo::HasNodeAttr(kAttrLabelIndex, node)) {
  115. MS_LOG(EXCEPTION) << node->DebugString() << " has no attr kAttrLabelIndex";
  116. }
  117. uint32_t label_id = AnfAlgo::GetNodeAttr<uint32_t>(node, kAttrLabelIndex);
  118. if (auto iter = label_id_to_label_set->find(label_id); iter != label_id_to_label_set->end()) {
  119. MS_LOG(EXCEPTION) << "There are more than one node has same label id " << label_id
  120. << ", node: " << iter->second->DebugString() << " and " << node->DebugString();
  121. }
  122. (*label_id_to_label_set)[label_id] = node;
  123. }
  124. }
  125. static std::vector<CNodePtr> GetTargetLabelSetNodes(NotNull<CNodePtr> jump_node,
  126. const std::map<uint32_t, CNodePtr> &label_id_to_label_set) {
  127. std::vector<uint32_t> target_label_list;
  128. std::vector<CNodePtr> target_labelset_nodes;
  129. if (IsPrimitiveCNode(jump_node.get(), prim::kPrimLabelGoto)) {
  130. if (!AnfAlgo::HasNodeAttr(kAttrLabelIndex, jump_node)) {
  131. MS_LOG(EXCEPTION) << jump_node->DebugString() << " has no attr kAttrLabelIndex";
  132. }
  133. uint32_t label_id = AnfAlgo::GetNodeAttr<uint32_t>(jump_node.get(), kAttrLabelIndex);
  134. target_label_list.push_back(label_id);
  135. } else if (IsPrimitiveCNode(jump_node.get(), prim::kPrimLabelSwitch)) {
  136. if (!AnfAlgo::HasNodeAttr(kAttrLabelSwitchList, jump_node)) {
  137. MS_LOG(EXCEPTION) << jump_node->DebugString() << " has no attr kPrimLabelSwitch";
  138. }
  139. target_label_list = AnfAlgo::GetNodeAttr<std::vector<uint32_t>>(jump_node.get(), kAttrLabelSwitchList);
  140. } else {
  141. MS_LOG(EXCEPTION) << "Unknown type jump node " << jump_node->DebugString();
  142. }
  143. for (auto label_id : target_label_list) {
  144. auto iter = label_id_to_label_set.find(label_id);
  145. if (iter == label_id_to_label_set.end()) {
  146. MS_LOG(EXCEPTION) << "Connot find LabelSet node has label id " << label_id;
  147. }
  148. target_labelset_nodes.push_back(iter->second);
  149. }
  150. return target_labelset_nodes;
  151. }
  152. static void EraseNodeFromExecOrder(const AnfNodePtr &node, const NotNull<std::vector<CNodePtr> *> exec_order) {
  153. MS_EXCEPTION_IF_NULL(node);
  154. auto exec_iter = std::find(exec_order->begin(), exec_order->end(), node);
  155. if (exec_iter == exec_order->end()) {
  156. MS_LOG(EXCEPTION) << "Cannot find " << node->DebugString() << " in exec order.";
  157. }
  158. exec_order->erase(exec_iter);
  159. }
  160. void AscendControlParser::AttachChildGraphToReturnNode(NotNull<KernelGraphPtr> graph,
  161. const NotNull<std::set<KernelGraphPtr> *> memo) {
  162. if (memo->find(graph) != memo->end()) {
  163. return;
  164. }
  165. memo->insert(graph.get());
  166. const std::vector<std::shared_ptr<KernelGraph>> &child_graph_order = graph->child_graph_order();
  167. if (child_graph_order.empty()) {
  168. return;
  169. }
  170. std::vector<AnfNodePtr> depend_inputs = {NewValueNode(std::make_shared<Primitive>(prim::kPrimPartial->name()))};
  171. for (auto &cg : child_graph_order) {
  172. MS_EXCEPTION_IF_NULL(cg);
  173. auto fg = cg->cast<FuncGraphPtr>();
  174. MS_EXCEPTION_IF_NULL(fg);
  175. depend_inputs.emplace_back(NewValueNode(fg));
  176. AttachChildGraphToReturnNode(NOT_NULL(cg), memo);
  177. }
  178. auto child_graphs = graph->NewCNode(depend_inputs);
  179. InsertDependToGraph(graph, NOT_NULL(child_graphs));
  180. }
  181. void AscendControlParser::LinkGraph(NotNull<KernelGraphPtr> kg) {
  182. std::set<KernelGraphPtr> memo;
  183. std::vector<std::pair<AnfNodePtr, AnfNodePtr>> link_list;
  184. // Insert Assign
  185. ChildGraphDataAssign(kg, NOT_NULL(&link_list), NOT_NULL(&memo));
  186. memo.clear();
  187. // Reuse Parameter
  188. ReuseParameter(kg, link_list);
  189. // replace call by label goto / label switch
  190. (void)ProcessKernelGraph(kg, nullptr, nullptr, NOT_NULL(&memo));
  191. memo.clear();
  192. // assign label resource
  193. device::ascend::AscendLabelAssign::GetInstance().AssignLabel(kg);
  194. AttachChildGraphToReturnNode(kg, NOT_NULL(&memo));
  195. }
  196. void AscendControlParser::EraseParameter(NotNull<KernelGraphPtr> root_graph,
  197. const std::set<KernelGraphPtr> &graph_list) {
  198. std::vector<CNodePtr> exec_order = root_graph->execution_order();
  199. std::set<CNodePtr> search_list(exec_order.begin(), exec_order.end());
  200. std::set<AnfNodePtr> root_inputs(root_graph->inputs().begin(), root_graph->inputs().end());
  201. auto ref_map = root_graph->GetRefMap();
  202. ReferenceCounter parameter_count([](int32_t read, int32_t write) -> bool { return write == 1; });
  203. std::multimap<AnfNodePtr, std::tuple<size_t, AnfNodePtr, size_t>> ref_multimap;
  204. std::transform(ref_map.begin(), ref_map.end(), std::inserter(ref_multimap, ref_multimap.end()),
  205. [](const std::pair<std::pair<AnfNodePtr, size_t>, std::pair<AnfNodePtr, size_t>> &p)
  206. -> std::pair<AnfNodePtr, std::tuple<size_t, AnfNodePtr, size_t>> {
  207. return {p.first.first, {p.first.second, p.second.first, p.second.second}};
  208. });
  209. std::set<CNodePtr> all_nodes;
  210. std::map<AnfNodePtr, CNodePtr> para_to_written_node;
  211. for (auto &graph : graph_list) {
  212. auto out = graph->get_return();
  213. MS_EXCEPTION_IF_NULL(out);
  214. search_list.insert(out->cast<CNodePtr>());
  215. auto nodes = TopoSort(out);
  216. for (auto &node : nodes) {
  217. MS_EXCEPTION_IF_NULL(node);
  218. auto cnode = node->cast<CNodePtr>();
  219. if (cnode != nullptr) {
  220. all_nodes.insert(cnode);
  221. }
  222. }
  223. }
  224. // prepare referance count
  225. for (auto &node : search_list) {
  226. MS_EXCEPTION_IF_NULL(node);
  227. // if assign node
  228. std::set<AnfNodePtr> refed_parameters;
  229. for (auto [iter, end] = ref_multimap.equal_range(node); iter != end; ++iter) {
  230. refed_parameters.insert(std::get<1>(iter->second));
  231. }
  232. for (auto &in : node->inputs()) {
  233. auto visit_node = AnfAlgo::VisitKernelWithReturnType(in, 0).first;
  234. if (!visit_node->isa<Parameter>() || root_inputs.find(visit_node) != root_inputs.end()) {
  235. continue;
  236. }
  237. if (refed_parameters.find(visit_node) != refed_parameters.end()) {
  238. parameter_count.AddWriteCount(visit_node, 1);
  239. para_to_written_node[visit_node] = node;
  240. } else {
  241. parameter_count.AddReadCount(visit_node, 1);
  242. }
  243. }
  244. }
  245. EraseAssign(std::make_shared<ReferenceCounter>(parameter_count), all_nodes, para_to_written_node, root_graph);
  246. }
  247. void AscendControlParser::EraseAssign(std::shared_ptr<ReferenceCounter> parameter_count,
  248. const std::set<CNodePtr> &all_nodes,
  249. const std::map<AnfNodePtr, CNodePtr> &para_to_written_node,
  250. NotNull<KernelGraphPtr> root_graph) {
  251. std::vector<CNodePtr> exec_order = root_graph->execution_order();
  252. while (parameter_count->HasValidElem()) {
  253. auto [para, read, written] = parameter_count->GetOneValidElem();
  254. MS_LOG(INFO) << para->DebugString() << " was read " << read << " times, written " << written << " times.";
  255. auto assign_iter = para_to_written_node.find(para);
  256. if (assign_iter == para_to_written_node.end()) {
  257. MS_LOG(EXCEPTION) << "Cannot find assign node that write " << para->DebugString();
  258. }
  259. auto &assign_node = assign_iter->second;
  260. MS_EXCEPTION_IF_NULL(assign_node);
  261. if (!IsPrimitiveCNode(assign_node, prim::kPrimAssign)) {
  262. parameter_count->EraseElem(para);
  263. continue;
  264. }
  265. MS_LOG(INFO) << "Erase " << assign_node->DebugString(5);
  266. EraseNodeFromExecOrder(assign_node, NOT_NULL(&exec_order));
  267. auto source = assign_node->input(kCNodeAssignSource);
  268. MS_EXCEPTION_IF_NULL(source);
  269. auto visit_source = AnfAlgo::VisitKernelWithReturnType(source, 0).first;
  270. parameter_count->AddWriteCount(para, -1);
  271. parameter_count->AddReadCount(para, -1);
  272. if (visit_source->isa<Parameter>()) {
  273. parameter_count->AddReadCount(visit_source, read - 1);
  274. }
  275. for (auto &node : all_nodes) {
  276. for (size_t i = 0; i < node->size(); ++i) {
  277. if (node->input(i) == para) {
  278. MS_LOG_INFO << "Replace " << node->DebugString() << " input " << i << " by " << source->DebugString();
  279. node->set_input(i, source);
  280. }
  281. }
  282. }
  283. }
  284. root_graph->set_execution_order(exec_order);
  285. }
  286. void AscendControlParser::EraseLabel(NotNull<KernelGraphPtr> root_graph) {
  287. std::vector<CNodePtr> exec_order = root_graph->execution_order();
  288. ReferenceCounter label_count([](int32_t read, int32_t write) -> bool { return read <= 1; });
  289. std::map<AnfNodePtr, CNodePtr> label_to_written_node;
  290. std::map<uint32_t, CNodePtr> label_id_to_label_set;
  291. UpdateLabelIdToLabelSetMap(exec_order, NOT_NULL(&label_id_to_label_set));
  292. CNodePtr last_node = nullptr;
  293. for (auto &cur_node : exec_order) {
  294. MS_EXCEPTION_IF_NULL(cur_node);
  295. if (AnfAlgo::IsCondControlKernel(cur_node)) {
  296. std::vector<CNodePtr> target_labelset_nodes = GetTargetLabelSetNodes(NOT_NULL(cur_node), label_id_to_label_set);
  297. for (auto &label_set : target_labelset_nodes) {
  298. label_count.AddReadCount(label_set, 1);
  299. label_to_written_node[label_set] = cur_node;
  300. }
  301. } else if (IsPrimitiveCNode(cur_node, prim::kPrimLabelSet)) {
  302. label_count.AddWriteCount(cur_node, 1);
  303. if (last_node != nullptr && !AnfAlgo::IsCondControlKernel(last_node)) {
  304. label_count.AddReadCount(cur_node, 1);
  305. label_to_written_node[cur_node] = last_node;
  306. }
  307. }
  308. last_node = cur_node;
  309. }
  310. while (label_count.HasValidElem()) {
  311. auto [label_set, read, written] = label_count.GetOneValidElem();
  312. MS_LOG(INFO) << label_set->DebugString() << " was read " << read << " times, written " << written << " times.";
  313. auto iter = label_to_written_node.find(label_set);
  314. if (read > 0 && iter == label_to_written_node.end()) {
  315. MS_LOG(EXCEPTION) << "Cannot find node jump to " << label_set->DebugString();
  316. }
  317. CNodePtr jump_node = read > 0 ? iter->second : nullptr;
  318. if (jump_node == nullptr || IsPrimitiveCNode(jump_node, prim::kPrimLabelGoto)) {
  319. MS_LOG(INFO) << "Erase node " << label_set->DebugString();
  320. EraseNodeFromExecOrder(label_set, NOT_NULL(&exec_order));
  321. }
  322. if (jump_node != nullptr && IsPrimitiveCNode(jump_node, prim::kPrimLabelGoto)) {
  323. MS_LOG(INFO) << "Erase node " << jump_node->DebugString();
  324. EraseNodeFromExecOrder(jump_node, NOT_NULL(&exec_order));
  325. }
  326. label_count.EraseElem(label_set);
  327. }
  328. root_graph->set_execution_order(exec_order);
  329. }
  330. void AscendControlParser::ExecutorValidate(NotNull<KernelGraphPtr> root_graph) {
  331. std::set<KernelGraphPtr> memo;
  332. (void)RecurseGraph(root_graph, NOT_NULL(&memo));
  333. EraseParameter(root_graph, memo);
  334. EraseLabel(root_graph);
  335. auto context_ptr = MsContext::GetInstance();
  336. MS_EXCEPTION_IF_NULL(context_ptr);
  337. auto save_graphs_path = context_ptr->save_graphs_path();
  338. if (save_graphs_path.empty()) {
  339. save_graphs_path = ".";
  340. }
  341. if (context_ptr->save_graphs_flag()) {
  342. std::string file_path = save_graphs_path + "/after_erase_label_and_parameter.ir";
  343. DumpIR(file_path, root_graph.get());
  344. }
  345. }
  346. std::vector<std::pair<KernelGraphPtr, std::vector<AnfNodePtr>>> AscendControlParser::ParseCallSwitchNode(
  347. NotNull<CNodePtr> cnode) {
  348. std::vector<std::pair<KernelGraphPtr, std::vector<AnfNodePtr>>> ret;
  349. if (IsPrimitiveCNode(cnode.get(), prim::kPrimCall)) {
  350. if (cnode->size() <= kCNodeCallArg) {
  351. MS_LOG(EXCEPTION) << "Call node " << cnode->DebugString() << " has invalid inputs size " << cnode->size();
  352. }
  353. auto call_arg = cnode->input(kCNodeCallArg);
  354. MS_EXCEPTION_IF_NULL(call_arg);
  355. ret.emplace_back(GetValueNode<KernelGraphPtr>(call_arg),
  356. std::vector<AnfNodePtr>(cnode->inputs().begin() + kCNodeCallArg + 1, cnode->inputs().end()));
  357. } else if (IsPrimitiveCNode(cnode.get(), prim::kPrimSwitch)) {
  358. const std::vector<AnfNodePtr> &switch_inputs = cnode->inputs();
  359. if (switch_inputs.size() < kCNodeSwitchLength) {
  360. MS_LOG(EXCEPTION) << "Switch node " << cnode->DebugString() << " has invalid inputs size "
  361. << switch_inputs.size();
  362. }
  363. for (auto iter = switch_inputs.begin() + kCNodeSwitchCond + 1; iter != switch_inputs.end(); ++iter) {
  364. const auto &[target_graph, args] = ParsePartial(NOT_NULL(*iter));
  365. ret.emplace_back(target_graph, args);
  366. }
  367. } else {
  368. MS_LOG(EXCEPTION) << "Unsupported call node: " << cnode->DebugString(5);
  369. }
  370. return ret;
  371. }
  372. void AscendControlParser::ChildGraphDataAssign(
  373. NotNull<KernelGraphPtr> kg, const NotNull<std::vector<std::pair<AnfNodePtr, AnfNodePtr>> *> link_list,
  374. const NotNull<std::set<KernelGraphPtr> *> memo) {
  375. if (memo->find(kg) != memo->end()) {
  376. return;
  377. }
  378. memo->insert(kg.get());
  379. MS_LOG(INFO) << "Start link data for " << kg->ToString();
  380. const std::vector<CNodePtr> &nodes = kg->execution_order();
  381. for (auto &node : nodes) {
  382. if (!(IsPrimitiveCNode(node, prim::kPrimCall) || IsPrimitiveCNode(node, prim::kPrimSwitch))) {
  383. continue;
  384. }
  385. auto child_graph_list = ParseCallSwitchNode(NOT_NULL(node));
  386. for (auto &[child_graph, args] : child_graph_list) {
  387. MS_EXCEPTION_IF_NULL(child_graph);
  388. const std::vector<AnfNodePtr> &params = child_graph->inputs();
  389. if (args.size() != params.size()) {
  390. MS_LOG(EXCEPTION) << child_graph->ToString() << " needs " << params.size() << " inputs but call node "
  391. << node->DebugString(5) << " gives " << args.size();
  392. }
  393. for (size_t i = 0; i < args.size(); ++i) {
  394. InsertMultipleAssignToGraph(kg, node, NOT_NULL(args[i]), NOT_NULL(params[i]));
  395. }
  396. }
  397. }
  398. kg->SetExecOrderByDefault();
  399. for (auto &child_graph : kg->child_graph_order()) {
  400. ChildGraphDataAssign(NOT_NULL(child_graph), link_list, memo);
  401. }
  402. }
  403. NotNull<CNodePtr> AscendControlParser::GetStartLabel(NotNull<KernelGraphPtr> kg, const CNodePtr &last_node,
  404. const CNodePtr &last_label) {
  405. CNodePtr start_label;
  406. if (last_node != nullptr && last_label != nullptr) {
  407. start_label = kg->NewCNode({std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelSetOpName))});
  408. MS_LOG(INFO) << "Insert start label " << start_label->DebugString() << " to " << kg->ToString();
  409. kg->set_start_label(start_label);
  410. } else {
  411. // no goto node will jump to start label of root graph, so return a fake label
  412. start_label = std::make_shared<CNode>(std::vector<AnfNodePtr>(), FuncGraphPtr(nullptr));
  413. }
  414. return NOT_NULL(start_label);
  415. }
  416. NotNull<CNodePtr> AscendControlParser::ProcessKernelGraph(NotNull<KernelGraphPtr> kg, const CNodePtr &last_node,
  417. const CNodePtr &last_label,
  418. const NotNull<std::set<KernelGraphPtr> *> memo) {
  419. MS_LOG(INFO) << "Start process KernelGraph " << kg->ToString();
  420. // 1. recursive condition
  421. if (memo->find(kg) != memo->end()) {
  422. MS_LOG(INFO) << "KernelGraph has beed processed: " << kg->ToString();
  423. return NOT_NULL(kg->get_start_label());
  424. }
  425. memo->insert(kg.get());
  426. // 2. args replace placeholder
  427. LinkParentGraph(kg, last_node, last_label);
  428. // 3. topological sort
  429. kg->SetExecOrderByDefault();
  430. const std::vector<CNodePtr> &nodes = kg->execution_order();
  431. // 4. insert first_label
  432. CNodePtr start_label = GetStartLabel(kg, last_node, last_label);
  433. // 5. traverse
  434. for (size_t i = 0; i < nodes.size(); ++i) {
  435. auto &cnode = nodes[i];
  436. MS_EXCEPTION_IF_NULL(cnode);
  437. if (!(AnfAlgo::CheckPrimitiveType(cnode, prim::kPrimCall) ||
  438. AnfAlgo::CheckPrimitiveType(cnode, prim::kPrimSwitch) ||
  439. AnfAlgo::CheckPrimitiveType(cnode, prim::kPrimSwitchLayer))) {
  440. continue;
  441. }
  442. if (IsPrimitiveCNode(cnode, prim::kPrimCall)) {
  443. RecurseCall(kg, NOT_NULL(cnode), GetNextRealKernel(nodes, i + 1), memo);
  444. } else if (IsPrimitiveCNode(cnode, prim::kPrimSwitch)) {
  445. RecurseSwitch(kg, NOT_NULL(cnode), GetNextRealKernel(nodes, i + 1), memo);
  446. } else if (IsPrimitiveCNode(cnode, prim::kPrimSwitchLayer)) {
  447. RecurseSwitchLayer(kg, NOT_NULL(cnode), GetNextRealKernel(nodes, i + 1), memo);
  448. } else {
  449. MS_LOG(EXCEPTION) << "Unexpected node: " << cnode->DebugString();
  450. }
  451. }
  452. kg->SetExecOrderByDefault();
  453. MS_LOG(INFO) << "End KernelGraph process: " << kg->ToString();
  454. return NOT_NULL(start_label);
  455. }
  456. void AscendControlParser::InsertDependToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> attch_node) {
  457. auto return_node = kg->get_return();
  458. MS_EXCEPTION_IF_NULL(return_node);
  459. std::vector<AnfNodePtr> inputs = {NewValueNode(std::make_shared<Primitive>(prim::kPrimDepend->name())),
  460. return_node->input(kFirstDataInputIndex), attch_node.get()};
  461. auto depend_node = kg->NewCNode(inputs);
  462. return_node->set_input(kFirstDataInputIndex, depend_node);
  463. }
  464. void AscendControlParser::InsertControlDependToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> first_node,
  465. NotNull<AnfNodePtr> second_node) {
  466. MS_LOG(INFO) << "Insert control depend at the end of graph, the first node is " << first_node->DebugString()
  467. << ", the second node is " << second_node->DebugString();
  468. std::vector<AnfNodePtr> inputs = {NewValueNode(std::make_shared<Primitive>(prim::kPrimControlDepend->name())),
  469. first_node, second_node};
  470. auto control_depend = kg->NewCNode(inputs);
  471. InsertDependToGraph(kg, NOT_NULL(control_depend));
  472. }
  473. void AscendControlParser::LinkParentGraph(NotNull<KernelGraphPtr> kg, const CNodePtr &from_graph_call_node,
  474. const CNodePtr &last_label) {
  475. // if not entry graph, replace return with label_goto
  476. if (from_graph_call_node != nullptr && last_label != nullptr) {
  477. auto label_goto =
  478. kg->NewCNode({std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelGotoOpName)), last_label});
  479. MS_EXCEPTION_IF_NULL(label_goto);
  480. MS_LOG(INFO) << "Insert end goto " << label_goto->DebugString() << " to " << kg->ToString();
  481. kg->set_end_goto(label_goto);
  482. }
  483. }
  484. void AscendControlParser::AttachOriginalInputsToGraph(NotNull<KernelGraphPtr> graph,
  485. const std::vector<AnfNodePtr> orig_inputs) {
  486. std::vector<AnfNodePtr> make_tuple_inputs = {
  487. mindspore::NewValueNode(std::make_shared<Primitive>(prim::kPrimMakeTuple->name()))};
  488. std::copy(orig_inputs.begin(), orig_inputs.end(), std::back_inserter(make_tuple_inputs));
  489. auto make_tuple = graph->NewCNode(make_tuple_inputs);
  490. InsertDependToGraph(graph, NOT_NULL(make_tuple));
  491. }
  492. void AscendControlParser::RecurseCall(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node, const CNodePtr &next_node,
  493. const NotNull<std::set<KernelGraphPtr> *> memo) {
  494. MS_LOG(INFO) << "Process call func " << cur_node->DebugString();
  495. // 1 get kernel graph
  496. std::vector<AnfNodePtr> origin_inputs = cur_node->inputs();
  497. if (kCNodeCallArg >= origin_inputs.size()) {
  498. MS_LOG(EXCEPTION) << "Index out of range,size:" << origin_inputs.size();
  499. }
  500. std::vector<AnfNodePtr> new_inputs = {std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelGotoOpName))};
  501. if (!IsValueNode<KernelGraph>(origin_inputs[kCNodeCallArg])) {
  502. MS_LOG(WARNING) << "Node " << cur_node->DebugString(10) << " index " << kCNodeCallArg << " is not a ValueNode";
  503. return;
  504. }
  505. // 2 return label
  506. auto back_label = kg->NewCNode({std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelSetOpName))});
  507. MS_LOG(INFO) << "Insert back label " << back_label->DebugString() << " to " << kg->ToString() << " call node "
  508. << cur_node->DebugString();
  509. // 3 add depend relationship
  510. InsertControlDependToGraph(kg, cur_node, NOT_NULL(back_label));
  511. if (next_node != nullptr && next_node != kg->get_return()) {
  512. InsertControlDependToGraph(kg, NOT_NULL(back_label), NOT_NULL(next_node));
  513. }
  514. auto call_kg = GetValueNode<KernelGraphPtr>(origin_inputs[kCNodeCallArg]);
  515. // 4 modify call op to goto op
  516. cur_node->set_input(kCNodePrim, new_inputs[kCNodePrim]);
  517. // 5 recurse sub graph
  518. CNodePtr sub_label = ProcessKernelGraph(NOT_NULL(call_kg), cur_node, back_label, memo);
  519. new_inputs.push_back(sub_label);
  520. cur_node->set_inputs(new_inputs);
  521. cur_node->set_abstract(nullptr);
  522. AnfAlgo::SetNodeAttr(kAttrChildGraph, MakeValue<std::vector<KernelGraphPtr>>({call_kg}), cur_node.get());
  523. origin_inputs.assign(origin_inputs.begin() + kCNodeCallArg + 1, origin_inputs.end());
  524. AttachOriginalInputsToGraph(kg, origin_inputs);
  525. MS_LOG(INFO) << "Succeed processing call func " << cur_node->DebugString();
  526. }
  527. void AscendControlParser::RecurseSwitch(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node,
  528. const CNodePtr &next_node, const NotNull<std::set<KernelGraphPtr> *> memo) {
  529. MS_LOG(INFO) << "Process switch node " << cur_node->DebugString();
  530. if (cur_node->size() < kCNodeSwitchLength) {
  531. MS_LOG(EXCEPTION) << "Inputs of apply node must more than " << kCNodeSwitchLength;
  532. }
  533. // 1 return label
  534. auto back_label = kg->NewCNode({std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelSetOpName))});
  535. MS_EXCEPTION_IF_NULL(back_label);
  536. MS_LOG(INFO) << "Insert back label " << back_label->DebugString() << " to " << kg->ToString() << " switch node "
  537. << cur_node->DebugString();
  538. // 2 add depend relationship
  539. InsertControlDependToGraph(kg, cur_node, NOT_NULL(back_label));
  540. if (next_node != nullptr && next_node != kg->get_return()) {
  541. InsertControlDependToGraph(kg, NOT_NULL(back_label), NOT_NULL(next_node));
  542. }
  543. // 3 recurse sub graph
  544. const std::vector<AnfNodePtr> &origin_switch_inputs = cur_node->inputs();
  545. if (kCNodeSwitchCond >= origin_switch_inputs.size()) {
  546. MS_LOG(EXCEPTION) << "The size of origin_switch_inputs is not more than " << kCNodeSwitchCond;
  547. }
  548. std::vector<AnfNodePtr> new_switch_inputs = {
  549. std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelSwitchOpName)),
  550. origin_switch_inputs[kCNodeSwitchCond]};
  551. std::vector<KernelGraphPtr> child_graphs;
  552. for (size_t i = kCNodeSwitchCond + 1; i < kCNodeSwitchLength; ++i) {
  553. // 3.1 branch kernel graph and args
  554. KernelGraphPtr branch_fg;
  555. std::vector<AnfNodePtr> origin_inputs;
  556. std::tie(branch_fg, origin_inputs) = ParsePartial(NOT_NULL(origin_switch_inputs[i]));
  557. child_graphs.push_back(branch_fg);
  558. // 3.2 recurse sub graph
  559. CNodePtr branch_label = ProcessKernelGraph(NOT_NULL(branch_fg), cur_node, back_label, memo);
  560. new_switch_inputs.push_back(branch_label);
  561. AttachOriginalInputsToGraph(kg, origin_inputs);
  562. }
  563. std::swap(new_switch_inputs[kCNodeSwitchTrue], new_switch_inputs[kCNodeSwitchFalse]);
  564. cur_node->set_inputs(new_switch_inputs);
  565. cur_node->set_abstract(nullptr);
  566. AnfAlgo::SetNodeAttr(kAttrChildGraph, MakeValue<std::vector<KernelGraphPtr>>(child_graphs), cur_node.get());
  567. MS_LOG(INFO) << "Succeed processing switch func " << cur_node->DebugString();
  568. }
  569. void AscendControlParser::RecurseSwitchLayer(NotNull<KernelGraphPtr> kg, NotNull<CNodePtr> cur_node,
  570. const CNodePtr &next_node,
  571. const NotNull<std::set<KernelGraphPtr> *> memo) {
  572. MS_LOG(INFO) << "Process switch node " << cur_node->DebugString();
  573. if (cur_node->size() < kCNodeSwitchLayerLength) {
  574. MS_LOG(EXCEPTION) << "Inputs of apply node must more than " << kCNodeSwitchLayerLength;
  575. }
  576. auto branch_tuple = cur_node->input(kCNodeSwitchLayerBranch);
  577. MS_EXCEPTION_IF_NULL(branch_tuple);
  578. if (!branch_tuple->isa<CNode>()) {
  579. MS_LOG(EXCEPTION) << branch_tuple->DebugString() << " is not a CNode";
  580. }
  581. const std::vector<AnfNodePtr> &branch_partial = utils::cast<CNodePtr>(branch_tuple)->inputs();
  582. // 1 return label
  583. auto back_label = kg->NewCNode({std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelSetOpName))});
  584. // 2 add depend relationship
  585. InsertControlDependToGraph(kg, cur_node, NOT_NULL(back_label));
  586. if (next_node != nullptr && next_node != kg->get_return()) {
  587. InsertControlDependToGraph(kg, NOT_NULL(back_label), NOT_NULL(next_node));
  588. }
  589. // 3 recurse sub graph
  590. const std::vector<AnfNodePtr> &origin_switch_inputs = cur_node->inputs();
  591. if (kCNodeSwitchCond >= origin_switch_inputs.size()) {
  592. MS_LOG(EXCEPTION) << "Index out of range:" << origin_switch_inputs.size() << ".";
  593. }
  594. std::vector<AnfNodePtr> new_switch_inputs = {
  595. std::make_shared<ValueNode>(std::make_shared<Primitive>(kLabelSwitchOpName)),
  596. origin_switch_inputs[kCNodeSwitchCond]};
  597. std::vector<KernelGraphPtr> child_graphs;
  598. for (size_t i = 0; i < branch_partial.size(); ++i) {
  599. // 3.1 branch kernel graph and args
  600. KernelGraphPtr branch_fg;
  601. std::vector<AnfNodePtr> origin_inputs;
  602. std::tie(branch_fg, origin_inputs) = ParsePartial(NOT_NULL(origin_switch_inputs[i]));
  603. child_graphs.push_back(branch_fg);
  604. // 3.2 recurse sub graph
  605. CNodePtr branch_label = ProcessKernelGraph(NOT_NULL(branch_fg), cur_node, back_label, memo);
  606. new_switch_inputs.push_back(branch_label);
  607. AttachOriginalInputsToGraph(kg, origin_inputs);
  608. }
  609. new_switch_inputs.insert(new_switch_inputs.end(), branch_partial.begin(), branch_partial.end());
  610. cur_node->set_inputs(new_switch_inputs);
  611. cur_node->set_abstract(nullptr);
  612. AnfAlgo::SetNodeAttr(kAttrChildGraph, MakeValue<std::vector<KernelGraphPtr>>(child_graphs), cur_node.get());
  613. MS_LOG(INFO) << "Succeed processing switch layer " << cur_node->DebugString();
  614. }
  615. std::tuple<KernelGraphPtr, std::vector<AnfNodePtr>> AscendControlParser::ParsePartial(NotNull<AnfNodePtr> node) {
  616. if (!node.get()->isa<CNode>()) {
  617. if (IsValueNode<KernelGraph>(node)) {
  618. return {GetValueNode<KernelGraphPtr>(node), {}};
  619. }
  620. MS_LOG(EXCEPTION) << "Switch branches must be partial, node: " << node->DebugString();
  621. }
  622. // 2.1 branch kernel graph and args
  623. auto partial_cnode = utils::cast<CNodePtr>(node.get());
  624. MS_EXCEPTION_IF_NULL(partial_cnode);
  625. if (partial_cnode->size() < kCNodePartialLength) {
  626. MS_LOG(EXCEPTION) << "Inputs of partial node must more than " << kCNodePartialLength;
  627. }
  628. const auto &partial_inputs = partial_cnode->inputs();
  629. if (kCNodePartialFunc >= partial_inputs.size()) {
  630. MS_LOG(EXCEPTION) << "Index out of range:" << partial_inputs.size() << ".";
  631. }
  632. auto branch_kg = GetValueNode<KernelGraphPtr>(partial_inputs[kCNodePartialFunc]);
  633. return {branch_kg, std::vector<AnfNodePtr>(partial_inputs.begin() + kCNodePartialFunc + 1, partial_inputs.end())};
  634. }
  635. void AscendControlParser::InsertMultipleAssignToGraph(NotNull<KernelGraphPtr> from_graph, const AnfNodePtr &jump_node,
  636. NotNull<AnfNodePtr> from, NotNull<AnfNodePtr> to) {
  637. std::vector<AnfNodePtr> from_outputs = AnfAlgo::GetAllOutput(from, {prim::kPrimTupleGetItem});
  638. std::vector<AnfNodePtr> to_outputs = AnfAlgo::GetAllOutput(to, {prim::kPrimTupleGetItem});
  639. MS_LOG(INFO) << "Insert multi-assign from [" << from->DebugString() << "] to [" << to->DebugString() << "]";
  640. if (from_outputs.size() != to_outputs.size()) {
  641. MS_LOG(EXCEPTION) << "From outputs size[" << from_outputs.size() << "] is not equal to to outputs size["
  642. << to_outputs.size() << "]";
  643. }
  644. for (size_t i = 0; i < from_outputs.size(); i++) {
  645. auto assign_node = InsertAssignToGraph(from_graph, NOT_NULL(from_outputs[i]), NOT_NULL(to_outputs[i]));
  646. if (assign_node == nullptr) {
  647. continue;
  648. }
  649. const auto &from_graph_exe_order = from_graph->execution_order();
  650. if (jump_node == nullptr) {
  651. if (!from_graph_exe_order.empty()) {
  652. InsertControlDependToGraph(from_graph, NOT_NULL(*(from_graph_exe_order.rbegin())), NOT_NULL(assign_node));
  653. } else {
  654. InsertDependToGraph(from_graph, NOT_NULL(assign_node));
  655. }
  656. continue;
  657. }
  658. auto jump_node_iter = std::find(from_graph_exe_order.begin(), from_graph_exe_order.end(), jump_node);
  659. if (jump_node_iter == from_graph_exe_order.end()) {
  660. MS_LOG(EXCEPTION) << "Cannot find jump node " << jump_node->DebugString() << " in graph "
  661. << from_graph->ToString();
  662. }
  663. // insert assign between jump_node -1 and jump_node
  664. if (jump_node_iter != from_graph_exe_order.begin()) {
  665. InsertControlDependToGraph(from_graph, NOT_NULL(*(jump_node_iter - 1)), NOT_NULL(assign_node));
  666. }
  667. InsertControlDependToGraph(from_graph, NOT_NULL(assign_node), NOT_NULL(jump_node));
  668. }
  669. }
  670. AnfNodePtr AscendControlParser::InsertAssignToGraph(NotNull<KernelGraphPtr> kg, NotNull<AnfNodePtr> from,
  671. NotNull<AnfNodePtr> to) {
  672. if (AnfAlgo::OutputAddrExist(from, 0) && AnfAlgo::OutputAddrExist(to, 0) &&
  673. AnfAlgo::GetOutputAddr(from, 0) == AnfAlgo::GetOutputAddr(to, 0)) {
  674. return nullptr;
  675. }
  676. if (from.get() == to.get()) {
  677. return nullptr;
  678. }
  679. MS_LOG(INFO) << "Insert assign to graph " << kg->ToString() << " from " << from->DebugString() << " to "
  680. << to->DebugString();
  681. // config inputs of assign node
  682. std::vector<AnfNodePtr> inputs = {NewValueNode(std::make_shared<Primitive>(prim::kPrimAssign->name())), to, from};
  683. // generate a new cnode
  684. auto assign_node = kg->NewCNode(inputs);
  685. MS_EXCEPTION_IF_NULL(assign_node);
  686. assign_node->set_abstract(to->abstract());
  687. return assign_node;
  688. }
  689. std::vector<CNodePtr> AscendControlParser::RecurseGraph(NotNull<KernelGraphPtr> graph,
  690. const NotNull<std::set<KernelGraphPtr> *> memo) {
  691. MS_LOG(INFO) << "Graph:" << graph->graph_id() << " start";
  692. if (memo->find(graph) != memo->end()) {
  693. return {};
  694. }
  695. memo->insert(graph.get());
  696. graph->SetExecOrderByDefault();
  697. std::vector<CNodePtr> cnodes = graph->execution_order();
  698. auto end_label_goto = graph->get_end_goto();
  699. if (cnodes.rbegin() != cnodes.rend() && *cnodes.rbegin() == end_label_goto) {
  700. cnodes.pop_back();
  701. }
  702. AnfAlgo::ReorderExecList(NOT_NULL(&cnodes));
  703. if (end_label_goto != nullptr) {
  704. cnodes.push_back(end_label_goto);
  705. }
  706. std::vector<CNodePtr> execution_order;
  707. uint32_t child_order_index = 0;
  708. auto recurse_child_graph = [&](uint32_t index, uint32_t label_index, const CNodePtr &node) {
  709. if (!CheckLabelIndex(index, label_index, node)) {
  710. MS_LOG(EXCEPTION) << "Check label index fail";
  711. }
  712. if (child_order_index >= graph->child_graph_order().size()) {
  713. MS_LOG(EXCEPTION) << "Index out of range:" << graph->child_graph_order().size();
  714. }
  715. auto child_graph = graph->child_graph_order()[child_order_index++];
  716. auto child_execution_order = RecurseGraph(NOT_NULL(child_graph), memo);
  717. execution_order.insert(execution_order.end(), child_execution_order.begin(), child_execution_order.end());
  718. };
  719. for (auto &node : cnodes) {
  720. uint32_t child_graph_index = 0;
  721. execution_order.push_back(node);
  722. if (node == graph->get_end_goto()) {
  723. continue;
  724. }
  725. if (AnfAlgo::CheckPrimitiveType(node, prim::kPrimLabelSwitch)) {
  726. std::vector<uint32_t> label_switch_list = AnfAlgo::GetNodeAttr<std::vector<uint32_t>>(node, kAttrLabelSwitchList);
  727. for (auto iter = label_switch_list.rbegin(); iter != label_switch_list.rend(); ++iter) {
  728. recurse_child_graph(child_graph_index++, *iter, node);
  729. }
  730. } else if (AnfAlgo::CheckPrimitiveType(node, prim::kPrimLabelGoto)) {
  731. uint32_t label_index = AnfAlgo::GetNodeAttr<uint32_t>(node, kAttrLabelIndex);
  732. recurse_child_graph(child_graph_index, label_index, node);
  733. }
  734. }
  735. graph->set_execution_order(execution_order);
  736. graph->PrintGraphExecuteOrder();
  737. return execution_order;
  738. }
  739. bool AscendControlParser::CheckLabelIndex(uint32_t index, uint32_t label_index, const CNodePtr &cur_label) {
  740. auto child_graphs = AnfAlgo::GetNodeAttr<std::vector<KernelGraphPtr>>(cur_label, kAttrChildGraph);
  741. // check index and child order size
  742. if (child_graphs.size() <= IntToSize(index)) {
  743. MS_LOG(EXCEPTION) << "Child graph index is wrong, current node " << cur_label->ToString() << " child graph size "
  744. << child_graphs.size() << " goto index " << index;
  745. }
  746. auto child_graph = child_graphs[index];
  747. MS_EXCEPTION_IF_NULL(child_graph);
  748. // get start_label_set_index of child graph
  749. auto start_label_set = child_graph->get_start_label();
  750. uint32_t start_label_set_index = AnfAlgo::GetNodeAttr<uint32_t>(start_label_set, kAttrLabelIndex);
  751. if (label_index != start_label_set_index) {
  752. MS_EXCEPTION_IF_NULL(cur_label);
  753. MS_EXCEPTION_IF_NULL(start_label_set);
  754. MS_LOG(WARNING) << cur_label->DebugString() << " index " << label_index << " but " << start_label_set->DebugString()
  755. << " index " << start_label_set_index;
  756. return false;
  757. } else {
  758. return true;
  759. }
  760. }
  761. void AscendControlParser::ReferenceCounter::AddReadCount(const AnfNodePtr &key, int32_t num) {
  762. auto iter = count_.find(key);
  763. if (iter != count_.end()) {
  764. iter->second.first += num;
  765. } else {
  766. count_[key] = {num, 0};
  767. }
  768. }
  769. void AscendControlParser::ReferenceCounter::AddWriteCount(const AnfNodePtr &key, int32_t num) {
  770. auto iter = count_.find(key);
  771. if (iter != count_.end()) {
  772. iter->second.second += num;
  773. } else {
  774. count_[key] = {0, num};
  775. }
  776. }
  777. void AscendControlParser::ReferenceCounter::EraseElem(const AnfNodePtr &key) { count_.erase(key); }
  778. bool AscendControlParser::ReferenceCounter::HasValidElem() const {
  779. auto it = std::find_if(count_.begin(), count_.end(),
  780. [this](const std::pair<AnfNodePtr, std::pair<uint32_t, uint32_t>> &p) -> bool {
  781. auto &[read, written] = p.second;
  782. return predicate_(read, written);
  783. });
  784. return it != count_.end();
  785. }
  786. std::tuple<AnfNodePtr, int32_t, int32_t> AscendControlParser::ReferenceCounter::GetOneValidElem() const {
  787. auto it = std::find_if(count_.begin(), count_.end(),
  788. [this](const std::pair<AnfNodePtr, std::pair<uint32_t, uint32_t>> &p) -> bool {
  789. auto &[read, written] = p.second;
  790. return predicate_(read, written);
  791. });
  792. if (it == count_.end()) {
  793. MS_LOG(EXCEPTION) << "No valid parameter.";
  794. }
  795. return {it->first, it->second.first, it->second.second};
  796. }
  797. } // namespace session
  798. } // namespace mindspore