Skip to content

Coding Style

Chao Liu edited this page May 25, 2022 · 19 revisions

Naming Style

  • Class: ClassName
  • Class member function: void MemberFunctionName()
  • Class member variable: class_member_
  • Template argument: TemplateArgument
  • Function: void function_name()
  • Function arguement: function_argument_name or functionArgumentName
  • Local variable: local_variable_name or localVariableName
  • Compiler time constant: kConstant ???
  • pointer: p_pointer_name or pPointerName

Integer Type

  • For index, only opaque type index_t and long_index_t should be used, concrete integer type like int, int32_t, long is not allowed
  • If tensor data that is integer type, only concrete type like int32_t, uint32_t, int64_t are allow. Also, use int32_t instead of int, use uint32_t instead of unsigned

Enum

  • Use enum class instead of enum

Tensor Descriptor

  • A tensor descriptor must clearly indicate:
    • Each dimension of tensor in the correct order
    • The scope of the tensor: grid/block/wave/thread level
    • For example, for grid level input image tensor In[N, C, Hi, Wi] should be declared as const InGridDescriptor_N_C_Hi_Wi in_grid_desc_n_c_hi_wi
  • Use CamelCase for variables that describe the shape of tensor: NumOfDimension, Length, Stride, GemmM
  • use xx_yy_zz or xxYyZz for index: i, i_pad, iPad

Type conversion

  • Avoid explicit type conversion in GPU code, use ck::type_convert for casting

file

  • use #pragma once in header files

git

  • use git mv instead of mv to move files, to keep file history

External dependency

  • It's ok for CPU code to have external dependency.
  • For GPU code (used by function with __device__ or __global__ keyword), don't use external dependency like std.

Misc

  • Must add bracket for all if/else, switch/case
  • xs means "a container of x object", not "number of x objects"