-
Notifications
You must be signed in to change notification settings - Fork 122
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
[POTENTIAL BUG]: CopyToCpu is using refs in unsafe way but there is no indication of that. #1209
Comments
Hi @En3Tho, thank you for raising this potential bug report and welcome to the ILGPU community! Indeed, these functions are considering access to either pinned managed/or even unmanaged pointers to be targeted directly from GPU drivers at the moment. I agree that we should improve documentation of these functions to help people understand potential side effects (as in undefined behavior...) and potentially enhance this function with |
I think it would be good to have different My main concern is that someone might try using this on web server for example where some tasks are a perfect fit for gpu. Active memory hogs like webservers are triggering gc quite often and it could really lead to the whole app crashing. Usually using So an ideal solution in my opinion would be 2 overloads: |
Sounds reasonable to me. Please note, that we can add an additional overload without any limitations. However, changing the semantics of an existing function is not possible due to backwards compatibility (since it has been used for several years now). We could deprecate the current function, while keeping its semantics. Additionally, we can introduce an overload featuring |
Describe the bug
This routine calls
CopyToCPUUnsafeAsync
which does not pin/fix refs and simply calls Unsafe.AsPointer on them. This could potentially lead to situations where pointer could end up pointing at invalid memory region if GC kicks in while copy operation is ongoing.I guess there is an implicit assumtion that all refs should be pinned before use. But I personally would have expected ref taking api to pin those manually, e.g.
fixed p = ref ...
I think there are few ways to deal with that:
fixed
then route to pointer-taking apisEnvironment
Steps to reproduce
In the description
Expected behavior
In the description
Additional context
No response
The text was updated successfully, but these errors were encountered: