summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2015-06-25 12:58:42 +0800
committerDeterminant <[email protected]>2015-06-25 12:58:42 +0800
commit8b2aa75b9d7c0b4d4333e7847e3ad90c5fcf97fb (patch)
tree7a7ac0325bb15597fb473e7b3bcf1a54e4e5bd16
parent5e407d74130accfbbf94d2cabcb03fc126a89410 (diff)
use the standard nerv error reporting in io lib
-rw-r--r--Makefile3
-rw-r--r--nerv/Makefile35
-rw-r--r--nerv/examples/oop_example.c2
-rw-r--r--nerv/examples/swb_baseline.lua2
-rw-r--r--nerv/io/chunk_file.c19
-rw-r--r--nerv/io/init.c2
-rw-r--r--nerv/lib/common.c (renamed from nerv/common.c)7
-rw-r--r--nerv/lib/common.h (renamed from nerv/common.h)26
-rw-r--r--nerv/lib/io/chunk_file.c116
-rw-r--r--nerv/lib/io/chunk_file.h32
-rw-r--r--nerv/lib/matrix/cumatrix.c2
-rw-r--r--nerv/lib/matrix/generic/cumatrix.c76
-rw-r--r--nerv/lib/matrix/generic/cumatrix.h2
-rw-r--r--nerv/lib/matrix/generic/matrix.c8
-rw-r--r--nerv/lib/matrix/generic/mmatrix.c14
-rw-r--r--nerv/lib/matrix/generic/mmatrix.h3
-rw-r--r--nerv/lib/matrix/mmatrix.c4
-rw-r--r--nerv/matrix/cumatrix.c2
-rw-r--r--nerv/matrix/generic/cumatrix.c4
-rw-r--r--nerv/matrix/generic/matrix.c2
-rw-r--r--nerv/matrix/generic/mmatrix.c4
-rw-r--r--nerv/matrix/init.c2
-rw-r--r--nerv/matrix/mmatrix.c2
-rw-r--r--nerv/nerv.c2
m---------speech0
25 files changed, 189 insertions, 182 deletions
diff --git a/Makefile b/Makefile
index 04a9cf4..bfcd56f 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,5 @@ luarocks:
PREFIX=$(PREFIX) ./tools/build_luarocks.sh
install:
cd nerv; $(PREFIX)/bin/luarocks make
- ln -sfv $(PREFIX)/lib/lua/5.1/libnerv.so $(PREFIX)/lib/ # FIXME: bad trick
speech:
- cd speech; $(PREFIX)/bin/luarocks make
+ cd speech/htk_io; $(PREFIX)/bin/luarocks make
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 $< $@
diff --git a/nerv/examples/oop_example.c b/nerv/examples/oop_example.c
index 59dfc5a..e46cf96 100644
--- a/nerv/examples/oop_example.c
+++ b/nerv/examples/oop_example.c
@@ -1,7 +1,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
-#include "../common.h"
+#include "../lib/common.h"
#define SQR(x) ((x) * (x))
diff --git a/nerv/examples/swb_baseline.lua b/nerv/examples/swb_baseline.lua
index 8b7e01a..7b60d53 100644
--- a/nerv/examples/swb_baseline.lua
+++ b/nerv/examples/swb_baseline.lua
@@ -1,4 +1,4 @@
-require 'speech.init'
+require 'htk_io'
gconf = {lrate = 0.8, wcost = 1e-6, momentum = 0.9,
cumat_type = nerv.CuMatrixFloat,
mmat_type = nerv.MMatrixFloat,
diff --git a/nerv/io/chunk_file.c b/nerv/io/chunk_file.c
index e275d9b..8ff9daa 100644
--- a/nerv/io/chunk_file.c
+++ b/nerv/io/chunk_file.c
@@ -1,7 +1,7 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
-#include "../common.h"
+#include "../lib/common.h"
#include "chunk_file.h"
#define INVALID_FORMAT_ERROR(fn) \
@@ -17,15 +17,12 @@ const char *nerv_chunk_info_tname = "nerv.ChunkInfo";
const char *nerv_chunk_data_tname = "nerv.ChunkData";
int nerv_lua_chunk_file_new(lua_State *L) {
- int status;
+ Status status;
const char *fn = luaL_checkstring(L, 1);
ChunkFile *cfp = nerv_chunk_file_create(fn,
luaL_checkstring(L, 2),
&status);
- if (status != CF_NORMAL)
- {
- nerv_error(L, "%s: %s", fn, nerv_chunk_file_errstr(status));
- }
+ NERV_LUA_CHECK_STATUS(L, status);
lua_newtable(L);
luaT_pushudata(L, cfp, nerv_chunk_file_handle_tname);
lua_setfield(L, -2, "handle");
@@ -77,7 +74,7 @@ static void writer(void *L) {
}
int nerv_lua_chunk_file_write_chunkdata(lua_State *L) {
- int status;
+ Status status;
ChunkFile *cfp = luaT_checkudata(L, 1, nerv_chunk_file_handle_tname);
const char *mdstr = lua_tolstring(L, 2, NULL);
lua_getfield(L, 3, "write");
@@ -85,17 +82,17 @@ int nerv_lua_chunk_file_write_chunkdata(lua_State *L) {
nerv_error(L, "\"write\" method must be implemented");
lua_pushvalue(L, 3); /* lua writer itself */
lua_pushvalue(L, 1); /* pass handle as parameter to write() */
- nerv_chunk_file_write_chunkdata(cfp, mdstr, writer, (void *)L);
+ nerv_chunk_file_write_chunkdata(cfp, mdstr, writer, (void *)L, &status);
+ NERV_LUA_CHECK_STATUS(L, status);
return 0;
}
int nerv_lua_chunk_file_get_chunkdata(lua_State *L) {
- int status;
+ Status status;
ChunkFile *cfp = luaT_checkudata(L, 1, nerv_chunk_file_handle_tname);
ChunkInfo *cip = luaT_checkudata(L, 2, nerv_chunk_info_tname);
ChunkData *cdp = nerv_chunk_file_get_chunkdata(cfp, cip, &status);
- if (status != CF_NORMAL)
- nerv_error(L, "%s", nerv_chunk_file_errstr(status));
+ NERV_LUA_CHECK_STATUS(L, status);
luaT_pushudata(L, cdp, nerv_chunk_data_tname);
return 1;
}
diff --git a/nerv/io/init.c b/nerv/io/init.c
index 70585f7..f3f86e3 100644
--- a/nerv/io/init.c
+++ b/nerv/io/init.c
@@ -1,4 +1,4 @@
-#include "../common.h"
+#include "../lib/common.h"
extern void nerv_chunk_file_init(lua_State *L);
void nerv_io_init(lua_State *L) {
diff --git a/nerv/common.c b/nerv/lib/common.c
index 0584438..db667b2 100644
--- a/nerv/common.c
+++ b/nerv/lib/common.c
@@ -28,6 +28,13 @@ int nerv_error_status(lua_State *L, Status *status) {
case MAT_INVALID_IDX: mmesg = "invalid index"; break;
case MAT_CUDA_ERR: mmesg = "cuda error"; break;
case MAT_CUBLAS_ERR: mmesg = "cublas error"; break;
+ case CF_INVALID_FORMAT: mmesg = "invalid format"; break;
+ case CF_END_OF_FILE: mmesg = "unexpected end of file"; break;
+ case CF_SECTION_OVERFLOW: mmesg = "section overflow"; break;
+ case CF_WRITE_ERROR: mmesg = "error while writing"; break;
+ case CF_ERR_OPEN_FILE: mmesg = "error while opening file"; break;
+ case CF_INVALID_OP: mmesg = "invalid operation"; break;
+ default: mmesg = "unknown"; break;
}
if (status->msg)
nerv_error(L, "%s: %s @%s:%d", mmesg, status->msg,
diff --git a/nerv/common.h b/nerv/lib/common.h
index 413ca51..1c588d1 100644
--- a/nerv/common.h
+++ b/nerv/lib/common.h
@@ -3,12 +3,13 @@
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
-#include "lib/luaT/luaT.h"
+#include "luaT/luaT.h"
#include <stdio.h>
#include <stdlib.h>
-enum {
- MAT_NORMAL,
+typedef enum ErrCode {
+ NERV_NORMAL,
+ /* matrix err */
MAT_GENERAL_ERR,
MAT_INSUF_MEM,
MAT_INVALID_FORMAT,
@@ -21,11 +22,18 @@ enum {
MAT_IDX_VECTOR_EXP,
MAT_INVALID_IDX,
MAT_CUDA_ERR,
- MAT_CUBLAS_ERR
-};
+ MAT_CUBLAS_ERR,
+ /* chunk file err */
+ CF_INVALID_FORMAT,
+ CF_END_OF_FILE,
+ CF_SECTION_OVERFLOW,
+ CF_WRITE_ERROR,
+ CF_ERR_OPEN_FILE,
+ CF_INVALID_OP,
+} ErrCode;
typedef struct Status {
- int err_code;
+ ErrCode err_code;
const char *file;
int lineno;
const char *msg;
@@ -33,8 +41,8 @@ typedef struct Status {
#define NERV_SET_STATUS(status, code, m) \
do { \
- (status)->err_code = code; \
- (status)->msg = m; \
+ (status)->err_code = (code); \
+ (status)->msg = (m); \
(status)->file = __FILE__; \
(status)->lineno = __LINE__; \
} while (0)
@@ -47,7 +55,7 @@ typedef struct Status {
#define NERV_LUA_CHECK_STATUS(L, status) \
do { \
- if (status.err_code != MAT_NORMAL) \
+ if (status.err_code != NERV_NORMAL) \
nerv_error_status(L, &status); \
} while (0)
diff --git a/nerv/lib/io/chunk_file.c b/nerv/lib/io/chunk_file.c
index e70ffc9..4e00b0b 100644
--- a/nerv/lib/io/chunk_file.c
+++ b/nerv/lib/io/chunk_file.c
@@ -1,23 +1,25 @@
-#include "../../common.h"
+#include "../common.h"
#include "chunk_file.h"
#include <stdlib.h>
#include <string.h>
#define PARAM_HEADER_SIZE 16
-static size_t read_chunk_header_plain(FILE *fp, int *status) {
+static size_t read_chunk_header_plain(FILE *fp, Status *status) {
static char buff[PARAM_HEADER_SIZE];
int i;
size_t size = 0;
if (fread(buff, 1, PARAM_HEADER_SIZE, fp) != PARAM_HEADER_SIZE)
{
- if (feof(fp)) *status = CF_END_OF_FILE;
+ if (feof(fp))
+ NERV_SET_STATUS(status, CF_END_OF_FILE, 0);
else
{
- *status = CF_INVALID_FORMAT;
+ NERV_SET_STATUS(status, CF_INVALID_FORMAT, 0);
return 0;
}
}
- else *status = CF_NORMAL;
+ else
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
for (i = 0; i < PARAM_HEADER_SIZE; i++)
if (isdigit(buff[i]))
size = size * 10 + buff[i] - '0';
@@ -25,25 +27,19 @@ static size_t read_chunk_header_plain(FILE *fp, int *status) {
return size;
}
-static void write_chunk_header_plain(FILE *fp, size_t size, int *status) {
+static void write_chunk_header_plain(FILE *fp, size_t size, Status *status) {
static char buff[PARAM_HEADER_SIZE];
int i;
for (i = PARAM_HEADER_SIZE - 3; i > 0; i--, size /= 10)
buff[i] = size % 10 + '0';
if (size)
- {
- *status = CF_SECTION_OVERFLOW;
- return;
- }
+ NERV_EXIT_STATUS(status, CF_SECTION_OVERFLOW, 0);
buff[0] = '[';
buff[PARAM_HEADER_SIZE - 2] = ']';
buff[PARAM_HEADER_SIZE - 1] = '\n';
if (fwrite(buff, 1, PARAM_HEADER_SIZE, fp) != PARAM_HEADER_SIZE)
- {
- *status = CF_WRITE_ERROR;
- return;
- }
- *status = CF_NORMAL;
+ NERV_EXIT_STATUS(status, CF_WRITE_ERROR, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
static ChunkData *get_chunk_data(FILE *fp, ChunkInfo *info) {
@@ -56,48 +52,47 @@ static ChunkData *get_chunk_data(FILE *fp, ChunkInfo *info) {
return cdp;
}
-static const char *read_chunk_metadata(FILE *fp, const char *fn, int *status) {
+static const char *read_chunk_metadata(FILE *fp, const char *fn,
+ Status *status) {
#define LINEBUFF_SIZE 1024
#define LUA_RETURN "return "
#define LUA_RETURN_LEN (sizeof(LUA_RETURN) - 1)
static char buff[LUA_RETURN_LEN + LINEBUFF_SIZE] = LUA_RETURN;
- *status = fgets(buff + LUA_RETURN_LEN,
- LINEBUFF_SIZE, fp) == (buff + LUA_RETURN_LEN) ? \
- CF_NORMAL : CF_INVALID_FORMAT;
+ NERV_SET_STATUS(status, (fgets(buff + LUA_RETURN_LEN,
+ LINEBUFF_SIZE, fp) == (buff + LUA_RETURN_LEN) ? \
+ NERV_NORMAL : CF_INVALID_FORMAT), 0);
fprintf(stderr, "metadata: %s\n", buff);
return buff;
}
-static void write_chunk_metadata(FILE *fp, const char *mdstr, int *status) {
+static void write_chunk_metadata(FILE *fp, const char *mdstr,
+ Status *status) {
size_t size = strlen(mdstr);
if (fwrite(mdstr, 1, size, fp) != size ||
fprintf(fp, "\n") < 0)
- {
- *status = CF_WRITE_ERROR;
- return;
- }
+ NERV_EXIT_STATUS(status, CF_WRITE_ERROR, 0);
/* fprintf(stderr, "metadata: %s\n", metadata_str); */
- *status = CF_NORMAL;
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
-static ChunkFile *open_write(const char *fn, int *status) {
+static ChunkFile *open_write(const char *fn, Status *status) {
ChunkFile *cfp;
FILE *fp = fopen(fn, "w");
if (!fp)
{
- *status = CF_ERR_OPEN_FILE;
+ NERV_SET_STATUS(status, CF_ERR_OPEN_FILE, 0);
return NULL;
}
cfp = (ChunkFile *)malloc(sizeof(ChunkFile));
cfp->fp = fp;
cfp->info = NULL;
cfp->status = CF_WRITE;
- *status = CF_NORMAL;
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return cfp;
}
-static ChunkFile *open_read(const char *fn, int *status) {
+static ChunkFile *open_read(const char *fn, Status *status) {
size_t chunk_len;
off_t offset;
int i;
@@ -108,7 +103,7 @@ static ChunkFile *open_read(const char *fn, int *status) {
if (!fp)
{
- *status = CF_ERR_OPEN_FILE;
+ NERV_SET_STATUS(status, CF_ERR_OPEN_FILE, 0);
return NULL;
}
cfp = (ChunkFile *)malloc(sizeof(ChunkFile));
@@ -121,18 +116,18 @@ static ChunkFile *open_read(const char *fn, int *status) {
/* skip to the begining of chunk i */
if (fseeko(fp, offset, SEEK_SET) != 0)
{
- *status = CF_INVALID_FORMAT;
+ NERV_SET_STATUS(status, CF_INVALID_FORMAT, 0);
return NULL;
}
/* read header */
chunk_len = read_chunk_header_plain(fp, status);
- if (*status == CF_END_OF_FILE) break;
- if (*status != CF_NORMAL)
+ if (status->err_code == CF_END_OF_FILE) break;
+ if (status->err_code != NERV_NORMAL)
return NULL;
cip = (ChunkInfo *)malloc(sizeof(ChunkInfo));
/* read metadata */
mdstr = read_chunk_metadata(fp, fn, status);
- if (*status != CF_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
cip->metadata = strdup(mdstr);
cip->offset = ftello(fp);
@@ -142,14 +137,15 @@ static ChunkFile *open_read(const char *fn, int *status) {
cip->next = head;
head = cip;
}
- *status = CF_NORMAL;
cfp->fp = fp;
cfp->info = head;
cfp->status = CF_READ;
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return cfp;
}
-ChunkFile *nerv_chunk_file_create(const char *fn, const char *mode, int *status) {
+ChunkFile *nerv_chunk_file_create(const char *fn, const char *mode,
+ Status *status) {
int rd = 1, bin = 0;
size_t i, len = strlen(mode);
for (i = 0; i < len; i++)
@@ -163,41 +159,45 @@ ChunkFile *nerv_chunk_file_create(const char *fn, const char *mode, int *status)
open_write(fn, status);
}
-int nerv_chunk_file_write_chunkdata(ChunkFile *cfp, const char *mdstr,
- ChunkDataWriter_t writer, void *writer_arg) {
- int status;
+void nerv_chunk_file_write_chunkdata(ChunkFile *cfp, const char *mdstr,
+ ChunkDataWriter_t writer, void *writer_arg,
+ Status *status) {
off_t start;
size_t size;
if (cfp->status != CF_WRITE)
- return CF_INVALID_OP;
+ NERV_EXIT_STATUS(status, CF_INVALID_OP, 0);
start = ftello(cfp->fp);
- write_chunk_header_plain(cfp->fp, 0, &status); /* fill zeros */
- if (status != CF_NORMAL) return status;
- write_chunk_metadata(cfp->fp, mdstr, &status);
- if (status != CF_NORMAL) return status;
+ write_chunk_header_plain(cfp->fp, 0, status); /* fill zeros */
+ if (status->err_code != NERV_NORMAL)
+ return;
+ write_chunk_metadata(cfp->fp, mdstr, status);
+ if (status->err_code != NERV_NORMAL)
+ return;
writer(writer_arg);
size = ftello(cfp->fp) - start;
fseeko(cfp->fp, start, SEEK_SET);
/* write the calced size */
- write_chunk_header_plain(cfp->fp, size, &status);
- if (status != CF_NORMAL) return status;
+ write_chunk_header_plain(cfp->fp, size, status);
+ if (status->err_code != NERV_NORMAL)
+ return;
fseeko(cfp->fp, 0, SEEK_END);
- return CF_NORMAL;
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
-ChunkData *nerv_chunk_file_get_chunkdata(ChunkFile *cfp, ChunkInfo *cip, int *status) {
+ChunkData *nerv_chunk_file_get_chunkdata(ChunkFile *cfp, ChunkInfo *cip,
+ Status *status) {
ChunkData *cdp;
if (cfp->status != CF_READ)
{
- *status = CF_INVALID_OP;
+ NERV_SET_STATUS(status, CF_INVALID_OP, 0);
return NULL;
}
if (!(cdp = get_chunk_data(cfp->fp, cip)))
{
- *status = CF_END_OF_FILE;
+ NERV_SET_STATUS(status, CF_END_OF_FILE, 0);
return NULL;
}
- *status = CF_NORMAL;
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return cdp;
}
@@ -227,17 +227,3 @@ void nerv_chunk_data_destroy(ChunkData *cdp) {
free(cdp->data);
free(cdp);
}
-
-const char *nerv_chunk_file_errstr(int status) {
- switch (status)
- {
- case CF_INVALID_FORMAT: return "invalid format";
- case CF_END_OF_FILE: return "unexpected end of file";
- case CF_SECTION_OVERFLOW: return "section overflow";
- case CF_WRITE_ERROR: return "error while writing";
- case CF_ERR_OPEN_FILE: return "error while opening file";
- case CF_INVALID_OP: return "invalid operation";
- default: return "unknown";
- }
- return NULL;
-}
diff --git a/nerv/lib/io/chunk_file.h b/nerv/lib/io/chunk_file.h
index 71f0d03..f08d838 100644
--- a/nerv/lib/io/chunk_file.h
+++ b/nerv/lib/io/chunk_file.h
@@ -1,18 +1,6 @@
#ifndef NERV_CHUNK_FILE_H
#define NERV_CHUNK_FILE_H
-#include "../../common.h"
-enum {
- CF_NORMAL,
- CF_INVALID_FORMAT,
- CF_END_OF_FILE,
- CF_SECTION_OVERFLOW,
- CF_WRITE_ERROR,
- CF_ERR_OPEN_FILE,
- CF_INVALID_OP,
- CF_READ,
- CF_WRITE,
- CF_CLOSED
-};
+#include "../common.h"
typedef struct ChunkInfo {
struct ChunkInfo *next;
@@ -23,7 +11,11 @@ typedef struct ChunkInfo {
typedef struct ChunkFile {
FILE *fp;
ChunkInfo *info;
- int status;
+ enum {
+ CF_READ,
+ CF_WRITE,
+ CF_CLOSED
+ } status;
} ChunkFile;
typedef struct ChunkData {
@@ -32,12 +24,14 @@ typedef struct ChunkData {
} ChunkData;
typedef void (*ChunkDataWriter_t)(void *);
-ChunkFile *nerv_chunk_file_create(const char *fn, const char *mode, int *status);
-int nerv_chunk_file_write_chunkdata(ChunkFile *cfp, const char *mdstr,
- ChunkDataWriter_t writer, void *writer_arg);
-ChunkData *nerv_chunk_file_get_chunkdata(ChunkFile *cfp, ChunkInfo *cip, int *status);
+ChunkFile *nerv_chunk_file_create(const char *fn, const char *mode,
+ Status *status);
+void nerv_chunk_file_write_chunkdata(ChunkFile *cfp, const char *mdstr,
+ ChunkDataWriter_t writer, void *writer_arg,
+ Status *status);
+ChunkData *nerv_chunk_file_get_chunkdata(ChunkFile *cfp, ChunkInfo *cip,
+ Status *status);
void nerv_chunk_file_close(ChunkFile *cfp);
void nerv_chunk_file_destroy(ChunkFile *cfp);
void nerv_chunk_data_destroy(ChunkData *cdp);
-const char *nerv_chunk_file_errstr(int status);
#endif
diff --git a/nerv/lib/matrix/cumatrix.c b/nerv/lib/matrix/cumatrix.c
index 9641197..aa81bfc 100644
--- a/nerv/lib/matrix/cumatrix.c
+++ b/nerv/lib/matrix/cumatrix.c
@@ -1,5 +1,5 @@
#define NERV_GENERIC_CUMATRIX
-#include "../../common.h"
+#include "../common.h"
#include "cuda_helper.h"
#include <string.h>
#define PROFILE_HASHMAP_SIZE 123457
diff --git a/nerv/lib/matrix/generic/cumatrix.c b/nerv/lib/matrix/generic/cumatrix.c
index 11aacec..772b78d 100644
--- a/nerv/lib/matrix/generic/cumatrix.c
+++ b/nerv/lib/matrix/generic/cumatrix.c
@@ -7,7 +7,7 @@
#define NERV_GENERIC_MATRIX
#define NERV_GENERIC_CUKERNEL
-#include "../../../common.h"
+#include "../../common.h"
#include "../cukernel.h"
#include "../cuda_helper.h"
@@ -27,7 +27,7 @@ void nerv_matrix_(add)(Matrix *c, const Matrix *a, const Matrix *b,
MATRIX_ELEM_PTR(c), c->stride / sizeof(MATRIX_ELEM)),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(mul)(Matrix *c, const Matrix *a, const Matrix *b,
@@ -54,7 +54,7 @@ void nerv_matrix_(mul)(Matrix *c, const Matrix *a, const Matrix *b,
MATRIX_ELEM_PTR(c), c->stride / sizeof(MATRIX_ELEM)),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(sigmoid)(Matrix *a, const Matrix *b, Status *status) {
@@ -62,7 +62,7 @@ void nerv_matrix_(sigmoid)(Matrix *a, const Matrix *b, Status *status) {
PROFILE_START
cudak_(cuda_sigmoid)(b, a);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(sigmoid_grad)(Matrix *nerr, const Matrix *err,
@@ -72,7 +72,7 @@ void nerv_matrix_(sigmoid_grad)(Matrix *nerr, const Matrix *err,
PROFILE_START
cudak_(cuda_sigmoid_grad)(output, err, nerr);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
Matrix *nerv_matrix_(softmax)(Matrix *b, const Matrix *a, Status *status) {
@@ -80,16 +80,16 @@ Matrix *nerv_matrix_(softmax)(Matrix *b, const Matrix *a, Status *status) {
Matrix *dno;
CHECK_SAME_DIMENSION_RET(a, b, status);
max = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
max_idx = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
{
nerv_matrix_(destroy)(max, status);
return NULL;
}
dno = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
{ /* FIXME: destroy may also fail? */
nerv_matrix_(destroy)(max, status);
nerv_matrix_(destroy)(max_idx, status);
@@ -102,63 +102,63 @@ Matrix *nerv_matrix_(softmax)(Matrix *b, const Matrix *a, Status *status) {
PROFILE_STOP
nerv_matrix_(destroy)(max, status);
nerv_matrix_(destroy)(dno, status);
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return max_idx;
}
Matrix *nerv_matrix_(rowsum)(Matrix *a, Status *status) {
Matrix *b = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
PROFILE_START
cudak_(cuda_rowsum)(a, b);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return b;
}
Matrix *nerv_matrix_(colsum)(Matrix *a, Status *status) {
Matrix *b = nerv_matrix_(create)(1, a->ncol, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
PROFILE_START
cudak_(cuda_colsum)(a, b);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return b;
}
Matrix *nerv_matrix_(colsame)(Matrix *a, const Matrix *ref,
Status *status) {
Matrix *b = nerv_matrix_(create)(1, a->ncol, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
CHECK_SAME_DIMENSION_RET(a, ref, status);
PROFILE_START
cudak_(cuda_colsame)(a, ref, b);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return b;
}
Matrix *nerv_matrix_(rowmax)(Matrix *a, Status *status) {
Matrix *b = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
PROFILE_START
cudak_(cuda_rowmax)(a, b);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return b;
}
void nerv_matrix_(rowmax_idx)(Matrix *a, Matrix **b, Matrix **idx,
Status *status) {
*b = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return;
*idx = nerv_matrix_(create)(a->nrow, 1, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
{
/* FIXME: destroy may also fail? */
nerv_matrix_(destroy)(*b, status);
@@ -167,7 +167,7 @@ void nerv_matrix_(rowmax_idx)(Matrix *a, Matrix **b, Matrix **idx,
PROFILE_START
cudak_(cuda_rowmax_idx)(a, *b, *idx);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(add_row)(Matrix *b, const Matrix *a, double beta,
@@ -179,14 +179,14 @@ void nerv_matrix_(add_row)(Matrix *b, const Matrix *a, double beta,
PROFILE_START
cudak_(cuda_add_row)(a, b, beta);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(fill)(Matrix *self, double val, Status *status) {
PROFILE_START
cudak_(cuda_fill)(self, val);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(copy_fromd)(Matrix *a, const Matrix *b,
@@ -205,7 +205,7 @@ void nerv_matrix_(copy_fromd)(Matrix *a, const Matrix *b,
cudaMemcpyDeviceToDevice),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(copy_fromh)(Matrix *a, const Matrix *b,
@@ -224,7 +224,7 @@ void nerv_matrix_(copy_fromh)(Matrix *a, const Matrix *b,
cudaMemcpyHostToDevice),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(copy_toh)(Matrix *a, const Matrix *b,
@@ -243,13 +243,13 @@ void nerv_matrix_(copy_toh)(Matrix *a, const Matrix *b,
cudaMemcpyDeviceToHost),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
Matrix *nerv_matrix_(trans)(Matrix *a, Status *status) {
MATRIX_ELEM alpha = 1, beta = 0;
Matrix *b = nerv_matrix_(create)(a->ncol, a->nrow, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
/* FIXME: possible memory leak when lua error is raised */
PROFILE_START
@@ -263,7 +263,7 @@ Matrix *nerv_matrix_(trans)(Matrix *a, Status *status) {
MATRIX_ELEM_PTR(b), b->stride / sizeof(MATRIX_ELEM)),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return b;
}
@@ -274,7 +274,7 @@ void nerv_matrix_(mul_elem)(Matrix *c, const Matrix *a, const Matrix *b,
PROFILE_START
cudak_(cuda_mul_elem)(a, b, c);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(log_elem)(Matrix *b, const Matrix *a, Status *status) {
@@ -282,7 +282,7 @@ void nerv_matrix_(log_elem)(Matrix *b, const Matrix *a, Status *status) {
PROFILE_START
cudak_(cuda_log_elem)(a, b);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
Matrix *nerv_matrix_(decompress)(const Matrix *a, int orig_col, Status *status) {
@@ -293,13 +293,13 @@ Matrix *nerv_matrix_(decompress)(const Matrix *a, int orig_col, Status *status)
return NULL;
}
b = nerv_matrix_(create)(a->nrow, orig_col, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
PROFILE_START
cudak_(cuda_fill)(b, 0.0);
cudak_(cuda_decompress)(a, b);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return b;
}
@@ -332,7 +332,7 @@ void nerv_matrix_(copy_rows_fromh_by_idx)(Matrix *a, const Matrix *b,
CUDA_SAFE_CALL(cudaStreamDestroy(streams[i]), status);
}
free(streams);
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(expand_frm)(Matrix *a, const Matrix *b,
@@ -345,7 +345,7 @@ void nerv_matrix_(expand_frm)(Matrix *a, const Matrix *b,
PROFILE_START
cudak_(cuda_expand_frm)(b, a, context);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(rearrange_frm)(Matrix *a, const Matrix *b,
@@ -357,7 +357,7 @@ void nerv_matrix_(rearrange_frm)(Matrix *a, const Matrix *b,
PROFILE_START
cudak_(cuda_rearrange_frm)(b, a, step);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(scale_rows_by_col)(Matrix *a, const Matrix *b,
@@ -369,7 +369,7 @@ void nerv_matrix_(scale_rows_by_col)(Matrix *a, const Matrix *b,
PROFILE_START
cudak_(cuda_scale_rows_by_col)(b, a);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(scale_rows_by_row)(Matrix *a, const Matrix *b,
@@ -381,12 +381,12 @@ void nerv_matrix_(scale_rows_by_row)(Matrix *a, const Matrix *b,
PROFILE_START
cudak_(cuda_scale_rows_by_row)(b, a);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
static void cuda_matrix_(free)(MATRIX_ELEM *ptr, Status *status) {
CUDA_SAFE_SYNC_CALL(cudaFree(ptr), status);
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
static void cuda_matrix_(alloc)(MATRIX_ELEM **dptr,
@@ -396,7 +396,7 @@ static void cuda_matrix_(alloc)(MATRIX_ELEM **dptr,
CUDA_SAFE_SYNC_CALL(cudaMallocPitch((void **)dptr, stride, width, height),
status);
PROFILE_STOP
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
#include "matrix.c"
diff --git a/nerv/lib/matrix/generic/cumatrix.h b/nerv/lib/matrix/generic/cumatrix.h
index 9a4f87e..5cfe9d5 100644
--- a/nerv/lib/matrix/generic/cumatrix.h
+++ b/nerv/lib/matrix/generic/cumatrix.h
@@ -1,4 +1,4 @@
-#include "../../../common.h"
+#include "../../common.h"
void nerv_matrix_(add)(Matrix *c, const Matrix *a, const Matrix *b,
MATRIX_ELEM alpha, MATRIX_ELEM beta,
diff --git a/nerv/lib/matrix/generic/matrix.c b/nerv/lib/matrix/generic/matrix.c
index 91577e1..a64759e 100644
--- a/nerv/lib/matrix/generic/matrix.c
+++ b/nerv/lib/matrix/generic/matrix.c
@@ -1,5 +1,5 @@
#ifdef NERV_GENERIC_MATRIX
-#include "../../../common.h"
+#include "../../common.h"
#include "matrix.h"
/* FIXME: malloc failure detection */
@@ -12,7 +12,7 @@ static void nerv_matrix_(data_free)(Matrix *self, Status *status) {
free(self->data_ref);
free(self);
}
- else NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ else NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
static void nerv_matrix_(data_retain)(Matrix *self) {
@@ -27,7 +27,7 @@ Matrix *nerv_matrix_(create)(long nrow, long ncol, Status *status) {
MATRIX_DATA_ALLOC(&MATRIX_ELEM_PTR(self), &self->stride,
sizeof(MATRIX_ELEM) * self->ncol, self->nrow,
status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
{
free(self);
return NULL;
@@ -35,7 +35,7 @@ Matrix *nerv_matrix_(create)(long nrow, long ncol, Status *status) {
self->data_ref = (long *)malloc(sizeof(long));
*self->data_ref = 0;
nerv_matrix_(data_retain)(self);
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return self;
}
diff --git a/nerv/lib/matrix/generic/mmatrix.c b/nerv/lib/matrix/generic/mmatrix.c
index e3d1f93..225079e 100644
--- a/nerv/lib/matrix/generic/mmatrix.c
+++ b/nerv/lib/matrix/generic/mmatrix.c
@@ -5,13 +5,13 @@
#define MATRIX_DATA_ALLOC(dptr, stride, width, height, status) \
host_matrix_(alloc)(dptr, stride, width, height, status)
#define NERV_GENERIC_MATRIX
-#include "../../../common.h"
+#include "../../common.h"
#include "../../io/chunk_file.h"
#include "string.h"
static void host_matrix_(free)(MATRIX_ELEM *ptr, Status *status) {
free(ptr);
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
static void host_matrix_(alloc)(MATRIX_ELEM **dptr, size_t *stride,
@@ -19,7 +19,7 @@ static void host_matrix_(alloc)(MATRIX_ELEM **dptr, size_t *stride,
if ((*dptr = (MATRIX_ELEM *)malloc(width * height)) == NULL)
NERV_EXIT_STATUS(status, MAT_INSUF_MEM, 0);
*stride = width;
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
#include "matrix.c"
@@ -31,7 +31,7 @@ Matrix *nerv_matrix_(load)(ChunkData *cdp, Status *status) {
if (fscanf(fp, "%ld %ld", &nrow, &ncol) != 2)
NERV_EXIT_STATUS(status, MAT_INVALID_FORMAT, 0);
self = nerv_matrix_(create)(nrow, ncol, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
for (i = 0; i < nrow; i++)
{
@@ -43,7 +43,7 @@ Matrix *nerv_matrix_(load)(ChunkData *cdp, Status *status) {
NERV_EXIT_STATUS(status, MAT_INVALID_FORMAT, 0);
}
}
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
return self;
}
@@ -62,7 +62,7 @@ void nerv_matrix_(save)(Matrix *self, ChunkFile *cfp, Status *status) {
if (fprintf(fp, "\n") < 0)
NERV_EXIT_STATUS(status, MAT_WRITE_ERROR, 0);
}
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
void nerv_matrix_(copy_from)(Matrix *a, const Matrix *b,
@@ -76,7 +76,7 @@ void nerv_matrix_(copy_from)(Matrix *a, const Matrix *b,
memmove(MATRIX_ROW_PTR(a, a_begin),
MATRIX_ROW_PTR(b, b_begin),
sizeof(MATRIX_ELEM) * b->ncol * (b_end - b_begin));
- NERV_SET_STATUS(status, MAT_NORMAL, 0);
+ NERV_SET_STATUS(status, NERV_NORMAL, 0);
}
#endif
diff --git a/nerv/lib/matrix/generic/mmatrix.h b/nerv/lib/matrix/generic/mmatrix.h
index 5336e7a..f00a04d 100644
--- a/nerv/lib/matrix/generic/mmatrix.h
+++ b/nerv/lib/matrix/generic/mmatrix.h
@@ -1,4 +1,5 @@
-#include "../../../common.h"
+#include "../../common.h"
+#include "../../io/chunk_file.h"
Matrix *nerv_matrix_(load)(ChunkData *cdp, Status *status);
void nerv_matrix_(save)(Matrix *self, ChunkFile *cfp, Status *status);
diff --git a/nerv/lib/matrix/mmatrix.c b/nerv/lib/matrix/mmatrix.c
index 2f58e7f..94f1ea8 100644
--- a/nerv/lib/matrix/mmatrix.c
+++ b/nerv/lib/matrix/mmatrix.c
@@ -1,6 +1,6 @@
#define NERV_GENERIC_MMATRIX
#include <stdlib.h>
-#include "../../common.h"
+#include "../common.h"
#define MATRIX_USE_FLOAT
#define host_matrix_(NAME) host_matrix_float_##NAME
@@ -37,7 +37,7 @@
Matrix *nerv_matrix_(perm_gen)(int ncol, Status *status) {
int i;
Matrix *self = nerv_matrix_(create)(1, ncol, status);
- if (status->err_code != MAT_NORMAL)
+ if (status->err_code != NERV_NORMAL)
return NULL;
long *prow = self->data.i;
for (i = 0; i < ncol; i++)
diff --git a/nerv/matrix/cumatrix.c b/nerv/matrix/cumatrix.c
index 1bcb0f1..fef03fc 100644
--- a/nerv/matrix/cumatrix.c
+++ b/nerv/matrix/cumatrix.c
@@ -1,5 +1,5 @@
#define NERV_GENERIC_CUMATRIX
-#include "../common.h"
+#include "../lib/common.h"
#include "../lib/matrix/cumatrix.h"
#include "../lib/matrix/cuda_helper.h"
#include <string.h>
diff --git a/nerv/matrix/generic/cumatrix.c b/nerv/matrix/generic/cumatrix.c
index 859718e..311b503 100644
--- a/nerv/matrix/generic/cumatrix.c
+++ b/nerv/matrix/generic/cumatrix.c
@@ -1,5 +1,4 @@
#ifdef NERV_GENERIC_CUMATRIX
-#include "../../lib/matrix/generic/matrix.h"
#include "elem_type.h"
#define MATRIX_DATA_WRITE(L, data, idx, val) cuda_matrix_(write)(L, data, idx, val)
#define MATRIX_DATA_READ(L, data, idx) cuda_matrix_(read)(L, data, idx)
@@ -7,7 +6,8 @@
#define MATRIX_BASE_TNAME nerv_matrix_cuda_tname
#define NERV_GENERIC_MATRIX
#define NERV_GENERIC_CUKERNEL
-#include "../../common.h"
+#include "../../lib/common.h"
+#include "../../lib/matrix/generic/matrix.h"
#include "../../lib/matrix/generic/cumatrix.h"
static int nerv_matrix_(lua_add)(lua_State *L) {
diff --git a/nerv/matrix/generic/matrix.c b/nerv/matrix/generic/matrix.c
index 9d2521b..ff89e54 100644
--- a/nerv/matrix/generic/matrix.c
+++ b/nerv/matrix/generic/matrix.c
@@ -1,5 +1,5 @@
#ifdef NERV_GENERIC_MATRIX
-#include "../../common.h"
+#include "../../lib/common.h"
#include "../../lib/matrix/generic/matrix.h"
extern const char *nerv_matrix_(tname);
diff --git a/nerv/matrix/generic/mmatrix.c b/nerv/matrix/generic/mmatrix.c
index 233102a..01dd9e5 100644
--- a/nerv/matrix/generic/mmatrix.c
+++ b/nerv/matrix/generic/mmatrix.c
@@ -6,9 +6,9 @@
#define MATRIX_INIT(L) host_matrix_(init)(L)
#define MATRIX_BASE_TNAME nerv_matrix_host_tname
#define NERV_GENERIC_MATRIX
-#include "../../common.h"
-#include "../../io/chunk_file.h"
+#include "../../lib/common.h"
#include "../../lib/matrix/generic/mmatrix.h"
+#include "../../io/chunk_file.h"
#include "string.h"
int nerv_matrix_(lua_get_elem)(lua_State *L) {
diff --git a/nerv/matrix/init.c b/nerv/matrix/init.c
index 27472b9..78a0dd9 100644
--- a/nerv/matrix/init.c
+++ b/nerv/matrix/init.c
@@ -1,4 +1,4 @@
-#include "../common.h"
+#include "../lib/common.h"
const char *nerv_matrix_tname = "nerv.Matrix";
const char *nerv_matrix_cuda_tname = "nerv.CuMatrix";
diff --git a/nerv/matrix/mmatrix.c b/nerv/matrix/mmatrix.c
index b25af03..5561572 100644
--- a/nerv/matrix/mmatrix.c
+++ b/nerv/matrix/mmatrix.c
@@ -1,6 +1,6 @@
#define NERV_GENERIC_MMATRIX
#include <stdlib.h>
-#include "../common.h"
+#include "../lib/common.h"
void nerv_matrix_host_float_lua_init(lua_State *L);
void nerv_matrix_host_double_lua_init(lua_State *L);
void nerv_matrix_host_int_lua_init(lua_State *L);
diff --git a/nerv/nerv.c b/nerv/nerv.c
index a59eadc..879dea9 100644
--- a/nerv/nerv.c
+++ b/nerv/nerv.c
@@ -1,4 +1,4 @@
-#include "common.h"
+#include "lib/common.h"
extern void nerv_example_init(lua_State *L);
extern void nerv_matrix_init(lua_State *L);
diff --git a/speech b/speech
-Subproject b6301089cde20f4c825c7f5deaf179082aad63d
+Subproject a74183ddb4ab8383bfe214b3745eb8a0a99ee47