HBDK Tool API Reference
hbdk4.compiler.apis.compile(m:Module, path: str, march: MarchBase | str, opt: int = 2, jobs: int = 4, max_time_per_fc: float = 0.0, debug: bool = False, hbdk3_compatible_mode: bool = False, progress_bar: bool = False, advice: float = 0.0, balance: int = 100, input_no_padding: bool = False, output_no_padding: bool = False)
Compile hbir module to hbm or hbo.
If the suffix of the output is ‘hbo’, it will compile to generate an hbo file.
Afterward, you need to call the link function to perform linking or packing operations.
- Parameters:
- m ( *) – a helper for mlir.Module that manages hbdk operations
- march ( *) – BPU march, options are “bayes”, “nash-e”, “nash-m”, “nash-p”
- path ( *) – A filesystem path to save hbm or hbo. Must ends with “.hbm” or “.hbo”
- opt ( *) – Optimization level. Defaults to 2.
- jobs ( *) – Number of threads launched during compiler optimization. Defaults to 4.
- max_time_per_fc ( *) – Set maximum time constraint (unit:us) for per funccall.
- debug ( *) – Set whether to contain debug info in HBM
- hbdk3_compatible_mode ( *) – Set whether to compile in hbdk3 compatible mode, True use hbm3 and False use hbm4
- progress_bar ( *) – Set whether to show progress bar
- advice ( *) – Print advice on ops that take longer more than the specified time (unit:us)
- advice – Print advice on ops that take longer more than the specified time (unit:us) The integer should be between 0 (minimal DDR access) and 100 (minimal cycles)
- Raises:
- * ValueError – When “path” is not ended with “.hbm”
- * ValueError – When “balance” is not in range of [0,100]
hbdk4.compiler.apis.convert(m:Module, march: MarchBase | str, advice=False, advice_path='')
Convert hbir to backend ir.
- Parameters:
- m ( *) – a helper for mlir.Module that manages hbdk operations
- march ( *) – BPU march, options are “bayes”, “nash-e”, “nash-m”, “nash-p”
hbdk4.compiler.apis.load(path: str)
load mlir text or bytecode to mlir.Module
- Parameters:
path ( *) – A filesystem path to load bytecode. Must end with “.bc”
- Raises:
* ValueError – When “path” is not ended with “.bc”
- Returns:
a helper for mlir.Module that manages hbdk operations
- Return type:
hbdk4.compiler.apis.save(m:Module, path: str)
save mlir.Module to mlir bytecode
- Parameters:
- m ( *) – a helper for mlir.Module that manages hbdk operations
- path ( *) – A filesystem path to save bytecode. Must end with “.bc”
- Raises:
* ValueError – When “path” is not ended with “.bc”
hbdk4.compiler.apis.statistics(m:Module)
Print op statics of given mlir module.
- Parameters:
m ( *) – a helper for mlir.Module that manages hbdk operations
hbdk4.compiler.apis.visualize(m:Module, onnx_file: str | None = None)
Visualize mlir using netron.
- Parameters:
- m ( *) – a helper for mlir.Module that manages hbdk operations
- onnx_file ( *) – path to store onnx proto if it is None then create directory in /tmp
class hbdk4.compiler.overlay.Argument(func: Function, idx: int, is_arg: bool)
erase()
Remove the argument from function argument
- Returns:
The first element is True when the removal done. The second element is the diagnostic if it cannot be removed.
- Return type:
Tuple
property get_attached_op: List[Operation]
Get the argument attached operations. For input argument, return operations uses the argument. For output argument, return the operation defining the argument.
- Returns:
_description_
- Return type:
List[Operation]
insert_image_convert(mode: str = 'nv12')
Insert image_convert op. Change input parameter type.
- Parameters:
mode ( *) – Specify conversion mode, optional values are “nv12”(default) and “gray”.
Example:
module = load("model.bc")
func = module[0]
func.inputs[0].insert_image_convert("nv12")
insert_image_preprocess(mode: str, divisor: int, mean: List[float], std: List[float], is_signed: bool = True)
Insert image_convert op. Change input parameter type.
- Parameters:
mode ( *) – Specify conversion mode, optional values are “none”, “yuvbt601full2rgb”(default), “yuvbt601full2bgr”, “yuvbt601video2rgb” and “yuvbt601video2bgr”.
Example:
module = load("model.bc")
func = module[0]
func.inputs[0].insert_image_preprocess("yuvbt601full2rgb", 255, [0.485, 0.456, 0.406], [0.229, 0.224, 0.225], True)
insert_roi_resize(mode: str, interp_mode='bilinear', pad_mode='zeros')
Insert roi_resize op. Change input parameter type.
- Parameters:
- mode ( *) – Specify conversion mode, optional values are “nv12”(default) and “gray”.
- interp_mode ( *) – Specify interpolation mode, optional values are “bilinear”(default) and “nearest”.
- pad_mode ( *) – Specify fill mode, optional values are “zeros”(default) and “border”.
Example:
module = load("model.bc")
func = module[0]
func.inputs[0].insert_roi_resize(
mode = "nv12",
interp_mode = "nearest",
pad_mode = "zeros"
)
insert_split(dim: int)
Insert split op.
Split a single input/output parameter into multiple input/output parameters with a specified dimension of 1.
- Parameters:
dim ( *) – Dimension along which to split the tensor.
Example:
module = load("model.bc")
func = module[0]
func.inputs[0].insert_split(0)
insert_transpose(permutes: List[int])
Insert transpose op. Change input/output parameter dimension order.
- Parameters:
permutes ( *) – Dimension transformation arrangement. Must contain all dimensions of the original input parameters, starting from 0
Example:
module = load("model.bc")
func = module[0]
func.inputs[0].insert_transpose([3, 1, 2, 0])
property is_removable: Tuple
Check if the attached operation is removable. The operation should be single input and single output. For input argument, it should only be used by the operation. For output argument, the operation input should only be used by the operation.
- Returns:
The first element is bool indicating the removable flag. The second element is the diagnostic if it cannot be removed.
- Return type:
Tuple
remove_attached_op()
Remove the only attached operation
- Returns:
The first element is True when the removal done. The second element is the diagnostic if it cannot be removed.
- Return type:
Tuple
class hbdk4.compiler.overlay.Module(module: Module)
property functions: List[Function]
return all functions in module
- Returns:
function are wrapped in FunctionHelper in pair with its symbol name
- Return type:
List[FunctionHelper]
property graphs: List[Function]
return all functions in module
- Returns:
function are wrapped in FunctionHelper in pair with its symbol name
- Return type:
List[FunctionHelper]