You will modify only hostFE.c and kernel.cl. ### Q1 (5 points): Explain your implementation. How do you optimize the performance of convolution? Answer: Serial改成平行,優化的部分在於,當filter的值若是0時,不進入判斷作計算。 在hostFE.c 中把 local work size 設成 25 x 25,然而 global work size = imageWidth x imageHeight,如此可以確保圖片的每一個 pixel 皆有一個 work item 去對其做平行處理 ![](https://hackmd.io/_uploads/SJA4MPlv3.jpg) ### [Bonus] Q2 (10 points): Rewrite the program using CUDA. (1) Explain your CUDA implementation, (2) plot a chart to show the performance difference between using OpenCL and CUDA, and (3) explain the result. (1)explain your CUDA implementation CUDA地方寫了hostFE(),呼叫kernel去作運算,當filter的值若是0時,不進入判斷作計算。 ![](https://hackmd.io/_uploads/HkXciExv2.jpg) (2) plot a chart to show the performance difference between using OpenCL and CUDA using profiling to record system time ``` OpenCL執行5 times 的平均時間 ``` ![](https://hackmd.io/_uploads/H1GWnEgwh.jpg) ``` CUDA執行5 times 的平均時間 ``` ![](https://hackmd.io/_uploads/ryMWn4ew2.jpg) ``` Plot a chart to Compare cuda and OpenCL ``` ![](https://hackmd.io/_uploads/r15vh4gwn.jpg) (3) explain the result 根據上面的結果顯示,在所使用的演算法相同,使用同樣 NVIDIA 的 GPU 情況下,那麼使用 CUDA 的 performance 會比使用 OpenCL 還要好。 分析原因:OpenCL 是跨平台跨設備支援的程式編寫框架,相對於 CUDA 只支援 NVIDIA 的 GPU 設備的情況下,較難只針對 NVIDIA 的設備進行優化。因此針對 NVIDIA 的 GPU 在效能的比較上, CUDA 的表現會比 OpenCL 好。