Thread local state for caffe instead of singleton#2367
Thread local state for caffe instead of singleton#2367cypof wants to merge 1 commit intoBVLC:masterfrom
Conversation
|
I feel you have 3 different changes here:
Is there a reason to have those 3 features in one PR? |
|
No reason, I can split them. But I feel they should be merged together as a constraint. To make sure a thread cannot be created without its local state initialized. |
|
I see, but how bad is it if a thread is created without initializing a local state? For 1) + 2), I understand your point, let's see what the maintainers have to say. |
|
Forgetting to initialize the random seed will most likely just make runs not deterministic, which might be OK. Less likely is to have parts of an app to run on the wrong device. It doesn't cost anything to force inheriting state from the parent. I will split 3). |
|
Well it costs the creation of an instance a Caffe instance, which means handles to CUDA libraries in GPU mode. But it is very likely to be created later during execution of the thread. |
71db892 to
fb1c930
Compare
Part of #2351. Duplicate of #2067, it adds some initialization code in internal_thread, to make sure that when a thread is created, the parent thread state for Caffe is inherited, e.g. mode (GPU/CPU) and device. The random number generator is also initialized using a sample from the parent thread, which makes sure each thread will have a different sequence, but while keeping the whole app deterministic.