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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:aed:2822:: with SMTP id r31mr9459284qtd.87.1585738908216; Wed, 01 Apr 2020 04:01:48 -0700 (PDT) X-Received: by 2002:a4a:e047:: with SMTP id v7mr16230954oos.49.1585738907740; Wed, 01 Apr 2020 04:01:47 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 1 Apr 2020 04:01:47 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=2001:1c00:c1d:4b00:b997:f7a4:d434:f994; posting-account=-iT6ZQoAAAAlqBCInAc-vB6x1soT8Jhq NNTP-Posting-Host: 2001:1c00:c1d:4b00:b997:f7a4:d434:f994 References: <6c2c0e35-af07-4169-8be5-464ec7fd0fd5@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: GNAT vs Matlab - operation on multidimensional complex matrices From: darek Injection-Date: Wed, 01 Apr 2020 11:01:48 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:58265 Date: 2020-04-01T04:01:47-07:00 List-Id: Thanks for all your posts. At this moment I use the access types to avoid a= n overhead associated with allocation, and initialization of these arrays (= I know that the overhead is small but later on when I move from 4 to 16 rea= l channels every millisecond counts :)). This is a MIMO system so the numbe= r of virtual channels depends on the number of Tx's and Rx's. Now, the dat= a is streamed from the device at 62Mbs (4 x Tx, 4 x Rx =3D> 16 virtual cha= nnels) but in the future the data will arrive at ~ 250Mbs (4 x Tx, 16 x Rx = =3D> 64 virtual channels). For each virtual channel you need to compute 2D= complex FFT (so-called range-Doppler surface), and then combine them (digi= tal beamforming). Lots of number crunching here, and lots of fun ... =20 I will try to decompose the processing chain to handle even and odd channel= s separately, and try to run the computations in parallel on different CPUs= (I never use these capabilities, so I am expecting some issues there).=20 Regards, Darek On Tuesday, 31 March 2020 19:25:22 UTC+2, Shark8 wrote: > On Monday, March 23, 2020 at 5:16:20 PM UTC-6, darek wrote: > > Hi Everyone,=20 > > I am working on radar signal processing algorithms that use multidimen= sional complex arrays.=20 >=20 > Ok then; the following should have convention Fortran IIRC: >=20 > type tCubeReal is array (1..NumChannels, 1..NumAngles, 1..NumRanges) of m= Real > with Convention =3D> Fortran; >=20 > That doesn't matter much, for a speed-test, but given that you mention RA= DAR data it's probably best to mention it now, before you frustrate yoursel= f by accidentally mixing up column- and row-major formats. >=20 > >=20 > > To my surprise, the performance of some Matlab functions is much better= than compiled Ada code.=20 > >=20 > > procedure SpeedSumRealCube (NumIteration : Integer; Mtx : in tCubeR= eal; S: out mReal) is >=20 > Don't read from S, it's an OUT parameter, and it's best to treat it that = way. > (I'm not sure that it would get in the way of optimization, but could.) >=20 > > for k in 1..NumIteration loop > > for m in Mtx'Range(1) loop > > for n in Mtx'Range(2) loop > > for p in Mtx'Range(3) loop > > S :=3D S + Mtx(m, n, p); > > end loop; > > end loop; > > end loop; > > end loop; >=20 > The above could be replaced, in Ada2012 with: >=20 > Function Summation( Input : in tCubeReal ) return Complex is > Begin > Return Result : Complex :=3D (0.0 + i*0.0) do > For Element of Input loop > Result:=3D Result + Element; > End loop; > End return; > End Summation; >=20 > If you turn it into a generic, you could use it for both Complex and mRea= l; plus it more accurately mirrors your Matlab code. > ------------------------------------------------------------------------- >=20 > Is there a reason for the access-types? > If not, I would recommend getting rid of them. >=20 >=20 > > > > 1. Compiled with: gcc version 9.2.0 (tdm64-1) ( and gnat community edi= tion 2019), with the -O2 optimisation level.=20 > > 2. CPU: AMD64 Family 23 Model 24 Stepping 1 CPU0 2300 A= MD Ryzen 7 3750H with Radeon Vega Mobile Gfx > > 3. Win10 64bit=20 > >=20 > >=20 > > The results of the program execution: > >=20 > > Computation time: 0.616710300 > > Computation time per iteration: 6.16710300000000E-04 > > Sum is: 7.68000000000000E+08 > > Complex cube > > Complex type size is: 128 > >=20 > > Computation time: 3.707091000 > > Computation time per iteration: 3.70709100000000E-03 > > Sum is:( 7.68000000000000E+08, 7.68000000000000E+08) > >=20 > >=20 > > The executable produced by the gcc provide with the gnat community edit= ion gave very similar results. > >=20 > > More interesting part - the Matlab code. > > The results of the program execution: > >=20 > > TExe:0.260718, sum real=3D768000000.000000 > > TExe:0.789778, sum complex=3D <768000000.000000,768000000.000000>=20 > > Complex operations are 3.029242 times slower > >=20 > >=20 > > What is wrong with my code? Is it the Ada compiler doing bad job here? > > It seems that Matlab is performing really well here ... >=20 > IIRC Matlab has a *LOT* of optimization for Complex numbers/operations, b= ut you're right in that these are surprising.