Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete shceduling for "where" #712

Closed
comaniac opened this issue Dec 18, 2017 · 6 comments
Closed

Incomplete shceduling for "where" #712

comaniac opened this issue Dec 18, 2017 · 6 comments

Comments

@comaniac
Copy link
Contributor

comaniac commented Dec 18, 2017

I was trying TVM IR with the following simple computation pattern that creates a set of reference data ref to filter the computation at the next stage. Here is the code I used:

N = tvm.var('N')
V = tvm.var('V')

data = tvm.placeholder((N,V), name='data')
rv = tvm.reduce_axis((0, N), name='rv')

ref  = tvm.compute((N,), lambda n: data[n, 0], name='ref')
masked_data = tvm.compute((N,),
        lambda n: tvm.sum(data[n, rv], rv, ref[rv] == 1),
        name='masked_data')

s = tvm.create_schedule(masked_data.op)
print(tvm.lower(s, [data, ref, masked_data], simple_mode=True))

The output from lower is shown below:

produce masked_data {
  for (n, 0, N) {
    masked_data[n] = 0.000000f
    for (rv, 0, N) {
      if ((ref[rv] == 1.000000f)) {
        masked_data[n] = (masked_data[n] + data[((n*V) + rv)])
      }
    }
  }
}

As can be seen, the computation for ref was missing. Did I misunderstand anything of using TVM IR?

p.s. I know this piece of code looks silly since we can achieve the same functionality without creating ref. On the other hand, this is just the simplified code example to illustrate the problem I'm encountering.

@merrymercy
Copy link
Member

TVM fails to detect the dependence here. You can explicitly add it when creating schedule

s = tvm.create_schedule([ref.op, masked_data.op])

@comaniac
Copy link
Contributor Author

Thanks, it works!
Would you please confirm if this is a bug or not? I'll take a closer look and try to fix it if so.

@merrymercy
Copy link
Member

I think it is a bug. if you put ref in the body of tvm.sum, tvm can detect the dependency. But it fails when ref is in the condition.

@tqchen
Copy link
Member

tqchen commented Dec 20, 2017

seems to be a bug that should be fixed

@tqchen
Copy link
Member

tqchen commented Dec 22, 2017

@comaniac @merrymercy do you mind look into it and submit a fix? Likely we missed something when trace the dependency(in visitor or some recursive pattern)

@comaniac
Copy link
Contributor Author

Sure I'll take a close look later on, since I have other plans during the Christmas.

tqchen pushed a commit that referenced this issue Dec 23, 2017
* Make duplicated function name checker working

* Fix dependency checking problem for reducer condition (#712); add test

* Fix dependency checking problem for reducer condition (#712); add test

* Specify R to be computed inlined
tqchen pushed a commit to tqchen/tvm that referenced this issue Jul 6, 2018
* Make duplicated function name checker working

* Fix dependency checking problem for reducer condition (apache#712); add test

* Fix dependency checking problem for reducer condition (apache#712); add test

* Specify R to be computed inlined
sergei-mironov pushed a commit to sergei-mironov/tvm that referenced this issue Aug 8, 2018
* Make duplicated function name checker working

* Fix dependency checking problem for reducer condition (apache#712); add test

* Fix dependency checking problem for reducer condition (apache#712); add test

* Specify R to be computed inlined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants