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

PyOpenCL executor: accept device scalars for ValueArgs #453

Merged
merged 3 commits into from
Jul 1, 2021

Conversation

kaushikcfd
Copy link
Collaborator

@kaushikcfd kaushikcfd commented Jun 30, 2021

Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This was surprisingly lightweight. 😄 Two things below.

loopy/target/pyopencl.py Outdated Show resolved Hide resolved
loopy/target/pyopencl.py Outdated Show resolved Hide resolved
@kaushikcfd kaushikcfd force-pushed the executor_take_device_scalars branch from c4a5afe to 6f3be3f Compare June 30, 2021 21:23
preprocess_translation_unit_before_codegen -> preprocess_translation_unit_for_passed_args

Co-authored-by: Andreas Klöckner <inform@tiker.net>
Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Will go in after #451.

@inducer inducer merged commit e00dd09 into main Jul 1, 2021
@inducer inducer deleted the executor_take_device_scalars branch July 1, 2021 01:54
@inducer
Copy link
Owner

inducer commented Jul 1, 2021

Actually, scratch that. Goes in now. :) Thanks again.

@inducer
Copy link
Owner

inducer commented Jul 21, 2023

I think I will revert this; it does not properly do what it claims to do, because it looks at arguments at a point when it shouldn't. Case in point, if we change the test to:

def test_pyopencl_execution_accepts_device_scalars(ctx_factory):
    import pyopencl.array as cla

    ctx = ctx_factory()
    cq = cl.CommandQueue(ctx)

    knl = lp.make_kernel("{:}",
                         """
                         y = 2*x
                         """)

    evt, (out,) = knl(cq, x=cla.to_device(cq, np.asarray(21)))
    np.testing.assert_allclose(out.get(), 42)

    # adding this bit:
    evt, (out,) = knl(cq, x=np.int32(21))
    np.testing.assert_allclose(out.get(), 42)

things break, because the kernel to be executed got specialized to device scalars when it shouldn't have. Fixing this is non-trivial without a major hit to invocation performance, because to do this properly, we would need to compare the types of all arguments on every invocation. We can currently avoid that for kernels that do not have runtime-typed variables, resulting in a major cost savings that I do not want to give up.

inducer added a commit that referenced this pull request Jul 21, 2023
@inducer
Copy link
Owner

inducer commented Jul 21, 2023

#797 contains the revert.

inducer added a commit that referenced this pull request Jul 21, 2023
inducer added a commit that referenced this pull request Jul 21, 2023
inducer added a commit that referenced this pull request Jul 21, 2023
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

Successfully merging this pull request may close these issues.

Invoker cannot handle device scalars ArrayContext.np.sqrt fails for device scalars
2 participants