Skip to content

Commit

Permalink
Compile without CUDA too
Browse files Browse the repository at this point in the history
  • Loading branch information
nshmyrev committed Dec 24, 2021
1 parent 72bf210 commit 525b722
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,19 @@ VOSK_SOURCES= \
language_model.cc \
model.cc \
spk_model.cc \
batch_recognizer.cc \
vosk_api.cc

VOSK_HEADERS= \
recognizer.h \
language_model.h \
model.h \
batch_recognizer.h \
spk_model.h \
vosk_api.h

CFLAGS=-g -O3 -std=c++17 -Wno-deprecated-declarations -fPIC -DFST_NO_DYNAMIC_LINKING \
-I. -I$(KALDI_ROOT)/src -I$(OPENFST_ROOT)/include $(EXTRA_CFLAGS)

LIBS= \
$(KALDI_ROOT)/src/cudadecoder/kaldi-cudadecoder.a \
$(KALDI_ROOT)/src/cudafeat/kaldi-cudafeat.a \
$(KALDI_ROOT)/src/online2/kaldi-online2.a \
$(KALDI_ROOT)/src/decoder/kaldi-decoder.a \
$(KALDI_ROOT)/src/ivector/kaldi-ivector.a \
Expand Down Expand Up @@ -79,8 +75,15 @@ ifeq ($(HAVE_ACCELERATE), 1)
endif

ifeq ($(HAVE_CUDA), 1)
VOSK_SOURCES += batch_recognizer.cc
VOSK_HEADERS += batch_recognizer.h

CFLAGS+=-DHAVE_CUDA=1 -I$(CUDA_ROOT)/include
LIBS+=\

LIBS := \
$(KALDI_ROOT)/src/cudadecoder/kaldi-cudadecoder.a \
$(KALDI_ROOT)/src/cudafeat/kaldi-cudafeat.a \
$(LIBS) \
-L$(CUDA_ROOT)/lib64 -lcuda -lcublas -lcusparse -lcudart -lcurand -lcufft -lcusolver -lnvToolsExt
endif

Expand Down
24 changes: 23 additions & 1 deletion src/vosk_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#include "vosk_api.h"

#include "recognizer.h"
#include "batch_recognizer.h"
#include "model.h"
#include "spk_model.h"

#if HAVE_CUDA
#include "cudamatrix/cu-device.h"
#include "batch_recognizer.h"
#endif

#include <string.h>
Expand Down Expand Up @@ -187,40 +187,62 @@ void vosk_gpu_thread_init()

VoskBatchRecognizer *vosk_batch_recognizer_new()
{
#if HAVE_CUDA
return (VoskBatchRecognizer *)(new BatchRecognizer());
#else
return NULL;
#endif
}

void vosk_batch_recognizer_free(VoskBatchRecognizer *recognizer)
{
#if HAVE_CUDA
delete ((BatchRecognizer *)recognizer);
#endif
}

void vosk_batch_recognizer_accept_waveform(VoskBatchRecognizer *recognizer, int id, const char *data, int length)
{
#if HAVE_CUDA
((BatchRecognizer *)recognizer)->AcceptWaveform(id, data, length);
#endif
}

void vosk_batch_recognizer_finish_stream(VoskBatchRecognizer *recognizer, int id)
{
#if HAVE_CUDA
((BatchRecognizer *)recognizer)->FinishStream(id);
#endif
}

const char *vosk_batch_recognizer_front_result(VoskBatchRecognizer *recognizer, int id)
{
#if HAVE_CUDA
return ((BatchRecognizer *)recognizer)->FrontResult(id);
#else
return NULL;
#endif
}

void vosk_batch_recognizer_pop(VoskBatchRecognizer *recognizer, int id)
{
#if HAVE_CUDA
((BatchRecognizer *)recognizer)->Pop(id);
#endif
}

void vosk_batch_recognizer_wait(VoskBatchRecognizer *recognizer)
{
#if HAVE_CUDA
((BatchRecognizer *)recognizer)->WaitForCompletion();
#endif
}

int vosk_batch_recognizer_get_pending_chunks(VoskBatchRecognizer *recognizer, int id)
{
#if HAVE_CUDA
return ((BatchRecognizer *)recognizer)->GetPendingChunks(id);
#else
return 0;
#endif
}

0 comments on commit 525b722

Please sign in to comment.