# Memory operations on a custom backend

**URL:** <https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678>\
**Category:** hardware-backends\
**Created:** [June 28, 2022, 10:03am UTC](https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678 "2022-06-28T10:03:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![slai-nick](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@slai-nick](https://dev-discuss.pytorch.org/u/slai-nick)\
**Post date:** [June 28, 2022, 10:03am UTC](https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678/1 "2022-06-28T10:03:34Z")

</div>

Hi,

I a working on he integration for a new device in PyTorch.  
I have been reading the (good) documentation on adding a new backend, so far things seems pretty simple: adding operator implementations with a custom dispatcher key and compiling it as a C++ extension.  
However one piece of information is missing from my reading (sorry if I missed it from the doc), how do I make PyTorch able to handle the memory operations (allocation, memcpy, copy across different type of devices)?

I see a reference to [VulkanOpaqueTensorImpl](https://github.com/pytorch/pytorch/blob/1.7/aten/src/ATen/native/vulkan/VulkanOpaqueTensorImpl.h) that could be helpful, however I struggle to see which bit I can modify to make the allocations happen on my device.

What I was expecting to do is to providing callback functions for memory management.

Can I get a little help with this? Maybe some reference will do.  
Thank you!

---

<div class="post-metadata">

**Author:** ![byronyi](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/byronyi/32/112_2.png) [@byronyi](https://dev-discuss.pytorch.org/u/byronyi)\
**Post date:** [June 29, 2022, 10:33pm UTC](https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678/2 "2022-06-29T22:33:09Z")

</div>

You could take a look at [add open device registration test with cpp extensions by bdhirsh · Pull Request #80477 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/pull/80477).

---

<div class="post-metadata">

**Author:** ![bdhirsh](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/bdhirsh/32/575_2.png) [@bdhirsh](https://dev-discuss.pytorch.org/u/bdhirsh)\
**Post date:** [July 2, 2022, 2:14am UTC](https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678/3 "2022-07-02T02:14:19Z")

</div>

Yep! The PR that Bairen linked shows a basic example of adding a custom device with its own allocator, and copying to/from cpu. Let me know if you have any questions!

That PR also shows a basic example of open registration (adding a new PyTorch device in c++, with no changes needed to PyTorch core). Better docs for it coming soon!

---

<div class="post-metadata">

**Author:** ![slai-nick](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@slai-nick](https://dev-discuss.pytorch.org/u/slai-nick)\
**Post date:** [July 5, 2022, 9:24am UTC](https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678/4 "2022-07-05T09:24:12Z")

</div>

Thanks that’s what I was looking for!  
So it’s all about the Aten library.  
I am new to Pytorch dev so I was missing that bit… I really appreciate the quality of the documentation, thanks to the team!

---

<div class="post-metadata">

**Author:** ![slai-nick](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@slai-nick](https://dev-discuss.pytorch.org/u/slai-nick)\
**Post date:** [July 5, 2022, 10:32am UTC](https://dev-discuss.pytorch.org/t/memory-operations-on-a-custom-backend/678/5 "2022-07-05T10:32:58Z")

</div>

Would it be possible to get a summary of the steps needed/to consider for integrating a custom accelerator aside from the kernel registrations? Or maybe that PR already contains everything?
