Script runts at 100% CPU utilization

311 views
Skip to first unread message

nils.n...@gmail.com

unread,
Aug 20, 2021, 9:31:26 AM8/20/21
to Bonsai Users
Hi,

I have a script where I simultaneously track a red LED, a green LED and keypresses. I also send these data to Open Ephys via OSC.

When I am running my script (attached), the total CPU processor utilization across all cores is 100%. When I run Open Ephys at the same time, Bonsai utilization goes down to ~70-80% and the rest gets used by Open Ephys. Is it possible that this will lead to data losses, in either the neural or tracking data?

Is there any way to make my script run with less CPU utilization? I've asked my IT department who told me "You have an ATi GPU installed, can the software use it? If so, this will unload a lot from the CPU". Indeed, can the software use it? Or are there other ways to optimize my script? I have attached pictures of my computer system.

Best,
Nils

 
tracking_script_080221.layout
system_information.png
tracking_script_080221.bonsai

Gonçalo Lopes

unread,
Aug 28, 2021, 11:20:39 AM8/28/21
to nils.n...@gmail.com, Bonsai Users
Hi Nils,

I'm attaching a slightly modified script to remove some apparently unused operations, but I don't think it will make much difference.

From your system characteristics screenshot, it looks like you have 6 free cores available on the machine. These could more easily be used to speed up the system (e.g. by running tracking of different color planes in separate threads for example).

While you can definitely modify your code to use the GPU, it would take a large rethinking and reimplementation of your entire approach to processing the data, as you just cannot directly write the same types of programs for GPUs as for CPUs (memory sharing and execution characteristics are completely different). Some algorithms such as FindContours also don't have an immediate GPU equivalent, and finally GPUs don't normally have access to writing directly on the file system, for example to log text files, etc.

I still find it surprising you are hitting such limitations, as we routinely record from 5, 6 or even 8 FLIR/pointgrey cameras at the same time on a single computer with no problem. Can you share more information about your acquisition parameters? Frame rate, resolution, dynamic range of images, color space, etc? This might sometimes have a much bigger impact on the data bandwidth than any of the specific algorithms.

Hope this helps.



--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/c4d0ed95-d433-4f90-a739-1b698c95c235n%40googlegroups.com.
tracking_script_082821.bonsai
Message has been deleted

nils.n...@gmail.com

unread,
Aug 31, 2021, 6:20:00 AM8/31/21
to Bonsai Users
Dear Goncalo,

Thank you for your reply and help. How do I run tracking of different colors in separate threads? Do I adjust the Bonsai script, or do I need to change something outside of Bonsai?

I have attached pictures showing my camera parameters. Let me know if there's any other information you require (and if so, perhaps where I need to look to find this information). I have also attached a screenshot showing the CPU utilization being 100% when Bonsai is running.

Best,
Nils
custom_video_modes.JPG
script_running.png
Camera_settings.JPG
camera_information.JPG

nils.n...@gmail.com

unread,
Aug 31, 2021, 8:01:33 AM8/31/21
to Bonsai Users
Update: I found this post from the Bonsai multiple camera acquisition repo

" Note - CPU usage: As the video compression is run on the GPU, CPU usage should be low. If CPU usage goes to 100% and stays there while Bonsai is running, this is due to the Point Grey driver disabling CPU idle states. On Windows, this can be prevented by setting registry entry EnhancedHaltStateDisable to 0, found at HKEY_LOCAL_MACHINE\SOFTWARE\Point Grey Research, Inc. for 64-bit FlyCap2 installs, and HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Point Grey Research, Inc. for 32-bit. In the Point Grey RegistryControlUtility this value is controlled by the checkbox Disable C1E State."

So seems that it was the Point Grey drivers, and not Bonsai. In fact, just opening the Point Grey FlyCap2 software without having the camera installed also showed 100% CPU utilization. Following the step outlined above, the CPU utilization is now around 37% (see attached photo)!

I'm still curious how I can  track different colors in separate threads though.

Best,
Nils

script_running_after_fix.png

Gonçalo Lopes

unread,
Nov 6, 2021, 2:41:29 PM11/6/21
to nils.n...@gmail.com, Bonsai Users
Hi Nils,

This would require a combinator to route event notifications to the task pool or to a new thread (task pool would be more scalable to arbitrary multi-core scenarios like the Ryzen). This functionality is not publicly exposed in Bonsai yet, but you can easily make it by adding the following CSharpCombinator:

using System;
using System.Reactive.Concurrency;
using System.Reactive.Linq;
using Bonsai;

public class ObserveOnTaskScheduler : Combinator
{
    public override IObservable<TSource> Process<TSource>(IObservable<TSource> source)
    {
        return source.ObserveOn(Scheduler.TaskPool);
    }
}


It uses one feature in Rx which is deprecated, but this is a technicality given the simplicity.

Hope this helps

Reply all
Reply to author
Forward
0 new messages