Skip to main content

BackendError

Enum BackendError 

Source
#[non_exhaustive]
pub enum BackendError {
Show 18 variants CudaUnavailable(String), ShapeMismatch(ShapeError), DeviceMismatch, DeviceAllocationFailed(String), KernelLaunchFailed(String), DeviceUnavailable(String), TransferFailed(String), Unsupported(String), StorePoisoned, TapeMismatch, PendingForwardUnconsumed, MissingGradient(String), InvalidArgument(String), DeviceContextPoisoned(String), StaleDeviceGeneration { ordinal: usize, resource_generation: u64, current_generation: u64, }, DeviceContextRetiring { ordinal: usize, }, DeviceContextUnrecoverable { ordinal: usize, probe_error: String, }, DeviceContextCaptureInProgress { ordinal: usize, },
}
Expand description

バックエンド抽象層のエラー型(docs/public-api-design.md §4.4 を実装。 DeviceUnavailable variant はモジュール冒頭に記載のとおり本イシューで 追加した拡張)。

#[non_exhaustive] を付す理由: 公開 API 非破壊はガードレール条件 (.claude/rules/security.md)であり、CUDA/Metal 実装(TASK-1.9 以降) が進むにつれ想定される実行時失敗(同期エラー・ドライババージョン 不整合等)の variant 追加を非破壊にするため。

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

CudaUnavailable(String)

cudarc の動的ロードに失敗した(CUDA ドライバ・toolkit 不在等)。

§

ShapeMismatch(ShapeError)

入力テンソルの shape が演算の要求と合わない。

§

DeviceMismatch

デバイス間でテンソルが混在している等の不整合。

§

DeviceAllocationFailed(String)

デバイスメモリの確保に失敗した(upload/DeviceBuffer 確保等。 VRAM 枯渇・アロケータ失敗を含む)。

§

KernelLaunchFailed(String)

カーネル起動に失敗した(CUDA NVRTC のコンパイル・起動エラー、 Metal MTLComputeCommandEncoder のディスパッチ失敗等)。

§

DeviceUnavailable(String)

指定した Device が選択時点で利用不可(存在しない ordinal・ 対応する DeviceProvider 未登録等)。本イシュー(TASK-1.9a)で 追加した拡張 variant(モジュール冒頭のコメント参照)。

§

TransferFailed(String)

