GPU accelerated image processing for everyone
Authors: Robert Haase, Daniela Vorkel, April 2020
This macro shows how to trace the duration of image processing workflows. When doing so, we can trace the taken time for underlying operations, such as for the top-hat filter.
When executing this script, run it twice! You may observe that the second execution is faster, because of the warm-up effect.
// clean up first run ("Close All"); // get test data run("Blobs (25K)"); run("Invert LUT"); input = getTitle();
run("CLIJ2 Macro Extensions", "cl_device="); Ext.CLIJ2_clear(); // push images to GPU Ext.CLIJ2_push(input); // clean up ImageJ close();
Before running the actual filter or workflow, we start the time tracing.
Ext.CLIJ2_startTimeTracing(); radius = 10; Ext.CLIJ2_topHatBox(input, background_subtacted, radius, radius, 0); // show result Ext.CLIJ2_pull(background_subtacted);
After the workflow finished, we can have a look on all underlying operations and its execution time, for each single step and as total duration:
Ext.CLIJ2_stopTimeTracing(); Ext.CLIJ2_getTimeTracing(time_traces); print(time_traces);
> > timeTracing > > TopHatBox > > Minimum2DBox > < Minimum2DBox 1.4874 ms > > Maximum2DBox > < Maximum2DBox 1.5085 ms > > SubtractImages > < SubtractImages 0.9509 ms > < TopHatBox 4.1712 ms > < timeTracing 115.9438 ms >
For documentation purposes, we should also report which GPU was used
Ext.CLIJ2_getGPUProperties(gpu, memory, opencl_version); print("GPU: " + gpu); print("Memory in GB: " + (memory / 1024 / 1024 / 1024) ); print("OpenCL version: " + opencl_version);
> GPU: GeForce RTX 2060 SUPER > Memory in GB: 8 > OpenCL version: 1.2
At the end of the macro, clean up:
Ext.CLIJ2_clear();