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

[HIP] Remove reinstation of context #983

Closed

Conversation

hdelan
Copy link
Contributor

@hdelan hdelan commented Oct 20, 2023

Same as intel/llvm#4442 but for HIP. A lot of the conversation in the linked PR isn't relevant since we now use the primary context in both HIP and CUDA.

The main reason for this change is that we don't need to reinstate the context at every ScopedContext destruction, since any operation that relies on having a native context set uses a ScopedContext, and doesn't rely on any sort of implicit context stack. Making this change allows us to potentially remove a single HIP API call from each ScopedContext use.

@hdelan hdelan requested a review from a team as a code owner October 20, 2023 15:20
@hdelan hdelan requested a review from npmiller October 20, 2023 15:21
@hdelan
Copy link
Contributor Author

hdelan commented Oct 20, 2023

intel/llvm CI here intel/llvm#11617

@hdelan hdelan force-pushed the remove-reinstation-of-context branch from e4e0491 to 8a453f8 Compare October 23, 2023 09:33
@hdelan hdelan requested a review from jchlanda November 1, 2023 14:39
@jchlanda
Copy link
Contributor

jchlanda commented Nov 2, 2023

This does more than "Remove reinstation of context", the lifetime of hipCtx_t Original used to be the span of ScopedContext, whereas now it is only local to the constructor, not sure if you meant that?

source/adapters/hip/context.hpp Outdated Show resolved Hide resolved
source/adapters/hip/context.hpp Show resolved Hide resolved
@hdelan
Copy link
Contributor Author

hdelan commented Nov 2, 2023

This does more than "Remove reinstation of context", the lifetime of hipCtx_t Original used to be the span of ScopedContext, whereas now it is only local to the constructor, not sure if you meant that?

This is fine imo. There is no operation needed in the destructor and the ScopedContext has no other member funcs so Original only living as long as it is needed is fine.

@jchlanda
Copy link
Contributor

jchlanda commented Nov 3, 2023

This does more than "Remove reinstation of context", the lifetime of hipCtx_t Original used to be the span of ScopedContext, whereas now it is only local to the constructor, not sure if you meant that?

This is fine imo. There is no operation needed in the destructor and the ScopedContext has no other member funcs so Original only living as long as it is needed is fine.

I see, that's fine by me. One thing that I wonder about is the whole notion of ScopedContext, while it used to make sense, with the class being effectively an RAII over hipCtx_t, now it doesn't encapsulate the use. All it really does is it assures that we're using native context. I would consider renaming it to capture the intent better.

@hdelan
Copy link
Contributor Author

hdelan commented Nov 3, 2023

I see, that's fine by me. One thing that I wonder about is the whole notion of ScopedContext, while it used to make sense, with the class being effectively an RAII over hipCtx_t, now it doesn't encapsulate the use. All it really does is it assures that we're using native context. I would consider renaming it to capture the intent better.

I agree that the ScopedContext is no longer the RAII class it used to be. Perhaps a renaming falls outside the scope of this PR but I could potentially put up another PR renaming it to something else for both CUDA and HIP adapters.

@ldrumm
Copy link
Contributor

ldrumm commented Nov 3, 2023

I see, that's fine by me. One thing that I wonder about is the whole notion of ScopedContext, while it used to make sense, with the class being effectively an RAII over hipCtx_t, now it doesn't encapsulate the use. All it really does is it assures that we're using native context. I would consider renaming it to capture the intent better.

I agree that the ScopedContext is no longer the RAII class it used to be. Perhaps a renaming falls outside the scope of this PR but I could potentially put up another PR renaming it to something else for both CUDA and HIP adapters.

Yeah. I'm not married to this patch, and had kind of forgotten about it. Feel free to use it, or throw it away for something better. If you want me to rename it here, I can also do that

@hdelan
Copy link
Contributor Author

hdelan commented Nov 3, 2023

Yeah. I'm not married to this patch, and had kind of forgotten about it. Feel free to use it, or throw it away for something better. If you want me to rename it here, I can also do that

I think it's no longer worth renaming the scopedContext to scopedDevice. I think naming changes are actually difficult to merge since naming is hard and there is often no real need to rename other than "it fits better". So I am reluctant to try and rename this again. I think the current patch's changes should be able to get through (bringing it on par with CUDA adapter's ScopedContext) without doing a bigger renaming. Also I think we are the only ones really using this class so if we understand what we are doing with it then that's sort of all that matters.

@jchlanda
Copy link
Contributor

jchlanda commented Nov 6, 2023

Yeah. I'm not married to this patch, and had kind of forgotten about it. Feel free to use it, or throw it away for something better. If you want me to rename it here, I can also do that

I think it's no longer worth renaming the scopedContext to scopedDevice. I think naming changes are actually difficult to merge since naming is hard and there is often no real need to rename other than "it fits better". So I am reluctant to try and rename this again. I think the current patch's changes should be able to get through (bringing it on par with CUDA adapter's ScopedContext) without doing a bigger renaming. Also I think we are the only ones really using this class so if we understand what we are doing with it then that's sort of all that matters.

If the names makes more sense in Cuda and we're sticking to it in here to make things align, than I'm find with it.

@hdelan
Copy link
Contributor Author

hdelan commented Nov 8, 2023

@kbenzie do you think we can make this ready-to-merge?

@kbenzie kbenzie added the ready to merge Added to PR's which are ready to merge label Nov 8, 2023
@hdelan hdelan force-pushed the remove-reinstation-of-context branch from 60b81c0 to ceb15d4 Compare November 21, 2023 15:05
@hdelan hdelan mentioned this pull request Nov 21, 2023
@hdelan hdelan closed this Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Added to PR's which are ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants