- 浏览: 200941 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
悲梦天下:
楼主,有些视频到一半就没声音了,怎么破!!!
python视频教程 更新22(完) -
schi:
啊,我太傻了,都想到使用uv了,可以有更简单的方法,只要把uv ...
Get Reversed Normal Faces(获取反法线面) [原理] -
schi:
相对Pillow和PySide而言,显示图片opengl就显得 ...
display an image with pyopengl and Pillow -
schi:
我也是今天才偶然想到的,我以后可能用不着了,所有分享给有需要的 ...
Get Reversed Normal Faces(获取反法线面) [原理] -
baiyanbin:
支持楼主原创,关注楼主博客有一阵子了,国内认真认真搞技术的太少 ...
python视频教程 更新22(完)
Here an example how to use pyopencl in Maya.
yTwistNodeGPU.py
It's slower than yTwistNode.py(CPU) when I test it.
My testing hardware:
CPU: intel Xeon w3530 2.80GHz
Graphics card: nvidia quadro FX 1800
Test on a obj with 960002 vertexes.
GPU: about 18s a time
CPU: about 10s a time
But the slow part is not the GPU computing. It's the while loop. Two while loop take almost 18s.
yTwistNodeGPU.py
# -------------------------------------------------------------------------------- # Copyright (c) 2013 Mack Stone. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # -------------------------------------------------------------------------------- """ Simple deform node use pyopencl in Maya. @author: Mack Stone """ import sys import logging import maya.OpenMaya as om import maya.OpenMayaMPx as ompx from maya import utils import numpy import pyopencl as cl # opencl code, run on GPU kernelCode = """ __kernel void ytwist(__global const float4 *pos, __global float4 *newPos, float angle, float envelope) { int gid = get_global_id(0); newPos[gid].xyzw = pos[gid].xyzw; float ff = angle * pos[gid].y * envelope; if(ff != 0.0f) { float cct = cos(ff); float cst = sin(ff); newPos[gid].x = pos[gid].x * cct - pos[gid].z * cst; newPos[gid].z = pos[gid].x * cst + pos[gid].z * cct; } } """ class YTwistNode(ompx.MPxDeformerNode): NAME = "yTwistNode" ID = om.MTypeId(0x8702) angle = om.MObject() def __init__(self): ompx.MPxDeformerNode.__init__(self) # create context self._ctx = cl.create_some_context() # command queue self._queue = cl.CommandQueue(self._ctx) # create and build GPU program self._program = cl.Program(self._ctx, kernelCode).build() # setup logger formatter = logging.Formatter("%(asctime)s - %(message)s") utils._guiLogHandler.setFormatter(formatter) def deform(self, dataBlock, geomIter, matrix, multiIndex): logging.info("start deforming") # get the angle from the datablock angleHandle = dataBlock.inputValue( self.angle ) angleValue = angleHandle.asDouble() # get the envelope envelope = OpenMayaMPx.cvar.MPxDeformerNode_envelope envelopeHandle = dataBlock.inputValue( envelope ) envelopeValue = envelopeHandle.asFloat() # get all position data logging.info("get all position data") pos = numpy.zeros((geomIter.count(), 4), dtype=numpy.float32) while not geomIter.isDone(): point = geomIter.position() index = geomIter.index() pos[index, 0] = point.x pos[index, 1] = point.y pos[index, 2] = point.z pos[index, 3] = point.w geomIter.next() logging.info("start copy data to GPU") memf = cl.mem_flags # create buffer from pos posBuf = cl.Buffer(self._ctx, memf.READ_ONLY | memf.COPY_HOST_PTR, hostbuf=pos) # create write buffer outBuf = cl.Buffer(self._ctx, memf.WRITE_ONLY, pos.nbytes) # run GPU Program logging.info("run GPU Program") self._program.ytwist(self._queue, pos.shape, None, posBuf, outBuf, numpy.float32(angleValue), numpy.float32(envelopeValue)) logging.info("end GPU Program") # copy data back to memory newPos = numpy.zeros_like(pos) cl.enqueue_copy(self._queue, newPos, outBuf).wait() # set positions logging.info("set all position") geomIter.reset() while not geomIter.isDone(): point = geomIter.position() index = geomIter.index() point.x = float(newPos[index, 0]) point.y = float(newPos[index, 1]) point.z = float(newPos[index, 2]) geomIter.next() logging.info("end deform") @staticmethod def creator(): return ompx.asMPxPtr(YTwistNode()) @staticmethod def initialize(): # angle nAttr = om.MFnNumericAttribute() YTwistNode.angle = nAttr.create("angle", "fa", om.MFnNumericData.kDouble, 0.0) nAttr.setKeyable(1) # add attribute YTwistNode.addAttribute(YTwistNode.angle) outputGeom = ompx.cvar.MPxDeformerNode_outputGeom YTwistNode.attributeAffects(YTwistNode.angle, outputGeom) # initialize the script plug-in def initializePlugin(mobject): mplugin = ompx.MFnPlugin(mobject) try: mplugin.registerNode(YTwistNode.NAME, YTwistNode.ID, YTwistNode.creator, YTwistNode.initialize, ompx.MPxNode.kDeformerNode ) except: sys.stderr.write("Failed to register node: %s\n" % YTwistNode.NAME) # uninitialize the script plug-in def uninitializePlugin(mobject): mplugin = ompx.MFnPlugin(mobject) try: mplugin.deregisterNode(YTwistNode.ID) except: sys.stderr.write("Failed to unregister node: %s\n" % YTwistNode.NAME )
It's slower than yTwistNode.py(CPU) when I test it.
My testing hardware:
CPU: intel Xeon w3530 2.80GHz
Graphics card: nvidia quadro FX 1800
Test on a obj with 960002 vertexes.
GPU: about 18s a time
CPU: about 10s a time
But the slow part is not the GPU computing. It's the while loop. Two while loop take almost 18s.
发表评论
-
uv重叠(uv overlap)
2014-06-28 22:28 5205两年多前我需要解决uv重叠的问题,当时觉得是一个挺有挑 ... -
dx11 Shaders for maya
2014-06-09 17:48 2110我准备花点时间来弄点d ... -
Maya plugin with OpenCL C++ example
2014-04-23 12:19 3139GPU, Python and Maya使用的是python和 ... -
cmdReporterHighlighter
2014-01-19 19:30 833A syntaxhighlighter I wrote ... -
那条线代表什么
2013-11-07 12:32 1203好几个月前我问了前同事一个问题:那条线代表什么? 同事在玩 ... -
Modern OpenGL with python (freeglut, glfw, PySide/PyQt)
2013-11-04 15:28 6488Base on this tutorial 基于这个教程 ht ... -
python视频教程 更新22(完)
2013-09-07 20:31 2198实际上最后的类实战的ood是不正确,虽然Point类和Vect ... -
Add MEL syntax highlighting for expression editor[给表达式编辑器添加mel的高光显示]
2013-08-30 18:16 1893I don't use mel for years. But ... -
mentalray cause maya2012 crash on standalone mode
2013-03-28 20:27 1026如果你想使用maya2012和python来做些批处理,你就要 ... -
python基础视频教程
2013-08-14 15:56 1676我打算做一系列的python基础视频教程。 目前的计划是从0基 ... -
convert color image to grayscale with pyopencl(example code)
2013-03-09 20:38 2209grayscale.py import pyopencl as ... -
sierpinski triangle 2d maya plug-in(with python API 2.0)
2012-11-07 16:55 2288因为python API 2.0可用的类很少,OpenMaya ... -
sierpinski triangle 2d in maya(with python API 2.0)
2012-10-22 20:41 1967在国庆前我刚好完成手上的工作,有两三天的空闲,于是就去 ... -
mel,cmds,python API哪个更快?
2012-09-13 14:37 3887昨天偶然的跟同事谈论 ... -
Maya Python API 2.0 - MGlobal
2012-08-31 18:07 2280MGlobal是一个静态类,提供通用的API涵数. 包括获取m ... -
Get Reversed Normal Faces(获取反法线面)
2012-08-20 18:34 1717这不是一个教程,这是 ... -
Maya Python API 2.0 - MSelectionList
2012-07-09 14:03 2496从Maya2012开始我们迎来了新的Python API, ... -
我讨厌给UI起名字,也懒得起名字
2012-07-05 14:35 1325从我开始给Maya开发UI工具的时候起就觉得给窗口起名是件麻烦 ... -
算法(algorithm) 101
2012-07-02 23:01 1125在Maya中实现深度/广度优先搜索算法 Depth-First ... -
使用Visual C++ 2010 Express来开发Maya x64插件
2012-07-02 22:57 4880Visual C++ 2010 Express是微 ...
相关推荐
3、Python OpenCV配置CUDA以支持GPU加速 (不使用Visual Studio) 可以使用该OpenCV 库版本利用GPU进行图像处理 4、OpenCV是计算机视觉和机器学习软件库,功能非常强大,通过pip安装的Python版本仅支持CPU运算,可以...
Python脚本,用于在GPU空闲时监视GPU访问并管理外部程序
Hands-On-GPU-Programming-with-Python-and-CUDA-master源代码
使用Python和CUDA进行动手GPU编程 这是Packt发布的《 进行的代码库。 探索使用CUDA的高性能并行计算这本书是关于什么的? 使用Python和CUDA进行动手GPU编程必将步入正轨:您将首先学习如何应用阿姆达尔定律,使用...
tensorflow_gpu-1.4.0-cp35-cp35m-win_amd64.whl 用于安装在win7 或win10上面,可以搭配python3.5+cuda8.0+cudnn6.0,亲测能用。
You will learn, by example, how to perform GPU programming with Python, and you'll look at using integrations such as PyCUDA, PyOpenCL, CuPy and Numba with Anaconda for various tasks such as machine ...
python cuda gpu 高性能运算 代码
推荐此书,该书讲述了GPU和着色语言的原理,对CG语法讲的很透!光照算法方面对各向异性也有所涉及,对体绘制的光线投射算法讲的很好,还没有见过这么通俗易懂的!难怪作者将中文名取为:GPU编程与CG语言之阳春白雪下...
还压缩包里面包含了Python并发编程PDF文档与配套代码Code,适合当今深度学习GPU并发分布式计算,欢迎大家下载学习。
opencv-python使用GPU资源--虚拟环境安装与编译opencv源码(csdn)————程序
【2】Python环境及相关依赖包: 【3】Theano包安装: 【4】C++环境安装:直接安装微软的VisualStudio环境 【5】并行计算架构CUDA7.5的安装 【6】cuda7.5和VS2013的配置 【7】配置Cudnn加速 【8】修改配置文件....
openpose-1.7.0-binaries-win64-gpu-python3.7-flir-3d_recommended.zip
python cuda gpu 高性能运算 代码2
Tensorflow GPU 1.0版本 Linux Ubuntu Python2.7. 更多版本下载: https://pypi.python.org/pypi/tensorflow-gpu/1.0.0
GPU Programming and High Performance Computing
opencv4.2 cuda10 python3.7编译版,之前下载了很多,都是没有python的编译文件,就自己编译了一下
CNTK for Python on Windows, with GPU.
GPU编程实战-基于Python和CUDA.pdf
Tensorflow 1.6 GPU版 适用于python3.5。 安装步骤(Windows 7 64bit 测试通过): 1.下载并安装tensorflow_gpu-1.6.0-cp35-cp35m-win_amd64.whl 2.安装CUDA® Toolkit 9.0。完成后可运行deviceQuery例程来检测是否...
pytorch, 在 python 强大的GPU加速张量和动态神经网络 PyTorch是一个 python 软件包,提供两个高级功能:强GPU加速的张量计算( 就像 NumPy )基于磁带的autograd系统深层神经网络你可以重用你喜欢的python 包,如 ...