cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
322 stars 92 forks source link

[API][Docs] Rename APIs that create schedules; allow users to return tensors #63

Closed seanlatias closed 5 years ago

seanlatias commented 5 years ago

We show an example here.

# speficy the default data type for all tensors
hcl.init(hcl.Float())

A = hcl.placeholder(...)

def foo(A):
  B = hcl.compute(A.shape, lambda x: A[x] + 1)
  C = hcl.compute(A.shape, lambda x: A[x] + 2)
  return B, C

# only need to specify the inputs here
# note that the inputs list does not include B and C
# it is also not possible for users to include B and C, which are inside a function
scheme = hcl.create_scheme([A], foo)
# apply quantization schemes
schedule = hcl.create_schedule_from_scheme(scheme)
# apply compute cutomization primitives

print hcl.lower(schedule) # no need to specify inputs list here
f = hcl.build(schedule) # same as above

_A = hcl.asarray(...)
_B = hcl.asarray(...)
_C = hcl.asarray(...)
f(_A, _B, _C) # the generated function has 3 arguments