# Pytorch to Triton for Non-GPU Devices

**URL:** https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007
**Category:** compiler
**Created:** [April 17, 2024, 10:04pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007 "2024-04-17T22:04:25Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![fhossein-quic](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/fhossein-quic/32/1341_2.png) [@fhossein-quic](https://dev-discuss.pytorch.org/u/fhossein-quic)
#### Post date: [April 17, 2024, 10:04pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/1 "2024-04-17T22:04:26Z")

</div>

Does Pytorch offers any mean to convert Pytorch to triton for non-GPU devices?  
It seems that `Torchinductor` does this but only for `device="CUDA"`. I am working on a costume non-GPU device. Is there a way to hack my way into `torchInductor` to generate Triton kernels for `device="cpu"`?

---

<div class="post-metadata">

### Author: ![TyFeng](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@TyFeng](https://dev-discuss.pytorch.org/u/TyFeng)
#### Post date: [April 21, 2024, 8:39pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/2 "2024-04-21T20:39:57Z")

</div>

Do you want to run triton on a CPU device? This seems impossible, or a bit complicated. You can set the environment variable TORCH\_COMPILE\_DEBUG=1 and then use torch.compile(m, backend=“inductor”) to compile the python code, and then you will find a triton code file in a certain directory. [https://pytorch.org/tutorials/intermediate/inductor\_debug\_cpu.html](https://pytorch.org/tutorials/intermediate/inductor_debug_cpu.html) Finally, Triton-IR will use Triton compiler to generate LLVM IR, and then use LibLLVM to generate PTX code to run on the GPU. I think if you want to run on cpu, you can generate cpu binaries for LLVM IR through LLVM lib. I have not checked the llvm ir generated by triton. This is an approximate guess.

---

<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: [April 23, 2024, 6:20pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/3 "2024-04-23T18:20:13Z")

</div>

There isn’t a CPU backend for Triton yet, so TorchInductor generates C++.

@bertmaher is working on a CPU backend for Triton though.

---

<div class="post-metadata">

### Author: ![fhossein-quic](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/fhossein-quic/32/1341_2.png) [@fhossein-quic](https://dev-discuss.pytorch.org/u/fhossein-quic)
#### Post date: [April 24, 2024, 3:16pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/4 "2024-04-24T15:16:17Z")

</div>

> [@jansel](#):
>
> @bertmaher is working on a CPU backend for Triton though.

Yes, non-GPU backends can be added to triton as well. That’s why I am wondering on how torch–\>triton conversion could work for CPU.

---

<div class="post-metadata">

### Author: ![fhossein-quic](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/fhossein-quic/32/1341_2.png) [@fhossein-quic](https://dev-discuss.pytorch.org/u/fhossein-quic)
#### Post date: [April 24, 2024, 3:31pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/5 "2024-04-24T15:31:34Z")

</div>

Actually, I want to generate triton kernels out of pytroch model when there is no cuda device, i.e. getting triton code out of `torch.compile(m, backend=“inductor”)` when `device="cpu"`. And then, to be able to get LLVM IR from these triton kernels using a custom non-GPU triton backend.

---

<div class="post-metadata">

### Author: ![JoeLi12345](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/joeli12345/32/2220_2.png) [@JoeLi12345](https://dev-discuss.pytorch.org/u/JoeLi12345)
#### Post date: [August 8, 2024, 11:14pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/6 "2024-08-08T23:14:10Z")

</div>

Were you ever able to figure out how to access the generated TorchInductor Triton kernels when running PyTorch for device=“cpu”?

---

<div class="post-metadata">

### Author: ![fhossein-quic](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/fhossein-quic/32/1341_2.png) [@fhossein-quic](https://dev-discuss.pytorch.org/u/fhossein-quic)
#### Post date: [August 19, 2024, 4:52pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/7 "2024-08-19T16:52:03Z")

</div>

Yes, but I had to manually modify the torchInductor code to make it generate triton kernels for cpu.

---

<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: [August 30, 2024, 5:58pm UTC](https://dev-discuss.pytorch.org/t/pytorch-to-triton-for-non-gpu-devices/2007/8 "2024-08-30T17:58:32Z")

</div>

> <https://github.com/pytorch/pytorch/pull/133408>
>
> Stack from \[ghstack\](https://github.com/ezyang/ghstack) (oldest at bottom):
> \* \_\_…-\>\_\_ #133408
> 
> The goal is to use Inductor-generated kernels to stress test the new Triton CPU backend.
> 
> cc @XilunWu @H-Huang @awgu @kwen2501 @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @c-p-i-o @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @ColinPeppler @amjames @desertfire @chauhang @rec
