# Generic CPU and GPU loops with tiled iteration

**URL:** <https://discourse.julialang.org/t/generic-cpu-and-gpu-loops-with-tiled-iteration/20295>\
**Category:** GPU\
**Created:** [January 30, 2019, 10:11pm UTC](https://discourse.julialang.org/t/generic-cpu-and-gpu-loops-with-tiled-iteration/20295 "2019-01-30T22:11:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![datnamer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datnamer/32/3471_2.png) [@datnamer](https://discourse.julialang.org/u/datnamer)\
**Post date:** [January 30, 2019, 10:11pm UTC](https://discourse.julialang.org/t/generic-cpu-and-gpu-loops-with-tiled-iteration/20295/1 "2019-01-30T22:11:28Z")

</div>

Can [Tilediteration](https://github.com/JuliaArrays/TiledIteration.jl) be used to write loops that work on GPU and CPUs without having to have separate kernels for the latter or stuff everything into broadcast(s)?

@tim.holy

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [January 30, 2019, 11:56pm UTC](https://discourse.julialang.org/t/generic-cpu-and-gpu-loops-with-tiled-iteration/20295/2 "2019-01-30T23:56:11Z")

</div>

Most likely, but I’m guessing it’s useful only if want your GPU kernels explicitly looping over blocks of pixels. If you do the typical one-output-pixel-per-thread then it may not be relevant.

TiledIteration’s main advantage is in reusing cache, “halide-like.”

---

<div class="post-metadata">

**Author:** ![datnamer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datnamer/32/3471_2.png) [@datnamer](https://discourse.julialang.org/u/datnamer)\
**Post date:** [January 31, 2019, 12:31am UTC](https://discourse.julialang.org/t/generic-cpu-and-gpu-loops-with-tiled-iteration/20295/3 "2019-01-31T00:31:51Z")

</div>

> [@tim.holy](#):
>
> GPU kernels explicitly looping over blocks of pixels. If you do the typical one-output-pixel-per-thread then it may not be relevant.
> 
> TiledIteration’s main advantage is in reusing cache, “ha

I don’t mean images necessarily, but any generic looping operation like matrix multiply or sum. Or do you mean a pixel more generically.

Like here: [Writing fast stencil computation kernels that work on both CPUs and GPUs - #3 by maleadt](https://discourse.julialang.org/t/writing-fast-stencil-computation-kernels-that-work-on-both-cpus-and-gpus/20200/3)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [January 31, 2019, 3:55am UTC](https://discourse.julialang.org/t/generic-cpu-and-gpu-loops-with-tiled-iteration/20295/4 "2019-01-31T03:55:11Z")

</div>

Yes, images are just arrays so I just mean processing the work associated with a particular output location. If your stencils are very local then you most likely want to use the raw `blockIdx` etc if you’re interested in maximal performance.
