Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

drop 'gpu' accelerator selector

CJ Paisd55ea7ef12b8
diff --git a/src-tauri/src/managers/transcription.rs b/src-tauri/src/managers/transcription.rs
index 30e3af4c..248736f5 100644
--- a/src-tauri/src/managers/transcription.rs
+++ b/src-tauri/src/managers/transcription.rs
@@ -559,10 +559,40 @@ impl TranscriptionManager {
None => {
let settings = get_settings(&self.app_handle);
let accelerator = settings.transcribe_accelerator;
+<<<<<<< Updated upstream
(
select_transcribe_backend(accelerator),
resolve_gpu_device(accelerator, settings.transcribe_gpu_device),
)
+||||||| Stash base
+ let device = resolve_gpu_device(
+ accelerator,
+ settings.transcribe_gpu_device.as_deref(),
+ );
+ // Backend::Auto accepts an exact CPU/GPU device. When
+ // no exact device is saved, retain Handy's strict
+ // accelerator/backend policy and native fallback.
+ let backend = if device.is_some() {
+ Backend::Auto
+ } else {
+ select_transcribe_backend(accelerator)
+ };
+ (backend, device)
+=======
+ let device = resolve_gpu_device(
+ accelerator,
+ settings.transcribe_gpu_device.as_deref(),
+ );
+ // Backend::Auto accepts an exact GPU device. Without a
+ // valid exact device, backend selection handles the
+ // retired generic GPU state and host CPU guard.
+ let backend = if device.is_some() {
+ Backend::Auto
+ } else {
+ select_transcribe_backend(accelerator)
+ };
+ (backend, device)
+>>>>>>> Stashed changes
}
};
let model_options = ModelOptions {
@@ -1939,12 +1969,13 @@ fn resolve_device_index(index: usize) -> Result<(Backend, i32)> {
/// Map Handy's whisper accelerator setting to a transcribe-cpp [`Backend`].
///
-/// `Auto` lets the library pick the best device (with CPU fallback). `Cpu` forces
-/// strict CPU. `Gpu` requests the platform GPU backend, but only if a device for
-/// it is actually registered — otherwise it falls back to `Auto` so the load
-/// never fails outright on a machine without that GPU backend. An emulated x64
-/// process on Windows ARM64 forces strict CPU for every setting.
+/// `Auto` lets the library pick the best device (with CPU fallback), while
+/// `Cpu` forces strict CPU. `Gpu` only remains as the companion setting for an
+/// exact device; without a valid exact device it has the retired generic GPU
+/// state's new Auto semantics. An emulated x64 process on Windows ARM64 forces
+/// strict CPU for every setting.
fn select_transcribe_backend(setting: TranscribeAcceleratorSetting) -> Backend {
+<<<<<<< Updated upstream
match effective_transcribe_accelerator(setting, transcribe_gpu_disabled_for_host()) {
TranscribeAcceleratorSetting::Cpu => Backend::Cpu,
TranscribeAcceleratorSetting::Auto => Backend::Auto,
@@ -1953,30 +1984,27 @@ fn select_transcribe_backend(setting: TranscribeAcceleratorSetting) -> Backend {
let candidates = [Backend::Metal];
#[cfg(not(target_os = "macos"))]
let candidates = [Backend::Cuda, Backend::Vulkan];
+||||||| Stash base
+ match effective_transcribe_accelerator(setting, transcribe_gpu_disabled_for_host()) {
+ TranscribeAcceleratorSetting::Cpu => Backend::Cpu,
+ TranscribeAcceleratorSetting::Auto => Backend::Auto,
+ TranscribeAcceleratorSetting::Gpu => {
+ #[cfg(target_os = "macos")]
+ let candidates = [Backend::Metal];
+ #[cfg(not(target_os = "macos"))]
+ let candidates = [Backend::Cuda, Backend::Rocm, Backend::Vulkan];
+=======
+ select_transcribe_backend_for_host(setting, transcribe_gpu_disabled_for_host())
+}
+>>>>>>> Stashed changes
- match candidates
- .into_iter()
- .find(|&b| transcribe_cpp::backend_available(b))
- {
- Some(b) => b,
- None => {
- #[cfg(target_os = "linux")]
- warn!(
- "GPU acceleration was requested, but no transcribe.cpp GPU backend is \
- registered; falling back to Auto (usually CPU). Run with \
- --list-devices to inspect detected devices; VK_LOADER_DEBUG=error can \
- reveal Vulkan loader or driver failures"
- );
- #[cfg(not(target_os = "linux"))]
- warn!(
- "GPU acceleration was requested, but no transcribe.cpp GPU backend is \
- registered; falling back to Auto (usually CPU). Run with \
- --list-devices to inspect detected devices"
- );
- Backend::Auto
- }
- }
- }
+fn select_transcribe_backend_for_host(
+ setting: TranscribeAcceleratorSetting,
+ gpu_disabled: bool,
+) -> Backend {
+ match effective_transcribe_accelerator(setting, gpu_disabled) {
+ TranscribeAcceleratorSetting::Cpu => Backend::Cpu,
+ TranscribeAcceleratorSetting::Auto | TranscribeAcceleratorSetting::Gpu => Backend::Auto,
}
}
@@ -2003,7 +2031,13 @@ fn resolve_gpu_device(setting: TranscribeAcceleratorSetting, gpu_device: i32) ->
gpu_device
} else {
warn!(
+<<<<<<< Updated upstream
"Stored transcribe GPU device index {} is no longer available; using auto",
+||||||| Stash base
+ "Stored transcribe GPU device '{}' is no longer available; using automatic GPU selection",
+=======
+ "Stored transcribe GPU device '{}' is no longer available; using automatic device selection",
+>>>>>>> Stashed changes
gpu_device
);
0
@@ -2159,6 +2193,18 @@ mod tests {
available_transcribe_accelerators(false),
["auto", "cpu", "gpu"]
);
+ assert_eq!(
+ select_transcribe_backend_for_host(TranscribeAcceleratorSetting::Auto, false),
+ Backend::Auto
+ );
+ assert_eq!(
+ select_transcribe_backend_for_host(TranscribeAcceleratorSetting::Cpu, false),
+ Backend::Cpu
+ );
+ assert_eq!(
+ select_transcribe_backend_for_host(TranscribeAcceleratorSetting::Gpu, false),
+ Backend::Auto
+ );
for kind in ["cpu", "accel", "metal", "cuda", "vulkan", "gpu"] {
assert!(transcribe_device_allowed(kind, false));
}
@@ -2175,6 +2221,10 @@ mod tests {
effective_transcribe_accelerator(setting, true),
TranscribeAcceleratorSetting::Cpu
);
+ assert_eq!(
+ select_transcribe_backend_for_host(setting, true),
+ Backend::Cpu
+ );
}
assert_eq!(available_transcribe_accelerators(true), ["cpu"]);
assert!(transcribe_device_allowed("cpu", true));
diff --git a/src-tauri/src/settings.rs b/src-tauri/src/settings.rs
index f11d30e9..821c32fd 100644
--- a/src-tauri/src/settings.rs
+++ b/src-tauri/src/settings.rs
@@ -1076,10 +1076,35 @@ fn apply_settings_migrations(
settings.transcribe_accelerator = TranscribeAcceleratorSetting::Auto;
settings.transcribe_gpu_device = default_transcribe_gpu_device();
}
+<<<<<<< Updated upstream
+||||||| Stash base
+ }
+ if stored_schema_version < 2 {
+ // transcribe.cpp 0.2 replaced integer registry indices with opaque
+ // process-local handles. Clear every old index once; keeping the GPU
+ // accelerator preference for schema-1 users preserves their intent and
+ // lets the backend choose a valid GPU automatically.
+ settings.transcribe_gpu_device = default_transcribe_gpu_device();
+=======
+ }
+ if stored_schema_version < 2 {
+ // transcribe.cpp 0.2 replaced integer registry indices with opaque
+ // process-local handles. Clear every old index once.
+ settings.transcribe_gpu_device = default_transcribe_gpu_device();
+>>>>>>> Stashed changes
settings.settings_schema_version = CURRENT_SETTINGS_SCHEMA_VERSION;
updated = true;
}
+ // The generic GPU choice was removed in favor of Auto or an exact device.
+ // Normalize settings created by builds that exposed that short-lived option.
+ if settings.transcribe_accelerator == TranscribeAcceleratorSetting::Gpu
+ && settings.transcribe_gpu_device.is_none()
+ {
+ settings.transcribe_accelerator = TranscribeAcceleratorSetting::Auto;
+ updated = true;
+ }
+
// One-time overlay migration (only while the new key is absent): the retired
// overlay_position `none` meant "hide the overlay" → OverlayStyle::None; any
// other position had it visible → Live. The position enum no longer has a
@@ -1269,8 +1294,36 @@ mod tests {
assert_eq!(settings.sound_theme, SoundTheme::Pop);
assert!(settings.filler_word_removal_enabled);
+<<<<<<< Updated upstream
// A current-format store must not be rewritten on every read.
assert!(!apply_settings_migrations(&mut settings, &stored));
+||||||| Stash base
+ // The 0.1 integer device index is cleared once for transcribe.cpp 0.2,
+ // while preserving this user's explicit GPU accelerator preference.
+ assert!(apply_settings_migrations(&mut settings, &stored));
+ assert_eq!(
+ settings.settings_schema_version,
+ CURRENT_SETTINGS_SCHEMA_VERSION
+ );
+ assert_eq!(
+ settings.transcribe_accelerator,
+ TranscribeAcceleratorSetting::Gpu
+ );
+ assert_eq!(settings.transcribe_gpu_device, None);
+=======
+ // The 0.1 integer device index is cleared once for transcribe.cpp 0.2.
+ // Without an exact device, the retired generic GPU choice becomes Auto.
+ assert!(apply_settings_migrations(&mut settings, &stored));
+ assert_eq!(
+ settings.settings_schema_version,
+ CURRENT_SETTINGS_SCHEMA_VERSION
+ );
+ assert_eq!(
+ settings.transcribe_accelerator,
+ TranscribeAcceleratorSetting::Auto
+ );
+ assert_eq!(settings.transcribe_gpu_device, None);
+>>>>>>> Stashed changes
}
#[test]
@@ -1454,7 +1507,67 @@ mod tests {
}
#[test]
+<<<<<<< Updated upstream
fn gpu_device_migration_keeps_current_schema_positive_selection() {
+||||||| Stash base
+ fn gpu_device_migration_clears_v1_index_but_keeps_gpu_preference() {
+ let raw = serde_json::json!({
+ "settings_schema_version": 1,
+ "transcribe_accelerator": "gpu",
+ "transcribe_gpu_device": 2
+ });
+ let mut settings: AppSettings = serde_json::from_value(raw.clone()).unwrap();
+
+ assert!(apply_settings_migrations(&mut settings, &raw));
+ assert_eq!(
+ settings.transcribe_accelerator,
+ TranscribeAcceleratorSetting::Gpu
+ );
+ assert_eq!(settings.transcribe_gpu_device, None);
+ }
+
+ #[test]
+ fn gpu_device_migration_keeps_current_stable_selection() {
+=======
+ fn gpu_device_migration_maps_v1_automatic_gpu_to_auto() {
+ let raw = serde_json::json!({
+ "settings_schema_version": 1,
+ "transcribe_accelerator": "gpu",
+ "transcribe_gpu_device": 2
+ });
+ let mut settings: AppSettings = serde_json::from_value(raw.clone()).unwrap();
+
+ assert!(apply_settings_migrations(&mut settings, &raw));
+ assert_eq!(
+ settings.transcribe_accelerator,
+ TranscribeAcceleratorSetting::Auto
+ );
+ assert_eq!(settings.transcribe_gpu_device, None);
+ }
+
+ #[test]
+ fn gpu_device_migration_maps_current_automatic_gpu_to_auto() {
+ let raw = serde_json::json!({
+ "settings_schema_version": CURRENT_SETTINGS_SCHEMA_VERSION,
+ "onboarding_completed": false,
+ "whats_new_last_seen_version": default_whats_new_last_seen_version(),
+ "overlay_style": "live",
+ "transcribe_accelerator": "gpu",
+ "transcribe_gpu_device": null
+ });
+ let mut settings: AppSettings = serde_json::from_value(raw.clone()).unwrap();
+
+ assert!(apply_settings_migrations(&mut settings, &raw));
+ assert_eq!(
+ settings.transcribe_accelerator,
+ TranscribeAcceleratorSetting::Auto
+ );
+ assert_eq!(settings.transcribe_gpu_device, None);
+ }
+
+ #[test]
+ fn gpu_device_migration_keeps_current_stable_selection() {
+>>>>>>> Stashed changes
let mut settings = get_default_settings();
settings.transcribe_accelerator = TranscribeAcceleratorSetting::Gpu;
settings.transcribe_gpu_device = 2;
diff --git a/src/components/settings/AccelerationSelector.tsx b/src/components/settings/AccelerationSelector.tsx
index 7a936ab9..9c97152f 100644
--- a/src/components/settings/AccelerationSelector.tsx
+++ b/src/components/settings/AccelerationSelector.tsx
@@ -24,17 +24,35 @@ interface AccelerationSelectorProps {
/**
* transcribe.cpp dropdown encodes accelerator + device in a single value:
+<<<<<<< Updated upstream
* "auto" → accelerator=auto, gpu_device=-1
* "cpu" → accelerator=cpu, gpu_device=-1
* "gpu:0" → accelerator=gpu, gpu_device=0
* "gpu:1" → accelerator=gpu, gpu_device=1
+||||||| Stash base
+ * "auto" → accelerator=auto, gpu_device=null
+ * "cpu" → accelerator=cpu, gpu_device=null
+ * "gpu" → accelerator=gpu, auto GPU selection
+ * "gpu:<id>" → accelerator=gpu, stable opaque device identity
+=======
+ * "auto" → accelerator=auto, gpu_device=null
+ * "cpu" → accelerator=cpu, gpu_device=null
+ * "gpu:<id>" → accelerator=gpu, stable opaque device identity
+>>>>>>> Stashed changes
*/
function encodeTranscribeValue(
accelerator: TranscribeAcceleratorSetting,
gpuDevice: number,
): string {
if (accelerator === "cpu") return "cpu";
+<<<<<<< Updated upstream
if (accelerator === "gpu" && gpuDevice >= 0) return `gpu:${gpuDevice}`;
+||||||| Stash base
+ if (accelerator === "gpu")
+ return gpuDevice === null ? "gpu" : `gpu:${gpuDevice}`;
+=======
+ if (accelerator === "gpu" && gpuDevice !== null) return `gpu:${gpuDevice}`;
+>>>>>>> Stashed changes
return "auto";
}
@@ -42,7 +60,14 @@ function decodeTranscribeValue(value: string): {
accelerator: TranscribeAcceleratorSetting;
gpuDevice: number;
} {
+<<<<<<< Updated upstream
if (value === "cpu") return { accelerator: "cpu", gpuDevice: -1 };
+||||||| Stash base
+ if (value === "cpu") return { accelerator: "cpu", gpuDevice: null };
+ if (value === "gpu") return { accelerator: "gpu", gpuDevice: null };
+=======
+ if (value === "cpu") return { accelerator: "cpu", gpuDevice: null };
+>>>>>>> Stashed changes
if (value.startsWith("gpu:")) {
const id = parseInt(value.slice(4), 10);
return { accelerator: "gpu", gpuDevice: id };
@@ -119,8 +144,9 @@ export const AccelerationSelector: FC<AccelerationSelectorProps> = ({
const handleTranscribeChange = async (value: string) => {
const { accelerator, gpuDevice } = decodeTranscribeValue(value);
- await updateSetting("transcribe_accelerator", accelerator);
+ // Save the device first to avoid `gpu + null` being normalized to Auto.
await updateSetting("transcribe_gpu_device", gpuDevice);
+ await updateSetting("transcribe_accelerator", accelerator);
};
return (