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}

任务文件夹结构

task folder structure

任务管理器

# 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&

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java通过Spring MVC web应用程序向客户端发送文本文件   java是否可以在运行时动态实例化DAO类?   调用VB。来自Java的net函数   java在Android中通过单击打开特定文件夹   java如何使用maven pom。xml标识非标准项目结构中的testng测试用例?   java为什么FOP在大文件上崩溃?   Architecture python+flask和spring boot+java   java Kafka工具根本没有启动Ubuntu 19.10   如何使用Eclipse运行Java USB API for Windows   java如何在Eclipse中查看J2EE预览服务器/容器的日志/控制台?   网页抓取是否可以使用Java crawler crawler4j暂停和恢复抓取?   java当我第二次按下按钮时,应用程序停止工作   带有偏移量和限制的java SQLite分页问题   java如何在OSX mavericks中将端口80转发到8080   java从泛型方法调用非泛型方法   java My代码未按预期工作。十进制输出不是它应该的样子   节点。java中的js加密(jasypt)和nodejs中的解密   java乘法表不工作数组索引超出范围   java将JDBC与Firebirdsql连接起来