import { CheckCircle2, Cpu, Loader2, RefreshCw, XCircle } from "lucide-react"; import { useEffect, useState } from "react"; import { toast } from "sonner"; import { AlertBlock } from "@/components/shared/alert-block"; import { DialogAction } from "@/components/shared/dialog-action"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { api } from "@/utils/api"; interface GPUSupportProps { serverId?: string; } export function GPUSupport({ serverId }: GPUSupportProps) { const [isLoading, setIsLoading] = useState(false); const [isRefreshing, setIsRefreshing] = useState(false); const utils = api.useContext(); const { data: gpuStatus, isLoading: isChecking, refetch, } = api.settings.checkGPUStatus.useQuery( { serverId }, { enabled: serverId !== undefined, }, ); const setupGPU = api.settings.setupGPU.useMutation({ onMutate: () => { setIsLoading(true); }, onSuccess: async () => { toast.success("GPU support enabled successfully"); setIsLoading(false); await utils.settings.checkGPUStatus.invalidate({ serverId }); }, onError: (error) => { toast.error( error.message || "Failed to enable GPU support. Please check server logs.", ); setIsLoading(false); }, }); const handleRefresh = async () => { setIsRefreshing(true); try { await utils.settings.checkGPUStatus.invalidate({ serverId }); await refetch(); } catch { toast.error("Failed to refresh GPU status"); } finally { setIsRefreshing(false); } }; useEffect(() => { handleRefresh(); }, []); const handleEnableGPU = async () => { if (serverId === undefined) { toast.error("No server selected"); return; } try { await setupGPU.mutateAsync({ serverId }); } catch { // Error handling is done in mutation's onError } }; return (
GPU Configuration
Configure and monitor GPU support
System Requirements:
  • NVIDIA GPU hardware must be physically installed
  • NVIDIA drivers must be installed and running (check with nvidia-smi)
  • NVIDIA Container Runtime must be installed (nvidia-container-runtime)
  • User must have sudo/administrative privileges
  • System must support CUDA for GPU acceleration
{isChecking ? (
Checking GPU status...
) : (
{/* Prerequisites Section */}

Prerequisites

Shows all software checks and available hardware

{/* Configuration Status */}

Docker Swarm GPU Status

Shows the configuration state that changes with the Enable GPU

)}
); } interface StatusRowProps { label: string; isEnabled?: boolean; description?: string; value?: string | number; showIcon?: boolean; } export function StatusRow({ label, isEnabled, description, value, showIcon = true, }: StatusRowProps) { return (
{label}
{showIcon ? ( <> {description || (isEnabled ? "Installed" : "Not Installed")} {isEnabled ? ( ) : ( )} ) : ( {value} )}
); }