cornell-zhang/hcl-dialect

Error with Tutorial 2

Closed this issue · 1 comments

For tutorial 2, it says that you can't do >= operation between a tensor and int. I tried making the 0 a tensor, but then it said that you cannot do a >= operation between instance a tensor and tensor.

import heterocl as hcl

hcl.init()

A = hcl.placeholder((10,), "A")
def insertion_sort(A):

    # Introduce a stage.
    with hcl.Stage("S"):
        # for i in range(1, A.shape[0])
        # We can name the axis
        #took out the name part of the for loop because it was causing errors-Sofia
        with hcl.for_(1, A.shape[0]) as i:
            key = hcl.scalar(A[i], "key")
            j = hcl.scalar(i-1, "j")
            # while(j >= 0 && key < A[j])
            with hcl.while_(hcl.and_(j >= 0, key < A[j])):
                A[j+1] = A[j]
                j.v -= 1
            A[j+1] = key.v
s = hcl.create_schedule([A], insertion_sort)
print(hcl.lower(s))
f = hcl.build(s)

Error:

/home/smc447/hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/exceptions.py:72: DeprecationWarning:
[Deprecation] hcl.Stage() is deprecated, please remove it.
warnings.warn(self.message, category=self.category)
/home/smc447/hcl-dialect-prototype/build/tools/hcl/python_packages/hcl_core/hcl_mlir/exceptions.py:72: RuntimeWarning:
[Data Type] StoreOp has different input types. Cast from index to i32.
warnings.warn(self.message, category=self.category)
Traceback (most recent call last):
File "/export/scratch/users/smc447/tutorial/tutorial_02_imperative.py", line 68, in
s = hcl.create_schedule([A], insertion_sort)
File "/home/smc447/heterocl-mlir/python/heterocl/schedule.py", line 165, in create_schedule
return customize(inputs, func, name)
File "/home/smc447/heterocl-mlir/python/heterocl/schedule.py", line 155, in customize
raise e
File "/home/smc447/heterocl-mlir/python/heterocl/schedule.py", line 153, in customize
return build_schedule(inputs, func, name)
File "/home/smc447/heterocl-mlir/python/heterocl/schedule.py", line 66, in build_schedule
ret = func(*inputs)
File "/export/scratch/users/smc447/tutorial/tutorial_02_imperative.py", line 39, in insertion_sort
with hcl.while_(hcl.and_(j >= 0, key < A[j])):
TypeError: '>=' not supported between instances of 'Tensor' and 'int'

That is correct. In the MLIR-based HeteroCL we have added typing system and hcl.scalar is typed as a 0-dim Tensor, so there is a .v needed to load the value from it. I have updated tutorial 2 code.
Closing this thread as tutorial 2 passes test and is added in the CI