-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for round robin allocation of cuda cards to workers
A gunicorn post_fork hook has been added to set CUDA_VISIBLE_DEVICES, which sets the device torch will use. A app level config variable "APP_CUDA_DEVICE_COUNT" is required to indicate how many devices are to be used. The devices are allocated to the docker in the docker compose configuration.
- Loading branch information
1 parent
fca0a2f
commit effa069
Showing
3 changed files
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
def post_fork(server, worker): | ||
server.log.info("Worker spawned (pid: %s)", worker.pid) | ||
cuda_device_count = int(os.getenv("APP_CUDA_DEVICE_COUNT", -1)) | ||
|
||
if cuda_device_count > 0: | ||
# set variables for cuda resource allocation | ||
# Needs to be done before loading models | ||
# The number of devices to use should be set via | ||
# APP_CUDA_DEVICE_COUNT in env_app and the docker compose | ||
# file should allocate cards to the container | ||
cudaid = worker.age % cuda_device_count | ||
worker.log.info("Setting cuda device " + str(cudaid)) | ||
os.environ["CUDA_VISIBLE_DEVICES"] = str(cudaid) | ||
else: | ||
worker.log.info("APP_CUDA_DEVICE_COUNT device variables not set") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters