Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 1 | /// |
Adnan AlSinan | abc093b | 2022-02-08 16:57:06 +0000 | [diff] [blame] | 2 | /// Copyright (c) 2019-2022 Arm Limited. |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 3 | /// |
| 4 | /// SPDX-License-Identifier: MIT |
| 5 | /// |
| 6 | /// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | /// of this software and associated documentation files (the "Software"), to |
| 8 | /// deal in the Software without restriction, including without limitation the |
| 9 | /// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | /// sell copies of the Software, and to permit persons to whom the Software is |
| 11 | /// furnished to do so, subject to the following conditions: |
| 12 | /// |
| 13 | /// The above copyright notice and this permission notice shall be included in all |
| 14 | /// copies or substantial portions of the Software. |
| 15 | /// |
| 16 | /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | /// SOFTWARE. |
| 23 | /// |
| 24 | namespace arm_compute |
| 25 | { |
| 26 | /** |
Sheri Zhang | d813bab | 2021-04-30 16:53:41 +0100 | [diff] [blame] | 27 | @page contribution_guidelines Contribution Guidelines |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 28 | |
| 29 | @tableofcontents |
| 30 | |
| 31 | If you want to contribute to Arm Compute Library, be sure to review the following guidelines. |
| 32 | |
| 33 | The development is structured in the following way: |
| 34 | - Release repository: https://github.com/arm-software/ComputeLibrary |
| 35 | - Development repository: https://review.mlplatform.org/#/admin/projects/ml/ComputeLibrary |
| 36 | - Please report issues here: https://github.com/ARM-software/ComputeLibrary/issues |
| 37 | |
Adnan AlSinan | abc093b | 2022-02-08 16:57:06 +0000 | [diff] [blame] | 38 | @section S5_0_inc_lang Inclusive language guideline |
| 39 | As part of the initiative to use inclusive language, there are certain phrases and words that were removed or replaced by more inclusive ones. Examples include but not limited to: |
| 40 | \includedoc non_inclusive_language_examples.dox |
| 41 | |
| 42 | Please also follow this guideline when committing changes to Compute Library. |
ramelg01 | b4cd2dc | 2022-03-30 18:42:23 +0100 | [diff] [blame] | 43 | It is worth mentioning that the term "master" is still used in some comments but only in reference to external code links that Arm has no governance on. |
Adnan AlSinan | abc093b | 2022-02-08 16:57:06 +0000 | [diff] [blame] | 44 | |
Ramy Elgammal | fa8ff8e | 2022-08-12 16:57:10 +0100 | [diff] [blame] | 45 | Futhermore, starting from release (22.05), 'master' branch is no longer being used, it has been replaced by 'main'. Please update your clone jobs accordingly. |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 46 | @section S5_1_coding_standards Coding standards and guidelines |
| 47 | |
| 48 | Best practices (as suggested by clang-tidy): |
| 49 | |
| 50 | - No uninitialised values |
| 51 | |
| 52 | Helps to prevent undefined behaviour and allows to declare variables const if they are not changed after initialisation. See http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-type-member-init.html |
| 53 | |
| 54 | @code{.cpp} |
| 55 | const float32x4_t foo = vdupq_n_f32(0.f); |
| 56 | const float32x4_t bar = foo; |
| 57 | |
| 58 | const int32x4x2_t i_foo = {{ |
| 59 | vconvq_s32_f32(foo), |
| 60 | vconvq_s32_f32(foo) |
| 61 | }}; |
| 62 | const int32x4x2_t i_bar = i_foo; |
| 63 | @endcode |
| 64 | |
| 65 | - No C-style casts (in C++ source code) |
| 66 | |
| 67 | Only use static_cast, dynamic_cast, and (if required) reinterpret_cast and const_cast. See http://en.cppreference.com/w/cpp/language/explicit_cast for more information when to use which type of cast. C-style casts do not differentiate between the different cast types and thus make it easy to violate type safety. Also, due to the prefix notation it is less clear which part of an expression is going to be casted. See http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-pro-type-cstyle-cast.html |
| 68 | |
| 69 | - No implicit casts to bool |
| 70 | |
| 71 | Helps to increase readability and might help to catch bugs during refactoring. See http://clang.llvm.org/extra/clang-tidy/checks/readability-implicit-bool-cast.html |
| 72 | |
| 73 | @code{.cpp} |
| 74 | extern int *ptr; |
| 75 | if(ptr){} // Bad |
| 76 | if(ptr != nullptr) {} // Good |
| 77 | |
| 78 | extern int foo; |
| 79 | if(foo) {} // Bad |
| 80 | if(foo != 0) {} // Good |
| 81 | @endcode |
| 82 | |
| 83 | - Use nullptr instead of NULL or 0 |
| 84 | |
| 85 | The nullptr literal is type-checked and is therefore safer to use. See http://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html |
| 86 | |
| 87 | - No need to explicitly initialise std::string with an empty string |
| 88 | |
| 89 | The default constructor of std::string creates an empty string. In general it is therefore not necessary to specify it explicitly. See http://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-string-init.html |
| 90 | |
| 91 | @code{.cpp} |
| 92 | // Instead of |
| 93 | std::string foo(""); |
| 94 | std::string bar = ""; |
| 95 | |
| 96 | // The following has the same effect |
| 97 | std::string foo; |
| 98 | std::string bar; |
| 99 | @endcode |
| 100 | |
| 101 | - Braces for all control blocks and loops (which have a body) |
| 102 | |
| 103 | To increase readability and protect against refactoring errors the body of control block and loops must be wrapped in braces. See http://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html |
| 104 | |
| 105 | For now loops for which the body is empty do not have to add empty braces. This exception might be revoked in the future. Anyway, situations in which this exception applies should be rare. |
| 106 | |
| 107 | @code{.cpp} |
| 108 | Iterator it; |
| 109 | while(it.next()); // No need for braces here |
| 110 | |
| 111 | // Make more use of it |
| 112 | @endcode |
| 113 | |
| 114 | - Only one declaration per line |
| 115 | |
| 116 | Increase readability and thus prevent errors. |
| 117 | |
| 118 | @code{.cpp} |
| 119 | int a, b; // BAD |
| 120 | int c, *d; // EVEN WORSE |
| 121 | |
| 122 | int e = 0; // GOOD |
| 123 | int *p = nullptr; // GOOD |
| 124 | @endcode |
| 125 | |
| 126 | - Pass primitive types (and those that are cheap to copy or move) by value |
| 127 | |
| 128 | For primitive types it is more efficient to pass them by value instead of by const reference because: |
| 129 | |
| 130 | - the data type might be smaller than the "reference type" |
| 131 | - pass by value avoids aliasing and thus allows for better optimisations |
| 132 | - pass by value is likely to avoid one level of indirection (references are often implemented as auto dereferenced pointers) |
| 133 | |
| 134 | This advice also applies to non-primitive types that have cheap copy or move operations and the function needs a local copy of the argument anyway. |
| 135 | |
| 136 | More information: |
| 137 | |
| 138 | - http://stackoverflow.com/a/14013189 |
| 139 | - http://stackoverflow.com/a/270435 |
| 140 | - http://web.archive.org/web/20140113221447/http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/ |
| 141 | |
| 142 | @code{.cpp} |
| 143 | void foo(int i, long l, float32x4_t f); // Pass-by-value for builtin types |
| 144 | void bar(const float32x4x4_t &f); // As this is a struct pass-by-const-reference is probably better |
| 145 | void foobar(const MyLargeCustomTypeClass &m); // Definitely better as const-reference except if a copy has to be made anyway. |
| 146 | @endcode |
| 147 | |
| 148 | - Don't use unions |
| 149 | |
Jakub Sujak | ee301b3 | 2021-06-04 09:46:08 +0100 | [diff] [blame] | 150 | Unions cannot be used to convert values between different types because (in C++) it is undefined behaviour to read from a member other than the last one that has been assigned to. This limits the use of unions to a few corner cases and therefore the general advice is not to use unions. See http://releases.llvm.org/3.8.0/tools/clang/tools/extra/docs/clang-tidy/checks/cppcoreguidelines-pro-type-union-access.html |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 151 | |
| 152 | - Use pre-increment/pre-decrement whenever possible |
| 153 | |
Jakub Sujak | ee301b3 | 2021-06-04 09:46:08 +0100 | [diff] [blame] | 154 | In contrast to the pre-increment the post-increment has to make a copy of the incremented object. This might not be a problem for primitive types like int but for class like objects that overload the operators, like iterators, it can have a huge impact on the performance. See http://stackoverflow.com/a/9205011 |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 155 | |
| 156 | To be consistent across the different cases the general advice is to use the pre-increment operator unless post-increment is explicitly required. The same rules apply for the decrement operator. |
| 157 | |
| 158 | @code{.cpp} |
| 159 | for(size_t i = 0; i < 9; i++); // BAD |
| 160 | for(size_t i = 0; i < 9; ++i); // GOOD |
| 161 | @endcode |
| 162 | |
| 163 | - Don't use uint in C/C++ |
| 164 | |
| 165 | The C and C++ standards don't define a uint type. Though some compilers seem to support it by default it would require to include the header sys/types.h. Instead we use the slightly more verbose unsigned int type. |
| 166 | |
| 167 | - Don't use unsigned int in function's signature |
| 168 | |
| 169 | Unsigned integers are good for representing bitfields and modular arithmetic. The fact that unsigned arithmetic doesn't model the behavior of a simple integer, but is instead defined by the standard to model modular arithmetic (wrapping around on overflow/underflow), means that a significant class of bugs cannot be diagnosed by the compiler. Mixing signedness of integer types is responsible for an equally large class of problems. |
| 170 | |
| 171 | - No "Yoda-style" comparisons |
| 172 | |
| 173 | As compilers are now able to warn about accidental assignments if it is likely that the intention has been to compare values it is no longer required to place literals on the left-hand side of the comparison operator. Sticking to the natural order increases the readability and thus prevents logical errors (which cannot be spotted by the compiler). In the rare case that the desired result is to assign a value and check it the expression has to be surrounded by parentheses. |
| 174 | |
| 175 | @code{.cpp} |
| 176 | if(nullptr == ptr || false == cond) // BAD |
| 177 | { |
| 178 | //... |
| 179 | } |
| 180 | |
| 181 | if(ptr == nullptr || cond == false) // GOOD |
| 182 | { |
| 183 | //... |
| 184 | } |
| 185 | |
| 186 | if(ptr = nullptr || cond = false) // Most likely a mistake. Will cause a compiler warning |
| 187 | { |
| 188 | //... |
| 189 | } |
| 190 | |
| 191 | if((ptr = nullptr) || (cond = false)) // Trust me, I know what I'm doing. No warning. |
| 192 | { |
| 193 | //... |
| 194 | } |
| 195 | @endcode |
| 196 | |
| 197 | @subsection S5_1_1_rules Rules |
| 198 | |
| 199 | - Use spaces for indentation and alignment. No tabs! Indentation should be done with 4 spaces. |
| 200 | - Unix line returns in all the files. |
| 201 | - Pointers and reference symbols attached to the variable name, not the type (i.e. char \&foo;, and not char& foo). |
| 202 | - No trailing spaces or tabs at the end of lines. |
| 203 | - No spaces or tabs on empty lines. |
| 204 | - Put { and } on a new line and increase the indentation level for code inside the scope (except for namespaces). |
| 205 | - Single space before and after comparison operators ==, <, >, !=. |
| 206 | - No space around parenthesis. |
| 207 | - No space before, one space after ; (unless it is at the end of a line). |
| 208 | |
| 209 | @code{.cpp} |
| 210 | for(int i = 0; i < width * height; ++i) |
| 211 | { |
| 212 | void *d = foo(ptr, i, &addr); |
| 213 | static_cast<uint8_t *>(data)[i] = static_cast<uint8_t *>(d)[0]; |
| 214 | } |
| 215 | @endcode |
| 216 | |
| 217 | - Put a comment after \#else, \#endif, and namespace closing brace indicating the related name |
| 218 | |
| 219 | @code{.cpp} |
| 220 | namespace mali |
| 221 | { |
| 222 | #ifdef MALI_DEBUG |
| 223 | ... |
| 224 | #else // MALI_DEBUG |
| 225 | ... |
| 226 | #endif // MALI_DEBUG |
| 227 | } // namespace mali |
| 228 | @endcode |
| 229 | |
| 230 | - CamelCase for class names only and lower case words separated with _ (snake_case) for all the functions / methods / variables / arguments / attributes. |
| 231 | |
| 232 | @code{.cpp} |
| 233 | class ClassName |
| 234 | { |
| 235 | public: |
| 236 | void my_function(); |
| 237 | int my_attribute() const; // Accessor = attribute name minus '_', const if it's a simple type |
| 238 | private: |
| 239 | int _my_attribute; // '_' in front of name |
| 240 | }; |
| 241 | @endcode |
| 242 | |
| 243 | - Use quotes instead of angular brackets to include local headers. Use angular brackets for system headers. |
| 244 | - Also include the module header first, then local headers, and lastly system headers. All groups should be separated by a blank line and sorted lexicographically within each group. |
| 245 | - Where applicable the C++ version of system headers has to be included, e.g. cstddef instead of stddef.h. |
| 246 | - See http://llvm.org/docs/CodingStandards.html#include-style |
| 247 | |
| 248 | @code{.cpp} |
| 249 | #include "MyClass.h" |
| 250 | |
| 251 | #include "arm_cv/core/Helpers.h" |
| 252 | #include "arm_cv/core/Types.h" |
| 253 | |
| 254 | #include <cstddef> |
| 255 | #include <numeric> |
| 256 | @endcode |
| 257 | |
| 258 | - Only use "auto" when the type can be explicitly deduced from the assignment. |
| 259 | |
| 260 | @code{.cpp} |
| 261 | auto a = static_cast<float*>(bar); // OK: there is an explicit cast |
| 262 | auto b = std::make_unique<Image>(foo); // OK: we can see it's going to be an std::unique_ptr<Image> |
| 263 | auto c = img.ptr(); // NO: Can't tell what the type is without knowing the API. |
| 264 | auto d = vdup_n_u8(0); // NO: It's not obvious what type this function returns. |
| 265 | @endcode |
| 266 | |
SiCong Li | 1fad9f2 | 2023-03-23 17:16:26 +0000 | [diff] [blame] | 267 | - When to use const |
| 268 | |
| 269 | - Local variables: Use const as much as possible. E.g. all read-ony variables should be declared as const. |
| 270 | |
| 271 | - Function parameters |
| 272 | |
| 273 | - Top-level const must not be used in the function declaration or definition. (Note that this applies to all types, including non-primitive types) |
| 274 | This is because for function parameters, top-level const in function declaration is always ignored by the compiler (it is meaningless). |
| 275 | Therefore we should omit top-level const to reduce visual clutter. In addition, its omission can improve API/ABI |
| 276 | stability to some extent as there is one fewer varying factor in function signatures. |
| 277 | |
| 278 | Note that we could in theory allow top-level const in only definition (which is not ignored by the compiler) but not declaration. |
| 279 | But certain toolchains are known to require the declaration and definition to match exactly. |
| 280 | |
| 281 | - Use low-level const (of references and pointers) as much as possible. |
| 282 | @code{.cpp} |
| 283 | // Primitive types |
| 284 | void foo(const int a); // NO: Top-level const must not be used in function declaration or definition |
| 285 | void foo(int a); // OK |
| 286 | // Pointer to primitive types |
| 287 | void foo(int *const a); // NO: Top-level const |
| 288 | void foo(const int *const a); // NO: Top-level const |
| 289 | void foo(int *a); // OK. But only if foo needs to mutate the underlying object |
| 290 | void foo(const int *a); // OK but not recommended: See section above about passing primitives by value |
| 291 | // Reference to primitive types |
| 292 | // There's no "top-level const" for references |
| 293 | void foo(int &a); // OK. But only if foo needs to mutate the underlying object |
| 294 | void foo(const int &a); // OK but not recommended: See section above about passing primitives by value |
| 295 | |
| 296 | // Custom types |
| 297 | void foo(const Goo g); // NO: Top-level const |
| 298 | void foo(Goo g); // OK |
| 299 | // Pointer to custom types |
| 300 | void foo(Goo *const g); // NO: Top-level const |
| 301 | void foo(Goo *g); // OK. But only if foo needs to mutate the underlying object |
| 302 | void foo(const Goo *g); // OK |
| 303 | // Reference to custom types |
| 304 | void foo(Goo &g); // OK. But only if foo needs to mutate the underlying object |
| 305 | void foo(const Goo &g); // OK |
| 306 | @endcode |
| 307 | |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 308 | - OpenCL: |
| 309 | - Use __ in front of the memory types qualifiers and kernel: __kernel, __constant, __private, __global, __local. |
| 310 | - Indicate how the global workgroup size / offset / local workgroup size are being calculated. |
| 311 | |
| 312 | - Doxygen: |
| 313 | |
| 314 | - No '*' in front of argument names |
| 315 | - [in], [out] or [in,out] *in front* of arguments |
Viet-Hoa Do | aa79405 | 2022-05-23 16:47:42 +0100 | [diff] [blame] | 316 | - Skip a line between the description and params and between params and \@return (If there is a return) |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 317 | - Align params names and params descriptions (Using spaces), and with a single space between the widest column and the next one. |
| 318 | - Use an upper case at the beginning of the description |
| 319 | |
| 320 | @snippet arm_compute/runtime/NEON/functions/NEActivationLayer.h NEActivationLayer snippet |
| 321 | |
| 322 | @subsection S5_1_2_how_to_check_the_rules How to check the rules |
| 323 | |
| 324 | astyle (http://astyle.sourceforge.net/) and clang-format (https://clang.llvm.org/docs/ClangFormat.html) can check and help you apply some of these rules. |
| 325 | |
| 326 | @subsection S5_1_3_library_size_guidelines Library size: best practices and guidelines |
| 327 | |
| 328 | @subsubsection S5_1_3_1_template_suggestions Template suggestions |
| 329 | |
| 330 | When writing a new patch we should also have in mind the effect it will have in the final library size. We can try some of the following things: |
| 331 | |
| 332 | - Place non-dependent template code in a different non-templated class/method |
| 333 | |
| 334 | @code{.cpp} |
| 335 | template<typename T> |
| 336 | class Foo |
| 337 | { |
| 338 | public: |
| 339 | enum { v1, v2 }; |
| 340 | // ... |
| 341 | }; |
| 342 | @endcode |
| 343 | |
| 344 | can be converted to: |
| 345 | |
| 346 | @code{.cpp} |
| 347 | struct Foo_base |
| 348 | { |
| 349 | enum { v1, v2 }; |
| 350 | // ... |
| 351 | }; |
| 352 | |
| 353 | template<typename T> |
| 354 | class Foo : public Foo_base |
| 355 | { |
| 356 | public: |
| 357 | // ... |
| 358 | }; |
| 359 | @endcode |
| 360 | |
| 361 | - In some cases it's preferable to use runtime switches instead of template parameters |
| 362 | |
| 363 | - Sometimes we can rewrite the code without templates and without any (significant) performance loss. Let's say that we've written a function where the only use of the templated argument is used for casting: |
| 364 | |
| 365 | @code{.cpp} |
| 366 | template <typename T> |
| 367 | void NETemplatedKernel::run(const Window &window) |
| 368 | { |
| 369 | ... |
| 370 | *(reinterpret_cast<T *>(out.ptr())) = *(reinterpret_cast<const T *>(in.ptr())); |
| 371 | ... |
| 372 | } |
| 373 | @endcode |
| 374 | |
| 375 | The above snippet can be transformed to: |
| 376 | |
| 377 | @code{.cpp} |
| 378 | void NENonTemplatedKernel::run(const Window &window) |
| 379 | { |
| 380 | ... |
| 381 | std::memcpy(out.ptr(), in.ptr(), element_size); |
| 382 | ... |
| 383 | } |
| 384 | @endcode |
| 385 | |
| 386 | @subsection S5_1_4_secure_coding_practices Secure coding practices |
| 387 | |
| 388 | @subsubsection S5_1_4_1_general_coding_practices General Coding Practices |
| 389 | |
| 390 | - **Use tested and approved managed code** rather than creating new unmanaged code for common tasks. |
| 391 | - **Utilize locking to prevent multiple simultaneous requests** or use a synchronization mechanism to prevent race conditions. |
| 392 | - **Protect shared variables and resources** from inappropriate concurrent access. |
| 393 | - **Explicitly initialize all your variables and other data stores**, either during declaration or just before the first usage. |
| 394 | - **In cases where the application must run with elevated privileges, raise privileges as late as possible, and drop them as soon as possible**. |
| 395 | - **Avoid calculation errors** by understanding your programming language's underlying representation and how it interacts with numeric calculation. Pay close attention to byte size discrepancies, precision, signed/unsigned distinctions, truncation, conversion and casting between types, "not-a-number" calculations, and how your language handles numbers that are too large or too small for its underlying representation. |
| 396 | - **Restrict users from generating new code** or altering existing code. |
| 397 | |
| 398 | |
| 399 | @subsubsection S5_1_4_2_secure_coding_best_practices Secure Coding Best Practices |
| 400 | |
| 401 | - **Validate input**. Validate input from all untrusted data sources. Proper input validation can eliminate the vast majority of software vulnerabilities. Be suspicious of most external data sources, including command line arguments, network interfaces, environmental variables, and user controlled files. |
| 402 | - **Heed compiler warnings**. Compile code using the default compiler flags that exist in the SConstruct file. |
| 403 | - Use **static analysis tools** to detect and eliminate additional security flaws. |
| 404 | - **Keep it simple**. Keep the design as simple and small as possible. Complex designs increase the likelihood that errors will be made in their implementation, configuration, and use. Additionally, the effort required to achieve an appropriate level of assurance increases dramatically as security mechanisms become more complex. |
| 405 | - **Default deny**. Base access decisions on permission rather than exclusion. This means that, by default, access is denied and the protection scheme identifies conditions under which access is permitted |
| 406 | - **Adhere to the principle of least privilege**. Every process should execute with the least set of privileges necessary to complete the job. Any elevated permission should only be accessed for the least amount of time required to complete the privileged task. This approach reduces the opportunities an attacker has to execute arbitrary code with elevated privileges. |
| 407 | - **Sanitize data sent to other systems**. Sanitize all data passed to complex subsystems such as command shells, relational databases, and commercial off-the-shelf (COTS) components. Attackers may be able to invoke unused functionality in these components through the use of various injection attacks. This is not necessarily an input validation problem because the complex subsystem being invoked does not understand the context in which the call is made. Because the calling process understands the context, it is responsible for sanitizing the data before invoking the subsystem. |
| 408 | - **Practice defense in depth**. Manage risk with multiple defensive strategies, so that if one layer of defense turns out to be inadequate, another layer of defense can prevent a security flaw from becoming an exploitable vulnerability and/or limit the consequences of a successful exploit. For example, combining secure programming techniques with secure runtime environments should reduce the likelihood that vulnerabilities remaining in the code at deployment time can be exploited in the operational environment. |
| 409 | |
Sang-Hoon Park | 776c235 | 2020-10-21 10:30:20 +0100 | [diff] [blame] | 410 | @subsection S5_1_5_guidelines_for_stable_api_abi Guidelines for stable API/ABI |
| 411 | |
| 412 | The Application Programming Interface (API) and Application Binary Interface (ABI) are the interfaces exposed |
| 413 | to users so their programs can interact with the library efficiently and effectively. Even though changing API/ABI |
| 414 | in a way that does not give backward compatibility is not necessarily bad if it can improve other users' experience and the library, |
| 415 | contributions should be made with the awareness of API/ABI stability. If you'd like to make changes that affects |
| 416 | the library's API/ABI, please review and follow the guidelines shown in this section. Also, please note that |
| 417 | these guidelines are not exhaustive list but discussing things that might be easily overlooked. |
| 418 | |
| 419 | @subsubsection S5_1_5_1_guidelines_for_api Guidelines for API |
| 420 | |
| 421 | - When adding new arguments, consider grouping arguments (including the old ones) into a struct rather than adding arguments with default values. |
| 422 | Introducing a new struct might break the API/ABI once, but it will be helpful to keep the stability. |
| 423 | - When new member variables are added, please make sure they are initialized. |
| 424 | - Avoid adding enum elements in the middle. |
| 425 | - When removing arguments, follow the deprecation process described in the following section. |
| 426 | - When changing behavior affecting API contracts, follow the deprecation process described in the following section. |
| 427 | |
| 428 | @subsubsection S5_1_5_2_guidelines_for_abi Guidelines for ABI |
| 429 | |
| 430 | We recommend to read through <a href="https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B">this page</a> |
| 431 | and double check your contributions to see if they include the changes listed. |
| 432 | |
| 433 | Also, for classes that requires strong ABI stability, consider using <a href="https://en.cppreference.com/w/cpp/language/pimpl">pImpl idiom</a>. |
| 434 | |
| 435 | @subsubsection S5_1_5_3_api_deprecation_process API deprecation process |
| 436 | |
| 437 | In order to deprecate an existing API, these rules should be followed. |
| 438 | |
| 439 | - Removal of a deprecated API should wait at least for one official release. |
| 440 | - Deprecation of runtime APIs should strictly follow the aforementioned period, whereas core APIs can have more flexibility as they are mostly used internally rather than user-facing. |
| 441 | - Any API changes (update, addition and deprecation) in all components should be well documented by the contribution itself. |
| 442 | |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 443 | Also, it is recommended to use the following utility macros which is designed to work with both clang and gcc using C++14 and later. |
Sang-Hoon Park | 776c235 | 2020-10-21 10:30:20 +0100 | [diff] [blame] | 444 | |
| 445 | - ARM_COMPUTE_DEPRECATED: Just deprecate the wrapped function |
| 446 | - ARM_COMPUTE_DEPRECATED_REL: Deprecate the wrapped function and also capture the release that was deprecated |
| 447 | - ARM_COMPUTE_DEPRECATED_REL_REPLACE: Deprecate the wrapped function and also capture the release that was deprecated along with a possible replacement candidate |
| 448 | |
| 449 | @code{.cpp} |
| 450 | ARM_COMPUTE_DEPRECATED_REL_REPLACE(20.08, DoNewThing) |
| 451 | void DoOldThing(); |
| 452 | |
| 453 | void DoNewThing(); |
| 454 | @endcode |
| 455 | |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 456 | @section S5_2_how_to_submit_a_patch How to submit a patch |
| 457 | |
| 458 | To be able to submit a patch to our development repository you need to have a GitHub account. With that, you will be able to sign in to Gerrit where your patch will be reviewed. |
| 459 | |
| 460 | Next step is to clone the Compute Library repository: |
| 461 | |
| 462 | git clone "ssh://<your-github-id>@review.mlplatform.org:29418/ml/ComputeLibrary" |
| 463 | |
| 464 | If you have cloned from GitHub or through HTTP, make sure you add a new git remote using SSH: |
| 465 | |
| 466 | git remote add acl-gerrit "ssh://<your-github-id>@review.mlplatform.org:29418/ml/ComputeLibrary" |
| 467 | |
| 468 | After that, you will need to upload an SSH key to https://review.mlplatform.org/#/settings/ssh-keys |
| 469 | |
| 470 | Then, make sure to install the commit-msg Git hook in order to add a change-ID to the commit message of your patch: |
| 471 | |
| 472 | cd "ComputeLibrary" && mkdir -p .git/hooks && curl -Lo `git rev-parse --git-dir`/hooks/commit-msg https://review.mlplatform.org/tools/hooks/commit-msg; chmod +x `git rev-parse --git-dir`/hooks/commit-msg) |
| 473 | |
| 474 | When your patch is ready, remember to sign off your contribution by adding a line with your name and e-mail address to every git commit message: |
| 475 | |
| 476 | Signed-off-by: John Doe <john.doe@example.org> |
| 477 | |
| 478 | You must use your real name, no pseudonyms or anonymous contributions are accepted. |
| 479 | |
| 480 | You can add this to your patch with: |
| 481 | |
| 482 | git commit -s --amend |
| 483 | |
| 484 | You are now ready to submit your patch for review: |
| 485 | |
ramelg01 | 36a1c11 | 2022-03-29 19:09:56 +0100 | [diff] [blame] | 486 | git push acl-gerrit HEAD:refs/for/main |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 487 | |
| 488 | @section S5_3_code_review Patch acceptance and code review |
| 489 | |
Jakub Sujak | ee301b3 | 2021-06-04 09:46:08 +0100 | [diff] [blame] | 490 | Once a patch is uploaded for review, there is a pre-commit test that runs on a Jenkins server for continuous integration tests. In order to be merged a patch needs to: |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 491 | |
| 492 | - get a "+1 Verified" from the pre-commit job |
| 493 | - get a "+1 Comments-Addressed", in case of comments from reviewers the committer has to address them all. A comment is considered addressed when the first line of the reply contains the word "Done" |
| 494 | - get a "+2" from a reviewer, that means the patch has the final approval |
| 495 | |
ramelg01 | b2eba7f | 2021-12-23 08:32:08 +0000 | [diff] [blame] | 496 | At the moment, the Jenkins server is not publicly accessible and for security reasons patches submitted by non-allowlisted committers do not trigger the pre-commit tests. For this reason, one of the maintainers has to manually trigger the job. |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 497 | |
| 498 | If the pre-commit test fails, the Jenkins job will post a comment on Gerrit with the details about the failure so that the committer will be able to reproduce the error and fix the issue, if any (sometimes there can be infrastructure issues, a test platform disconnecting for example, where the job needs to be retriggered). |
| 499 | |
| 500 | */ |
| 501 | } // namespace arm_compute |