Research Article

Facile Conversion and Optimization of Structured Illumination Image Reconstruction Code into the GPU Environment

Figure 3

The impact of code revision. (a) Complex, unedited code. (b) Simplified and improved code. Revised code of forward_diff() and back_diff() functions that use the built-in and avoid creating memory (matrixes) in each function call. We use the built-in function, diff(), that calculates the differences between adjacent elements, and the differences are stored in a preallocated matrix (out). The matrix is passed as a parameter to the revised function to avoid creating temporary matrixes in each function call, i.e., reduced slow main memory operations. The variable, position, is created and used to indicate where to store the output of diff(), in the preallocated matrix, i.e., out. For example, in the code of the right of (b), the output location is adjusted by increasing one of the dimensions based on the third parameter (dim) by 1. This variable could be removed in the code on the left of (b) by updating the last line of code to out(1:SIZE(1), 1:SIZE(2), 1:SIZE(3). We kept using the variable to be consistent within both codes of (b). Note that the diff () function may create matrixes internally or use preallocated matrixes, which are hidden from users. We assume that the overhead would be negligible due to MATLAB’s highly optimized built-in functions.
(a)
(b)