I’m combining lots of images into a single one and then add custom ticks and labels to the final image using Plots.jl library, then save it on the disk. However, we have millions of images to be processed, and it becomes very difficult for the CPU to do this in a reasonable amount of time.
After doing a Google search, I found that the ArrayFire library performs array operations on the GPU. I tested the load_image() function of ArrayFire for reading 10k images on GPU and I observed a 3-4x increase in speed comparing to the same operation on CPU with Images.jl’s load() function.
Next, I hopelessly tried my AFArray with Plots.jl and it didn’t work. Then I thought that if I perform the iterative operations on the GPU and then convert the whole array to something that plot() accepts, I shouldn’t have a great loss of performance, and asked this question on stackoverflow. After getting acquainted with the reinterpret() function, I realized the conversion from AFArray to Array{RGB{Float32},2} takes a huge amount of time (over a minute). Therefore I’m here to ask a few questions:
Is there a clean way to plot images and draw axes and ticks entirely on the GPU?
Is there a faster way to convert AFArray to something that plot() function would accept?
Is there any other library working on GPU that would accept AFArray?
I am aware of the Makie.jl library and tried to do the same process with it and if I remember correctly it doesn’t have the hackable ticks feature that Plots has. This guy asked about that but he didn’t get an answer for Makie.jl.
Should probably move the array to CPU memory first, and then convert to the type you need. Otherwise I suspect it is doing element by element copy from GPU to CPU.
It would be possible to plot images directly from the GPU in GLMakie, but it’s currently not implemented.
takes a huge amount of time (over a minute)
This must be a bug, it should only take a couple of ms (edit: @anon43133060 theory sounds about right ).
Did you try ImageIO & PNGFiles for loading? I heard they are supposed to be faster!
load_image() function of ArrayFire for reading 10k images on GPU and I observed a 3-4x
I hardly believe, that this is due to putting things on the GPU - putting it on the GPU is likely doing even more work. Instead, it’s likely simply faster, because they’re using a faster image loading library (on the CPU). One should check what they’re using and why it’s faster!
Thank you so much for your answer! Unfortunately, I underestimated the potential of the Makie.jl library and I deeply regret it. Today I think I’ll be translating all my code into this library.
It would be possible to plot images directly from the GPU in GLMakie
That would be something I happily use Looking forward to it.
putting it on the GPU is likely doing even more work
they’re using a faster image loading library
Ahh I get it now, so it wasn’t my GPU doing the trick. Maybe I should look for other ways to improve my performance but first let me see if Makie.jl and ImageIO does any better job with plotting.