Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Makefile « src - github.com/moses-smt/nplm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9e8f1b707ff294073c7c566e63cba9e37d7a552d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
### Compilation options.

# C++ compiler. Tested with g++ and Intel icpc.
#CXX=/usr/bin/g++
CXX=/opt/local/bin/g++-mp-4.7
#CXX=icpc

# Compiler options. Note that -DEIGEN_NO_DEBUG is essential for good performance!
#CFLAGS=-g
CFLAGS=-O3 -DEIGEN_NO_DEBUG -DNDEBUG 

# Architecture. Set to x86_64 or i686 to override.
ARCH:=$(shell uname -m)
# Operating system. Set to override (the only option that makes any difference is Darwin).
OS:=$(shell uname -s)

# To build static binaries, uncomment the line below:
#STATIC=1

### Required libraries. You must install these prior to building.

# Set this to the root directory of Boost (should have a subdirectory named boost):

#BOOST=/usr/usc/boost/1.51.0
#BOOST=/usr
BOOST=/opt/local
# Where to find Boost header files
BOOST_INC=$(BOOST)/include

# Set this to the root directory of Eigen (should have a subdirectory named Eigen):
EIGEN=../3rdparty

### Optional libraries.

# To disable multithreading, comment out the line below:
OMP=1

# To use the MKL library, uncomment the line below and set it to the MKL root:
#MKL=/usr/usc/intel/12.1.1/mkl
# Set to 1 if you want to use the Single Dynamic Library; comment out otherwise.
# This is required for building the Python extensions, but doesn't work with building a static binary.
MKL_SINGLE=1

# For Python bindings, set the following and run 'make python/nplm.so'.
PYTHON_VERSION=2.7
#PYTHON_ROOT=/opt/local/Library/Frameworks/Python.framework/Versions/$(PYTHON_VERSION)
PYTHON_ROOT=/home/nlg-01/chiangd/pkg64/python
CYTHON=$(PYTHON_ROOT)/bin/cython

##### End of configurable options #####

# used for profiling
#USE_CHRONO=1

TCLAP=../3rdparty/tclap/include

# Currently, this is needed only if USE_CHRONO is defined:
# Where to find Boost libraries
BOOST_LIB=$(BOOST)/lib
# On some systems, a suffix is appended for the multithreaded version.
#BOOST_LIB_SUFFIX=
BOOST_LIB_SUFFIX=-mt

BOOST_CFLAGS=-I$(BOOST_INC)
BOOST_LDFLAGS=
BOOST_LDLIBS=-lboost_iostreams$(BOOST_LIB_SUFFIX) -lboost_system$(BOOST_LIB_SUFFIX) -lboost_filesystem$(BOOST_LIB_SUFFIX)
#BOOST_LDLIBS=-lboost_system$(BOOST_LIB_SUFFIX) -lboost_thread$(BOOST_LIB_SUFFIX)
ifdef USE_CHRONO
  BOOST_CFLAGS+=-DUSE_CHRONO
  BOOST_LDLIBS+=-lboost_system$(BOOST_LIB_SUFFIX) -lboost_chrono$(BOOST_LIB_SUFFIX)
endif
ifdef BOOST_LDLIBS
  BOOST_LDFLAGS+=-L$(BOOST_LIB) -Wl,-rpath -Wl,$(BOOST_LIB)
endif

ifdef OMP
  ifneq (,$(findstring g++,$(CXX)))
    OMP_CFLAGS=-fopenmp
    OMP_LDFLAGS=-fopenmp
  endif
  ifneq (,$(findstring icpc,$(CXX)))
    OMP_CFLAGS=-openmp
    OMP_LDFLAGS=-openmp
  endif
endif