ホスト⇔デバイス転送(buffer::MemoryOps::upload/download)が 失敗した。TASK-1.9b(#45)で追加した拡張 variant。

DeviceAllocationFailed はバッファ確保自体の失敗(VRAM 枯渇等)を 表すのに対し、本 variant は確保済みバッファに対するコピー (CUDA cuMemcpyHtoD/cuMemcpyDtoH、Metal readback 等)の失敗を 表す(両者を区別することで呼び出し元が「確保からやり直すべきか・ 転送のみ再試行すべきか」を判別できる)。#[non_exhaustive] の 非破壊拡張として追加した(モジュール冒頭コメント参照)。

§

Unsupported(String)

指定したバックエンドが当該演算のカーネルを未実装であることを表す (TASK-1.9c・#46 で追加した拡張 variant)。CUDA/Metal は本イシュー 時点で GEMM カーネルのみ実装済みのため、crate::backend_ops::BackendOps の elementwise・reduction メソッドはこの variant を返す fail-safe 実装とする(panic!/unwrap() しない。 .claude/rules/coding-rust.md)。GPU 側カーネルの実装自体は本 イシューのスコープ外(out-of-scope-tracking.md 対象)。

§

StorePoisoned

デバイス上パラメータ更新(fandhe_ai_autodiff::optim::device_store:: DeviceParamStore。イシュー #935・docs/device-resident-update-design.md §3.1)が「以前の step() 失敗により実行時エラー後の状態」で 呼ばれたことを表す。DeviceParamStore は sgd_step_device の 実行時エラー(GPU 側の実際の起動失敗等。件数・shape 不一致のような 事前検証で弾ける契約違反とは別)を検出すると内部状態を poisoned へ 遷移し、以降の step/sync_to_host/register_resident_params/ snapshot_resident_params をすべてこの variant で fail-closed に 拒否する(「部分的に更新されたデバイス側パラメータをそのまま学習 継続・推論に使ってしまう」ことを構造的に防ぐ。.claude/rules/ security.md A08)。回復は新しい DeviceParamStore の再構築のみ。

§

TapeMismatch

DeviceParamStore::step/sync_to_host 等に、DeviceParamStore 構築時・直近の register_resident_params 呼び出しと異なる Tape(TapeId 不一致)を渡した(fandhe_ai_autodiff::var::Var の クロステープ検査〈AutodiffError::TapeMismatch〉と同種の契約を デバイス常駐パラメータ側にも課す。イシュー #935)。

§

PendingForwardUnconsumed

DeviceParamStore::register_resident_params(forward 用の デバイス→ホスト download・葉ノード登録)を、直前の登録が step() で消費(または abandon_pending_forward() で破棄)される 前に再度呼んだ。1 回の forward 記録に対し高々 1 回の step() が 対応する契約(イシュー #935・設計文書 §3.3a)を守るための fail-closed 拒否。

§

MissingGradient(String)

DeviceParamStore::step が Gradients::get で該当パラメータの 勾配を取得しようとしたが Ok(None)(loss へ未到達)だった。 fandhe_ai::compat::sequential::SequentialVars::trainable_grads と 同じ fail-closed 方針(黙って一部パラメータの更新をスキップしない。 .claude/rules/security.md A03)。

§

InvalidArgument(String)

DeviceParamStore の構築・step 呼び出し引数が構造的に不正 (パラメータ件数と勾配件数の不一致・momentum 構成〈velocity バッファの有無〉が前回 step から変化した等)。既存 variant (ShapeMismatch・DeviceMismatch)のいずれにも意味的に適合しない 引数検証失敗をここへ集約する(イシュー #935)。

§

DeviceContextPoisoned(String)

デバイスの ordinal が回復可能な poison 状態にある(イシュー #1013・docs/backend-cuda-async-execution-design.md §5)。

カーネル起動直後の都度 synchronize() を除去した非同期実行契約 の下では、ある演算の実行時エラー(sticky な driver エラー)の 発覚が後続の別演算まで遅延しうる。backend-cuda::context_cache はこれを検出した ordinal を fail-closed に拒否し、以降の演算 入口をこの variant で拒否する。回復には該当 ordinal の invalidate による再生成が必要(backend-cuda 内部 API。 呼び出し元は本 variant を受け取った場合、当該 ordinal を経由する 既存ハンドル・バッファをすべて破棄し、新たに tape_for 等で 取り直す)。

§

StaleDeviceGeneration

デバイスバッファ・ハンドルが保持する世代([crate::buffer:: DeviceBuffer::generation])が、対象 ordinal の現行世代と一致 しない(イシュー #1013)。

現行世代自体は健全(BackendError::DeviceContextPoisoned とは 独立)だが、渡されたハンドルは invalidate による再生成前の 旧世代に属するため、演算入口が使用を拒否する。呼び出し元は 現行世代のキャッシュ(tape_for 等)からハンドルを取り直す 必要がある(invalidate を呼ぶ必要はない)。

Fields

§ordinal: usize

対象デバイスの ordinal。

§resource_generation: u64

渡されたハンドル・バッファが属する世代。

§current_generation: u64

対象 ordinal の現行世代。

§

DeviceContextRetiring

対象 ordinal が invalidate(poison からの復旧処理)の drain 中 であり、一時的に演算入口を拒否した(イシュー #1013)。

DeviceContextPoisoned とは異なり、この状態は短時間で解消する (復旧が成功すれば Active へ、失敗すれば DeviceContextUnrecoverable へ遷移する)。呼び出し元は短時間の再試行、またはそのままエラーを 上位へ伝播するかを選べる。

Fields

§ordinal: usize

対象デバイスの ordinal。

§

DeviceContextUnrecoverable

対象 ordinal の復旧処理(invalidate)自体が失敗し、恒久的な poison 状態(unrecoverable)へ確定した(イシュー #1013)。

ストリーム完了同期の失敗、または復旧用の実処理プローブ (256B alloc → H2D → 恒等カーネル起動 → D2H → 値照合)の不一致・ 上限回数超過を意味する。同一プロセス内に回復手段はなく、 プロセスの再起動が必要(fail-open を避けるための最終防御。 .claude/rules/security.md A08)。

Fields

§ordinal: usize

対象デバイスの ordinal。

§probe_error: String

復旧処理が失敗した際のエラー内容(診断用)。

§

DeviceContextCaptureInProgress

対象 ordinal が別スレッドによる CUDA Graph capture 中であり、 一時的に演算入口を拒否した(イシュー #1349・Cursor Bugbot 指摘・ PR #1390 是正。backend-cuda::context_cache::begin_driver_call の capture 排他制御が発行する)。

DeviceContextRetiring と同様、この状態は capture を開始した スレッドが capture 区間を抜ける(CaptureGuard の drop)まで の短時間で自然に解消する一過性の競合であり、Unsupported (恒久的な未実装・設定誤り)とは意味が異なる。呼び出し元 (fandhe_ai_autodiff::optim::device_store::DeviceParamStore::step の CUDA Graph 可用性問い合わせ等)はこの variant を、他の BackendError variant と同じ「恒久的な致命的失敗」として扱って はならない(例えば DeviceParamStore を永久 poison してはならない。 呼び出し元は次回 step() で再試行するか、graph capture を使わない 直接実行経路へ今回分だけフォールバックする)。

Fields

§ordinal: usize

対象デバイスの ordinal。

Trait Implementations§

Source§

impl Debug for BackendError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for BackendError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Error for BackendError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<BackendError> for AutodiffError

Source§

fn from(err: BackendError) -> AutodiffError

Converts to this type from the input type.
Source§

impl From<BinningError> for BackendError

Source§

fn from(err: BinningError) -> BackendError

Converts to this type from the input type.
Source§

impl From<FftError> for BackendError

Source§

fn from(err: FftError) -> BackendError

Converts to this type from the input type.
Source§

impl From<FusionPlanError> for BackendError

FusionPlanError を BackendError へ変換する(TASK-12.1d・ #164)。fandhe_ai_autodiff::tape::build_lazy_plan (crates/autodiff/src/tape.rs)は自身の遅延ノード連鎖から組み立てた ops を FusionPlan::from_ops へ渡し、戻り値を Result<_, BackendError>(層 1/層 2 の実体化ヘルパーが共通で扱うエラー型。 AutodiffError::Backend 経由で呼び出し元へ伝播する)へ ? でそのまま 合流させる契約のため、この変換が必要になる。from_ops の防御的検証 エラーは実運用では到達しない想定(本モジュール冒頭「構築経路」参照) のため、各 variant を対応する ShapeError::ElementCountMismatch/ ShapeError::ElementCountOverflow へロスありで丸める(autodiff 側は Unsupported と区別さえできればよく、fail-safe な per-op フォールバック〈materialize_fallible〉へ委ねる設計とは独立に、この 変換自体は「型不変条件違反」を表す ShapeMismatch 系へ寄せる)。

Source§

fn from(err: FusionPlanError) -> BackendError

Converts to this type from the input type.
Source§

impl From<PadModeError> for BackendError

Source§

fn from(err: PadModeError) -> BackendError

Converts to this type from the input type.
Source§

impl From<StatReduceError> for BackendError

Source§

fn from(err: StatReduceError) -> BackendError

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V