[Py] pyOpenCL 初學筆記 on Mac

pyOpenCL 初學筆記 (凌亂未整理版)
參考網頁:http://www.drdobbs.com/open-source/easy-opencl-with-python/240162614

安裝:使用 Anaconda distribution :

下面是查詢 cl.platform 的資訊。

搜尋可用的裝置:pyopencl.Platform 物件中 get_device()

cl.device_type 有以下分類:

  •  CL_DEVICE_TYPE_CPU
    An OpenCL device that is the host processor. The host processor runs the OpenCL implementations and is a single or multi-core CPU.
  • CL_DEVICE_TYPE_GPU
    An OpenCL device that is a GPU. By this we mean that the device can also be used to accelerate a 3D API such as OpenGL or DirectX.
  • CL_DEVICE_TYPE_ACCELERATOR
    Dedicated OpenCL accelerators (for example the IBM CELL Blade). These devices communicate with the host processor using a peripheral interconnect such as PCIe.
  • CL_DEVICE_TYPE_CUSTOM
    Dedicated accelerators that do not support programs written in OpenCL C.
  • CL_DEVICE_TYPE_DEFAULT
    The default OpenCL device in the system. The default device cannot be aCL_DEVICE_TYPE_CUSTOM device.
  • CL_DEVICE_TYPE_ALL
    All OpenCL devices available in the system except CL_DEVICE_TYPE_CUSTOM devices..

所以只想查詢 GPU 的話,可以用:

接著是查詢 Device 的相關屬性(Properties),即 pyOpenCL 中 pyopencl.Device 物件屬性,如:記憶體大小、位元等。

其他資訊可見技術文件(Specifications)中第 37 至 49 頁,將前綴「CL_DEVICE_ 」去掉並小寫後即可得到相關資訊。

Building and Deploying a Kernel

To build and deploy a basic OpenCL kernel, you usually need to follow these steps in a typical OpenCL C++ host program:

  1. Obtain an OpenCL platform. 獲得平台資訊。
  2. Obtain a device id for at least one device (accelerator). 獲得裝置資訊(CPU、GPU…)
  3. Create a context for the selected device or devices. (?)
  4. Create the accelerator program from source code. (撰寫 openCL C 程式)
  5. Build the program. (編譯程式)
  6. Create one or more kernels from the program functions.
  7. Create a command queue for the target device. (創造命令佇(ㄓㄨˋ)列)
  8. Allocate device memory and move input data from the host to the device memory. (在裝置端劃分記憶體並由主控端將資料送入裝置記憶體中)
  9. Associate the arguments to the kernel with kernel object. (?在裝置中設置 kernel 物件的變數)
  10. Deploy the kernel for device execution.(指派裝置 kernel 核心執行)
  11. Move the kernel’s output data to host memory. (將輸出傳送到主控端記憶體中)
  12. Release context, program, kernels and memory. (清除及釋放內容?程式、核心與記憶體)

 


請多多指教!

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料