Deprecate cross_proj .rai naming and cleanup

This commit is contained in:
Sachin Kumawat 2026-08-07 14:07:10 -07:00
parent c801520de3
commit 62c448e43e
6 changed files with 14 additions and 34 deletions

View File

@ -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}

View File

@ -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;

View File

@ -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;

View File

@ -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<flexmlrt::client::ErtTensorType> & input_tensors,
const std::vector<flexmlrt::client::ErtTensorType> & 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;
}

View File

@ -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);

View File

@ -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