design patterns -凯发k8网页登录

main content

design patterns

gpu coder™ supports some design patterns that map efficiently to gpu structures.

stencil processing

stencil kernel operations compute each element of the output array as a function of a small region of the input array. you can express many filtering operations as a stencil operation. examples include convolution, median filtering, and finite element methods.

in the gpu coder implementation of the stencil kernel, each thread computes one element of the output array. because a given input element is accessed repeatedly for computing multiple neighboring output elements, gpu coder uses shared memory to improve memory bandwidth and data locality.

use the function and create cuda® code for stencil functions. for an example that demonstrates stencil preocessing, see stencil processing on gpu.

note

starting in r2022b, generate cuda kernels for stencil like operations by using stencilfun function. gpucoder.stencilkernel is not recommended.

for very large input sizes, the function may produce cuda code that does not numerically match the matlab® simulation. in such cases, consider reducing the size of the input to produce accurate results.

matrix-matrix processing

many scientific applications contain matrix-matrix operations including the general matrix to matrix multiplication (gemm), of the form c = ab where you can optionally transpose a and b. the code for such matrix-matrix operations typically takes the pattern:

for x = 1:m
    for y = 1:n
        for z = 1:k
            c(x,y) = f(a(x,z),b(z,y));
        end
    end
end

where f() is a user-defined function. in these operations, a row from one input matrix and a column from the second input matrix is used to compute the corresponding element of the output matrix. every thread reloads the row and column. this design pattern allows optimization of this structure by reusing data and making each thread compute multiple output elements.

for example, f() can be a regular matrix multiply, f()=@mtimes. for such patterns, gpu coder provides the matrixmatrix kernel to create a highly efficient, fast implementation of matrix-matrix operations on the gpu.

use the function and create cuda code for performing matrix-matrix type operations.

see also

| | | |

related examples

more about

网站地图