Commit 255e4ce
Fix
Currently, `sub_materialize` (through `sub_materialize_axes`) falls back
to materializing on CPU. This PR generalizes that logic by determining
the output destination with `similar`, which helps to support non-Array
types like GPU arrays. As a stand-in for other GPU arrays, I test this
using
[JLArrays.JLArray](https://github.com/JuliaGPU/GPUArrays.jl/tree/master/lib/JLArrays),
which is a reference implementation for the GPUArrays.jl interface that
runs on CPU.
An alternative design would be to define memory layouts for GPU arrays
(i.e. #9), which would allow more customizability for GPU array
backends, however I think it is helpful to have fallbacks that "just
work" if reasonable parts of the Base AbstractArray interface are
implemented.
I hit this issue because I was testing out
[`BlockArrays.BlockedArray`](https://juliaarrays.github.io/BlockArrays.jl/stable/man/blockedarrays)
wrapping a GPU array and noticed that calling `A[Block(1, 1)]` to access
a block instantiated the block on CPU, this PR fixes that issue.
---------
Co-authored-by: Sheehan Olver <[email protected]>sub_materialize for GPU arrays (#261)1 parent 067e9c4 commit 255e4ce
3 files changed
+17
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | 8 | | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | | - | |
| 42 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
| 130 | + | |
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
407 | 417 | | |
408 | 418 | | |
409 | 419 | | |
| |||
0 commit comments