-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Make test_types.py work for the Metal backend #527
Conversation
Sounds to be a good solution for this!
So that the problem is, ti.all_archs didn't pass x to test_foo in the first case? |
That's strange, in: taichi/python/taichi/lang/__init__.py Line 211 in 57287cf
test arguments should be recognized...
|
Yeah, I think Similar issue: https://stackoverflow.com/questions/12197263/pytest-parameterize-decorator-not-working-with-kwargs |
Maybe we could customize our own def parametrize(xs):
def decorator(foo):
def wrapped(*args, **kwargs):
for x in xs:
foo(x, *args, **kwargs)
return wrapped
return decorator
@parametrize([1, 2, 3])
@ti.all_archs
def test_func(x):
assert x == 233 |
SG! While I generally don't prefer maintaining our own utilities for such things that are not essential to Taichi, I guess having a |
Cool implementation! I just opened an issue for this, see pytest-dev/pytest#6810. |
Their reply: pytest-dev/pytest#6810 (comment). taichi/python/taichi/lang/__init__.py Line 211 in 57287cf
How do you think? |
Thank you so much for following up with the pytest team! Yeah, after decorating the tests with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thank you @k-ye @archibate!
* Use @functools.wrap, thanks to @archibate! * Initialize LLVM runtime for Metal backend as well.
Related issue id = #504 #396
Hi @archibate
Sorry i changed your tests quite a bit, in order to make it work for the Metal backend as well. The problem with Metal is that it doesn't support 64bit buffers, so we had to separate the tests into 64-bit vs the rest.
I found a nice decorator
@pytest.mark.parametrize()
(doc) that can somewhat simplify the code.Also I saw that you got this "variables are expected to be declared before kernel invocation" problem, therefore had to create another wrapper inside each test? IIUC,
ti.all_archs(_with)
resets the test case here:taichi/python/taichi/lang/__init__.py
Line 224 in 57287cf
So by putting
@ti.all_archs
at the bottom of the decorator chain, we no longer need to wrap it, because it resets Taichi every time the test case is called. (Unfortunately, this doesn't apply to this PR, as explained below)At last, I tried something like this:
But
@pytest.mark.parametrize
didn't work well with@ti.all_archs
this way. So I had to once again, wrap the_test_foo()
insidetest_foo()
, so that@ti.all_archs
can correctly apply the decoration: