Discussion:
[PyCUDA] What do I need to do when mixing PyCUDA, Reikna and scikit-cuda?
Rasmus Diederichsen
2018-07-31 07:07:28 UTC
Permalink
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
Bogdan Opanchuk
2018-07-31 07:16:54 UTC
Permalink
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 <
Post by 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
https://lists.tiker.net/listinfo/pycuda
Rasmus Diederichsen
2018-07-31 08:05:41 UTC
Permalink
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).
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.
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
https://lists.tiker.net/listinfo/pycuda <https://lists.tiker.net/listinfo/pycuda>
Bogdan Opanchuk
2018-07-31 10:27:56 UTC
Permalink
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 <
Post by 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).
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 <
Post by 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
https://lists.tiker.net/listinfo/pycuda
Rasmus Diederichsen
2018-07-31 10:30:13 UTC
Permalink
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.
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?
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).
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.
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
https://lists.tiker.net/listinfo/pycuda <https://lists.tiker.net/listinfo/pycuda>
Loading...