ifdef MKL
  ifdef MKL_SINGLE
    ifeq ($(ARCH),x86_64)
      MKL_LDFLAGS=-L$(MKL)/lib/intel64 -Wl,-rpath -Wl,$(MKL)/lib/intel64
    endif
    ifeq ($(ARCH),i686)
      MKL_LDFLAGS=-L$(MKL)/lib/ia32 -Wl,-rpath -Wl,$(MKL)/lib/ia32
    endif
    MKL_CFLAGS=-I$(MKL)/include -DEIGEN_USE_MKL_ALL -DMKL_SINGLE
    MKL_LDLIBS=-lmkl_rt

  else

    MKL_CFLAGS=-I$(MKL)/include -DEIGEN_USE_MKL_ALL
    MKL_LDLIBS=-Wl,--start-group
    ifeq ($(ARCH),x86_64)
      MKL_LDFLAGS=-L$(MKL)/lib/intel64 -Wl,-rpath -Wl,$(MKL)/lib/intel64
      MKL_LDLIBS+=-lmkl_intel_lp64
    endif
    ifeq ($(ARCH),i686)
      MKL_LDFLAGS=-L$(MKL)/lib/ia32 -Wl,-rpath -Wl,$(MKL)/lib/ia32
      MKL_LDLIBS+=-lmkl_intel
    endif

    ifneq (,$(findstring g++,$(CXX)))
      MKL_LDLIBS+=-lmkl_gnu_thread
    endif
    ifneq (,$(findstring icpc,$(CXX)))
      MKL_LDLIBS+=-lmkl_intel_thread
    endif

    MKL_LDLIBS+=-lmkl_core -Wl,--end-group
endif
endif


ifdef STATIC
  LDFLAGS+=-static
endif

ALL_CFLAGS=$(OMP_CFLAGS) $(MKL_CFLAGS) $(BOOST_CFLAGS) -I$(TCLAP) -I$(EIGEN) $(CFLAGS)
ALL_LDFLAGS=$(OMP_LDFLAGS) $(MKL_LDFLAGS) $(BOOST_LDFLAGS) $(LDFLAGS)
ALL_LDLIBS=$(MKL_LDLIBS) $(BOOST_LDLIBS)

PYTHON_CFLAGS+=-I$(PYTHON_ROOT)/include/python$(PYTHON_VERSION)
ifeq ($(OS),Darwin)
  # avoid having to link in libpython
  PYTHON_LDFLAGS+=-undefined dynamic_lookup
endif

# Some other programs

AR=ar
RANLIB=ranlib

# Rules

BINS=trainNeuralNetwork testNeuralNetwork prepareNeuralLM testNeuralLM prepareNeuralTM
LIBS=libnplm.a libnplm.so
OBJS=util.o model.o

all: $(BINS) $(LIBS)

clean:
	rm -f *.o shared/*.o python/*.o $(BINS) $(LIBS) python/nplm.{cpp,so} python/nptm.{cpp,so}

install: all
	mkdir -p ../bin
	cp $(BINS) ../bin
	mkdir -p ../lib
	cp $(LIBS) ../lib

%.o: %.cpp
	$(CXX) -c $(ALL_CFLAGS) $< -o $@

shared/%.o: %.cpp
	$(CXX) -c -fPIC $(ALL_CFLAGS) $< -o $@

trainNeuralNetwork: trainNeuralNetwork.o $(OBJS)
	$(CXX) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@

testNeuralNetwork: testNeuralNetwork.o $(OBJS)
	$(CXX) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@

prepareNeuralLM: prepareNeuralLM.o $(OBJS)
	$(CXX) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@

testNeuralLM: testNeuralLM.o $(OBJS)
	$(CXX) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@

prepareNeuralTM: prepareNeuralTM.o $(OBJS)
	$(CXX) $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@

libnplm.a: neuralLM.o $(OBJS)
	rm -f $@
	$(AR) rv $@ $^
	$(RANLIB) $@

libnplm.so: $(addprefix shared/,neuralLM.o $(OBJS))
	$(CXX) -shared $(ALL_LDFLAGS) $^ $(ALL_LDLIBS) -o $@

%.cpp: %.pyx
	$(CYTHON) --cplus $^ -o $@

python/nplm.o: python/nplm.cpp
	$(CXX) -c -fPIC -I. $(ALL_CFLAGS) $(PYTHON_CFLAGS) $< -o $@

python/nplm.so: python/nplm.o $(addprefix shared/,neuralLM.o $(OBJS))
	$(CXX) -shared $(ALL_LDFLAGS) $(PYTHON_LDFLAGS) $^ $(ALL_LDLIBS) $(PYTHON_LDLIBS) -o $@ 

python/nptm.o: python/nptm.cpp
	$(CXX) -c -fPIC -I. $(ALL_CFLAGS) $(PYTHON_CFLAGS) $< -o $@

python/nptm.so: python/nptm.o $(addprefix shared/,neuralTM.o $(OBJS))
	$(CXX) -shared $(ALL_LDFLAGS) $(PYTHON_LDFLAGS) $^ $(ALL_LDLIBS) $(PYTHON_LDLIBS) -o $@