Skip to content

Commit

Permalink
[CODEGEN] Fix let expression (apache#1727)
Browse files Browse the repository at this point in the history
  • Loading branch information
merrymercy authored and tqchen committed Sep 18, 2018
1 parent 2b46d37 commit 0bf8d1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/codegen/codegen_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,11 +652,10 @@ void CodeGenC::VisitStmt_(const Store* op) {
}

void CodeGenC::VisitExpr_(const Let* op, std::ostream& os) { // NOLINT(*)
CHECK(print_ssa_form_)
<< "LetExpr is only supported by print SSA form";
std::string value = PrintExpr(op->value);
CHECK(!var_idmap_.count(op->var.get()));
var_idmap_[op->var.get()] = value;
os << PrintExpr(op->body);
}

void CodeGenC::VisitExpr_(const Ramp* op, std::ostream& os) { // NOLINT(*)
Expand Down
15 changes: 15 additions & 0 deletions topi/tests/python/test_topi_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ def test_squeeze():
verify_squeeze((1, 1, 1, 4), (1, 2))
verify_squeeze((1, 1, 1, 1), None)

# a special case to trigger inline let expression
A = tvm.placeholder((2,), 'float32', 'A')
E = topi.squeeze(A)
C = tvm.compute((1,), lambda i: E[(2 * A[0] - 1).astype('int32')])
for device in ['cuda', 'opencl']:
ctx = tvm.context(device, 0)
if ctx.exist:
with tvm.target.create(device):
s = topi.generic.schedule_injective(C)
func = tvm.build(s, [A, C])
a = tvm.nd.array(np.array((1, 2)).astype('float32'), ctx=ctx)
c = tvm.nd.empty((1,), dtype='float32', ctx=ctx)
func(a, c)
assert c.asnumpy()[0] == 2


def test_concatenate():
verify_concatenate([(2,), (2,), (2,)], 0)
Expand Down

0 comments on commit 0bf8d1d

Please sign in to comment.