|
| 1 | +.. meta:: |
| 2 | + :description: How to contribute to hipBLAS |
| 3 | + :keywords: hipBLAS, rocBLAS, BLAS, ROCm, API, contribution |
| 4 | + |
| 5 | +.. _contribute: |
| 6 | + |
| 7 | +******************************************************************** |
| 8 | +Contributing to hipBLAS |
| 9 | +******************************************************************** |
| 10 | + |
| 11 | +This topic explains how to contribute to the hipBLAS code base, including coding |
| 12 | +and pull request (PR) guidelines and information about static code analysis. |
| 13 | + |
| 14 | +Pull request guidelines |
| 15 | +======================= |
| 16 | + |
| 17 | +The hipBLAS code contribution guidelines closely follow the `GitHub |
| 18 | +pull requests <https://help.github.com/articles/using-pull-requests/>`__ model. |
| 19 | +The hipBLAS repository follows a workflow that dictates a ``release`` branch, from which releases are cut, and a |
| 20 | +``develop`` branch, which serves as an integration branch for new code. Pull requests should |
| 21 | +adhere to these guidelines: |
| 22 | + |
| 23 | +* Target the **develop** branch for integration. |
| 24 | +* Ensure code builds successfully. |
| 25 | +* Do not break existing test cases. |
| 26 | +* New unit tests should integrate with the existing GoogleTest framework. |
| 27 | +* Tests must have good code coverage. |
| 28 | + |
| 29 | +Coding guidelines: |
| 30 | +================== |
| 31 | + |
| 32 | +* Don't use unnamed namespaces inside of header files. |
| 33 | +* Use either ``template`` or ``inline`` (or both) for functions defined outside of classes in header files. |
| 34 | +* Do not declare namespace-scope (not ``class``-scope) functions ``static`` inside of header files |
| 35 | + unless: |
| 36 | + |
| 37 | + * There is a very good reason. |
| 38 | + * The function does not have any non-``const`` ``static`` local variables. |
| 39 | + * It is acceptable that each compilation unit will have its own independent definition of the function and |
| 40 | + its ``static`` local variables. |
| 41 | + |
| 42 | + .. note:: |
| 43 | + |
| 44 | + ``static`` ``class`` member functions defined in header files are okay. |
| 45 | + |
| 46 | +* Use ``static`` for ``constexpr`` ``template`` variables until C++17. After C++17, |
| 47 | + ``constexpr`` variables become ``inline`` variables and can be defined in multiple compilation units. |
| 48 | + It is okay if the ``constexpr`` variables remain ``static`` in C++17, but it means there might |
| 49 | + be some redundancy between compilation units. |
| 50 | + |
| 51 | +Code format |
| 52 | +----------- |
| 53 | + |
| 54 | +C and C++ code is formatted using ``clang-format``. To run ``clang-format``, |
| 55 | +use the version in the ``/opt/rocm/llvm/bin`` directory. Don't use your |
| 56 | +system's built-in ``clang-format``, because it might be an older version that |
| 57 | +could generate different results. |
| 58 | + |
| 59 | +To format a file, use: |
| 60 | + |
| 61 | +:: |
| 62 | + |
| 63 | + /opt/rocm/llvm/bin/clang-format -style=file -i <path-to-source-file> |
| 64 | + |
| 65 | +To format all files, run the following script in hipBLAS directory: |
| 66 | + |
| 67 | +:: |
| 68 | + |
| 69 | + #!/bin/bash |
| 70 | + git ls-files -z *.cc *.cpp *.h *.hpp *.cl *.h.in *.hpp.in *.cpp.in | xargs -0 /opt/rocm/llvm/bin/clang-format -style=file -i |
| 71 | + |
| 72 | +The githooks application can also be installed to format the code on a per-commit basis: |
| 73 | + |
| 74 | +:: |
| 75 | + |
| 76 | + ./.githooks/install |
| 77 | + |
| 78 | +Static code analysis |
| 79 | +===================== |
| 80 | + |
| 81 | +``cppcheck`` is an open-source static analysis tool. hipBLAS uses this tool to perform static code analysis. |
| 82 | + |
| 83 | +Use the following command to run ``cppcheck`` locally and generate the report for all files. |
| 84 | + |
| 85 | +.. code:: bash |
| 86 | +
|
| 87 | + $ cd hipBLAS |
| 88 | + $ cppcheck --enable=all --inconclusive --library=googletest --inline-suppr -i./build --suppressions-list=./CppCheckSuppressions.txt --template="{file}:{line}: {severity}: {id} :{message}" . 2> cppcheck_report.txt |
| 89 | +
|
| 90 | +For more information on the ``cppcheck`` command line options, see the `cppcheck <http://cppcheck.net/>`_ manual. |
0 commit comments