Skip to content

Commit

Permalink
Bug-fix] Fix tir allocation with multiple lanes
Browse files Browse the repository at this point in the history
This PR stemmed from #6907
and it is fixing a small error in the getter and setter of a buffer for
the case where `t.lanes > 1`. I also added a test to stress the issue.
  • Loading branch information
Giuseppe Rossini committed Nov 19, 2020
1 parent b7318a7 commit de9b4c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/tvm/tir/ir_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __getitem__(self, index):
index = self._linear_index(index)
if t.lanes > 1:
base = index * t.lanes
index = _expr.Ramp(base, const(1, base.dtype), t.lanes)
index = _expr.Ramp(base, 1, t.lanes)
return _expr.Load(self._content_type, self._buffer_var, index)

def __setitem__(self, index, value):
Expand All @@ -116,7 +116,7 @@ def __setitem__(self, index, value):
t = DataType(self._content_type)
if t.lanes > 1:
base = index * t.lanes
index = _expr.Ramp(base, const(1, base.dtype), t.lanes)
index = _expr.Ramp(base, 1, t.lanes)
self._builder.emit(_stmt.Store(self._buffer_var, value, index))


Expand Down
16 changes: 16 additions & 0 deletions tests/python/unittest/test_tir_ir_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
import tvm.testing


def test_allocate_with_lanes():
ib = tvm.tir.ir_builder.create()
n = te.size_var("n")
A = ib.allocate("float32x4", n, name="A", scope="global")
B = ib.allocate("float32x4", n, name="A", scope="global")
A[0] = tvm.tir.const(0, "float32x4")
B[0] = A[0]
body = ib.get()
assert A == A
print(body)
assert isinstance(body, tvm.tir.AttrStmt)
body = body.body
assert isinstance(body, tvm.tir.Allocate)


def test_for():
ib = tvm.tir.ir_builder.create()
n = te.size_var("n")
Expand Down Expand Up @@ -177,5 +192,6 @@ def check_target(target):
test_prefetch()
test_if()
test_for()
test_allocate_with_lanes()
test_cpu()
test_gpu()

0 comments on commit de9b4c9

Please sign in to comment.