# Difference between revisions of "CUDA examples"

m (→Gram-Schmidt method) |
(→Scalar product) |
||

Line 9: | Line 9: | ||

Due to its very small computational cost, the scalar product is certainly 'not' suited for porting to a GPU. However, if a complex algorithm requires a scalar product and the algorithm is ported to a GPU, it is necessary to also port the scalar product to the GPU. Otherwise, one would need to transfer data back to the CPU, which is even more time consuming. | Due to its very small computational cost, the scalar product is certainly 'not' suited for porting to a GPU. However, if a complex algorithm requires a scalar product and the algorithm is ported to a GPU, it is necessary to also port the scalar product to the GPU. Otherwise, one would need to transfer data back to the CPU, which is even more time consuming. | ||

− | This example demonstrates several possible strategies | + | This example demonstrates several possible strategies. It also serves as a good example for the use of atomic operations, and how they can be avoided. e.g. on older hardware. Some of the examples deliberatedly don't work to show the pitfalls of massively parallel computation, and to demonstrate that atomic operations are really necessary. Note that the use of atomic operations is rather slow, and therefore in this example no speed up is gained by using them. However, the use of atomic operations makes the code considerably shorter and easier to read, which is important in a scientific environment, where code is continously developed further. |

{{Download|ScalarGPU-0.1.tar.gz|Code example scalar product|tgz}} | {{Download|ScalarGPU-0.1.tar.gz|Code example scalar product|tgz}} |

## Revision as of 18:37, 1 February 2011

# Gram-Schmidt method

This example implements the Gram-Schmidt orthogonalization method for fully occupied matrices. While for sparse matrices, the Householder method is typically more efficient, the Gram-Schmidt method is still widely used for fully occupied matrices due to its robustness. And due to its structure, the method can be easily implemented on GPUs using CUDA.

Code example Gram-Schmidt method (23 KB)

# Scalar product

Due to its very small computational cost, the scalar product is certainly 'not' suited for porting to a GPU. However, if a complex algorithm requires a scalar product and the algorithm is ported to a GPU, it is necessary to also port the scalar product to the GPU. Otherwise, one would need to transfer data back to the CPU, which is even more time consuming.

This example demonstrates several possible strategies. It also serves as a good example for the use of atomic operations, and how they can be avoided. e.g. on older hardware. Some of the examples deliberatedly don't work to show the pitfalls of massively parallel computation, and to demonstrate that atomic operations are really necessary. Note that the use of atomic operations is rather slow, and therefore in this example no speed up is gained by using them. However, the use of atomic operations makes the code considerably shorter and easier to read, which is important in a scientific environment, where code is continously developed further.

Code example scalar product (17 KB)