Skip to main content

A Simple Pytorch version for CFU

Project description

torch-cfu

This project is for adding custom function unit to accelerate AI algorithm.

How to install

You can install it by pip for the latest version. And assume that you have installed torch before.

pip install torch-cfu

How to use

First you need to 'import torch', then 'import torch_cfu'. And you are able to rename default device name to whatever you want.

$ python
Python 3.8.18 (default, Sep 11 2023, 13:40:15) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torch_cfu
>>> torch_cfu.custom_device(0)
device(type='privateuseone', index=0)
>>> torch.utils.rename_privateuse1_backend("cfu")
>>> torch_cfu.custom_device(0)
device(type='cfu', index=0)
>>>
>>> x = torch.ones(4, 4, device='cfu:0')
Custom aten::empty.memory_format() called!
Custom allocator's allocate() called!
>>> x.device
device(type='cfu', index=0)
>>> x.is_cpu
False
>>> exit()
Custom allocator's delete() called!

How to add new custom kernels in C++

  1. Writing custom kernels in C++, and registering them to the PyTorch dispatcher
  2. Providing a user API for your custom device, so users can invoke the custom code using torch.foo(..., device="custom_device")
  3. Registering a custom memory allocator
  4. Registering a custom device guard

Reference

python setup.py sdist bdist_wheel
twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_cfu-0.0.3.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file torch_cfu-0.0.3.tar.gz.

File metadata

  • Download URL: torch_cfu-0.0.3.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/65.3.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

File hashes

Hashes for torch_cfu-0.0.3.tar.gz
Algorithm Hash digest
SHA256 fcfc6da69d8f5cb6f1fc409f3193632f64ed4e424d41567bf96e47eb5371b32e
MD5 5c0ed93695173e66a25598062eadfa4e
BLAKE2b-256 022869c0649715f202466a084920b0f088aba0600a4608c71c4c75fa96fccac6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page