diff options
Diffstat (limited to 'kaldi_io')
-rw-r--r-- | kaldi_io/Makefile | 5 | ||||
-rw-r--r-- | kaldi_io/src/cwrapper_kaldi.cpp | 29 | ||||
-rw-r--r-- | kaldi_io/src/cwrapper_kaldi.h | 15 | ||||
-rw-r--r-- | kaldi_io/src/init.c | 17 | ||||
-rw-r--r-- | kaldi_io/src/test.c | 7 |
5 files changed, 48 insertions, 25 deletions
diff --git a/kaldi_io/Makefile b/kaldi_io/Makefile index 1066fc5..13b365f 100644 --- a/kaldi_io/Makefile +++ b/kaldi_io/Makefile @@ -1,5 +1,5 @@ # Change KDIR to `kaldi-trunk' path (Kaldi must be compiled with --share) -KDIR := /home/stuymf/kaldi-trunk/ +KDIR := /slfs1/users/ymz09/kaldi/ SHELL := /bin/bash BUILD_DIR := $(CURDIR)/build @@ -20,6 +20,7 @@ OBJ_SUBDIR := $(addprefix $(OBJ_DIR)/,$(SUBDIR)) LUA_SUBDIR := $(addprefix $(LUA_DIR)/,$(SUBDIR)) LUA_LIBS := $(addprefix $(LUA_DIR)/,$(LUA_LIBS)) LIB_PATH := $(LUA_BINDIR)/../lib +LUALIB_PATH := $(LUA_BINDIR)/../lib/lua/5.1/ build: $(OBJ_DIR) $(OBJ_SUBDIR) $(OBJS) $(OBJ_DIR)/src/test install: $(LUA_DIR) $(LUA_SUBDIR) $(LUA_LIBS) $(LIBS) @@ -32,7 +33,7 @@ $(OBJ_DIR) $(LUA_DIR) $(OBJ_SUBDIR) $(LUA_SUBDIR): $(LUA_DIR)/%.lua: %.lua cp $< $@ $(LIBS): $(OBJ_DIR)/src/cwrapper_kaldi.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o - gcc -shared -fPIC -o $@ $(OBJ_DIR)/src/cwrapper_kaldi.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o -lstdc++ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -lluaT $(KL) + gcc -shared -fPIC -o $@ $(OBJ_DIR)/src/cwrapper_kaldi.o $(OBJ_DIR)/init.o $(OBJ_DIR)/src/init.o -lstdc++ -Wl,-rpath=$(LIB_PATH) -L$(LIB_PATH) -lnervcore -Wl,-rpath=$(LUALIB_PATH) -L$(LUALIB_PATH) -lnerv -lluaT $(KL) $(OBJ_DIR)/src/cwrapper_kaldi.o: src/cwrapper_kaldi.cpp g++ -o $@ -c $< -DHAVE_ATLAS $(KALDIINCLUDE) -g -fPIC $(INCLUDE) -DKALDI_DOUBLEPRECISION=0 -msse2 -DHAVE_POSIX_MEMALIGN $(OBJ_DIR)/src/test: $(OBJ_DIR)/src/cwrapper_kaldi.o $(OBJ_DIR)/src/test.o diff --git a/kaldi_io/src/cwrapper_kaldi.cpp b/kaldi_io/src/cwrapper_kaldi.cpp index d16f316..83331ce 100644 --- a/kaldi_io/src/cwrapper_kaldi.cpp +++ b/kaldi_io/src/cwrapper_kaldi.cpp @@ -10,10 +10,11 @@ extern "C" { #include "cwrapper_kaldi.h" #include "string.h" #include "assert.h" -#include "nerv/common.h" +#include "nerv/lib/common.h" +#include "nerv/lib/matrix/mmatrix.h" - extern Matrix *nerv_matrix_host_float_create(long nrow, long ncol, Status *status); - extern Matrix *nerv_matrix_host_double_create(long nrow, long ncol, Status *status); + extern Matrix *nerv_matrix_host_float_create(long nrow, long ncol, MContext *context, Status *status); + extern Matrix *nerv_matrix_host_double_create(long nrow, long ncol, MContext *context, Status *status); struct KaldiFeatureRepo { kaldi::SequentialBaseFloatMatrixReader* feature_reader; @@ -26,7 +27,8 @@ extern "C" { return repo; } - Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L, int debug) { + Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L, + int debug, MContext *context) { Matrix *mat; /* nerv implementation */ repo->utt = repo->feature_reader->Key(); @@ -37,9 +39,9 @@ extern "C" { Status status; assert(sizeof(BaseFloat) == sizeof(float)); if(sizeof(BaseFloat) == sizeof(float)) - mat = nerv_matrix_host_float_create(n, m, &status); + mat = nerv_matrix_host_float_create(n, m, context, &status); else if(sizeof(BaseFloat) == sizeof(double)) - mat = nerv_matrix_host_double_create(n, m, &status); + mat = nerv_matrix_host_double_create(n, m, context, &status); NERV_LUA_CHECK_STATUS(L, status); size_t stride = mat->stride; if (debug) @@ -99,7 +101,10 @@ extern "C" { return repo; } - Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, int debug) { + Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo, + KaldiFeatureRepo *frepo, + int nframes, lua_State *L, + int debug, MContext *context) { Matrix *mat; /* nerv implementation */ StringToString_t::iterator mit = repo->map.find(frepo->utt); if (mit == repo->map.end()) @@ -115,9 +120,9 @@ extern "C" { Status status; assert(sizeof(BaseFloat) == sizeof(float)); if(sizeof(BaseFloat) == sizeof(float)) - mat = nerv_matrix_host_float_create(n, m, &status); + mat = nerv_matrix_host_float_create(n, m, context, &status); else if(sizeof(BaseFloat) == sizeof(double)) - mat = nerv_matrix_host_double_create(n, m, &status); + mat = nerv_matrix_host_double_create(n, m, context, &status); NERV_LUA_CHECK_STATUS(L, status); size_t stride = mat->stride; if (debug) @@ -149,7 +154,7 @@ extern "C" { Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, - int debug) { + int debug, MContext *context) { Matrix *mat; kaldi::Posterior targets = repo->targets_reader->Value(frepo->utt); @@ -159,9 +164,9 @@ extern "C" { Status status; assert(sizeof(BaseFloat) == sizeof(float)); if(sizeof(BaseFloat) == sizeof(float)) - mat = nerv_matrix_host_float_create(n, m, &status); + mat = nerv_matrix_host_float_create(n, m, context, &status); else if(sizeof(BaseFloat) == sizeof(double)) - mat = nerv_matrix_host_double_create(n, m, &status); + mat = nerv_matrix_host_double_create(n, m, context, &status); NERV_LUA_CHECK_STATUS(L, status); size_t stride = mat->stride; if (debug) diff --git a/kaldi_io/src/cwrapper_kaldi.h b/kaldi_io/src/cwrapper_kaldi.h index c8a7a25..db20087 100644 --- a/kaldi_io/src/cwrapper_kaldi.h +++ b/kaldi_io/src/cwrapper_kaldi.h @@ -1,7 +1,7 @@ #ifndef NERV_kaldi_KALDI_IO_CWRAPPER #define NERV_kaldi_KALDI_IO_CWRAPPER -#include "nerv/matrix/matrix.h" -#include "nerv/common.h" +#include "nerv/lib/matrix/mmatrix.h" +#include "nerv/lib/common.h" #ifdef __cplusplus extern "C" { #endif @@ -9,7 +9,8 @@ extern "C" { typedef struct KaldiFeatureRepo KaldiFeatureRepo; KaldiFeatureRepo *kaldi_feature_repo_new(const char *); - Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L, int debug); + Matrix *kaldi_feature_repo_read_utterance(KaldiFeatureRepo *repo, lua_State *L, + int debug, MContext *context); void kaldi_feature_repo_next(KaldiFeatureRepo *repo); int kaldi_feature_repo_is_end(KaldiFeatureRepo *repo); const char *kaldi_feature_repo_key(KaldiFeatureRepo *repo); @@ -21,14 +22,18 @@ extern "C" { Matrix *kaldi_label_repo_read_utterance(KaldiLabelRepo *repo, KaldiFeatureRepo *, int, lua_State *L, - int debug); + int debug, + MContext *context); void kaldi_label_repo_destroy(KaldiLabelRepo *repo); typedef struct KaldiLookupFeatureRepo KaldiLookupFeatureRepo; KaldiLookupFeatureRepo *kaldi_lookup_feature_repo_new(const char *, const char *); - Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo, KaldiFeatureRepo *frepo, int nframes, lua_State *L, int debug); + Matrix *kaldi_lookup_feature_repo_read_utterance(KaldiLookupFeatureRepo *repo, + KaldiFeatureRepo *frepo, + int nframes, lua_State *L, + int debug, MContext *context); void kaldi_lookup_feature_repo_destroy(KaldiLookupFeatureRepo *repo); #ifdef __cplusplus diff --git a/kaldi_io/src/init.c b/kaldi_io/src/init.c index 529895b..e8b4ea6 100644 --- a/kaldi_io/src/init.c +++ b/kaldi_io/src/init.c @@ -1,4 +1,5 @@ -#include "nerv/common.h" +#include "nerv/lib/common.h" +#include "nerv/matrix/matrix.h" #include "cwrapper_kaldi.h" #include <stdio.h> @@ -21,12 +22,14 @@ static int feat_repo_destroy(lua_State *L) { } static int feat_repo_current_utterance(lua_State *L) { + MContext *context; + MMATRIX_GET_CONTEXT(L, 3); KaldiFeatureRepo *repo = luaT_checkudata(L, 1, nerv_kaldi_feat_repo_tname); int debug; if (!lua_isboolean(L, 2)) nerv_error(L, "debug flag should be a boolean"); debug = lua_toboolean(L, 2); - Matrix *utter = kaldi_feature_repo_read_utterance(repo, L, debug); + Matrix *utter = kaldi_feature_repo_read_utterance(repo, L, debug, context); luaT_pushudata(L, utter, nerv_matrix_host_float_tname); return 1; } @@ -72,6 +75,8 @@ static int lookup_feat_repo_destroy(lua_State *L) { } static int lookup_feat_repo_read_utterance(lua_State *L) { + MContext *context; + MMATRIX_GET_CONTEXT(L, 5); KaldiLookupFeatureRepo *repo = luaT_checkudata(L, 1, nerv_kaldi_lookup_feat_repo_tname); KaldiFeatureRepo *feat_repo = luaT_checkudata(L, 2, nerv_kaldi_feat_repo_tname); int nframes, debug; @@ -81,7 +86,8 @@ static int lookup_feat_repo_read_utterance(lua_State *L) { if (!lua_isboolean(L, 4)) nerv_error(L, "debug flag should be a boolean"); debug = lua_toboolean(L, 4); - Matrix *utter = kaldi_lookup_feature_repo_read_utterance(repo, feat_repo, nframes, L, debug); + Matrix *utter = kaldi_lookup_feature_repo_read_utterance(repo, feat_repo, + nframes, L, debug, context); luaT_pushudata(L, utter, nerv_matrix_host_float_tname); return 1; } @@ -100,6 +106,8 @@ static int label_repo_new(lua_State *L) { } static int label_repo_read_utterance(lua_State *L) { + MContext *context; + MMATRIX_GET_CONTEXT(L, 5); KaldiLabelRepo *repo = luaT_checkudata(L, 1, nerv_kaldi_label_repo_tname); KaldiFeatureRepo *feat_repo = luaT_checkudata(L, 2, nerv_kaldi_feat_repo_tname); int nframes, debug; @@ -109,7 +117,8 @@ static int label_repo_read_utterance(lua_State *L) { if (!lua_isboolean(L, 4)) nerv_error(L, "debug flag should be a boolean"); debug = lua_toboolean(L, 4); - Matrix *utter = kaldi_label_repo_read_utterance(repo, feat_repo, nframes, L, debug); + Matrix *utter = kaldi_label_repo_read_utterance(repo, feat_repo, nframes, + L, debug, context); luaT_pushudata(L, utter, nerv_matrix_host_float_tname); return 1; } diff --git a/kaldi_io/src/test.c b/kaldi_io/src/test.c index e92b4c9..e3368df 100644 --- a/kaldi_io/src/test.c +++ b/kaldi_io/src/test.c @@ -7,8 +7,11 @@ **********************************************************************************/ #include "cwrapper_kaldi.h" +#include "nerv/lib/matrix/mmatrix.h" #include <stdio.h> +MContext context; + char feature_rspecifier[] = {"ark:/slfs6/users/ymz09/kaldi/src/featbin/copy-feats scp:/slfs6/users/ymz09/swb_ivec/train_bp.scp ark:- |"}; void print_nerv_matrix(Matrix *mat) { @@ -30,13 +33,13 @@ int main(int argc, char *argv[]) Matrix *mat; KaldiFeatureRepo *repo = kaldi_feature_repo_new(feature_rspecifier); - mat = kaldi_feature_repo_read_utterance(repo, NULL, 1); + mat = kaldi_feature_repo_read_utterance(repo, NULL, 1, &context); printf("1st uttrance\n"); print_nerv_matrix(mat); kaldi_feature_repo_next(repo); - mat = kaldi_feature_repo_read_utterance(repo, NULL, 1); + mat = kaldi_feature_repo_read_utterance(repo, NULL, 1, &context); printf("2nd uttrance\n"); print_nerv_matrix(mat); |