Hey, we are currently investigating using ViennaCL inside our open source surgical simulator framework OSS (www.opensurgsim.org). Right now it's only very simple work, matrix vector multiplication, the matrix is resident, the vector gets copied up every frame and the result copied down, but when I execute this on multiple threads i am getting a crash in ViennaCL with the error message
ViennaCL: FATAL ERROR: Kernel start failed for 'assign_cpu'.
ViennaCL: Smaller work sizes could not solve the problem.
Is this a threading issue or a memory issue. In general are the ViennaCL functions threadsafe?
Thanks, Harald
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
this looks a lot like a threading (race condition) problem, because internal datastructures may be (falsely) shared across threads. Which ViennaCL call is causing the problem? OpenCL per se is not entirely thread safe, so it's also a matter which functions to call with multiple threads.
Best regards,
Karli
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
So I looked a little bit deeper into this and it looks like it stems from the fact that at the time when we call our first viennacl::copy the context is not initialised yet, therefore the static viennacl::ocl::context & context(long id) function in backend.hpp will fall into the branch that creates the queue and will be executed twice for each thread. It looks like calling get_context() before entering the multithreaded code, solves that problem.
Making the inside of the if branch thread safe would solve that or requiring explicit initialisation might prevent other people from falling into the same trap.
Harald
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hey, we are currently investigating using ViennaCL inside our open source surgical simulator framework OSS (www.opensurgsim.org). Right now it's only very simple work, matrix vector multiplication, the matrix is resident, the vector gets copied up every frame and the result copied down, but when I execute this on multiple threads i am getting a crash in ViennaCL with the error message
ViennaCL: FATAL ERROR: Kernel start failed for 'assign_cpu'.
ViennaCL: Smaller work sizes could not solve the problem.
Is this a threading issue or a memory issue. In general are the ViennaCL functions threadsafe?
Thanks, Harald
Hi Harald,
this looks a lot like a threading (race condition) problem, because internal datastructures may be (falsely) shared across threads. Which ViennaCL call is causing the problem? OpenCL per se is not entirely thread safe, so it's also a matter which functions to call with multiple threads.
Best regards,
Karli
So I looked a little bit deeper into this and it looks like it stems from the fact that at the time when we call our first viennacl::copy the context is not initialised yet, therefore the
static viennacl::ocl::context & context(long id)
function inbackend.hpp
will fall into the branch that creates the queue and will be executed twice for each thread. It looks like callingget_context()
before entering the multithreaded code, solves that problem.Making the inside of the if branch thread safe would solve that or requiring explicit initialisation might prevent other people from falling into the same trap.
Harald
Hi Harald,
thanks for the feedback. I'll see what I can do (keeping convenience without introducing performance hits).
Best regards,
Karli