CUDA管理-多进程、计划作业、分布式处理
cudam的Python项目详细描述
cudam
CUDA管理-多进程、计划作业、分布式处理
检查所有CUDA服务器状态的命令
date >> cuda_status.txt &&echo'cuda1' >> cuda_status.txt && ssh cuda1 'nvidia-smi' >> cuda_status.txt &&echo'cuda2' >> cuda_status.txt && ssh cuda2 'nvidia-smi' >> cuda_status.txt &&echo'cuda3' >> cuda_status.txt && ssh cuda3 'nvidia-smi' >> cuda_status.txt &&echo'cuda4' >> cuda_status.txt && ssh cuda4 'nvidia-smi' >> cuda_status.txt &&echo'cuda5' >> cuda_status.txt && ssh cuda5 'nvidia-smi' >> cuda_status.txt &&echo'cuda6' >> cuda_status.txt && ssh cuda6 'nvidia-smi' >> cuda_status.txt &&echo'cuda11' >> cuda_status.txt && ssh cuda11 'nvidia-smi' >> cuda_status.txt
在多台计算机上使用多个GPU的服务器客户端模式
服务器端-开发在单个gpu上运行的代码
# here is a dumb function to evaluate densenet# it should be replaced by the actual code of evaluationdefevaluate_densenet(model):acc=0.99returnacc
客户端大小-开发代码以将模型发送到服务器进行评估
- 在服务器列表配置文件中添加可用的GPU服务器
# configuration of server list cuda4,8000 cuda4,8001 cuda5,8000 cuda5,8001 cuda5,8002
- 并发计算模型的客户机代码
fromcudam.cudam_socket.clientimportGPUClientPoolDEFAULT_RUN_CODE_WORK_DIRECTORY="/home/www/server"# the folder where the server side code resides DEFAULT_RUN_CODE_PATH="server_file"# the file name of the server side codeSERVER_LIST_CONFIG='config/server_list.txt'# the configuration file of the server listdefpool_evaluate_densenet(model_list):# generat the arguments which will passed to client poolarr_args=[]forminmodel_list:singe_args={'model':m}arr_args.append({'path':DEFAULT_RUN_CODE_PATH,'entry':"evaluate_densenet",'work_directory':DEFAULT_RUN_CODE_WORK_DIRECTORY,'args':singe_args,'use_cuda':True# whether to use GPU or not})# init client poolserver_list=GPUClientPool.load_server_list_from_file(SERVER_LIST_CONFIG)pool=GPUClientPool(server_list)# perform evaluationeval_result=pool.run_code_batch(arr_args)returneval_result# main entranceif__name__=='__main__':model_list=[]# dumb model list which needs to be replaced by real modelspool_evaluate_densenet(model_list)
启动服务器
- 安装此包后,
cudam_server.py
应自动复制到bin路径;如果没有,请手动将此文件复制到项目的根文件夹。可以通过运行以下命令启动服务器:
nohup python cudam_server.py -s 1 -i cuda1 -p 8000 -g 0 >& log/nohup_cuda_1_8000_0.log &
运行客户端python代码来评估一批模型
任务管理器
任务模板
#!/usr/bin/env bashwhilegetopts g: option;docase"${option}" in g)GPU_ID=${OPTARG};;esacdone print_help(){printf"Parameter g(GPU ID) is mandatory\n"printf"g values - GPU ID"exit1}if[ -z "${GPU_ID}"];then print_help fiecho"start task on GPU: $GPU_ID"# the root directory of your python scriptcd ~/code/psocnn/ # the main python script accepting the gpu ID in -g argument python3 main.py -g ${GPU_ID}
任务文件夹结构
任务管理器
# start task manager nohup cudam_task_manager.py -n 2 -s 2 -i 60 -f 300&# snap gpu cudam_snap_gpu.py -s 2 -l 60 -g 1
为特定用户安装cumdam,不能将本地路径添加到可执行路径
切换到项目的根文件夹
安装cudam软件包
pip install --user cudam
- 创建可执行文件的软链接
ln -s /home/{YOURUSER}/.local/bin/cudam_task_manager.py cudam_task_manager.py ln -s /home/{YOURUSER}/.local/bin/cudam_snap_gpu.py cudam_snap_gpu.py
- 运行任务管理器
# run interactively python cudam_task_manager.py -n 2 -s 2 -i 60 -f 300# run in background nohup python cudam_task_manager.py -n 2 -s 2 -i 60 -f 300&