From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.107.3.84 with SMTP id 81mr6438295iod.103.1518872148097; Sat, 17 Feb 2018 04:55:48 -0800 (PST) X-Received: by 10.157.112.141 with SMTP id l13mr346308otj.1.1518872147748; Sat, 17 Feb 2018 04:55:47 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.am4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!w142no754012ita.0!news-out.google.com!t6ni315itg.0!nntp.google.com!w142no754011ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 17 Feb 2018 04:55:47 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.116.179.50; posting-account=z-xFXQkAAABpEOAnT3LViyFXc8dmoW_p NNTP-Posting-Host: 87.116.179.50 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: GNAT can't vectorize Real_Matrix multiplication from Ada.Numerics.Real_Arrays. What a surprise! From: Bojan Bozovic Injection-Date: Sat, 17 Feb 2018 12:55:48 +0000 Content-Type: text/plain; charset="UTF-8" X-Received-Body-CRC: 375108679 X-Received-Bytes: 6701 Xref: reader02.eternal-september.org comp.lang.ada:50486 Date: 2018-02-17T04:55:47-08:00 List-Id: -- code with Ada.Calendar; with Ada.Text_IO; with Ada.Numerics.Real_Arrays; use Ada.Calendar; use Ada.Text_IO; use Ada.Numerics.Real_Arrays; procedure Matrix_Mul is package F_IO is new Ada.Text_IO.Fixed_IO (Day_Duration); use F_IO; Start_Time, End_Time : Time; procedure Put (X : Real_Matrix) is begin for I in X'Range (1) loop for J in X'Range (2) loop Put (Float'Image (Float (X (I, J)))); end loop; New_Line; end loop; end Put; Matrix_A, Matrix_B, Result : Real_Matrix (1 .. 4, 1 .. 4); Elapsed_Time : Duration; Sum : Float; begin Matrix_A := ((1.0, 1.0, 1.0, 1.0), (2.0, 2.0, 2.0, 2.0), (3.0, 3.0, 3.0, 3.0), (4.0, 4.0, 4.0, 4.0)); Matrix_B := ((16.0, 15.0, 14.0, 13.0), (12.0, 11.0, 10.0, 9.0), (8.0, 7.0, 6.0, 5.0), (4.0, 3.0, 2.0, 1.0)); Start_Time := Clock; for Iteration in 1 .. 10_000_000 loop Result := Matrix_A * Matrix_B; end loop; End_Time := Clock; Elapsed_Time := End_Time - Start_Time; Put (Result); New_Line; Put ("Elapsed Time is "); Put (Elapsed_Time); New_Line; Start_Time := Clock; for Iteration in 1 .. 10_000_000 loop for I in Matrix_A'Range (1) loop for J in Matrix_A'Range (2) loop Sum := 0.0; for K in Matrix_A'Range (2) loop Sum := Sum + Matrix_A (I, K) * Matrix_B (K, J); end loop; Result (I, J) := Sum; end loop; end loop; end loop; End_Time := Clock; Elapsed_Time := End_Time - Start_Time; Put (Result); New_Line; Put ("Elapsed time is "); Put (Elapsed_Time); New_Line; end Matrix_Mul; -- end code Results: FSF GNAT 7.2.0 x64 C:\Users\Bojan\Documents>gnatmake -O3 -fopt-info -march=skylake matrix_mul.adb -largs -s gcc -c -O3 -fopt-info -march=skylake matrix_mul.adb matrix_mul.adb:56:41: note: loop turned into non-loop; it never loops. matrix_mul.adb:56:41: note: loop with 4 iterations completely unrolled matrix_mul.adb:54:38: note: loop turned into non-loop; it never loops. matrix_mul.adb:54:38: note: loop with 4 iterations completely unrolled matrix_mul.adb:53:35: note: loop turned into non-loop; it never loops. matrix_mul.adb:53:35: note: loop with 4 iterations completely unrolled matrix_mul.adb:40:15: note: basic block vectorized matrix_mul.adb:42:26: note: basic block vectorized matrix_mul.adb:18:31: note: basic block vectorized matrix_mul.adb:49:9: note: basic block vectorized C:/MSYS64/MINGW64/lib/gcc/x86_64-w64-mingw32/7.2.0/adainclude/a-tifiio.adb:706:10: note: basic block vectorized matrix_mul.adb:64:17: note: basic block vectorized matrix_mul.adb:18:31: note: basic block vectorized matrix_mul.adb:68:9: note: basic block vectorized C:/MSYS64/MINGW64/lib/gcc/x86_64-w64-mingw32/7.2.0/adainclude/a-tifiio.adb:706:10: note: basic block vectorized gnatbind -x matrix_mul.ali gnatlink matrix_mul.ali -O3 -fopt-info -march=skylake -s C:\Users\Bojan\Documents>matrix_mul 4.00000E+01 3.60000E+01 3.20000E+01 2.80000E+01 8.00000E+01 7.20000E+01 6.40000E+01 5.60000E+01 1.20000E+02 1.08000E+02 9.60000E+01 8.40000E+01 1.60000E+02 1.44000E+02 1.28000E+02 1.12000E+02 Elapsed Time is 1.338206667 4.00000E+01 3.60000E+01 3.20000E+01 2.80000E+01 8.00000E+01 7.20000E+01 6.40000E+01 5.60000E+01 1.20000E+02 1.08000E+02 9.60000E+01 8.40000E+01 1.60000E+02 1.44000E+02 1.28000E+02 1.12000E+02 Elapsed time is 0.000000445 C:\Users\Bojan\Documents>set path=C:\GNAT\2017\BIN;%path% Results GPL GNAT/2017 from AdaCore. C:\Users\Bojan\Documents>gnatmake -O3 -fopt-info -mavx2 matrix_mul.adb -largs -s gcc -c -O3 -fopt-info -mavx2 matrix_mul.adb matrix_mul.adb:56:41: note: loop turned into non-loop; it never loops. matrix_mul.adb:56:41: note: loop with 4 iterations completely unrolled matrix_mul.adb:54:38: note: loop turned into non-loop; it never loops. matrix_mul.adb:54:38: note: loop with 4 iterations completely unrolled matrix_mul.adb:53:35: note: loop turned into non-loop; it never loops. matrix_mul.adb:53:35: note: loop with 4 iterations completely unrolled matrix_mul.adb:40:15: note: basic block vectorized matrix_mul.adb:68:9: note: basic block vectorized gnatbind -x matrix_mul.ali gnatlink matrix_mul.ali -O3 -fopt-info -mavx2 -s C:\Users\Bojan\Documents>matrix_mul 4.00000E+01 3.60000E+01 3.20000E+01 2.80000E+01 8.00000E+01 7.20000E+01 6.40000E+01 5.60000E+01 1.20000E+02 1.08000E+02 9.60000E+01 8.40000E+01 1.60000E+02 1.44000E+02 1.28000E+02 1.12000E+02 Elapsed Time is 2.145337334 4.00000E+01 3.60000E+01 3.20000E+01 2.80000E+01 8.00000E+01 7.20000E+01 6.40000E+01 5.60000E+01 1.20000E+02 1.08000E+02 9.60000E+01 8.40000E+01 1.60000E+02 1.44000E+02 1.28000E+02 1.12000E+02 Elapsed time is 0.000000444 C:\Users\Bojan\Documents>gcc --version gcc (GCC) 6.3.1 20170510 (for GNAT GPL 2017 20170515) Copyright (C) 2016 Free Software Foundation, Inc. This is free software; see the source for copying conditions. See your AdaCore support agreement for details of warranty and support. If you do not have a current support agreement, then there is absolutely no warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Should I submit this as bug to AdaCore? My computer is Intel Core i3-6100U (Skylake AVX2). Please try to reproduce.