MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / TEST

Function TEST

test/cpp/compat/torch_library_dispatch_test.cc:108–124  ·  view source on GitHub ↗

An operator registered only under BackendSelect must be queryable under that key and must NOT appear under CPU.

Source from the content-addressed store, hash-verified

106// An operator registered only under BackendSelect must be queryable under
107// that key and must NOT appear under CPU.
108TEST(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).

Callers

nothing calls this directly

Calls 11

IValueClass · 0.85
pick_implFunction · 0.85
find_operatorMethod · 0.80
call_with_argsMethod · 0.80
findMethod · 0.45
endMethod · 0.45
add_argMethod · 0.45
is_intMethod · 0.45
get_valueMethod · 0.45
to_intMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected