bart icon indicating copy to clipboard operation
bart copied to clipboard

MacOS M1 ARM run errors

Open emilljungberg opened this issue 3 years ago • 2 comments

Hi, I've been trying to get BART working on my Macbook pro with the Apple M1 Pro chip (see thread on mailing list).

The summary is that I can get it to compile fine but some of the tests fail, and unsurprisingly some commands returns images with NaN. Summary below of the steps I've taken to compile and the results from the tests

Compile

Changed the following lines in the Makefile to make it compile. (Note that I'm using homebrew instead of macports for the dependencies and thus the different paths for the libraries

Line 25:  OMP ?=0
Line 59:  MACPORTS ?= 0
Line 118: CC?= gcc
Line 137: BLAS_BASE ?= /opt/homebrew/opt/openblas/
Line 157: FFTW_BASE ?= /opt/homebrew/

I'm running Mac OS 12.1 with the following gcc configuration

$ gcc -v
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

The compilation step goes through without errors but throws a few warnings including:

/Users/emil/Code/bart-0.7.00/src/misc/misc.c:593:17: warning: unknown attribute 'optimize' ignored [-Wunknown-attributes]
 __attribute__((optimize("-fno-finite-math-only")))
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/emil/Code/bart-0.7.00/src/misc/misc.c:599:16: warning: unknown attribute 'optimize' ignored [-Wunknown-attributes]
__attribute__((optimize("-fno-finite-math-only")))

Tests

When I run make test it goes through most of the tests it seems but stops on the following

...
set -e; mkdir /Users/emil/Code/bart-0.7.00/tests/tmp/$$/ ; cd /Users/emil/Code/bart-0.7.00/tests/tmp/$$/				;\
	/Users/emil/Code/bart-0.7.00/traj -r -x256 -y128 t.ra								;\
	/Users/emil/Code/bart-0.7.00/scale 0.5 t.ra t2.ra									;\
	/Users/emil/Code/bart-0.7.00/nufft t2.ra /Users/emil/Code/bart-0.7.00/tests/out//phantom-exp.ra xek.ra				;\
	/Users/emil/Code/bart-0.7.00/reshape 96 32 1 xek.ra xek2.ra							;\
	/Users/emil/Code/bart-0.7.00/ones 2 128 128 o.ra									;\
	/Users/emil/Code/bart-0.7.00/delta 8 33 8 p.ra									;\
	/Users/emil/Code/bart-0.7.00/repmat 1 16 p.ra p2.ra								;\
	/Users/emil/Code/bart-0.7.00/repmat 6 4 p2.ra p3.ra								;\
	/Users/emil/Code/bart-0.7.00/reshape 7 1 1 128 p3.ra p4.ra							;\
	/Users/emil/Code/bart-0.7.00/reshape 96 32 1 p4.ra p5.ra								;\
	/Users/emil/Code/bart-0.7.00/fmac xek2.ra p5.ra xek3.ra								;\
	/Users/emil/Code/bart-0.7.00/repmat 1 256 p5.ra p6.ra								;\
	/Users/emil/Code/bart-0.7.00/pics -S -RT:7:0:0.02 -i100 -e -w1. -B/Users/emil/Code/bart-0.7.00/tests/out//expon-basis.ra -pp6.ra -t t2.ra xek3.ra o.ra x2.ra	;\
	/Users/emil/Code/bart-0.7.00/fmac -s 64 x2.ra /Users/emil/Code/bart-0.7.00/tests/out//expon-basis.ra xx.ra			;\
	/Users/emil/Code/bart-0.7.00/transpose 5 6 xx.ra xxT.ra								;\
	/Users/emil/Code/bart-0.7.00/scale 4. xxT.ra xxS.ra								;\
	/Users/emil/Code/bart-0.7.00/nrmse -t 0.05 /Users/emil/Code/bart-0.7.00/tests/out//phantom-exp.ra xxS.ra			;\
	rm *.ra ; cd .. ; rmdir /Users/emil/Code/bart-0.7.00/tests/tmp/$$/
Done.
Basis: [128 128   1   1   1  32   4   1   1   1   1   1   1   1   1   1 ]
Max:   [128 128   1   1   1   1   4   1   1   1   1   1   1   1   1   1 ]
[  1 256 128   1   1  32   4   1   1   1   1   1   1   1   1   1 ]
[128 128   1   1   1   1   4   1   1   1   1   1   1   1   1   1 ]
Maximum eigenvalue: 1.24e+02
TV regularization: 0.020000
ADMM
Total Time: 1.894010
0.378205
make[1]: *** [tests/test-pics-linsub-noncart] Error 1
make: *** [test] Error 2

When I run make utest it seems to pass all the tests up until

...
./test_ode_bloch
ERROR:     ./test_ode_bloch:  5/ 6 passed.
make[1]: *** [utests-all] Error 1
make: *** [utest] Error 2

Example

This is a brief example of code when it fails

bart phantom -x256 -s8 -k shepp
bart fft -i -u 3 shepp shepp_fft
bart rss 8 shepp_fft shepp_fft_rss
bart ecalib -m1 shepp sens
bart pics -S -l2 -r0.005 -i 50 shepp sens shepp_l2
Done.
Size: 65536 Samples: 65536 Acc: 1.00
l2 regularization: 0.005000
conjugate gradients
WARN: Warning: data corrupted
Total Time: 0.042768

pics fails here and the image is all NaN. When I look at the data it seems like the imaginary part of the sheep_fft_rss is NaN for some voxels.

This is the coil images for shepp_fft, real on top and imaginary below. Looks okay image

The output from rss, i.e., shepp_fft_rss is more confusing though image

Not sure what to conclude from this, but maybe there is some numerical issue? Let me know if there are any other tests I can run to figure out what causes these errors.

emilljungberg avatar Jan 26 '22 07:01 emilljungberg

Can you try the latest version on the master branch?

uecker avatar Jan 26 '22 07:01 uecker

Latest version on master branch compiles fine. Output of tests

make utest
...
ALL CPU UNIT TESTS PASSED.
make test
...
set -e; mkdir /Users/emil/Code/bart_master/tests/tmp/$$/ ; cd /Users/emil/Code/bart_master/tests/tmp/$$/	;\
	/Users/emil/Code/bart_master/cc -G -p 4 /Users/emil/Code/bart_master/tests/out//shepplogan_coil_ksp.ra ksp-cc4.ra		;\
	/Users/emil/Code/bart_master/rss 11 ksp-cc4.ra ksp0-cc4.ra					;\
	/Users/emil/Code/bart_master/rss 11 /Users/emil/Code/bart_master/tests/out//shepplogan_coil_ksp.ra ksp0.ra			;\
	/Users/emil/Code/bart_master/nrmse -t 0.0001 ksp0.ra ksp0-cc4.ra					;\
	rm *.ra ; cd .. ; rmdir /Users/emil/Code/bart_master/tests/tmp/$$/
Done.
nan
make[1]: *** [tests/test-cc-geom] Error 1
make: *** [test] Error 2

When I run the same test recons as above, it seems produce valid images (for these examples at least). The pics image was all NaN before, now it works and it doesn't throw any errors/warnings during the pics command either. image

emilljungberg avatar Jan 26 '22 08:01 emilljungberg

Hi, I am working to install BART on Mac M1 and I am at the same stage you were last year. Have you been able to use BART since then on your Mac?

jtamir avatar Jan 31 '23 05:01 jtamir

Yes it has been working fine. I haven't been using the RSS command much for anything but recon with pics and espirit etc works just fine.

emilljungberg avatar Jan 31 '23 08:01 emilljungberg

All issues with M1 should be fixed with recent commit from github.

uecker avatar Mar 19 '23 19:03 uecker