ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Callback with GPU processing

asked 2016-07-12 08:05:47 -0500

bjff gravatar image

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.

edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar image gvdhoorn  ( 2016-07-12 08:09:54 -0500 )edit

Hello, did you ever find a solution to this problem as I'm experiencing the same issue

WillAndrew gravatar image WillAndrew  ( 2016-08-03 09:56:38 -0500 )edit

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.

bjff gravatar image bjff  ( 2016-08-03 18:50:27 -0500 )edit

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.

WillAndrew gravatar image WillAndrew  ( 2016-08-04 04:21:13 -0500 )edit

You can ignore my comment/question, I completely forgot that you can do the following while not rospy.is_shutdown(). Thanks for your help

WillAndrew gravatar image WillAndrew  ( 2016-08-04 05:23:53 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-01-24 03:48:02 -0500

sjsingh gravatar image

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.

edit flag offensive delete link more

Comments

But it doesn't make much sense

what makes you say that?

gvdhoorn gravatar image gvdhoorn  ( 2017-01-24 04:40:05 -0500 )edit

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.

sjsingh gravatar image sjsingh  ( 2017-01-24 05:09:22 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-12 08:05:47 -0500

Seen: 708 times

Last updated: Jul 12 '16