Implement proper hardware compatibility patterns when working with different GPU backends and AI frameworks. Many AI applications need to support multiple hardware platforms (NVIDIA CUDA, AMD ROCm, Intel XPU, Moore Threads, DirectML, ZLUDA) which have different capabilities and limitations.
Implement proper hardware compatibility patterns when working with different GPU backends and AI frameworks. Many AI applications need to support multiple hardware platforms (NVIDIA CUDA, AMD ROCm, Intel XPU, Moore Threads, DirectML, ZLUDA) which have different capabilities and limitations.
Key practices:
Example implementation:
# Device-specific handling with fallbacks
if image.device.type == 'musa':
# Moore Threads GPU doesn't support bicubic with antialias
image = image.cpu()
image = torch.nn.functional.interpolate(image, size=scale_size, mode="bicubic", antialias=True)
image = image.to('musa')
else:
image = torch.nn.functional.interpolate(image, size=scale_size, mode="bicubic", antialias=True)
# Hardware detection with specific optimizations
if "[ZLUDA]" in torch_device_name:
torch.backends.cudnn.enabled = False
torch.backends.cuda.enable_flash_sdp(False)
torch.backends.cuda.enable_math_sdp(True)
torch.backends.cuda.enable_mem_efficient_sdp(False)
# DirectML-specific tensor operations
if comfy.model_management.is_directml_enabled():
latents_ubyte = latents_ubyte.to(dtype=torch.uint8)
latents_ubyte = latents_ubyte.to(device="cpu", dtype=torch.uint8, non_blocking=...)
This approach ensures AI applications work reliably across different hardware while taking advantage of platform-specific optimizations where available.
Enter the URL of a public GitHub repository