0
$\begingroup$

Rosanswers logo

I have a python node that does heavy image processing on GPU. If a method call on image processing instance is invoked inside the callback function, the GPU computation appears to be copied to CPU (i.e. it's heavily loaded too and results in as-on-CPU time). The only way to solve it was to have the callback function activate a global trigger and run image processing in Main only when the trigger is activated. This doesn't allow using services of course.

Does anyone know what is the underlying logic that's causing it and whether there's a more elegant solution? Thanks.


Originally posted by bjff on ROS Answers with karma: 11 on 2016-07-12

Post score: 1


Original comments

Comment by gvdhoorn on 2016-07-12:
Not really an answer, but I seem to remember this has something to do with the 'context' in which Python calls into your GPGPU library. Ie: some objects are not copied / shared correctly between the main thread (that initialises your GPGPU access) and the thread handling the svc invocation.

Comment by WillAndrew on 2016-08-03:
Hello, did you ever find a solution to this problem as I'm experiencing the same issue

Comment by bjff on 2016-08-03:
Not quite. I decided to stick to the original workaround, i.e. activate a global trigger by subscriber callback and execute image processing only when the trigger is on.

Comment by WillAndrew on 2016-08-04:
Are you achieving this in Python? I'd like to implement the same but I'm not sure how to check a global variable in the main thread once rospy.spin() is invoked. Plus there's no rospy equivalent of spinOnce(). I may end up having to write a C++ wrapper which I'd ideally like to avoid.

Comment by WillAndrew on 2016-08-04:
You can ignore my comment/question, I completely forgot that you can do the following while not rospy.is_shutdown(). Thanks for your help

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Add these lines in your callback function somewhere at the top

caffe.set_mode_gpu()
caffe.set_device(args.gpu_id)

This works seamlessly. But it doesn't make much sense. And it is better than the while loop solution.


Originally posted by sjsingh with karma: 31 on 2017-01-24

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by gvdhoorn on 2017-01-24:\

But it doesn't make much sense

what makes you say that?

Comment by sjsingh on 2017-01-24:
I mean I didn't understand how it worked(new to python and ros), I just tried it out and it works fine and is robust.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.