visioncpp.codegen¶
-
visioncpp.codegen.
clang_format
(code, clang_format=None)[source]¶ Run clang-format over C++ code.
This function is safe to call, regardless of whether clang-format is present on the system. If clang-format is not found, the returned code is the same as the input.
- Arguments:
- code (str): C++ code. clang_format (str, optional): Path to clang-format.
- Returns:
- str: Formatted C++ code.
-
visioncpp.codegen.
find_clang_format
()[source]¶ Find clang-format binary.
- Returns:
- str: Path to clang-format if found, else None.
-
visioncpp.codegen.
generate
(expression, devtype, use_clang_format=True)[source]¶ Generate C++ code for an expression tree.
- Arguments:
- expression (VisionCpp.Operation): Root of the expression tree. devtype (str, optional): Execution device type.
- Returns:
- str: C++ code.
-
visioncpp.codegen.
get_device
(devtype='cpu', name='device')[source]¶ Return the lines to construct a VisionCPP device.
- Arguments:
- devtype (str, optional): Either “gpu” or “cpu”. name (str, optional): Name of the constructed device variable.
- Returns:
- str[]: C++ lines.
- Raises:
- VisionCppException: If device type is neither “cpu” or “gpu”.