60 cuda全域性性能優化

2022-04-27 10:39:11 字數 3310 閱讀 5812

0 引言

cuda執行緒模型涉及grid的塊劃分和執行緒配置,直接影響到全域性運算速度。根據文件《cuda_c_programming_guide》,效能優化有三個方面的基本策略。

(1)最大化並行執行以實現最大的利用率.

(2)優化記憶體使用,以實現最大的記憶體吞吐量.

(3)優化指令使用,以實現最大的指令吞吐量.

對於應用程式的特定部分,哪些策略將產生最佳效能收益取決於該部分的效能受哪方面的限制;例如,優化主要受記憶體訪問限制的核心的指令使用不會產生任何顯著的效能提公升。因此,應該不斷地通過測量和監視效能限制器(例如使用cuda profiler)來指導優化工作。此外,將特定核心的浮點操作吞吐量或記憶體吞吐量(無論哪個更有意義)與裝置的相應峰值理論吞吐量進行比較,可以看出核心有多大的改進空間。

1 定位問題

(1)發現採用兩組資料進行訓練時,速度存在比較大的差異。其中,資料1耗時 time1 = 68163 ms, 資料2耗時 time2 = 42930 ms.  time1 = 1.59 * time2

通過cuda函式 gettimeofday 發現資料2關鍵函式的時間分布如下。

time of pre-computetdf is 106063 mms

time of computetdf is 96 mms

time of post-computetdf is 157454 mms

time of pre-computetdf is 11495 mms

time of computetdf is 108 mms

time of post-computetdf is 149239 mms

time of pre-computetdf is 8958 mms

time of computetdf is 95 mms

time of post-computetdf is 133390 mms

其中, pre-computetdf包含資料的預處理和記憶體分配與拷貝操作,computetdf呼叫核函式計算tdf值,post-computetdf計算local-tdf以及將gpu中的資料拷貝回cpu. 從時間上來看,cuda部分的操作並非計算效能不佳的瓶頸,其瓶頸集中在pre-post-computetdf上。

(2)分別考察pre-post-computetdf中進行資料預處理和記憶體分配與拷貝的時間,結果如下。

資料2資料處理部分的耗時記錄:

time of pre-computetdf without memory copy is 1542 mms

time of post-computetdf without memory copy is 1003 mms

time of pre-computetdf without memory copy is 2182 mms

time of post-computetdf without memory copy is 924 mms

time of pre-computetdf without memory copy is 2066 mms

time of post-computetdf without memory copy is 928 mms

sum_time_of_data_dealing = 8645mms

資料2記憶體分配與拷貝部分的耗時記錄(例二):

time of memory copy of pre-computetdf is 93738 mms

time of memory copy of post-computetdf is 155900 mms

time of memory copy of pre-computetdf is 6428 mms

time of memory copy of post-computetdf is 140536 mms

time of memory copy of pre-computetdf is 7184 mms

time of memory copy of post-computetdf is 135659 mms

sum_time_of_memory_copy_2 = 539445mms = 62.4 * sum_time_of_data_dealing

可以確定時間主要消耗在了記憶體分配與拷貝部分上!時間差距應當出現在這一部分,計算資料1進行驗證

time of memory copy of pre-computetdf is 100188 mms

time of memory copy of post-computetdf is 244773 mms

time of memory copy of pre-computetdf is 6431 mms

time of memory copy of post-computetdf is 205273 mms

time of memory copy of pre-computetdf is 6668 mms

time of memory copy of post-computetdf is 203422 mms

sum_time_of_memory_copy_1 = 766755mms = 1.42 * sum_time_of_memory_copy_2,與1.59的差距大致相當。

(3)更進一步,分析time of memory copy of pre-computetdf 與 time of memory copy of post-computetdf的區別

sum_data1_pre = 1813.6950 ms

sum_data2_pre = 1863.4580 ms

sum_data1_post = 38564.5090 ms

sum_data2_post = 49542.4860 ms

difference_sum_data_post = 10978 ms

(4)尋找其他方面的差距

統計了 time_use_without_computing_tdf1 = 11245.0 ms,   time_use_without_computing_tdf2 =  1727.0 ms

以上兩部分 difference_sum_data_post + difference_time_use_without_computing_tdf = 20496 ms為兩組資料在效能上的主要差異,分析原因在於點雲規模不同,資料1點雲的平均規模在7萬級別,資料2點雲的規模在1萬級別,因此二者的表現差異比較大。 

2 解決問題

通過降取樣點雲可以提高運算效率。

Android6 0許可權全解析

android在 6.0中摒棄了之前的install time permissions model取而代之的是runtime permissions model,也就是動態許可權管理。這種改變讓使用者更加容易的控制自己的隱私,好處不言而喻。但是對於程式設計師來說,還是有點小負擔的,增加了一些學習和開...