ImFusion C++ SDK 4.5.0
ImFusion::TorchUtils::AutocastScope Class Reference

#include <TorchPlugin/include/ImFusion/Torch/TorchUtils.h>

RAII helper for managing PyTorch autocast state across engines. More...

Detailed Description

RAII helper for managing PyTorch autocast state across engines.

Automatically enables autocast on construction and restores previous state on destruction.

Example usage:

{
TorchUtils::AutocastScope autocast(at::kCUDA, at::kBFloat16);
output = model.forward(input); // Runs under autocast
} // Autocast state automatically restored
RAII helper for managing PyTorch autocast state across engines.
Definition TorchUtils.h:167

Public Member Functions

 AutocastScope (c10::DeviceType device, c10::ScalarType dtype)
 Enable autocast with specified device and dtype.
 ~AutocastScope ()
 Restore previous autocast state.
 AutocastScope (const AutocastScope &)=delete
AutocastScopeoperator= (const AutocastScope &)=delete
 AutocastScope (AutocastScope &&)=delete
AutocastScopeoperator= (AutocastScope &&)=delete

Constructor & Destructor Documentation

◆ AutocastScope()

ImFusion::TorchUtils::AutocastScope::AutocastScope ( c10::DeviceType device,
c10::ScalarType dtype )

Enable autocast with specified device and dtype.

Parameters
deviceTarget device (at::kCUDA, at::kCPU, at::kMPS)
dtypeTarget dtype (at::kHalf for FP16, at::kBFloat16 for BF16)

The documentation for this class was generated from the following file:
  • TorchPlugin/include/ImFusion/Torch/TorchUtils.h
Search Tab / S to search, Esc to close