List all instructions matching a pattern.
| 217 | |
| 218 | // List all instructions matching a pattern. |
| 219 | void DoListCommand(const HloModule& module, const std::vector<string>& tokens) { |
| 220 | string pattern = ""; |
| 221 | string type = "name"; |
| 222 | if (tokens.size() == 2) { |
| 223 | pattern = tokens[1]; |
| 224 | } else if (tokens.size() == 3) { |
| 225 | type = tokens[1]; |
| 226 | pattern = tokens[2]; |
| 227 | } else { |
| 228 | std::cout << "Illegal list query syntax. Use " |
| 229 | << R"("list [name|op_name|op_type] pattern".)" << std::endl; |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | std::cout << "Query results:" << std::endl; |
| 234 | for (const auto& computation : module.computations()) { |
| 235 | for (const auto& instr : computation->instructions()) { |
| 236 | if ((type == "name" && instr->name().find(pattern) != string::npos) || |
| 237 | (type == "op_name" && |
| 238 | instr->metadata().op_name().find(pattern) != string::npos) || |
| 239 | (type == "op_type" && |
| 240 | instr->metadata().op_type().find(pattern) != string::npos)) { |
| 241 | std::cout << " " << instr->name(); |
| 242 | std::cout << ", op_name '" << instr->metadata().op_name() << "'"; |
| 243 | std::cout << ", op_type '" << instr->metadata().op_type() << "'"; |
| 244 | std::cout << std::endl; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | // Print info about an instruction or computation. |
| 251 | void DoInfoCommand(const HloModule& module, const std::vector<string>& tokens) { |
no test coverage detected