From 62c448e43e18a25050f56db61add805076b811e3 Mon Sep 17 00:00:00 2001 From: Sachin Kumawat Date: Fri, 7 Aug 2026 14:07:10 -0700 Subject: [PATCH] Deprecate cross_proj .rai naming and cleanup --- src/CMakeLists.txt | 7 +++---- src/vitisai/whisper-vitisai-encoder.cpp | 9 +++------ src/vitisai/whisper-vitisai-encoder.h | 1 - src/vitisai/whisper-vitisai-helpers.cpp | 21 ++++++--------------- src/vitisai/whisper-vitisai-helpers.h | 1 - src/whisper.cpp | 9 ++------- 6 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d4f9bfb51..2ae7896f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -173,10 +173,9 @@ if (WHISPER_VITISAI) set_property(TARGET ${TARGET} PROPERTY POSITION_INDEPENDENT_CODE ON) set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_USE_VITISAI) - # Add C++17 standard for MSVC - if (MSVC) - target_compile_options(${TARGET} PRIVATE /std:c++17) - endif() + # FlexMLRT headers and this plugin require C++17. Keep it PRIVATE so the + # C++11 requirement of the whisper target is not bumped. + target_compile_features(${TARGET} PRIVATE cxx_std_17) target_compile_definitions(${TARGET} PRIVATE WHISPER_FLEXMLRT_LEGACY_RAI_OVERRIDES=${WHISPER_FLEXMLRT_LEGACY_RAI_OVERRIDES} diff --git a/src/vitisai/whisper-vitisai-encoder.cpp b/src/vitisai/whisper-vitisai-encoder.cpp index 2a1b6d280..24db7dcdf 100644 --- a/src/vitisai/whisper-vitisai-encoder.cpp +++ b/src/vitisai/whisper-vitisai-encoder.cpp @@ -86,8 +86,10 @@ struct whisper_vitisai_context * whisper_vitisai_init(const char * path_model) { options.executeMode = 2; options.extOptions["enable_preemption"] = true; + const bool model_is_rai = ctx->model_path.find(".rai") != std::string::npos; + // Check if model_path is rai file and if so, add fbs_buffer and fbs_buffer_size to the options - if (ctx->model_path.find(".rai") != std::string::npos) { + if (model_is_rai) { if (whisper_vitisai_helpers::map_rai_file(ctx->model_path.c_str(), &ctx->fbs_buffer, &ctx->fbs_buffer_size)) { options.extOptions["fbs_buffer"] = ctx->fbs_buffer; options.extOptions["fbs_buffer_size"] = ctx->fbs_buffer_size; @@ -104,7 +106,6 @@ struct whisper_vitisai_context * whisper_vitisai_init(const char * path_model) { #endif } - const bool model_is_rai = ctx->model_path.find(".rai") != std::string::npos; if (model_is_rai) { #if WHISPER_FLEXMLRT_LEGACY_RAI_OVERRIDES options.deviceName = "stx"; @@ -182,10 +183,6 @@ bool whisper_vitisai_has_cross_proj(const struct whisper_vitisai_context * ctx) return ctx && ctx->cross_k_out_idx >= 0 && ctx->cross_v_out_idx >= 0; } -bool whisper_vitisai_file_exists(const char * path) { - return whisper_vitisai_helpers::file_exists(path); -} - void whisper_vitisai_free(struct whisper_vitisai_context * ctx) { if (!ctx) { return; diff --git a/src/vitisai/whisper-vitisai-encoder.h b/src/vitisai/whisper-vitisai-encoder.h index f09003a64..ee96a1557 100644 --- a/src/vitisai/whisper-vitisai-encoder.h +++ b/src/vitisai/whisper-vitisai-encoder.h @@ -11,7 +11,6 @@ struct whisper_vitisai_context; struct whisper_vitisai_context * whisper_vitisai_init(const char * path_model); void whisper_vitisai_free(struct whisper_vitisai_context * ctx); bool whisper_vitisai_has_cross_proj(const struct whisper_vitisai_context * ctx); -bool whisper_vitisai_file_exists(const char * path); struct ggml_tensor; diff --git a/src/vitisai/whisper-vitisai-helpers.cpp b/src/vitisai/whisper-vitisai-helpers.cpp index 2ff509447..417634615 100644 --- a/src/vitisai/whisper-vitisai-helpers.cpp +++ b/src/vitisai/whisper-vitisai-helpers.cpp @@ -66,7 +66,7 @@ bool map_rai_file(const char * path, uint8_t ** buffer, size_t * size) { return false; } - *buffer = (uint8_t *) mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fileno(fd), 0); + *buffer = (uint8_t *) mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fileno(fd), 0); if (*buffer == MAP_FAILED) { fclose(fd); std::fprintf(stderr, "%s: %d: Failed to mmap rai file '%s'\n", __func__, __LINE__, path); @@ -86,19 +86,6 @@ void unmap_rai_file(uint8_t * buffer, size_t size) { #endif // _WIN32 } -bool file_exists(const char * path) { - if (!path) { - return false; - } - - FILE * file = fopen(path, "rb"); - if (!file) { - return false; - } - fclose(file); - return true; -} - const char * whisper_kv_type_name(ggml_type type) { switch (type) { case GGML_TYPE_F32: return "F32"; @@ -260,7 +247,7 @@ bool whisper_vitisai_bind_tensor_data( } bool whisper_vitisai_resolve_io_binding( - const char * caller, + [[maybe_unused]] const char * caller, const std::vector & input_tensors, const std::vector & output_tensors, whisper_vitisai_io_binding * binding, @@ -287,7 +274,9 @@ bool whisper_vitisai_resolve_io_binding( } } if (!found_named_mel) { +#if defined(WHISPER_DEBUG) std::fprintf(stderr, "%s: WARNING: mel input not found by name; falling back to input[0]\n", caller); +#endif } if (output_tensors.empty()) { @@ -306,7 +295,9 @@ bool whisper_vitisai_resolve_io_binding( } if (binding->embd_enc_out_idx < 0) { +#if defined(WHISPER_DEBUG) std::fprintf(stderr, "%s: WARNING: embd_enc output not found by name; falling back to output[0]\n", caller); +#endif binding->embd_enc_out_idx = 0; } diff --git a/src/vitisai/whisper-vitisai-helpers.h b/src/vitisai/whisper-vitisai-helpers.h index f6ab53902..d50a2f4a2 100644 --- a/src/vitisai/whisper-vitisai-helpers.h +++ b/src/vitisai/whisper-vitisai-helpers.h @@ -13,7 +13,6 @@ namespace whisper_vitisai_helpers { bool map_rai_file(const char * path, uint8_t ** buffer, size_t * size); void unmap_rai_file(uint8_t * buffer, size_t size); -bool file_exists(const char * path); const char * whisper_kv_type_name(ggml_type type); const char * whisper_flexml_dtype_name(flexmlrt::client::DataType type); diff --git a/src/whisper.cpp b/src/whisper.cpp index c64b210b0..317827142 100644 --- a/src/whisper.cpp +++ b/src/whisper.cpp @@ -3388,19 +3388,14 @@ static std::string whisper_get_coreml_path_encoder(std::string path_bin) { #endif #ifdef WHISPER_USE_VITISAI -// replace extension with Vitis AI encoder artifact +// replace extension with Vitis AI encoder artifact. Cross projection support is +// detected from the model's output tensors, not from the file name. static std::string whisper_get_vitisai_path_encoder_cache(std::string path_bin) { auto pos = path_bin.rfind('.'); if (pos != std::string::npos) { path_bin = path_bin.substr(0, pos); } - const std::string path_vitisai_cross = path_bin + "-encoder-cross-vitisai.rai"; - if (FILE * file = fopen(path_vitisai_cross.c_str(), "rb")) { - fclose(file); - return path_vitisai_cross; - } - return path_bin + "-encoder-vitisai.rai"; } #endif