Alright. I know that we can limit the number of cores used by a Keras (TF backend) model by using the following method:
K.set_session(K.tf.Session(config=K.tf.ConfigProto(intra_op_parallelism_threads=2, inter_op_parallelism_threads=2, device_count = {'CPU': 2})))
And we can specify individual tensor operations like this:
with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
But what if we want to specify a list of individual CPUs to be used by the Keras model?
I don't think you can change processor affinity in Tensorflow, that's the level of operating system.
However, Linux has an useful tool taskset
to help you.
For example,
taskset --cpu-list 0,1 python3 main.py
will assign core 0 and core 1 to the process that runs python3 main.py
.
You can verify that with htop
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With