# How to differentiate target devices in dynamo backends?

**URL:** https://dev-discuss.pytorch.org/t/how-to-differentiate-target-devices-in-dynamo-backends/1279
**Category:** compiler
**Created:** [May 23, 2023, 4:50pm UTC](https://dev-discuss.pytorch.org/t/how-to-differentiate-target-devices-in-dynamo-backends/1279 "2023-05-23T16:50:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Fami64](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/fami64/32/1104_2.png) [@Fami64](https://dev-discuss.pytorch.org/u/Fami64)
#### Post date: [May 23, 2023, 4:50pm UTC](https://dev-discuss.pytorch.org/t/how-to-differentiate-target-devices-in-dynamo-backends/1279/1 "2023-05-23T16:50:20Z")

</div>

Is there a way other than checking the torch.compile() input’s device type to pass the compilation target to the backend?

The dynamo backend I am working on can operate on multiple targets and I need to somehow differentiate between them. If all the device types were supported by pytorch, then the code would look like this:

```auto
device_type = device_from_inputs(example_inputs).type

if device_type == CPU:
   # compile for CPU
elif device_type == CUDA:
   # compile for CUDA
elif device_type == D1:
   # compile for D1
elif device_type == D2:
   # compile for D2

```

The issue is that while the backend can compile pytorch models for those devices and run the compiled model on them, some of those devices are not supported by pytorch as ATEN devices (e.g. D1 and D2). So, I cannot create a tensor with those device types to be passed to torch.compile() . I want to know if the only solution is to implement the support for those target devices in pytorch to do that differentiation?

---

<div class="post-metadata">

### Author: ![jansel](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/jansel/32/74_2.png) [@jansel](https://dev-discuss.pytorch.org/u/jansel)
#### Post date: [May 24, 2023, 3:55am UTC](https://dev-discuss.pytorch.org/t/how-to-differentiate-target-devices-in-dynamo-backends/1279/2 "2023-05-24T03:55:00Z")

</div>

You might be looking for: [Extending dispatcher for a new backend in C++ — PyTorch Tutorials 2.0.1+cu117 documentation](https://pytorch.org/tutorials/advanced/extend_dispatcher.html)

You can use the `PrivateUse1`/`AutogradPrivateUse1` dispatcher keys to register a tensor with a custom device and implementation.

TorchDynamo should be able to capture graphs containing `PrivateUseX` tensors, which you can then compile.
