From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 2EB883857829 for ; Thu, 18 Mar 2021 12:35:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2EB883857829 Received: by mail-ej1-x62e.google.com with SMTP id jy13so3665909ejc.2 for ; Thu, 18 Mar 2021 05:35:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=KTY9HQbRFEq4wEXkBmBmtigxIzCZD8vc5YUDgLdDffE=; b=BLY+3YrA/IcPN+/fu1H24cjIvtTXDft+6ZKITw1XH8ps4YxC1ayb/iYhe9UY0XqwmP Opb3PIy6C2dvaoXa1PveuQw8KcQbILZWNLD+JF9JDdlABWSvqXWO7MrrDZcSwuggQYfP xafj7bUhDI+FyzMS8LdUDEbgpFf2KC/jfRNfAxhl993nLzgwbNVUm6Av+0fi/+pGE7J8 4lRlb3uaEOUIh9WUtzupGZZHvaYTN7pT/1GSsKI5Qv0sn8oIQlRTfquMyyPhDK9e8XOf LR913+cFzZ1DKQgBSX9X9kBpwrIvje2XeIWP0l3oBgHm5ZQALsbPGms+zERfbf1JgJtb oeCw== X-Gm-Message-State: AOAM530YP4WuOEv1sAR1hG5/e5aLvBBoRrfWp56ruOGsiA/QNFfUx7l8 csjxiQHawW+kLWTqU2hBqJeFKFh0HWPPK3yKhxSx1m6V X-Google-Smtp-Source: ABdhPJzATDaTcv3k7ZsEVJIWBkCknOOkH18gkp1dka79Q7DPuvIL8Yn5EvAj6S8FE8KTmqGZoSe+9b2hHU7L8mZ79Gg= X-Received: by 2002:a17:906:bd2:: with SMTP id y18mr41048273ejg.482.1616070948954; Thu, 18 Mar 2021 05:35:48 -0700 (PDT) MIME-Version: 1.0 References: <20210318074849.GA22541@troutmask.apl.washington.edu> In-Reply-To: <20210318074849.GA22541@troutmask.apl.washington.edu> From: Richard Biener Date: Thu, 18 Mar 2021 13:35:38 +0100 Message-ID: Subject: Re: MATMUL broken with frontend optimization. To: Steve Kargl Cc: "fortran@gcc.gnu.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2021 12:35:51 -0000 On Thu, Mar 18, 2021 at 8:49 AM Steve Kargl via Fortran wrote: > > It seems that gfortran will inline MATMUL with optimization. > This produce very poor performance. In fact, gfortran will > inline MATMUL even if one specifies -fexternal-blas. This is > very bad. > > % cat a.f90 > program main > > implicit none > > integer, parameter :: imax =3D 20000, jmax =3D 10000 > real, allocatable :: inVect(:), matrix(:,:), outVect(:) > real :: start, finish > > allocate(invect(imax), matrix(imax,jmax), outvect(jmax)) > > call random_number(inVect) > call random_number(matrix) > > call cpu_time(start) > outVect =3D matmul(inVect, matrix) > call cpu_time(finish) > > print '("Time =3D ",f10.7," seconds. =E2=80=93 First Value =3D ",f10.4= )',finish-start,outVect(1) > end program main > > % gfcx -o z -O0 a.f90 && ./z > Time =3D 0.2234111 seconds. =E2=80=93 First Value =3D 4982.6362 > % nm z | grep matmul > U _gfortran_matmul_r4@@GFORTRAN_8 > % gfcx -o z -O1 a.f90 && ./z > Time =3D 0.3295890 seconds. =E2=80=93 First Value =3D 4971.0962 > % nm z | grep matmul > % gfcx -o z -O2 a.f90 && ./z > Time =3D 0.3299561 seconds. =E2=80=93 First Value =3D 5025.4902 > % nm z | grep matmul > % gfcx -o z -O2 -fexternal-blas a.f90 && ./z > Time =3D 0.3295580 seconds. =E2=80=93 First Value =3D 5022.8291 > > This last one is definitely broken. I did not link with > an external BLAS library. Please fix before 11.1 is > released. Since the libgfortran MATMUL should be vectorized I think it's not reasonable to inline any but _very_ small MATMUL at optimization levels that do not enable vectorization. Richard. > > -- > Steve