简体   繁体   English

PyOpenCL入门

[英]Getting started with PyOpenCL

I have recently discovered the power of GP-GPU (general purpose graphics processing unit) and want to take advantage of it to perform 'heavy' scientific and math calculations (that otherwise require big CPU clusters) on a single machine. 我最近发现了GP-GPU(通用图形处理单元)的强大功能,并希望利用它在一台机器上执行“繁重”的科学和数学计算(否则需要大型CPU集群)。

I know that there are several interfaces to operate on a GPU, the most prominent of those being CUDA and OpenCL. 我知道有几个接口可以在GPU上运行,其中最突出的是CUDA和OpenCL。 The latter has the advantage against CUDA to run on most graphics cards (NVIDIA, AMD, Intel) rather than NVIDA cards only. 后者具有防止CUDA在大多数显卡(NVIDIA,AMD,Intel)上运行的优势,而不仅仅是NVIDA卡。 In my case, I have an ordinary Intel 4000 GPU that seems to be well cooperating with OpenCL. 在我的情况下,我有一个普通的Intel 4000 GPU似乎与OpenCL很好地合作。

Now, I need to learn how to operate with PyOpenCL to get it on further! 现在,我需要学习如何使用PyOpenCL来进一步操作! So here comes the question: 所以这里有一个问题:

How can I get started with PyOpenCL? 我怎样才能开始使用PyOpenCL? What are the prerequisites? 有什么先决条件? Do I really need to be experienced in Python and/or OpenCL? 我真的需要有Python和/或OpenCL的经验吗?

My background is in fortran and as a matter of fact I need to translate and parallelize a lengthy fortran code to python (or pyopencl) that mainly deals with solving PDEs and diagonalizing matrices. 我的背景是在fortran中,事实上我需要将冗长的fortran代码翻译并并行化为python(或pyopencl),主要处理PDE和对角化矩阵。

I have read the two relevant websites http://enja.org/2011/02/22/adventures-in-pyopencl-part-1-getting-started-with-python/ and http://documen.tician.de/pyopencl/ but they are not really helpful for newbies (ie, dummies). 我已阅读了两个相关网站http://enja.org/2011/02/22/adventures-in-pyopencl-part-1-getting-started-with-python/http://documen.tician.de/ pyopencl /但它们对新手(即假人)并没有真正的帮助。

I just don't know what to begin with. 我只是不知道该怎么做。 I do not aspire on becoming an expert on the field, just to get to know how one can parallelize simple math and linear algebra on pyopencl. 我不想成为该领域的专家,只是为了了解如何在pyopencl上并行化简单的数学和线性代数。

Any advice and help is highly welcome! 任何建议和帮助都非常欢迎!

It seems you are looking for the fastest and most effective path to learn PyOpenCL. 您似乎正在寻找学习PyOpenCL的最快最有效的途径。 You do not need to know OpenCL (the hard part) at the start, but it will be helpful to know Python when you begin. 您不需要在开始时了解OpenCL(困难部分),但在开始时了解Python会很有帮助。

For learning Python syntax quickly, I recommend Codecademy's Python track: http://www.codecademy.com/tracks/python 为了快速学习Python语法,我推荐使用Codecademy的Python轨道: http//www.codecademy.com/tracks/python

Then, the Udacity parallel programming course is a great place to start with GPGPU (even though the course is taught in CUDA). 然后,Udacity并行编程课程是一个从GPGPU开始的好地方(即使课程是在CUDA中教授的)。 https://www.udacity.com/course/cs344 This course will teach you fundamental GPGPU concepts very quickly. https://www.udacity.com/course/cs344本课程将非常快速地教您基本的GPGPU概念。 You will not need a NVIDIA GPU to participate, because all the course assessments are done online. 您不需要NVIDIA GPU参与,因为所有课程评估都是在线完成的。

After (or during) the Udacity course, I recommend you read, run, and customize PyOpenCL code examples: https://github.com/inducer/pyopencl/tree/master/examples 在Udacity课程之后(或期间),我建议您阅读,运行和自定义PyOpenCL代码示例: https//github.com/inducer/pyopencl/tree/master/examples

