heterocl.api¶
|
Initialize a HeteroCL environment with configurations. |
|
Construct a HeteroCL placeholder for inputs/outputs. |
|
Create a quantization scheme. |
|
Create a schedule for compute optimizations. |
Create a schedule from a scheme. |
|
|
Get the generated IR of a given schedule. |
|
Build the executable according to the schedule and target. |
|
Cast an expression to specified data type. |
|
Construct a select branch with the given condition. |
|
Print a HeteroCL object. |
-
init
(init_dtype='int32')[source]¶ Initialize a HeteroCL environment with configurations.
This API must be called each time the users write an application. Within the same HeteroCL environment, users can try different combinations of customization primitives.
- Parameters
init_dtype (Type, optional) – The default data type for each variables
Examples
# app 1 hcl.init() A = hcl.placeholder(...) B = hcl.placeholder(...) def app1(A, B): # define the algorithm for app 1 s = hcl.create_scheme([A, B], app1) # apply customization primitives f1 = hcl.build(s) # execute f1 # app 2 - initialize again with a different data type hcl.init(hcl.Float()) A = hcl.placeholder(...) B = hcl.placeholder(...) C = hcl.placeholder(...) def app2(A, B, C): # define the algorithm for app 2 s = hcl.create_scheme([A, B, C], app2) f2 = hcl.build(s) # execute f2
-
placeholder
(shape, name=None, dtype=None)[source]¶ Construct a HeteroCL placeholder for inputs/outputs.
If the shape is an empty tuple, the returned value is a scalar.
- Parameters
- Returns
- Return type
Examples
# scalar - cannot be updated a = hcl.placeholder((), "a") # 1-dimensional tensor - can be updated A = hcl.placeholder((1,), "A")
-
create_scheme
(inputs, func)[source]¶ Create a quantization scheme.
The first argument is a list of inputs to the second argument, which is a function the defines the algorithm. The numbers of arguments should match. The function will be set with attributes for later optimizations. This API returns an object that has two methods: quantize and downsize.
- Parameters
inputs (Tensor or list of Tensor) – A list of placeholders that are inputs to the algorithm. It can be a single tensor
func (callable) – A function that defines the algorithm
- Returns
- Return type
Examples
A = hcl.placeholder((10,)) def algo(A): return hcl.compute(A.shape, lambda x: A[x]+1, "B") s = hcl.create_scheme(A, algo) s.downsize(algo.B, hcl.Int(8))
-
create_schedule
(inputs, func=None)[source]¶ Create a schedule for compute optimizations.
The first argument is a list of inputs to the second argument, which is a function the defines the algorithm. The numbers of arguments should match. The function will be set with attributes for later optimizations.
- Parameters
inputs (Tensor or list of Tensor) – A list of placeholders that are inputs to the algorithm. It can be a single tensor
func (callable, optional) – A function that defines the algorithm
- Returns
- Return type
See also
Notes
If the function is not provided, we can also create a schedule. However, users cannot create a quantization scheme anymore. We strongly recommend users to provide the function.
Examples
# example 1 - normal usage A = hcl.placeholder((10,)) def algo(A): return hcl.compute(A.shape, lambda x: A[x]+1, "B") s = hcl.create_schedule(A, algo) s[algo.B].unroll(algo.B.axis[0]) # example 2 - no function is provided A = hcl.placeholder((10,)) B = hcl.compute(A.shape, lambda x: A[x]+1) s = hcl.create_schedule(A) s[B].unroll(B.axis[0])
-
create_schedule_from_scheme
(scheme)[source]¶ Create a schedule from a scheme.
- Parameters
scheme (Scheme) – The quantization scheme that will be applied to the compute schedule
- Returns
- Return type
See also
Examples
A = hcl.placeholder((10,)) def algo(A): return hcl.compute(A.shape, lambda x: A[x]+1, "B") sm = hcl.create_scheme(A, algo) sl = hcl.create_schedule_from_scheme(sm)
-
build
(schedule, target=None, name='default_function', stmt=None)[source]¶ Build the executable according to the schedule and target.
The default target is llvm (i.e., CPU execution). If stmt is specified, the statements created by HeteroCL APIs will be ignored.
- Parameters
- Returns
- Return type