Skip to content

Commit

Permalink
sync code with internal version
Browse files Browse the repository at this point in the history
	- size reduction: compile multiple tools into one 'bart' binary
	- size reduction: do not compile with debugging by default
	- use -framework Accelerate instead of -f.. vecLib to fix
	  compilation for MacOS X Yosemite
	- Makefile: add compile-time OMP option for OpenMP

	- 'bart.m' matlab script to simplify calling of tools
	- mat2cfl: new tool to import certain matlab data files
	- nlinv: add option for real-value constrained reconstruction
	- normalize: normalize using l1 norm
	- ecalib/ecaltwo: option normalize sensitivities using l1 norm
	- (still commented out: normalize phase according to max. variance)

	- add power iteration algorithm
	- 'normalizel1' function to normalize using l1 norm
	- functions to construct matrix from non-overlapping blocks
	- add functions 'md_zarg' / 'md_zexpj'
	- fix 'md_zsadd' to take a complex scalar
	- runtime option to turn off cuda memory caching
	- MD_BIT, ..., bit fiddling macros
	- eliminate hard dependency on GSL in gridding code
	- other minor changes and enhancements
  • Loading branch information
uecker committed Jan 13, 2015
1 parent 5a85e6b commit ad38150
Show file tree
Hide file tree
Showing 89 changed files with 1,716 additions and 652 deletions.
60 changes: 43 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ CUDA=0
ACML=0
CULA=0
GSL=1
OMP=1

BUILDTYPE = Linux
UNAME = $(shell uname -s)
NNAME = $(shell uname -n)

MYLINK=ln

ifeq ($(UNAME),Darwin)
BUILDTYPE = MacOSX
ACML = 0
MYLINK = ln -s
endif

ARFLAGS = r
Expand Down Expand Up @@ -49,13 +53,12 @@ ALLDEPS = $(shell find $(srcdir) -name ".*.d")

OPT = -O3 -ffast-math
CPPFLAGS = $(DEPFLAG) -Wall -Wextra -I$(srcdir)/
CFLAGS = -g $(OPT) -std=c99 -Wmissing-prototypes -fopenmp -I$(srcdir)/
CXXFLAGS = -g $(OPT) -fopenmp -I$(srcdir)/
CFLAGS = $(OPT) -std=c99 -Wmissing-prototypes -I$(srcdir)/
CXXFLAGS = $(OPT) -I$(srcdir)/
CC = gcc
CXX = g++



#ifeq ($(BUILDTYPE), MacOSX)
# CC = gcc-mp-4.7
#endif
Expand Down Expand Up @@ -85,13 +88,18 @@ acml.top := /usr/local/acml/acml4.4.0/gfortran64_mp/

fftw.top := /usr/

# Matlab

matlab.top := /usr/local/matlab/

# ISMRM

ismrm.top := /usr/local/ismrmrd/





# Main build targets

TBASE=slice crop resize join transpose zeros ones flip circshift extract repmat bitmask
Expand All @@ -101,8 +109,9 @@ TRECO=sense pocsense rsense bpsense itsense nlinv nufft rof nusense
TCALIB=ecalib caldir walsh cc
TMRI=rss homodyne pattern poisson twixread
TSIM=phantom traj
TARGETS = $(TBASE) $(TFLP) $(TNUM) $(TRECO) $(TCALIB) $(TMRI) $(TSIM) $(TIO)

BTARGETS = $(TBASE) $(TFLP) $(TNUM)
XTARGETS = bart $(TRECO) $(TCALIB) $(TMRI) $(TSIM)
TARGETS = $(BTARGETS) $(XTARGETS)



Expand All @@ -125,14 +134,12 @@ MODULES_nufft = -lnoncart -liter -llinops
MODULES_rof = -liter -llinops
MODULES_bench = -lwavelet2 -lwavelet3 -llinops
MODULES_phantom = -lsimu
MODULES_bart += -lbox -lwavelet2 -lwavelet3 -llinops


-include Makefile.$(NNAME)
-include Makefile.local

ifeq ($(ACML),1)
TARGETS += $(TLOWRANK)
endif



Expand Down Expand Up @@ -162,7 +169,7 @@ ifeq ($(CUDA),1)
CUDA_H := -I$(cuda.top)/include
CPPFLAGS += -DUSE_CUDA $(CUDA_H)
ifeq ($(BUILDTYPE), MacOSX)
CUDA_L := -L$(cuda.top)/lib -lcufft -lcudart -lcublas -lcuda -m64
CUDA_L := -L$(cuda.top)/lib -lcufft -lcudart -lcublas -lcuda -m64 -lstdc++
else
CUDA_L := -L$(cuda.top)/lib64 -lcufft -lcudart -lcublas -lcuda -lstdc++
endif
Expand All @@ -171,7 +178,7 @@ CUDA_H :=
CUDA_L :=
endif

