To keep the style of the examples consistent, please follow the following guidelines when implementing your example.
Each example has to at least support CMake as build system. The simpler examples should also support Make.
Every example has to be able to be built separately from the others, but also has to be added to the top-level build scripts.
The formatting rules of the examples are enforced by clang-format using the .clang-format file in the top-level directory.
- Use
lower_snake_casestyle to name variables and functions (e.g. block_size, multiply_kernel and multiply_host). - Use
PascalCaseforclass,struct,enumand template argument definitions.
- Top-level directories use
PascalCase. - The directories in Libraries/ should use the exact name of the library they represent, including casing. If any directory does not represent a library, it should named in
camelCase. - Directories for individual examples use
snake_case. - Files generally use
snake_case, with the exception of files for which an existing convention already applies (README.md,LICENSE.md,CMakeLists.txt, etc). - Example binaries should be prefixed with the library name of the binary, so that there are no conflicts between libraries (e.g.
hipcub_device_sumandrocprim_device_sum).
Utility-functions (printing vectors, etc) and common error-handling code, that is used by all examples, should be moved to the common utility-header example_utils.hpp.
Error checking and handling should be applied where appropriate, e.g. when handling user input. HIP_CHECK should be used whenever possible. Exceptions should only be used if the complexity of the program requires it.
In most cases printing an explanation to stderr and terminating the program with an error code, as specified in the common header, is sufficient.
Results should be printed when they are helpful for the understanding and showcasing the example. However the output shouldn't be overwhelming, printing a vector with hundreds of entries is usually not useful.
A .gitignore file is required in every example subdirectory to exclude the binary generated when using Make.