aboutsummaryrefslogtreecommitdiff
path: root/nerv/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'nerv/Makefile')
-rw-r--r--nerv/Makefile35
1 files changed, 25 insertions, 10 deletions
diff --git a/nerv/Makefile b/nerv/Makefile
index 06a439a..224cc8a 100644
--- a/nerv/Makefile
+++ b/nerv/Makefile
@@ -1,17 +1,32 @@
.PHONY: build install clean
SHELL := /bin/bash
+
BUILD_DIR := $(CURDIR)/build
LIB_PATH := $(LUA_BINDIR)/../lib
+INC_PATH := $(LUA_BINDIR)/../include/nerv
+LUA_DIR = $(INST_LUADIR)/nerv
OBJ_DIR := $(BUILD_DIR)/objs
-CORE_OBJS := common.o lib/io/chunk_file.o lib/matrix/mmatrix.o lib/matrix/cumatrix.o lib/matrix/cukernel.o
+ISUBDIR := io matrix luaT
+SUBDIR := matrix io layer examples nn lib/io lib/luaT lib/matrix
+
+INC_SUBDIR := $(addprefix $(INC_PATH)/,$(ISUBDIR))
+OBJ_SUBDIR := $(addprefix $(OBJ_DIR)/,$(SUBDIR))
+LUA_SUBDIR := $(addprefix $(LUA_DIR)/,$(SUBDIR))
+
+INCS := common.h matrix/matrix.h io/chunk_file.h luaT/luaT.h
+CORE_OBJS := lib/common.o lib/io/chunk_file.o \
+ lib/matrix/mmatrix.o lib/matrix/cumatrix.o lib/matrix/cukernel.o
NERV_OBJS := nerv.o \
matrix/mmatrix.o matrix/cumatrix.o matrix/init.o \
io/init.o io/chunk_file.o \
examples/oop_example.o
LUAT_OBJS := lib/luaT/luaT.o
+
+INCS := $(addprefix $(INC_PATH)/,$(INCS))
CORE_OBJS := $(addprefix $(OBJ_DIR)/,$(CORE_OBJS))
NERV_OBJS := $(addprefix $(OBJ_DIR)/,$(NERV_OBJS))
LUAT_OBJS := $(addprefix $(OBJ_DIR)/,$(LUAT_OBJS))
+
OBJS := $(CORE_OBJS) $(NERV_OBJS) $(LUAT_OBJS)
LIBS := $(INST_LIBDIR)/libnerv.so $(LIB_PATH)/libnervcore.so $(LIB_PATH)/libluaT.so
LUA_LIBS := matrix/init.lua io/init.lua init.lua \
@@ -19,25 +34,23 @@ LUA_LIBS := matrix/init.lua io/init.lua init.lua \
layer/window.lua layer/bias.lua layer/combiner.lua layer/mse.lua \
nn/init.lua nn/layer_repo.lua nn/param_repo.lua nn/layer_dag.lua \
io/sgd_buffer.lua
+
INCLUDE := -I $(LUA_INCDIR) -DLUA_USE_APICHECK
#CUDA_BASE := /usr/local/cuda-6.5
CUDA_BASE := /usr/local/cuda-5.0
CUDA_INCLUDE := -I $(CUDA_BASE)/include/
INCLUDE += $(CUDA_INCLUDE)
-LDFLAGS := -L$(CUDA_BASE)/lib64/ -Wl,-rpath=$(CUDA_BASE)/lib64/ -lcudart -lcublas
+
+LDFLAGS := -L$(CUDA_BASE)/lib64/ -Wl,-rpath=$(CUDA_BASE)/lib64/ -lcudart -lcublas
CFLAGS := -Wall -Wextra -O2
-SUBDIR := matrix io layer examples nn lib/io lib/luaT lib/matrix
NVCC := $(CUDA_BASE)/bin/nvcc
NVCC_FLAGS := -Xcompiler -fPIC,-Wall,-Wextra
-LUA_DIR = $(INST_LUADIR)/nerv
-OBJ_SUBDIR := $(addprefix $(OBJ_DIR)/,$(SUBDIR))
-LUA_SUBDIR := $(addprefix $(LUA_DIR)/,$(SUBDIR))
LUA_LIBS := $(addprefix $(LUA_DIR)/,$(LUA_LIBS))
build: $(OBJ_DIR) $(OBJ_SUBDIR) $(OBJS)
-$(OBJ_DIR) $(LUA_DIR) $(OBJ_SUBDIR) $(LUA_SUBDIR):
+$(OBJ_DIR) $(LUA_DIR) $(OBJ_SUBDIR) $(LUA_SUBDIR) $(INC_SUBDIR):
-mkdir -p $@
$(OBJ_DIR)/%.o: %.c $(patsubst /%.o,/%.c,$@)
gcc -c -o $@ $< $(INCLUDE) -fPIC $(CFLAGS)
@@ -45,8 +58,7 @@ $(OBJ_DIR)/lib/matrix/cukernel.o: lib/matrix/cukernel.cu
$(NVCC) -c -o $@ $< $(INCLUDE) $(NVCC_FLAGS)
$(LUA_DIR)/%.lua: %.lua
cp $< $@
-#$(OBJ_DIR)/luaT.o:
-# gcc -c -o $@ luaT/luaT.c $(INCLUDE) -fPIC
+
$(LIB_PATH)/libnervcore.so: $(CORE_OBJS)
gcc -shared -o $@ $^ $(LDFLAGS)
$(LIB_PATH)/libluaT.so: $(LUAT_OBJS)
@@ -64,4 +76,7 @@ $(OBJ_DIR)/lib/matrix/cukernel.o: lib/matrix/generic/cukernel.cu
clean:
-rm -rf $(OBJ_DIR)
-install: $(LIBS) $(LUA_DIR) $(LUA_SUBDIR) $(LUA_LIBS)
+install: $(LIBS) $(LUA_DIR) $(LUA_SUBDIR) $(LUA_LIBS) $(INC_SUBDIR) $(INCS)
+
+$(INC_PATH)/%.h: lib/%.h
+ cp $< $@