[PyCUDA] What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[PyCUDA] What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?

Rasmus Diederichsen
I don't know cuda really and use the 3 libraries mentioned in the subject. I time and again run into CUDA errors of the form "Invalid resource handle" which appear in some cases, but not in others, i.e. the same function will error or not depending on what ran before it, even if totally unrelated. I gather from this that it has to do with state in CUDA, possibly mismanaging contexts. But since it's hard to reproduce without all my code, I can't open issues about this, so hopefully someone can just give me general pointers.

  • I am using the `pycuda.autoinit.context` for all the Reikna `Thread`s.
  • Neither reikna nor scikit-cuda seem to have functionality for setting context globally or passing it to functions
  • I have tried using my own context instead, but meet the same issues

What are the steps in general to ensure these issues don't come up? How can I handle this when multiple files are in play?

Cheers,
Rasmus

_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?

Bogdan Opanchuk-2
First of all, are you using multiple contexts or a single one? If you only have one context, `Thread(pycuda.autoinit.context)` should be enough for Reikna (don't know about scikit-cuda, though).

Now if you have several contexts, things become more complicated. CUDA maintains a global context stack, if you want to use a specific context, you have to make sure it is on top of the stack (using corresponding PyCUDA functions). For Reikna, you must use a `Thread` object created for a specific context (or anything derived from it) only when that context is active.

On Tue, Jul 31, 2018 at 5:07 PM, Rasmus Diederichsen <[hidden email]> wrote:
I don't know cuda really and use the 3 libraries mentioned in the subject. I time and again run into CUDA errors of the form "Invalid resource handle" which appear in some cases, but not in others, i.e. the same function will error or not depending on what ran before it, even if totally unrelated. I gather from this that it has to do with state in CUDA, possibly mismanaging contexts. But since it's hard to reproduce without all my code, I can't open issues about this, so hopefully someone can just give me general pointers.

  • I am using the `pycuda.autoinit.context` for all the Reikna `Thread`s.
  • Neither reikna nor scikit-cuda seem to have functionality for setting context globally or passing it to functions
  • I have tried using my own context instead, but meet the same issues

What are the steps in general to ensure these issues don't come up? How can I handle this when multiple files are in play?

Cheers,
Rasmus

_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda



_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda
Reply | Threaded
Open this post in threaded view
|

Re: What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?

Rasmus Diederichsen
I do aim to use only one context (I don't know why I would want more than one; the stuff I'm doing is mostly serial but the memory shouldn't leave the GPU).

On 31. Jul 2018, at 09:16, Bogdan Opanchuk <[hidden email]> wrote:

First of all, are you using multiple contexts or a single one? If you only have one context, `Thread(pycuda.autoinit.context)` should be enough for Reikna (don't know about scikit-cuda, though).

Now if you have several contexts, things become more complicated. CUDA maintains a global context stack, if you want to use a specific context, you have to make sure it is on top of the stack (using corresponding PyCUDA functions). For Reikna, you must use a `Thread` object created for a specific context (or anything derived from it) only when that context is active.

On Tue, Jul 31, 2018 at 5:07 PM, Rasmus Diederichsen <[hidden email]> wrote:
I don't know cuda really and use the 3 libraries mentioned in the subject. I time and again run into CUDA errors of the form "Invalid resource handle" which appear in some cases, but not in others, i.e. the same function will error or not depending on what ran before it, even if totally unrelated. I gather from this that it has to do with state in CUDA, possibly mismanaging contexts. But since it's hard to reproduce without all my code, I can't open issues about this, so hopefully someone can just give me general pointers.

  • I am using the `pycuda.autoinit.context` for all the Reikna `Thread`s.
  • Neither reikna nor scikit-cuda seem to have functionality for setting context globally or passing it to functions
  • I have tried using my own context instead, but meet the same issues

What are the steps in general to ensure these issues don't come up? How can I handle this when multiple files are in play?

Cheers,
Rasmus

_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda




_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?

Bogdan Opanchuk-2
Well, that's strange then. As far as I understand, scikit-cuda uses the existing context (unless explicitly asked to create a new one), and Reikna should too if you pass it the reference from pycuda.autoinit. I guess I can't say anything more definite without seeing the code. Any change you can reduce it to a shareable size while preserving the errors?

On Tue, Jul 31, 2018 at 6:05 PM, Rasmus Diederichsen <[hidden email]> wrote:
I do aim to use only one context (I don't know why I would want more than one; the stuff I'm doing is mostly serial but the memory shouldn't leave the GPU).

On 31. Jul 2018, at 09:16, Bogdan Opanchuk <[hidden email]> wrote:

First of all, are you using multiple contexts or a single one? If you only have one context, `Thread(pycuda.autoinit.context)` should be enough for Reikna (don't know about scikit-cuda, though).

Now if you have several contexts, things become more complicated. CUDA maintains a global context stack, if you want to use a specific context, you have to make sure it is on top of the stack (using corresponding PyCUDA functions). For Reikna, you must use a `Thread` object created for a specific context (or anything derived from it) only when that context is active.

On Tue, Jul 31, 2018 at 5:07 PM, Rasmus Diederichsen <[hidden email]> wrote:
I don't know cuda really and use the 3 libraries mentioned in the subject. I time and again run into CUDA errors of the form "Invalid resource handle" which appear in some cases, but not in others, i.e. the same function will error or not depending on what ran before it, even if totally unrelated. I gather from this that it has to do with state in CUDA, possibly mismanaging contexts. But since it's hard to reproduce without all my code, I can't open issues about this, so hopefully someone can just give me general pointers.

  • I am using the `pycuda.autoinit.context` for all the Reikna `Thread`s.
  • Neither reikna nor scikit-cuda seem to have functionality for setting context globally or passing it to functions
  • I have tried using my own context instead, but meet the same issues

What are the steps in general to ensure these issues don't come up? How can I handle this when multiple files are in play?

Cheers,
Rasmus

_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda





_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda
Reply | Threaded
Open this post in threaded view
|

Re: What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?

Rasmus Diederichsen
I may try later. For now, the problem has been fixed by manually creating a context and passing that to each function so that it can be used in `Thread`. I also pop() the context manually. Strangely, I just used pycuda.autoinit.context before, which should work in my opinion. Maybe it's an issue with pycuda.autoinit being imported several times or somethin?

Anyway, I appreciate your quick responses and helpfulness.

On 31. Jul 2018, at 12:27, Bogdan Opanchuk <[hidden email]> wrote:

Well, that's strange then. As far as I understand, scikit-cuda uses the existing context (unless explicitly asked to create a new one), and Reikna should too if you pass it the reference from pycuda.autoinit. I guess I can't say anything more definite without seeing the code. Any change you can reduce it to a shareable size while preserving the errors?

On Tue, Jul 31, 2018 at 6:05 PM, Rasmus Diederichsen <[hidden email]> wrote:
I do aim to use only one context (I don't know why I would want more than one; the stuff I'm doing is mostly serial but the memory shouldn't leave the GPU).

On 31. Jul 2018, at 09:16, Bogdan Opanchuk <[hidden email]> wrote:

First of all, are you using multiple contexts or a single one? If you only have one context, `Thread(pycuda.autoinit.context)` should be enough for Reikna (don't know about scikit-cuda, though).

Now if you have several contexts, things become more complicated. CUDA maintains a global context stack, if you want to use a specific context, you have to make sure it is on top of the stack (using corresponding PyCUDA functions). For Reikna, you must use a `Thread` object created for a specific context (or anything derived from it) only when that context is active.

On Tue, Jul 31, 2018 at 5:07 PM, Rasmus Diederichsen <[hidden email]> wrote:
I don't know cuda really and use the 3 libraries mentioned in the subject. I time and again run into CUDA errors of the form "Invalid resource handle" which appear in some cases, but not in others, i.e. the same function will error or not depending on what ran before it, even if totally unrelated. I gather from this that it has to do with state in CUDA, possibly mismanaging contexts. But since it's hard to reproduce without all my code, I can't open issues about this, so hopefully someone can just give me general pointers.

  • I am using the `pycuda.autoinit.context` for all the Reikna `Thread`s.
  • Neither reikna nor scikit-cuda seem to have functionality for setting context globally or passing it to functions
  • I have tried using my own context instead, but meet the same issues

What are the steps in general to ensure these issues don't come up? How can I handle this when multiple files are in play?

Cheers,
Rasmus

_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda






_______________________________________________
PyCUDA mailing list
[hidden email]
https://lists.tiker.net/listinfo/pycuda

signature.asc (849 bytes) Download Attachment