Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions demo/asr_infer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "../utils/audio_io.h"
#include "../utils/prompt_builder.h"

#include "time_compat.h"

#include <algorithm>
#include <cmath>
#include <cstdio>
Expand Down Expand Up @@ -220,6 +222,9 @@ int main(int argc, char ** argv) {

llama_model_params lm_mparams = llama_model_default_params();
lm_mparams.n_gpu_layers = 0; // CPU only
#ifdef _WIN32
lm_mparams.use_mmap = false; // MinGW/Windows lacks PrefetchVirtualMemory; mmap load fails
#endif

llama_model * lm_model = llama_load_model_from_file(params.lm_model_path.c_str(), lm_mparams);
if (!lm_model) {
Expand Down
30 changes: 30 additions & 0 deletions include/time_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Portability shim: provide clock_gettime(CLOCK_MONOTONIC, ...) on platforms
// (e.g. MinGW/Windows) where it is not available. No-op on POSIX systems that
// already provide it.
#ifndef VIBEASR_TIME_COMPAT_H
#define VIBEASR_TIME_COMPAT_H

#include <time.h>

#if defined(_WIN32) && !defined(CLOCK_MONOTONIC)

#include <chrono>

#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC 1
#endif

static inline int vibeasr_clock_gettime(int /*clk_id*/, struct timespec *ts) {
const auto now = std::chrono::steady_clock::now().time_since_epoch();
const auto secs = std::chrono::duration_cast<std::chrono::seconds>(now);
const auto nsecs = std::chrono::duration_cast<std::chrono::nanoseconds>(now - secs);
ts->tv_sec = static_cast<time_t>(secs.count());
ts->tv_nsec = static_cast<long>(nsecs.count());
return 0;
}

#define clock_gettime(clk, ts) vibeasr_clock_gettime((clk), (ts))

#endif // _WIN32 && !CLOCK_MONOTONIC

#endif // VIBEASR_TIME_COMPAT_H
5 changes: 5 additions & 0 deletions src/asr_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "../utils/audio_io.h"
#include "../utils/prompt_builder.h"

#include "time_compat.h"

#include <algorithm>
#include <cmath>
#include <cstdio>
Expand Down Expand Up @@ -363,6 +365,9 @@ int main(int argc, char ** argv) {

llama_model_params lm_mparams = llama_model_default_params();
lm_mparams.n_gpu_layers = 0;
#ifdef _WIN32
lm_mparams.use_mmap = false; // MinGW/Windows lacks PrefetchVirtualMemory; mmap load fails
#endif

llama_model * lm_model = llama_load_model_from_file(params.lm_model_path.c_str(), lm_mparams);
if (!lm_model) {
Expand Down
11 changes: 10 additions & 1 deletion src/vae.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "ggml-backend.h"
#include "ggml-vae-i8_s-mad.h"

#include "time_compat.h"

#include <algorithm>
#include <cassert>
#include <cmath>
Expand Down Expand Up @@ -646,8 +648,15 @@ static int32_t vae_encode_impl(

// Create computation context with sufficient memory
// F32 models need more memory than I8_S due to 4x larger intermediate tensors
#ifdef _WIN32
// Windows has no memory overcommit: a 128 GB reservation fails outright.
// 6 GB is ample for the VAE intermediate tensors at typical audio lengths.
const size_t vae_ctx_mem_size = (size_t)6 * 1024 * 1024 * 1024;
#else
const size_t vae_ctx_mem_size = (size_t)128 * 1024 * 1024 * 1024;
#endif
struct ggml_init_params ctx_params = {
/*.mem_size =*/ (size_t)128 * 1024 * 1024 * 1024,
/*.mem_size =*/ vae_ctx_mem_size,
/*.mem_buffer =*/ nullptr,
/*.no_alloc =*/ false, // Let ggml allocate tensors
};
Expand Down