When using the ray framework, there is an option to select the number of CPUs required for this task, as explained here.
Ex:
@ray.remote(num_cpus=4)
def f():
return 1
However this is unclear whether there is going to be actual CPU allocation:
- The function will litteraly be allocated
4
CPUs (using for example the CPU affinity, like in thetaskset
linux command, or thecpuset
docker argument) - Or the scheduler will use this
num_cpus
only internally, as scheduling metadata. For ex to decide whether he can start a new task requiring 16 cpus, where there are only 10 left. The task will still have access to all the CPUs and can 'use' more CPU time than requested innum_cpus
The option 2 seems more likely, but this is not stated in the documentation. And additionally, there seems to be a kind of option 1 for the GPUs, which makes the intentions of the scheduler unclear:
Ray will automatically set the environment variable CUDA_VISIBLE_DEVICES for that process.
The process is configured to use a certain GPU (but can bypass it, by resetting CUDA_VISIBLE_DEVICES
)
So, how is used num_cpus
in ray?