NVCCFLAGS = -DUSE_CUDA -Xcompiler -fPIC -Xcompiler -fopenmp -O3 -arch=sm_20 -I$(srcdir)/ -m64
NVCCFLAGS = -DUSE_CUDA -Xcompiler -fPIC -Xcompiler -fopenmp -O3 -arch=sm_20 -I$(srcdir)/ -m64 -ccbin $(CC)
#NVCCFLAGS = -Xcompiler -fPIC -Xcompiler -fopenmp -O3 -I$(srcdir)/


Expand All @@ -181,6 +188,16 @@ NVCCFLAGS = -DUSE_CUDA -Xcompiler -fPIC -Xcompiler -fopenmp -O3 -arch=sm_20 -I$(



ifeq ($(OMP),1)
CFLAGS += -fopenmp
CXXFLAGS += -fopenmp
else
CFLAGS += -Wno-unknown-pragmas
CXXFLAGS += -Wno-unknown-pragmas
endif



# cula

ifeq ($(CULA),1)
Expand Down Expand Up @@ -217,11 +234,11 @@ BLAS_L :=

ifeq ($(ACML),1)
BLAS_H := -I$(acml.top)/include
BLAS_L := $(wildcard $(acml.top)/lib/*.a) -lgfortran
BLAS_L := -L$(acml.top)/lib -lgfortran -lacml_mp -Wl,-rpath $(acml.top)/lib
CPPFLAGS += -DUSE_ACML
else
ifeq ($(BUILDTYPE), MacOSX)
BLAS_L := -lblas -framework vecLib
BLAS_L := -lblas -framework Accelerate
else
BLAS_L := -llapack -lblas
endif
Expand All @@ -238,8 +255,7 @@ FFTW_L := -L$(fftw.top)/lib -lfftw3f_threads -lfftw3f
# Matlab

MATLAB_H := -I$(matlab.top)/extern/include
MATLAB_L := -Wl,-rpath-link,$(matlab.top)/bin/glnxa64 -L$(matlab.top)/bin/glnxa64 -lmat -lmx -lm -lstdc++

MATLAB_L := -Wl,-rpath $(matlab.top)/bin/glnxa64 -L$(matlab.top)/bin/glnxa64 -lmat -lmx -lm -lstdc++

# ISMRM

Expand Down Expand Up @@ -267,16 +283,26 @@ all: $(TARGETS)



# special ismrmrd target
# special targets


bart: CPPFLAGS += -DMAIN_LIST="$(BTARGETS:%=%,) ()"


ismrmrd: $(srcdir)/ismrmrd.c -lismrm -lnum -lmisc
$(CC) $(CXXFLAGS) -o ismrmrd $+ $(CUDA_L) $(ISMRM_L) -lstdc++ -lm

mat2cfl: $(srcdir)/mat2cfl.c -lnum -lmisc
$(CC) $(CFLAGS) $(MATLAB_H) -omat2cfl $+ $(MATLAB_L) $(CUDA_L)


$(BTARGETS): bart
rm -f $@ && $(MYLINK) bart $@


.SECONDEXPANSION:
$(TARGETS): % : $(srcdir)/%.c $$(MODULES_%) $(MODULES)
$(CC) $(CPPFLAGS) $(CFLAGS) -Dmain_$@=main -o $@ $+ $(FFTW_L) $(CUDA_L) $(CULA_L) $(BLAS_L) $(GSL_L) -lm -lstdc++ -lpng
$(XTARGETS): % : $(srcdir)/%.c $$(MODULES_%) $(MODULES)
$(CC) $(CPPFLAGS) $(CFLAGS) -Dmain_$@=main -o $@ $+ $(FFTW_L) $(CUDA_L) $(CULA_L) $(BLAS_L) $(GSL_L) -lm #-lpng
# rm $(srcdir)/[email protected]


Expand Down
34 changes: 19 additions & 15 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,24 @@ install the ISMRM Raw Data format library (http://ismrmrd.sourceforge.net/).

Organization:

recon/ main directory / built software tools
recon/Makefile Makefile
recon/matlab Matlab helper scripts
recon/src/ source code
recon/src/calib source code for sensitivity calibration
recon/src/sense source code for SENSE or ESPIRiT reconstruction
recon/src/noir source code for nonlinear inversion
recon/src/sake source code for SAKE reconstruction
recon/src/wavelet2 source code for wavelets
recon/src/num base library with numerical functions
recon/src/iter iterative algorithms
recon/src/misc miscellaneous (e.g. I/O)
recon/src/ismrm support for ISMRM raw data format
recon/lib/ built software libraries
. main directory / built software tools
Makefile Makefile
matlab/ Matlab helper scripts
python/ Python helper functions
doc/ documentation
src/ source code
src/calib source code for sensitivity calibration
src/sense source code for SENSE or ESPIRiT reconstruction
src/noir source code for nonlinear inversion
src/sake source code for SAKE reconstruction
src/wavelet2 source code for wavelets
src/wavelet3 source code for new wavelets (experimental)
src/num base library with numerical functions
src/iter iterative algorithms
src/linops library of linear operators
src/misc miscellaneous (e.g. I/O)
src/ismrm support for ISMRM raw data format
lib/ built software libraries



Expand Down Expand Up @@ -175,7 +179,7 @@ dimensions run from 0 to N-1. Sometimes a set of dimensions is given
as a bitmask where the lowest bit corresponds to the 0st dimension.


For example, a Fourier transform of first three dimemensions can
For example, an inverse Fourier transform of first three dimensions can
be performed with the following command:


Expand Down
3 changes: 2 additions & 1 deletion doc/commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ ecalib [-t threshold] [-c crop_value] [-k kernel_size] [-r cal_size] [-m maps] <
-k ksize kernel size
-r cal_size Limits the size of the calibration region.
-m maps Number of maps to compute.
-1 perform only first part of the calibration
-I intensity correction
-1 perform only first part of the calibration


ecaltwo [-c crop] [-m maps] x y z <input> <sensitivities> [<ev_maps>]
Expand Down
43 changes: 43 additions & 0 deletions matlab/bart.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
% 2014 Martin Uecker <[email protected]>

function [varargout] = bart(cmd, varargin);

if isempty(getenv('TOOLBOX_PATH'))
error('Environment variable TOOLBOX_PATH is not set.');
end

if ismac==1
setenv('DYLD_LIBRARY_PATH', '');
else
setenv('LD_LIBRARY_PATH', '');
end

name = tempname;

in = cell(1, nargin - 1);

for i=1:nargin - 1,
in{i} = strcat(name, 'in', num2str(i));
writecfl(in{i}, varargin{i});
end

out = cell(1, nargout);

for i=1:nargout,
out{i} = strcat(name, 'out', num2str(i));
end

system([getenv('TOOLBOX_PATH'), '/', cmd, ' ', strjoin(in, ' '), ' ', strjoin(out, ' ')]);

for i=1:nargin - 1,
delete(strcat(in{i}, '.cfl'));
delete(strcat(in{i}, '.hdr'));
end

for i=1:nargout,
varargout{i} = readcfl(out{i});
delete(strcat(out{i}, '.cfl'));
delete(strcat(out{i}, '.hdr'));
end
end

13 changes: 13 additions & 0 deletions rules/box.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@



boxsrcs := $(BTARGETS:%=src/%.c)
boxobjs := $(boxsrcs:.c=.o)

.INTERMEDIATE: $(boxobjs)

lib/libbox.a: libbox.a($(boxobjs))
lib/libbox.a: CFLAGS += -Wno-missing-prototypes



77 changes: 77 additions & 0 deletions src/bart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* Copyright 2015. The Regents of the University of California.
* All rights reserved. Use of this source code is governed by
* a BSD-style license which can be found in the LICENSE file.
*
* Authors:
* 2014 Martin Uecker <[email protected]>
*/

#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <libgen.h>

#include "misc/misc.h"
#include "misc/cppmap.h"


#define DECLMAIN(x) \
extern int main_ ## x(int argc, char* argv[]);
MAP(DECLMAIN, MAIN_LIST)
#undef DECLMAIN

struct {

int (*main_fun)(int argc, char* argv[]);
const char* name;

} dispatch_table[] = {

#define DENTRY(x) { main_ ## x, # x },
MAP(DENTRY, MAIN_LIST)
#undef DENTRY
{ NULL, NULL }
};

static void usage(void)
{
printf("BART. Available commands are:");

for (int i = 0; NULL != dispatch_table[i].name; i++) {

if (0 == i % 6)
printf("\n");

printf("%-12s", dispatch_table[i].name);
}

printf("\n");
}

int main(int argc, char* argv[])
{
char* bn = basename(argv[0]);

if (0 == strcmp(bn, "bart")) {

if (1 == argc) {

usage();
exit(1);
}

return main(argc - 1, argv + 1);
}

for (int i = 0; NULL != dispatch_table[i].name; i++) {

if (0 == strcmp(bn, dispatch_table[i].name))
return dispatch_table[i].main_fun(argc, argv);
}

fprintf(stderr, "Unknown command.\n");
exit(1);
}


Loading

0 comments on commit ad38150

Please sign in to comment.