Python Multiprocessing with PyCUDA

参考:https://stackoverflow.com/questions/5904872/python-multiprocessing-with-pycuda

You need to get all your bananas lined up on the CUDA side of things first, then think about the best way to get this done in Python [shameless rep whoring, I know].

The CUDA multi-GPU model is pretty straightforward pre 4.0 - each GPU has its own context, and each context must be established by a different host thread. So the idea in pseudocode is:

  1. Application starts, process uses the API to determine the number of usable GPUS (beware things like compute mode in Linux)
  2. Application launches a new host thread per GPU, passing a GPU id. Each thread implicitly/explicitly calls equivalent of cuCtxCreate() passing the GPU id it has been assigned
  3. Profit!

In Python, this might look something like this:

import threading
from pycuda import driverclass gpuThread(threading.Thread):def __init__(self, gpuid):threading.Thread.__init__(self)self.ctx  = driver.Device(gpuid).make_context()self.device = self.ctx.get_device()def run(self):print "%s has device %s, api version %s"  \% (self.getName(), self.device.name(), self.ctx.get_api_version())# Profit!def join(self):self.ctx.detach()threading.Thread.join(self)driver.init()
ngpus = driver.Device.count()
for i in range(ngpus):t = gpuThread(i)t.start()t.join()

This assumes it is safe to just establish a context without any checking of the device beforehand. Ideally you would check the compute mode to make sure it is safe to try, then use an exception handler in case a device is busy. But hopefully this gives the basic idea.

Python Multiprocessing with PyCUDA相关推荐

  1. python multiprocessing模块

    python multiprocessing模块 原文地址 multiprocessing multiprocessing支持子进程.通信和共享数据.执行不同形式的同步,提供了Process.Queu ...

  2. python multiprocessing manager list error: [Errno 2] No such file or directory

    python multiprocessing manager list error: [Errno 2] No such file or directory for i in range(AMOUNT ...

  3. python multiprocessing — 基于进程的并行

    概述 multiprocessing 是一个用与 threading 模块相似API的支持产生进程的包. multiprocessing 包同时提供本地和远程并发,使用子进程代替线程,有效避免 Glo ...

  4. Intel Realsense D435 python multiprocessing 摄像头多进程流传输

    参考文章1:python 测试multiprocessing多进程 参考文章2:Intel Realsense D435 多摄像头目标识别架构

  5. [转]浅谈 python multiprocessing(多进程)下如何共享变量

    2019独角兽企业重金招聘Python工程师标准>>> 1.问题: 群中有同学贴了如下一段代码,问为何 list 最后打印的是空值? from multiprocessing imp ...

  6. python multiprocessing遇到Can’t pickle instancemethod问题

    rfyiamcool2016年1月18日  0 Comments 遇到一个坑,Can't pickle instancemethod - 前言: 今天写了一个小脚本,因为涉及到cpu运算的事件,所以用 ...

  7. python多路分支_用于多个参数的python multiprocessing pool.map

    在python多处理库中,是否有pool.map的变体支持多个参数? text ="test" def harvester(text, case): X = case[0] tex ...

  8. python multiprocessing lock_python多进程Lock锁

    无论是使用多线程或者多进程都会涉及资源的争夺,比如在多个任务同时读写一个文件,任务就是不断的争夺文件的读写控制权.其中一个任务读写,其他任务就不能执行相同的操作.所以我们使用锁的概念,举个通俗易懂的例 ...

  9. python multiprocessing 进程间如何共享数据、对象

    参考文章1:Python 进程间的数据共享 参考文章2:Python多进程编程-进程间共享 对象

最新文章

  1. 输入法按照选字频率排序的C语言程序算法,算法与数据结构之选择排序(C语言)...
  2. yii2-Ueditor百度编辑器
  3. 在ASP.NET MVC中使用IIS级别的URL Rewrite
  4. leetcode算法题--机器人的运动范围
  5. Linux开发环境搭建三 使用mount -t cifs 挂载windows共享目录方法与问题解决
  6. oracle分区list,Oracle 分区表中存在range-list表分区时遇到问题及解决办法
  7. Java面试中与源码有关的问题分享
  8. 2017年秋招-广联达面试及思考
  9. python飞机大战游戏代码_python实现飞机大战小游戏
  10. jspstudy启动mysql失败_linux系统mysql服务启动失败
  11. AC97声卡的驱动安装
  12. 主板开机重启条线安装图
  13. 用java判断是否是合法邮箱即验证邮箱格式
  14. 2022 Ubuntu国内流畅观看Cousera视频最简教程
  15. W3C school
  16. CITA架构与云计算服务
  17. 基于MATLAB的拼图游戏设计(图文详解,附完整代码)
  18. UVA - 1600 Patrol Robot (巡逻机器人)(bfs)
  19. C语言随机比大小循环,C语言基础知识之(三):循环、随机数
  20. xsy3320 string

热门文章

  1. 什么是初效过滤器_初效过滤器主要用于过滤多少微米的杂质?
  2. android androidx版本,Android AndroidX 简介与迁移
  3. mqtt协议视频教程_MQTT协议教程
  4. 口腔取模过程及注意事项_数字化口 腔的发展与展望
  5. 二叉树的层序遍历_NC15 求二叉树的层序遍历
  6. 计算机数据库三级应用题,计算机等级-数据库三级
  7. 焊缝标注vlx实用程序_焊缝标注实例(记住这七个技巧,受益无穷)
  8. 开发一次、多端覆盖的开源统一框架
  9. 6 个“吓人”的 Linux 命令
  10. 皮一皮:流散国外的珍宝。。。