# B10: matrix ###### tags: `sysprog2017` :::info 主講人: [jserv](http://wiki.csie.ncku.edu.tw/User/jserv) / 課程討論區: [2017 年系統軟體課程](https://www.facebook.com/groups/system.software2017/) :mega: 返回「[作業系統設計與實作](http://wiki.csie.ncku.edu.tw/sysprog/schedule)」課程進度表 ::: ## 預期目標 * 學習物件導向程式設計和資料封裝技巧 * 回顧效能分析和改善機制 * 從矩陣乘法運算的最佳化,思考整體系統效能的議題 * 提出測試矩陣乘法正確性和效能之有效機制 ## 作業要求 * 詳細閱讀 [Matrix Multiplication using SIMD](https://hackmd.io/s/Hk-llHEyx),試著重現實驗 * 在 GitHub 上 fork [matrix_oo](https://github.com/sysprog21/matrix_oo) 專案,指出原本設計的優缺點,並且提出改進方案 (從物件導向封裝、效能,還有資料驗證等觀點) * 提示: 可執行 `make check`,自動編譯測試程式並驗證 * 在 [matrix_oo](https://github.com/sysprog21/matrix_oo) 的基礎上,整合 [Matrix Multiplication using SIMD](https://hackmd.io/s/Hk-llHEyx) 的成果,注意,應該建立新的檔案,如 `matrix_sse.c` 和 `matrix_avx.c` 並且設計新的效能分析工具,需要用到程式碼的 `Stopwatch`,時間刻度用 millisecond (ms) * 克服 [matrix_oo](https://github.com/sysprog21/matrix_oo) 裡頭只支援 4x4 矩陣的限制,考慮 sub-matrix 和 column-major 來提升 cache 使用率 * 驗證過程需要考慮不同大小的矩陣 * 需要考慮到矩陣乘法的有效性,不是任意矩陣都可相互執行乘法 * 需要一併考慮 data alignment 議題 * 學習 crypto API 並設計介面使演算法容易擴充和比較 * 學習的案例: [Linaro Cortex String benchmark for ARMv8](https://wiki.linaro.org/WorkingGroups/Kernel/ARMv8/cortex-strings) * 關於 benchmark 設計可參考: [ssvb/tinymembench](https://github.com/ssvb/tinymembench) 和 [hglm/test-arm-kernel-memcpy](https://github.com/hglm/test-arm-kernel-memcpy) * 允許透過亂數作為資料輸入,驗證矩陣乘法的效能,需要視覺化 (透過 gnuplot 或 R) * 留意記憶體存取,避免 leak,參考 [你所不知道的C語言:技巧篇](https://hackmd.io/s/HyIdoLnjl) 提到的 smart pointer * 指出原有的程式碼是否 [thread-safe](https://en.wikipedia.org/wiki/Thread_safety),並提出改進方案 * 記錄開發過程於 [作業區](https://hackmd.io/s/ryPKJUm2l) * 截止日: Apr 8, 2017