Irrespective of the language of adoption for GPGPU computing such as Java,C/C++, Python, I would recommend you first get started with the basics of GPGPU computing and OpenCL. 无论GPGPU计算的采用语言如Java,C / C ++,Python,我都建议您首先开始使用GPGPU计算和OpenCL的基础知识。

You can use the following resources all are C/C++ oriented but this should you give enough knowledge about OpenCL, GPGPU hardware to get you started. 您可以使用以下资源,所有这些都是面向C / C ++的,但是这应该让您充分了解OpenCL,GPGPU硬件以帮助您入门。

  1. AMD OpenCL University Tool kit AMD OpenCL大学工具包

  2. Hetergeneous Computing with OpenCL Book 2nd Edition 使用OpenCL Book第2版进行异构计算

  3. NVIDIA OpenCL pages is another Excellent resorce NVIDIA OpenCL页面是另一个优秀的resorce

  4. Streamcomputing.eu has nice openCL starter articles. Streamcomputing.eu有很好的openCL入门文章。

  5. Intel OpenCL SDK tutorial 英特尔OpenCL SDK教程

PyOpenCL specific PyOpenCL具体

  1. OpenCL in Action: How to Accelerate Graphics and Computation has a chapter on PyOpenCL OpenCL in Action:如何加速图形和计算有一章关于PyOpenCL
  2. OpenCL Programming Guide has chapter PyOpenCL OpenCL编程指南有PyOpenCL章节

Both the books contain OpenCL 1.1 implementation but it should be good starting point for you. 这两本书都包含OpenCL 1.1实现,但它应该是你的好起点。

As someone new to GPU programming I found the relevant articles you mentioned fairly straightforward though I found the sample code ran perfectly from the command line but not in Eclipse with Anaconda. 作为GPU编程的新手,我发现您提到的相关文章相当简单,但我发现示例代码完全从命令行运行,但在Eclipse中没有使用Anaconda。 I think this may be because the Eclipse pyopencl from anaconda is different from the command line version, and I have yet to work out how to resolve this. 我想这可能是因为来自anaconda的Eclipse pyopencl与命令行版本不同,我还没有弄清楚如何解决这个问题。

For learning python there are a large number of resources online including free ebooks. 对于学习python,网上有大量资源,包括免费电子书。

https://wiki.python.org/moin/BeginnersGuide http://codecondo.com/10-ways-to-learn-python/ https://wiki.python.org/moin/BeginnersGuide http://codecondo.com/10-ways-to-learn-python/

should be good starters. 应该是好的先发者。 If you use Eclipse you should install pydev. 如果您使用Eclipse,则应安装pydev。 In any case install Anaconda https://docs.continuum.io/anaconda/install as this will save you a lot of hassle. 在任何情况下安装Anaconda https://docs.continuum.io/anaconda/install,因为这将为您节省很多麻烦。

I estimate a week or so to get to the level of proficiency you need in Python as long as you picj a few simple mini projects. 我估计需要一周左右的时间才能达到Python所需的熟练程度,只要你完成一些简单的迷你项目即可。 You may also find that with numpy and scipy and possibly ipython notebook you may not need to delve into GPU programming 您可能还会发现使用numpy和scipy以及可能的ipython笔记本,您可能不需要深入研究GPU编程

These links may help you avoid GPU programming or at least delay having to learn it. 这些链接可以帮助您避免GPU编程或至少延迟必须学习它。 Be aware that thr cost of switching between cores means you have ot assign a singificant amount of work to each core 请注意,在核心之间切换的成本意味着您必须为每个核心分配大量的工作

http://blog.dominodatalab.com/simple-parallelization/ https://pythonhosted.org/joblib/parallel.html http://blog.dominodatalab.com/simple-parallelization/ https://pythonhosted.org/joblib/parallel.html

Generally I find it more efficient, if less fun, to learn only one thing at a time. 一般来说,我发现它更有效,如果不那么有趣,一次只学习一件事。

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM