-
Couldn't load subscription status.
- Fork 737
General Code Guidelines
Wei, Jimmy T edited this page Mar 10, 2023
·
1 revision
We are defining our guidelines to drive the following 5 objectives:
- Emphasize KISS – Keep it Simple and Short -- Minimize the code you need to explain
- Write clean C++ code
- Use consistent variable and type naming
- Use consistent source code formatting
- Samples should be coded using DPC++ idioms and not directly use DPCT runtime functions unless demonstrating a DPCT workflow.
To make these objectives practical we need to choose specific rules to drive consistency
- "The C++ Core Guidelines" answer language questions.
- "Google Coding Style" drives consistent variable and type naming and source formatting.
- The
clang-formattool with the-style=googleoption is used to enforce consistent source formatting.clang-format -style=google -i file.cpp
We have found that a few modifications of the default style guidelines are preferred in the samples.
- Fewer source lines where possible
- Use
autofor declaring variables if it helps to shorten line length and does not obscure the concept being taught - Simple scalar types over objects when equivalent
- std:: types over user-defined types when equivalent
- The DPC++ .parallel_for() over SYCL .parallel_for()
- NOTE: to build DPC++ .parallel_for() requires the option
-fsycl-unnamed-lambda(default behavior).
- NOTE: to build DPC++ .parallel_for() requires the option
- Defining the default queue instead of over-specifying the selector
- Naming
constvalues as variables.- Do not use the
kprefix onconstvalue names unless you are defining a "magic constant" which should be emphasized
- Do not use the
- Use
\nvsstd::endl, unless an explicit flush is required
Source formatting
- C++ files have extension .cpp
- C++ header files have extension .hpp
- Enforce via
clang-format:clang-format -style=google -i file.cpp
- Home
- DPC++ what is it?
- Administration
- sample.json
- Sample Browser
- GitHub Steps for Contribution
- New Sample Submission
- Guidelines