Scheduling and Building
As shown in the following code, after the compute logic is defined, implement scheduling and building in the operator API implementation function.
Scheduling can be automatically generated using the auto_schedule API call. The configuration information includes the operator kernel name, input tensor, and output tensor.
with tvm.target.cce():
schedule = dsl.auto_schedule(result)
config = {
"name": kernel_name,
"tensor_list": [input_data, result]
"bool_storage_as_1bit":True
}
dsl.build(schedule, config)
- Use the auto_schedule API to perform Auto Schedule (using the schedule module). The argument of the auto_schedule API is the output tensor of the operator.
The process defines how to efficiently execute the described compute process on hardware. That is, map the computation to the corresponding backend instructions.
- name: name of the operator binary file generated after build. The value can contain a maximum of 200 characters, which must be a combination of letters, digits, and underscores (_), beginning with a letter or underscore (_).
- tensor_list: a list of input and output tensors. The parameter sequence and count must be the same as those in Operator Prototype Definition and Operator Function Declaration.
Note: The input tensor must be the tensor object returned by the placeholder API. The memory address of the tensor object cannot be overwritten.
For example: "tensor_list": [tensor_a, tensor_b, res], where, tensor_a and tensor_b are the input tensors, and res is the output tensor.
- bool_storage_as_1bit: If True, bools are stored in 1-bit format; if False, bools are stored in 8-bit format. Defaults to True.
When the mode argument passed to the tbe.dsl.vcmp call and the condition argument passed to the tbe.dsl.vsel call are bools, set this parameter to False.
- The build API is used to build the operator based on scheduling and configuration. During operator build, a dedicated kernel is built based on the input data shape, type, and operator arguments at model generation time.
- schedule: a schedule object of the operator.
- config: map of the build configurations.
After the build is complete, an operator binary file (.o) and an operator description file (.json) are generated.