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
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ VoiceActivityDetection::preprocess(std::span<float> waveform) const {
return frameBuffer;
}

void VoiceActivityDetection::unload() noexcept {
std::scoped_lock lock(inference_mutex_);
BaseModel::unload();
}

std::vector<types::Segment>
VoiceActivityDetection::generate(std::span<float> waveform) const {
std::scoped_lock lock(inference_mutex_);

auto windowedInput = preprocess(waveform);
auto [chunksNumber, remainder] = std::div(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <executorch/extension/tensor/tensor.h>
#include <executorch/extension/tensor/tensor_ptr.h>
#include <executorch/runtime/core/evalue.h>
#include <mutex>
#include <span>

#include "rnexecutorch/metaprogramming/ConstructorHelpers.h"
Expand All @@ -23,7 +24,19 @@ class VoiceActivityDetection : public BaseModel {
[[nodiscard("Registered non-void function")]] std::vector<types::Segment>
generate(std::span<float> waveform) const;

/**
* @brief Thread-safe unload that waits for any in-flight inference to
* complete.
*
* Mirrors VisionModel::unload(). Without this, BaseModel::unload() can
* destroy module_ while generate() is still calling forward() on a worker
* thread, causing SIGILL / SIGSEGV crashes.
*/
void unload() noexcept;

private:
mutable std::mutex inference_mutex_;

std::vector<std::array<float, constants::kPaddedWindowSize>>
preprocess(std::span<float> waveform) const;
std::vector<types::Segment> postprocess(const std::vector<float> &scores,
Expand Down
Loading