An operator registered only under BackendSelect must be queryable under that key and must NOT appear under CPU.
| 106 | // An operator registered only under BackendSelect must be queryable under |
| 107 | // that key and must NOT appear under CPU. |
| 108 | TEST(CompatTorchDispatchTest, BackendSelectOnlyRegistration) { |
| 109 | const auto qname = "compat_dispatch_test_lib::backend_select_only"; |
| 110 | auto* op = torch::OperatorRegistry::instance().find_operator(qname); |
| 111 | ASSERT_NE(op, nullptr); |
| 112 | |
| 113 | EXPECT_EQ(op->implementations.find(c10::DispatchKey::CPU), |
| 114 | op->implementations.end()); |
| 115 | |
| 116 | auto bs_it = op->implementations.find(c10::DispatchKey::BackendSelect); |
| 117 | ASSERT_NE(bs_it, op->implementations.end()); |
| 118 | |
| 119 | torch::FunctionArgs args; |
| 120 | args.add_arg(torch::IValue(int64_t(32))); |
| 121 | auto result = bs_it->second.call_with_args(args); |
| 122 | ASSERT_TRUE(result.get_value().is_int()); |
| 123 | EXPECT_EQ(result.get_value().to_int(), 42); // 32 + 10 |
| 124 | } |
| 125 | |
| 126 | // When CPU and BackendSelect are both registered, the priority lookup must |
| 127 | // pick CPU (higher priority in get_op_with_args). |
nothing calls this directly
no test coverage detected