NNFusion-CLI-Interface.md

December 15, 2020 · View on GitHub

How to add a new flag

  1. Include the object into your cmake command:

    target_link_library(your_object gflags)

  2. Include the head file "gflags/gfglas.h":

    This is included in "nnfusion_common.h", so mostly you don't have to include this mannually.

  3. DEFINE_bool(NAME, DEFUALT_VAL,"DESCRIPTION");

    Use this macro to defene a flag, this flag can be assigned value in CLI command. Here are other functions can be used: DEFINE_int32/int64/uint64/double/string …;

  4. DECLARE_bool(NAME);

    If the flag is defined in other cpp file, you can use this to declare an exsited flag.

  5. Bool flag = FLAGS_NAME;

    Remember the affix of "FLAGS_"

How to name a new flag

(Reference: GCC Options), not forced to follow

CategoriesaffixExample
Warning-W
Optimization-f-fkernel_tunning
Debugging-g
Machine-dependent-m
OtherAs your will

CLI Flags

Frontend

NameDefaultMessage
-format, -ftensorflowModel file format (tensorflow(default) or torchscript, onnx)
-params, -p"##UNSET##"Model input shape and type, fot torchscript, it's full shape like "1,1:float;2,3,4,5:double", for onnx, it's dynamic dim like "dim1_name:4;dim2_name:128"

Kernels

NameDefaultMessage
-frocm_fixed_kernelsTrueEnable Fixed kernel in ROCm codegen.
-frocm_candidate_kernelsTrueEnable some candidate kernels in ROCm.

Engine

NameDefaultMessage
-fdefault_deviceCUDAChoose defualt device from [CUDA, CPU, ROCm, HLSL] in the codegen.

Utility

NameDefaultMessage
-min_log_level0Logging level: 0 = DEBUG; 1 = INFO; 2 = WARNING; 3 = ERROR; 4 = FATAL.

Pass

NameDefaultMessage
-fcodegen_debugfalseAdd debug functions in Codegen-ed project.
-fcodegen_timingfalseAdd timing functions in Codegen-ed project.
-fadd_allreducefalseAdd Allreduce operater after ApplyGradient operator.
-fkernel_fusion_level20: no fuse; 1: fuse element kernels; 2: fuse elem+broadcast+reshape; 3: split independent groups
-ffold_reshape_optrueFolding Reshape operators.
-fconst_folding_backend""Choose which backend will be used in Constantfolding pass. Disable when not set.
-ftranspose_vecdotfalseEnable vectdot transpose.
-fkernel_selectiontrueSelect kernel before codegen.
-fkernel_tunningfalseTunning and choose best kernel when do kernel selection.
-frt_const_foldingfalseAdd runtime constant folding.
-fmem_tracefalseRecord and dump memory trace
-fmem_log_pathmemory.logThe file path of memory log.
-fnum_stream1Number of streams.
-fnuma_node_num1Number of numa_node.
-fthread_num_per_nodeCPU Cores / numa_node_numThread num of per node.
-fantares_codegen_server""Antares codegen server address and port, format: <ip>:<port>
-fnum_non_cpu1Number of devices.
-fkernels_as_filesfalseSaving kernels as standalone source code files.
-fkernels_files_number-1Saving kernels into how many source code files.
-fuse_default_streamtrueUse default stream.
-fcuda_init_streamdefaultThe stream of kernels in cuda_init().
-fstream_assign_policynaiveChoose stream-assign policy from [naive, kernel_prof_based].
-fpara_json_file./para_info.jsonKenel entry parameter info json file.
-ftraining_modefalseTurn on training mode.
-fextern_result_memoryfalseModel result tensor memory is managed externally.
-fenable_kernel_profilingfalseProfile kernel time cost.
-fmerge_prof_compilingfalse
-fautodifffalseAdd backward graph.
-fantares_modefalseEnable antares mode.
-fcsetrueCommon subexpression elimination.
-fpattern_substitutiontrueSubstitute listed patterns with more efficient implementations.