欢迎光临散文网 会员登陆 & 注册

MATLAB绘制曼德勃罗Mandelbrot集,并利用GPU加速

2021-12-07 23:23 作者:磁悬浮青蛙呱呱呱  | 我要投稿

     本文主要参考MATLAB帮助文件,Illustrating Three approaches to GPU Computing: The Mandelbrot Set,也可在网页https://ww2.mathworks.cn/help/parallel-computing/illustrating-three-approaches-to-gpu-computing-the-mandelbrot-set.html上看到同样的内容,代码如下:

      本机配置:CPU AMD Ryzen5 3600,GPU:RTX 3060,在maxIterations = 500;gridSize = 2000;xlim = [-1.5, 0.6];ylim = [ -1.2, 1.2];的条件下,生成的图片如下,计算耗时分别是9.89s,2.448s(4倍),0.232s(42.7倍),0.068s(144.6倍),

      可以用colormap函数改颜色,可选参数有parula,jet,hsv,hot,cool,spring,summer,
autumn,winter,gray,bone,copper,pink,lines,colorcube,prism,flag,white

count = log(count); 取对数运算不是必须,但能提高图像对比度,不取对数的效果如下,可以看出周围小分支的清晰度下降

pctdemo_processMandelbrotElement.cu、.m、.ptx···在MATLAB安装路径下,内容分别如下:

        使用GPU时容易遇到如下报错:The CUDA driver must recompile the GPU libraries because your device is more recent than the libraries.Recompiling can take several minutes. Learn more.
        来自MATLAB官方网站的解答(https://ww2.mathworks.cn/matlabcentral/answers/437756-how-can-i-recompile-the-gpu-libraries):
This is a known issue with CUDA 9.1 and the new Turing generation of GPUs. You don't need to do anything except ignore the initial warning or error.
There are multiple issues. The warning about recompiling of libraries is spurious and not relevant. The error from cublas is one-time only. And there is an equivalent error in cuDNN. A permanent workaround is to put the following into your startup.m file:

       一共有两个startup.m文件,分别是
C:\Program Files\Polyspace\R2019a\toolbox\fixedpoint\fixedpointtool\+fxptui\Startup.m,
C:\Program Files\Polyspace\R2019a\toolbox\matlab\external\interfaces\python\+python\+internal\startup.m,
      我在这两个文件中都加了warning off parallel:gpu:device:DeviceLibsNeedsRecompiling ……,然而没用,警告还是会弹出。


      用其它形式的迭代公式生成的图形。



MATLAB绘制曼德勃罗Mandelbrot集,并利用GPU加速的评论 (共 条)

分享到微博请遵守国家法律