Extension_device test can't work

I was start to add a new backend for pytorch out of tree, I tried to modify the test/inductor/test_extension_backend.py and reuse the test/inductor/extension_backends/extension_device.cpp to run a simple cpp_extension test, like this:

source_file_path = os.path.dirname(os.path.abspath(__file__))
source_file = os.path.join(
    source_file_path, "extension_device.cpp"
)

module = torch.utils.cpp_extension.load(
  name="extension_device1",
  sources=[
    str(source_file),
  ],
  build_directory="./build_path",
  extra_cflags=["-g"],
  verbose=True,
)

torch.utils.rename_privateuse1_backend("extension_device1")

device = module.custom_device()
x = torch.empty(3, 16)
print(x.data_ptr())
x = x.to(device)
print(x.data_ptr())
x = x.fill_(1)

this code works well, but the x.to(device) seems not go into the custom_to_device() fuction in extension_device.cpp, in other word, I add a printf() the custom_to_device() but nothing was printed.

can anybody tell me how to fix this?

Problem solved,
This “to.device” is just a facade. the real tensor.to will go into the custom backend’s allocate fuction,
such as DummyCustomAllocator::allocate fuction.
see :

pytorch/aten/src/ATen/native/native_functions.yaml:7599