Parallel Programming HW5 @NYCU, 2022 Fall
Q1
- Method 1:
malloc
+ cudaMalloc
- Pros:
-
- 每個 thread 只需要處理一個 pixel,能善用 GPU 平行處理。
-
- 沒使用 page-locked memory ,不會對system performance 造成太大影響。
- Cons:
-
- 各 thread 處理的計算量不同,導致比較快做完的 thread 需要等待比較慢做完的 thread。
-
cudaMalloc
使用 pageable memory,如果需要的 page 不在 memory 內,需要等待傳輸。
- Method 2:
cudaHostAlloc
+ cudaMallocPitch
- Pros:
-
cudaHostAlloc
使用 page-locked memory ,可以確保需要的 page 在 memory 內,避免等待傳輸。
-
- 若 data 是二維,且對齊存放,可以增加存取速度。
-
cudaMallocPitch
cuda 中這樣分配的二維數組內存保證了數組每一行首元素的地址值都按照 256 或 512 的倍數對齊,提高訪問效率
- Cons:
-
- 各 thread 處理的計算量不同,導致比較快做完的 thread 需要等待比較慢做完的 thread。
-
cudaHostAlloc
使用過多 page-locked memory ,會降低 system performance 。
- Method 3:
cudaHostAlloc
+ cudaMallocPitch
+ group
- Pros:
-
- 每個 thread 一次只可處理多個 pixel,可以減少搬動 global memory 到 shared memory 的次數。
-
cudaHostAlloc
使用 page-locked memory ,可以確保需要的 page 在 memory 內,避免等待傳輸。
-
- 若 data 是二維,且對齊存放,可以增加存取速度。
-
cudaMallocPitch
cuda 中這樣分配的二維數組內存保證了數組每一行首元素的地址值都按照 256 或 512 的倍數對齊,提高訪問效率
- Cons:
-
- 若 group 分配到的 pixel 計算量不平均,有些 group 內計算量都很大,有些計算量都很小,會導致效能不好。
-
cudaHostAlloc
使用過多 page-locked memory ,會降低 system performance 。
Assumption:
- Method 3 會有load unbalence 的問題,兩張測試圖片都有深淺不均的問題存在。所以 Method 3 效能最差。
cudaMallocPitch
比 cudaMalloc
較為複雜,會花更多時間,因此推測 Method 1 效能會比 Method 2 還要好。
- 推測效能排序: Method 1 > Method 2 > Method 3
Q2
veiw1:
|
Method 1 |
Method 2 |
Method 3 |
iteration=1000 |
6.556 |
9.012 |
9.065 |
iteration=10000 |
33.779 |
36.041 |
43.169 |
iteration=100000 |
310.885 |
314.805 |
382.159 |
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
veiw2:
|
Method 1 |
Method 2 |
Method 3 |
iteration=1000 |
3.761 |
6.260 |
6.507 |
iteration=10000 |
6.745 |
9.221 |
10.714 |
iteration=100000 |
29.948 |
32.349 |
46.315 |
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Q3
Assumptation: Method 1 > Method 2 > Method 3
Experimental Reslt: Method 1 > Method 2 > Method 3
實驗結果與我預期的一樣。
Method 3 因為每個 thread 要處理一個group 的 pixel ,會發生運算量分配不均的問題,因此效率最差。
Method 2 比 Method 1 效率差是因為 處理 Method 2 在 cudaMemcpy2D
會花比較久時間。使用 nvprof
可以看到實驗結果。
Method 1:
Method 2:
Q4
Can we do even better? Think a better approach and explain it. Implement your method in kernel4.cu
我使用 Method 1 去作修改。修改如下:
-
- 把原先 block size=16 改成 8,可以加快一些。
-
- 原本需要宣告 host img 和 device img ,最後透過 copy 把 host img copy 到 img 。我改成指宣告 device img,然後在 cudaMemcpy 直接把 device 的結果寫回 img ,可以比原先再快一些。
-
- 在
mandelKernel
中,會作多次 iteration 的像素點的圖形運算,使用 #pragma unroll
加速整體的速度。
實驗結果:
|
View 1 |
View2 |
iteration=1000 |
5.008 |
2.852 |
iteration=10000 |
23.771 |
4.613 |
iteration=100000 |
206.298 |
19.752 |
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →