# 2017q1 Homework5 (matrix) contributed by < `laochanlam` > ###### tags: `laochanlam` # 開發環境 - Ubuntu 16.10 ( 64 bit ) ``` Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 61 Model name: Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz Stepping: 4 CPU MHz: 2400.878 CPU max MHz: 3000.0000 CPU min MHz: 500.0000 BogoMIPS: 4788.90 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 4096K NUMA node0 CPU(s): 0-3 ``` # 相關連結 - [2017 年春季作業說明](https://hackmd.io/s/Bk-1zqIte#) - [2017q1 Homework5 (作業區)](https://hackmd.io/EYVgpgTALCCcUFoDsBjKiYEMUOAEyUwVlgDY8RMQAOKYAZlKA===) - [B10: matrix 作業要求](https://hackmd.io/s/rkrrpHm2e) - [課程進度與開放資源 Wiki](http://wiki.csie.ncku.edu.tw/sysprog/schedule) - [你所不知道的C語言:技巧篇](https://hackmd.io/s/HyIdoLnjl) # 開發紀錄 ## Matrix_oo 在理解 ```matrix_oo``` 程式碼的時候,看到了這個 ```C (struct timespec) { 0, 0 }; ``` 所以去看了一下 ```timespec``` 的結構 (應該要一早看的XD),結果如下 ```C struct timespec { time_t tv_sec; /*second*/ long tv_nsec;/*nanosecond*/ } ``` --- 以及在 ```matrix.h``` 中 ```C #define DECLARE_MATRIX(col, row) \ typedef struct { float values[col][row]; } Mat ## col ## x ## row ``` 的 ``` Mat ## col ## x ## row ``` 開始還以為是註解...XD 後來發現是 [Macro 的一些用法](http://blog.csdn.net/acs713/article/details/6891837)。 :::danger 你應該一併找出對應的 C99/C11 spec,不是只貼出連結 --jserv ::: --- 然後就是不懂 ```test-matrix.c``` 裡為什麼這裡要這樣寫: ```C MatrixAlgo *matrix_providers[] = { &NaiveMatrixProvider, }; ``` :::danger 你可以將 optimized implementation 更新在 provider list 中 --jserv ::: --- ### 考慮不同大小的矩陣 因為在 ```matrix_oo``` 中,Row 及 Col 的值是固定的,所以用了一些 Dynamic Allocation 等的方法改寫。 #### 動態宣告二維陣列 ```C float **data1 = (float **)malloc(row_m * sizeof(float *)); float *data_ptr = (float *)malloc(col_m * row_m * sizeof(float)); for (int i = 0; i < row_m; i++, data_ptr += col_m) data1[i] = data_ptr; ``` 然後出現了一個問題,就是若要自己宣告 const 的 8x8 陣列,放進 assign 中 ``` tests/test-matrix.c:51:22: warning: incompatible pointer types passing 'float [8][8]' to parameter of type 'float **' [-Wincompatible-pointer-types] ``` 會發現動態宣告的二維陣列跟自己宣告的陣列型態不同.. 解決方法只好再動態宣告一個動態陣列把值 assign 過去。 >有更好的解決方法嗎? >[name=laochanlam][color=blue] :::info 參見 [An Array of Pointers vs. a Multidimensional Array](http://nullprogram.com/blog/2016/10/27/),你需要先變更 memory layout --jserv ::: --- #### 整合 Matrix Multiplication using SIMD 成果 在這裡我把 ```test-matrix.c``` 跟 ```test-stopwatch.c``` 分離開來,原因是想獨立驗證的功能,所以再寫一個 ```main.c```。 在整合 SIMD 成果的時候才發現 matrix_naive 所用的是 float type 的資料,在使用 AVX 跟 SSE 整合起來時因為資料大小的不同而變得十分困難。 #### 現正遭遇及解決中的問題: 1. 多種不同型態之數據處理。 2. Memory Layout 的不同導致 SSE 及 AVX 不能以原來的方法實作 (記憶體非連續)。 # 補充知識 - [ ] crypto API - [ ] Makefile --- ## Makefile 對 Shell Script 十分不熟啊... ```Shell check: $(EXEC) @for test in $^ ; \ do \ echo "Execute $$test..." ; $$test && echo "OK!\n" ; \ done ``` 大概是把 ```$(EXEC)``` 中的東西都 run 過一次再加上 echo 這樣。 每次看 Makefile 總是會忘光光,只好紀錄下來慢慢看。 #### 參考及引用資料 [跟我一起写Makefile:使用函数](http://wiki.ubuntu.org.cn/%E8%B7%9F%E6%88%91%E4%B8%80%E8%B5%B7%E5%86%99Makefile:%E4%BD%BF%E7%94%A8%E5%87%BD%E6%95%B0) [Makefile 語法和示範](https://hackmd.io/s/SySTMXPvl#)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up