Menu

Mutlithreading issues

2017-02-08
2017-02-08
  • Harald Scheirich

    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

     
  • Karl Rupp

    Karl Rupp - 2017-02-08

    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

     
  • Harald Scheirich

    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

     
  • Karl Rupp

    Karl Rupp - 2017-02-10

    Hi Harald,

    thanks for the feedback. I'll see what I can do (keeping convenience without introducing performance hits).

    Best regards,
    Karli

     

Log in to post a comment.