-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL][CUDA] Ignore cuda prefetch hint if not supported #5043
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
Conversation
sycl/plugins/cuda/pi_cuda.cpp
Outdated
CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS, | ||
queue->get_context()->get_device()->get()); | ||
if (!isConcurrentManagedAccessAvailable) | ||
return PI_SUCCESS; |
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.
I think a warning would make sense, but I wonder what the best way to do it would be. I am not sure printing is the best option - at least not from the PI implementation. Maybe a better solution is to add a new "error" code, such as PI_UNSUPPORTED_OPERATION
, then the runtime can handle it accordingly.
On the other hand, prefetch is a "hint" so ignoring the operation entirely when we don't support it is arguably still valid.
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.
+1 for ignoring a hint if it cannot be used/not yet implemented.
For letting user know what happens we could use SYCL_RT_WARNING_LEVEL which is being introduced here #4918
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.
Would SYCL_RT_WARNING_LEVEL
be available in PI plugins? Otherwise it would still have to inform the runtime somehow.
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.
Interesting question. I tend to say that SYCL_RT_WARNING_LEVEL
should be available for the whole SYCL stack. Propagating detailed warning(which not only says something is not done, but also says why) to the core SYCL RT could be problematic.
Tagging @v-klochkov
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.
I have taken a look at using SYCL_RT_WARNING_LEVEL
within the cuda pi. However, it is unfortunately not available with pi_cuda. I tried a few things to get access to SYCLConfig, and the warning level. I believe making it available within the plugin would not be simple, as you would have to avoid cyclical dependencies between libpi_cuda.so
and libsycl.so
.
The easiest way would be to get the environment variable within the cuda pi. However, this has the downside of code duplication. Is there a preference on how to go forward with this? Many thanks
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.
@smaslov-intel, @v-klochkov, can you comment please?
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.
I think it is OK to re-read the SYCL_RT_WARNING_LEVEL
from plugins. We already do similar for SYCL_PI_TRACE
inside Level-Zero plugin:
llvm/sycl/plugins/level_zero/pi_level_zero.cpp
Line 1822 in 8213321
static const char *PiTrace = std::getenv("SYCL_PI_TRACE"); |
On the other hand maybe it is a good time to add formal support for backend-specific warnings/errors. Something like returning fixed PI_PLUGIN_SPECIFIC_ERROR, which would indicate that some warning/error is generated and can be obtained by a subsequent call to [new] piPluginGetLastError
.
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.
@smaslov-intel I think the PI_PLUGIN_SPECIFIC_ERROR
approach would seem the most reasonable way to emit a warning/error message. I have implemented it in 478a546 for the CUDA backend. Let me know if this approach seems okay and I will extend it to the other backends.
@steffenlarsen @romanovvlad @v-klochkov just pinging this one as there's not been much activity for a while, I think we just need to decide how to handle the warning, it was suggested that we use |
I would suggest waiting unless there is urgency. |
GPU RT remains the same after beginning of November'2021. It is still: 21.46.21636. That RT is too old for #4918 . It is good idea to split that patch into 2 parts: a) adding the new env variable and b) adding the switch to VC/GPU backend. Adding (a) would unblock this patch here. I am on vacation/sabbatical & traveling right now and temporarily cannot split the patch now even though that is very simple work . |
Thanks for the update, this isn't urgent so I think it can wait, though I did see that #4918 has been merged now, would this be sufficient to use |
Sorry pasted the wrong PR, I meant this one - #5319 |
47c7b58
to
478a546
Compare
sycl/include/CL/sycl/detail/pi.h
Outdated
/// points to. \param is_warning is a bool indicating if the message is a | ||
/// non-failing error. | ||
__SYCL_EXPORT pi_result piPluginGetLastError(char *message, size_t message_size, | ||
bool *is_warning); |
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.
Maybe we can not add "is_warning" but return PI_SUCCESS to indicate that upper RT should treat it as a warning , but return other PI error codes for something that is an error that SYCL RT should try to recover from or throw an exception back to the user.
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.
Also we need a way for SYCL RT to know the size of message
array. Or we can just return a pointer directly(without the copy) which can be used by the SYCL RT until the next PI call is done(assuming we take thread_local
approach from another comment).
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.
I have updated it to not use is_warning
but return a user specified code, so PI_SUCCESS is treated as a warning while others will trigger an error.
Additionally it now uses thread_local
so it returns a ptr to the message as suggested.
sycl/source/detail/plugin.hpp
Outdated
@@ -113,11 +114,35 @@ class plugin { | |||
/// \throw Exception if pi_result is not a PI_SUCCESS. | |||
template <typename Exception = cl::sycl::runtime_error> | |||
void checkPiResult(RT::PiResult pi_result) const { | |||
if (pi_result == PI_PLUGIN_SPECIFIC_ERROR) { | |||
char *message; |
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.
char *message; | |
char *message = nullptr; |
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.
I have made this change
sycl/source/detail/plugin.hpp
Outdated
@@ -100,7 +101,7 @@ class plugin { | |||
plugin &operator=(plugin &&other) noexcept = default; | |||
plugin(plugin &&other) noexcept = default; | |||
|
|||
~plugin() = default; | |||
~plugin() {} |
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.
Could you please tell why this change is needed?
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.
This change is no longer needed. I have undone it
sycl/plugins/cuda/pi_cuda.cpp
Outdated
@@ -57,6 +58,24 @@ pi_result map_error(CUresult result) { | |||
} | |||
} | |||
|
|||
// Global variables for PI_PLUGIN_SPECIFIC_ERROR | |||
static const size_t MaxMessageSize = 256; |
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.
static const size_t MaxMessageSize = 256; | |
constexpr size_t MaxMessageSize = 256; |
?
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.
This change has been applied
sycl/plugins/cuda/pi_cuda.cpp
Outdated
@@ -14,6 +14,7 @@ | |||
#include <CL/sycl/detail/cuda_definitions.hpp> | |||
#include <CL/sycl/detail/defines.hpp> | |||
#include <CL/sycl/detail/pi.hpp> | |||
#include <CL/sycl/detail/spinlock.hpp> |
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.
Is this header still needed?
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.
No it is not needed any more, I have removed it.
sycl/include/CL/sycl/detail/pi.h
Outdated
/// API to get Plugin specific warning and error messages. | ||
/// \param message is a pointer to an array of characters which will be filled | ||
/// with the error message. \param message_size is the size of the array message | ||
/// points to. \param is_warning is a bool indicating if the message is a | ||
/// non-failing error. |
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.
It seems the description should be updated.
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.
The description has now been updated.
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.
LGTM
@smaslov-intel would you be able to re-review the warning level changes? |
sycl/include/CL/sycl/detail/pi.h
Outdated
@@ -1769,6 +1772,13 @@ __SYCL_EXPORT pi_result piextPluginGetOpaqueData(void *opaque_data_param, | |||
/// \param PluginParameter placeholder for future use, currenly not used. | |||
__SYCL_EXPORT pi_result piTearDown(void *PluginParameter); | |||
|
|||
/// API to get Plugin specific warning and error messages. | |||
/// \param message is a returned address to the first element in the message. |
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.
Please clarify in the API who owns the storage of the message and what it's lifetime is.
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.
I have clarified the storage and lifetime of the message string
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.
LGTM, just a small ask to clarify error message storage ownership.
244fb58
to
98d20ee
Compare
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.
Thanks!
@pvchupin are there any other reviewers or is this okay to be merged? |
1. cuda prefetch issue seems to be fixed by: intel#5043 2. Performance issues with assert seem to be fixed by: intel#4505 intel#4516
Specific devices and OS's, like Windows, do not support concurrent managed memory.
cudaPrefetchAsync
requires concurrent managed access for unified memory. This PR removes the windows error message and replaces it with a check for concurrent managed access. As the SYCL prefetch operation is a hint, this can return a success.Let me know if there is a preferred error code to throw. Also, if it is best that a user warning is printed to indicate that the hint is being ignored as the device does not support the operation.