[go: nahoru, domu]

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

Fix type instability in copyto_stencil_kernel! #1850

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

charleskawczynski
Copy link
Member

This PR removes the window variable in copyto_stencil_kernel!, and instead, uses different windows depending on gid.

I'm actually not sure how the gpu even allows this block of code:

            (v, i, j, h) = cart_ind((Nv, Nq, Nq, Nh), gid).I
            hidx = (i, j, h)
            idx = v - 1 + li
            window =
                idx < lw ?
                LeftBoundaryWindow{Spaces.left_boundary_name(space)}() :
                (
                    idx > rw ?
                    RightBoundaryWindow{Spaces.right_boundary_name(space)}() :
                    Interior()
                )
            setidx!(
                space,
                out,
                idx,
                hidx,
                Operators.getidx(space, bc, window, idx, hidx),
            )

because

  • the type of window depends on the value of idx
  • the value of idx depends on the value of v
  • the value of v depends on the value of gid
  • the value of gid depends on the individual thread, which is most definitely non-deterministic

The only way I could see this being type stable is if the compiler can determine that all three branches result in the same return type, and that, then, it doesn't matter what the value of window will be within the scope of copyto_stencil_kernel!.

This is surprising to me. Any insights @vchuravy?

@vchuravy
Copy link

The compiler may actual perform this transformation for you? We can probably union-split this.

I'm actually not sure how the gpu even allows this block of code:

Then this is likely happening

@charleskawczynski
Copy link
Member Author

The compiler may actual perform this transformation for you? We can probably union-split this.

I'm actually not sure how the gpu even allows this block of code:

Then this is likely happening

Sheesh, that is surprising and sounds like some compiler magic 🪄

@charleskawczynski
Copy link
Member Author

Alright, I refactored this a bit, and this is now fewer lines of code and type stable. So I'm happy to move forward with it.

@charleskawczynski charleskawczynski merged commit a7ddf98 into main Sep 4, 2024
20 of 22 checks passed
@charleskawczynski charleskawczynski deleted the ck/cuda_stencil_tstability branch September 4, 2024 15:08
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.

None yet

2 participants