joaopauloschuler / neural-api

CAI NEURAL API - Pascal based deep learning neural network API optimized for AVX, AVX2 and AVX512 instruction sets plus OpenCL capable devices including AMD, Intel and NVIDIA.
GNU Lesser General Public License v2.1
371 stars 198 forks source link

Learning software with neural-api library need to be alone #43

Closed JeanYvesJonet closed 3 years ago

JeanYvesJonet commented 3 years ago

Hello, I did a software to learn with pair lists (delphi 10.3) . It's work fine. But if i run the software several times (>=2), to start several learning at the same time, nothing more happens. Software doesn't do anything anymore, they occupy 0% of the CPU. I need to kill all process. It's the same problem with or without CUDA OpenCL. Only one at the same time ! Do you know this problem ? Thanks

HuguesDug commented 3 years ago

Hello I think the problem is in TNeuralTHread, TNeuralThread.Create. The name of the event is not unique accross several instances running. The name should contain a random number or a program instance number or a PID or ... to make it unique, and then, it should run fine. You could, for example, add the application.handle to the name of the event. It would make the trick.

joaopauloschuler commented 3 years ago

Thank you for the bug report. I'll look into it.

HuguesDug commented 3 years ago

Hello,

From the documentation, I can read the following :

System.SyncObjs.TEvent.Create

Instantiates a TEvent object to represent an event object.

Call Create to create a TEvent object. Create can generate a new event object or can provide access to an existing named event object. ... Set Name to provide a name for a new event object or to specify an existing named event object. If no other thread or process will need to access the event object to wait for its signal, Name can be left blank. Name can be a string of up to 260 characters, not including the backslash character (). If Name is used to specify an existing event object, the value must match the name of the existing event in a case-sensitive comparison. If Name matches the name of an existing semaphore, mutex, or file-mapping object, the TEvent object will be created with Handle set to 0 and all method calls will fail.

As far as I can undestand from windows API, the name is shared accross the entire operating system. I would replace these 2 lines

FNeuronStart := TEvent.Create(nil, True, False, 'NStart '+IntToStr(pIndex)) ; FNeuronFinish := TEvent.Create(nil, True, False, 'NFinish '+IntToStr(pIndex)) ;

by FNeuronStart := TEvent.Create(nil, True, False, 'NStart '+IntToStr(Application.Handle)+IntToStr(pIndex)) ; FNeuronFinish := TEvent.Create(nil, True, False, 'NFinish '+IntToStr(Application.Handle)+IntToStr(pIndex)) ;

and give it a try. I think, if my assumption is correct, that it should do the trick.

joaopauloschuler commented 3 years ago

@HuguesDug , sounds like a very good idea! I'll give it a go.

joaopauloschuler commented 3 years ago

@HuguesDug, your solution works. Thank you very much.

HuguesDug commented 3 years ago

Always happy to help with debugging with great lib.

joaopauloschuler commented 3 years ago

@HuguesDug, fantastic!

Besides the problem you've reported, it also happens with FPC on Windows for another reason. If 2 processes share the same output file, neuralfit crashes.

I did this to avoid the problem at SimpleImageClassifier example:

NeuralFit.FileNameBase := 'SimpleImageClassifier-'+IntToStr(GetProcessId());