{"action":"created","issue":{"url":"https://api.github.com/repos/xianyi/OpenBLAS/issues/1622","repository_url":"https://api.github.com/repos/xianyi/OpenBLAS","labels_url":"https://api.github.com/repos/xianyi/OpenBLAS/issues/1622/labels{/name}","comments_url":"https://api.github.com/repos/xianyi/OpenBLAS/issues/1622/comments","events_url":"https://api.github.com/repos/xianyi/OpenBLAS/issues/1622/events","html_url":"https://github.com/xianyi/OpenBLAS/issues/1622","id":333022065,"node_id":"MDU6SXNzdWUzMzMwMjIwNjU=","number":1622,"title":"Threading threshold tuning needed for sgemm/dgemm","user":{"login":"fenrus75","id":1302037,"node_id":"MDQ6VXNlcjEzMDIwMzc=","avatar_url":"https://avatars3.githubusercontent.com/u/1302037?v=4","gravatar_id":"","url":"https://api.github.com/users/fenrus75","html_url":"https://github.com/fenrus75","followers_url":"https://api.github.com/users/fenrus75/followers","following_url":"https://api.github.com/users/fenrus75/following{/other_user}","gists_url":"https://api.github.com/users/fenrus75/gists{/gist_id}","starred_url":"https://api.github.com/users/fenrus75/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fenrus75/subscriptions","organizations_url":"https://api.github.com/users/fenrus75/orgs","repos_url":"https://api.github.com/users/fenrus75/repos","events_url":"https://api.github.com/users/fenrus75/events{/privacy}","received_events_url":"https://api.github.com/users/fenrus75/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/xianyi/OpenBLAS/milestones/20","html_url":"https://github.com/xianyi/OpenBLAS/milestone/20","labels_url":"https://api.github.com/repos/xianyi/OpenBLAS/milestones/20/labels","id":3378018,"node_id":"MDk6TWlsZXN0b25lMzM3ODAxOA==","number":20,"title":"0.3.1","description":"","creator":{"login":"martin-frbg","id":6192365,"node_id":"MDQ6VXNlcjYxOTIzNjU=","avatar_url":"https://avatars0.githubusercontent.com/u/6192365?v=4","gravatar_id":"","url":"https://api.github.com/users/martin-frbg","html_url":"https://github.com/martin-frbg","followers_url":"https://api.github.com/users/martin-frbg/followers","following_url":"https://api.github.com/users/martin-frbg/following{/other_user}","gists_url":"https://api.github.com/users/martin-frbg/gists{/gist_id}","starred_url":"https://api.github.com/users/martin-frbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martin-frbg/subscriptions","organizations_url":"https://api.github.com/users/martin-frbg/orgs","repos_url":"https://api.github.com/users/martin-frbg/repos","events_url":"https://api.github.com/users/martin-frbg/events{/privacy}","received_events_url":"https://api.github.com/users/martin-frbg/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":24,"state":"open","created_at":"2018-05-26T04:34:07Z","updated_at":"2018-06-23T13:01:03Z","due_on":"2018-06-30T07:00:00Z","closed_at":null},"comments":23,"created_at":"2018-06-16T23:21:08Z","updated_at":"2018-06-25T12:57:10Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Based on the data below, the threading threshold tuning might need some help; if you happen to have a good pointer then I'll play and help\r\n\r\nThe baseline for performance is this:\r\n```\r\nTARGET=SKYLAKEX F_COMPILER=GFORTRAN  SHARED=1 DYNAMIC_THREADS=1 USE_OPENMP=0  NUM_THREADS=1\r\n\r\n   Matrix       Float cycles            CPM                                     Double cycles           CPM\r\n   1 x 1               240.9         1.0000          0.0%                              306.7         1.0000          0.0%\r\n   4 x 4               326.4         1.3510          0.0%                              455.0         2.3328          0.0%\r\n   6 x 6               634.2         1.8255          0.0%                              693.3         1.7942          0.0%\r\n   8 x 8               477.3         0.4636          0.0%                              565.9         0.5081          0.0%\r\n  10 x 10              930.5         0.6906          0.0%                             1365.5         1.0598          0.0%\r\n  16 x 16             1166.8         0.2263          0.0%                             1438.2         0.2765          0.0%\r\n  20 x 20             2102.9         0.2329          0.0%                             3411.6         0.3882          0.0%\r\n  32 x 32             4572.0         0.1322          0.0%                             6164.2         0.1788          0.0%\r\n  40 x 40             7998.6         0.1212          0.0%                            12998.0         0.1983          0.0%\r\n  64 x 64            20376.5         0.0768          0.0%                            39989.2         0.1514          0.0%\r\n  80 x 80            37374.8         0.0725          0.0%                            71594.1         0.1392          0.0%\r\n 100 x 100           75786.8         0.0755          0.0%                           143355.2         0.1430          0.0%\r\n 128 x 128          127663.1         0.0608          0.0%                           251965.2         0.1200          0.0%\r\n 150 x 150          258028.7         0.0764          0.0%                           457672.6         0.1355          0.0%\r\n 200 x 200          477604.2         0.0597          0.0%                           971440.2         0.1214          0.0%\r\n 256 x 256          977700.6         0.0583          0.0%                          2259957.4         0.1347          0.0%\r\n 300 x 300         1720165.4         0.0637          0.0%                          3282089.5         0.1215          0.0%\r\n 400 x 400         3911583.9         0.0611          0.0%                          9495537.9         0.1484          0.0%\r\n 500 x 500         7490500.9         0.0599          0.0%                         27368762.1         0.2189          0.0%\r\n 512 x 512         8151211.0         0.0607          0.0%                         32727483.8         0.2438          0.0%\r\n 600 x 600        14568998.7         0.0674          0.0%                         27482490.9         0.1272          0.0%\r\n 700 x 700        28441907.2         0.0829          0.0%                         47884964.0         0.1396          0.0%\r\n 800 x 800        33472600.5         0.0654          0.0%                         71845317.9         0.1403          0.0%\r\n1000 x 1000         66664296.2       0.0667          0.0%                        217093066.9         0.2171          0.0%\r\n1024 x 1024         76171844.0       0.0709          0.0%                        261327051.0         0.2434          0.0%\r\n1200 x 1200        129456787.0       0.0749          0.0%                        304937633.0         0.1765          0.0%\r\n2000 x 2000        715247226.5       0.0894          0.0%                       1823524984.8         0.2279          0.0%\r\n```\r\n\r\nThe Cycles-per-multiply metric is likely the most useful as performance metric; for Float the hardware in question has a theoretical limit of 0.03125 CPM and we get close to half of theoretical as matrixes get bigger.\r\n\r\n\r\nOnce threading gets enabled (20 logical cpus, 10 physical cores on the system) things get interesting:\r\n(the percentages is performance delta to baseline, negative numbers are performance loss)\r\n```\r\nTARGET=SKYLAKEX F_COMPILER=GFORTRAN  SHARED=1 DYNAMIC_THREADS=1 USE_OPENMP=0  NUM_THREADS=20\r\n\r\n   Matrix       Float cycles            CPM                                     Double cycles           CPM\r\n   1 x 1               261.2         1.0000         -8.4%                              319.2         1.0000         -4.1%\r\n   4 x 4               343.0         1.2943         -5.1%                              464.8         2.2901         -2.1%\r\n   6 x 6               634.1         1.7314          0.0%                              707.2         1.8010         -2.0%\r\n   8 x 8               475.2         0.4199          0.4%                              576.0         0.5034         -1.8%\r\n  10 x 10              941.8         0.6817         -1.2%                             1366.0         1.0478         -0.0%\r\n  16 x 16             1192.4         0.2276         -2.2%                             1412.1         0.2671          1.8%\r\n  20 x 20             2132.0         0.2340         -1.4%                             3446.1         0.3910         -1.0%\r\n  32 x 32             4554.3         0.1310          0.4%                             6170.7         0.1786         -0.1%\r\n  40 x 40             8028.2         0.1214         -0.4%                            12959.8         0.1975          0.3%\r\n  64 x 64            20327.9         0.0766          0.2%                            40080.3         0.1517         -0.2%\r\n  80 x 80           156349.0         0.3049       -318.3%                           180205.0         0.3513       -151.7%\r\n 100 x 100          202101.6         0.2018       -166.7%                           220979.9         0.2207        -54.1%\r\n 128 x 128          306939.2         0.1462       -140.4%                           312681.5         0.1489        -24.1%\r\n 150 x 150          311053.7         0.0921        -20.6%                           361673.4         0.1071         21.0%\r\n 200 x 200          404916.4         0.0506         15.2%                           486996.6         0.0608         49.9%\r\n 256 x 256          599879.4         0.0357         38.6%                           743093.4         0.0443         67.1%\r\n 300 x 300          931914.4         0.0345         45.8%                          1248691.5         0.0462         62.0%\r\n 400 x 400          930678.0         0.0145         76.2%                          1645345.5         0.0257         82.7%\r\n 500 x 500         1740345.0         0.0139         76.8%                          2897384.9         0.0232         89.4%\r\n 512 x 512         2012971.7         0.0150         75.3%                          3223831.4         0.0240         90.1%\r\n 600 x 600         3428350.2         0.0159         76.5%                          5333402.9         0.0247         80.6%\r\n 700 x 700         4427124.5         0.0129         84.4%                          7267851.8         0.0212         84.8%\r\n 800 x 800         4461900.5         0.0087         86.7%                          8944377.1         0.0175         87.6%\r\n1000 x 1000          9285704.1       0.0093         86.1%                         16669766.7         0.0167         92.3%\r\n1024 x 1024         11111463.6       0.0103         85.4%                         19204966.9         0.0179         92.7%\r\n1200 x 1200         14541484.8       0.0084         88.8%                         26442997.1         0.0153         91.3%\r\n2000 x 2000         56051476.5       0.0070         92.2%                        109212662.6         0.0137         94.0%\r\n```\r\n\r\nFor very small matrixes there is a little bit of overhead, but thanks to @oon3m0oo and @sandwichmaker, this overhead is pretty tiny.\r\nHOWEVER, once threading kicks in (just after 64x64) performance tanks compares to the baseline, and does not recover until 200x200 size. \r\n\r\nThis is not related to OpenMP-versus-threads, with OpenMP the data looks like this:\r\n```\r\n   Matrix               Float cycles            CPM                                     Double cycles           CPM\r\n   1 x 1                       321.3         1.0000        -33.0%                              367.6         1.0000        -20.2%\r\n   4 x 4                       407.0         1.3538        -24.4%                              533.1         2.6029        -18.0%\r\n   6 x 6                       724.0         1.8690        -15.6%                              749.1         1.7712         -9.4%\r\n   8 x 8                       537.5         0.4243        -11.5%                              645.7         0.5452        -12.8%\r\n  10 x 10                     1010.8         0.6905         -8.2%                             1442.2         1.0756         -5.6%\r\n  16 x 16                     1234.5         0.2232         -4.8%                             1510.9         0.2794         -3.8%\r\n  20 x 20                     2187.3         0.2334         -2.4%                             3481.5         0.3894         -1.6%\r\n  32 x 32                     4552.2         0.1291         -0.5%                             6221.6         0.1787         -1.8%\r\n  40 x 40                     8160.9         0.1225         -1.5%                            13212.9         0.2007         -1.3%\r\n  64 x 64                    20592.2         0.0773          0.2%                            39986.8         0.1511          0.2%\r\n  80 x 80                   142826.6         0.2783       -275.9%                           167659.7         0.3267       -133.4%\r\n 100 x 100                  196696.8         0.1964       -162.9%                           210191.3         0.2098        -50.4%\r\n 128 x 128                  304810.0         0.1452       -132.4%                           304392.2         0.1450        -19.4%\r\n 150 x 150                  300171.4         0.0888        -14.0%                           354805.6         0.1050         21.7%\r\n 200 x 200                  391677.0         0.0489         20.3%                           487251.6         0.0609         50.1%\r\n 256 x 256                  599838.1         0.0357         37.7%                           741835.3         0.0442         65.9%\r\n 300 x 300                  930674.1         0.0345         45.6%                          1253722.9         0.0464         63.8%\r\n 400 x 400                  950285.4         0.0148         75.4%                          1638163.7         0.0256         79.8%\r\n 500 x 500                 1734750.9         0.0139         77.3%                          2909310.0         0.0233         88.8%\r\n 600 x 600                 3425653.7         0.0159         77.3%                          5346582.5         0.0248         79.7%\r\n 700 x 700                 4434540.4         0.0129         84.4%                          7263461.4         0.0212         84.2%\r\n 800 x 800                 4450149.4         0.0087         86.1%                          8915261.2         0.0174         88.2%\r\n1000 x 1000                9304762.8         0.0093         86.0%                         16688999.4         0.0167         92.1%\r\n1200 x 1200               14489066.5         0.0084         88.8%                         26425386.2         0.0153         91.3%\r\n2000 x 2000               55720002.7         0.0070         92.2%                        108477700.1         0.0136         93.5%\r\n```\r\n\r\nWhich shows OpenMP has a bit more baseline overhead, but has otherwise the same problem after 64x64 to 200x200\r\n\r\n\r\n\r\nSo my conclusion is that the threading kicks in at too small matrices currently.... if it started at 200x200 then there would be a win across the board."},"comment":{"url":"https://api.github.com/repos/xianyi/OpenBLAS/issues/comments/399942267","html_url":"https://github.com/xianyi/OpenBLAS/issues/1622#issuecomment-399942267","issue_url":"https://api.github.com/repos/xianyi/OpenBLAS/issues/1622","id":399942267,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTk0MjI2Nw==","user":{"login":"oon3m0oo","id":11841654,"node_id":"MDQ6VXNlcjExODQxNjU0","avatar_url":"https://avatars0.githubusercontent.com/u/11841654?v=4","gravatar_id":"","url":"https://api.github.com/users/oon3m0oo","html_url":"https://github.com/oon3m0oo","followers_url":"https://api.github.com/users/oon3m0oo/followers","following_url":"https://api.github.com/users/oon3m0oo/following{/other_user}","gists_url":"https://api.github.com/users/oon3m0oo/gists{/gist_id}","starred_url":"https://api.github.com/users/oon3m0oo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oon3m0oo/subscriptions","organizations_url":"https://api.github.com/users/oon3m0oo/orgs","repos_url":"https://api.github.com/users/oon3m0oo/repos","events_url":"https://api.github.com/users/oon3m0oo/events{/privacy}","received_events_url":"https://api.github.com/users/oon3m0oo/received_events","type":"User","site_admin":false},"created_at":"2018-06-25T12:57:10Z","updated_at":"2018-06-25T12:57:10Z","author_association":"CONTRIBUTOR","body":"I think those are exactly how the code is structured now, and having tried both eventfds and futexes in an attempt to make it fast, I have to conclude that spin-waiting is indeed the best thing to do.  I have, however, put up a PR (#1642) to make threading tools happy, if that's acceptable."}}
{"actor":{"display_login":"oon3m0oo"}}