diff --git a/src/controller/abstractServiceController.ts b/src/controller/abstractServiceController.ts index 8c09d9f0..b3e1b3bb 100644 --- a/src/controller/abstractServiceController.ts +++ b/src/controller/abstractServiceController.ts @@ -1,4 +1,4 @@ -import type { Service } from "../modules/service/types"; +import type { GPUStats, Service } from "../modules/service/types"; import type { Registry } from "../modules/settings/types"; import type { Interface } from "../shared/helpers/interfaces"; @@ -21,7 +21,7 @@ abstract class AbstractServiceController { abstract getLogs(serviceId: string): Promise; abstract getServiceStats(serviceId: string): Promise>; abstract getSystemStats(): Promise>; - abstract getGPUStats(): Promise>; + abstract getGPUStats(): Promise; abstract getInterfaces(): Promise; abstract addService(service: Service): Promise; abstract addRegistry(registry: Registry): Promise; diff --git a/src/controller/binariesController.ts b/src/controller/binariesController.ts index 46dfd8de..a434c877 100644 --- a/src/controller/binariesController.ts +++ b/src/controller/binariesController.ts @@ -1,7 +1,7 @@ import { invoke } from "@tauri-apps/api/tauri"; import type { Registry } from "modules/settings/types"; -import type { Service, ServiceBinary } from "../modules/service/types"; +import type { GPUStats, Service, ServiceBinary } from "../modules/service/types"; import type { Interface } from "../shared/helpers/interfaces"; import interfaces from "../shared/helpers/interfaces"; @@ -59,8 +59,8 @@ class BinariesController extends AbstractServiceController { return await invoke("get_logs_for_service", { serviceId }); } - async getGPUStats(): Promise> { - return await invoke>("get_gpu_stats"); + async getGPUStats(): Promise { + return await invoke("get_gpu_stats"); } async getServiceStats(serviceId: string): Promise> { diff --git a/src/controller/dockerController.ts b/src/controller/dockerController.ts index fd0aa663..d99f50c9 100644 --- a/src/controller/dockerController.ts +++ b/src/controller/dockerController.ts @@ -1,7 +1,7 @@ import type { Registry } from "modules/settings/types"; import downloadServiceStream from "../modules/service/api/downloadServiceStream"; -import type { Service, ServiceDocker } from "../modules/service/types"; +import type { GPUStats, Service, ServiceDocker } from "../modules/service/types"; import api from "../shared/api/v1"; import type { Interface } from "../shared/helpers/interfaces"; import useSettingStore from "../shared/store/setting"; @@ -83,7 +83,7 @@ class DockerController extends AbstractServiceController { return response.data; } - async getGPUStats(): Promise> { + async getGPUStats(): Promise { const response = await api().get("v1/gpu-stats-all/"); return response.data; } diff --git a/src/controller/serviceController.ts b/src/controller/serviceController.ts index aaa3a9d6..3ac720e5 100644 --- a/src/controller/serviceController.ts +++ b/src/controller/serviceController.ts @@ -1,4 +1,4 @@ -import type { Service } from "../modules/service/types"; +import type { GPUStats, Service } from "../modules/service/types"; import type { Registry } from "../modules/settings/types"; import type { Interface } from "../shared/helpers/interfaces"; import useSettingStore from "../shared/store/setting"; @@ -31,7 +31,7 @@ interface IServiceController { getLogs(serviceId: string, serviceType: Service["serviceType"]): Promise; getServiceStats(serviceId: string, serviceType: Service["serviceType"]): Promise; getSystemStats(serviceType: Service["serviceType"]): Promise; - getGPUStats(serviceType: Service["serviceType"]): Promise; + getGPUStats(serviceType: Service["serviceType"]): Promise; getInterfaces(serviceType: Service["serviceType"]): Promise; addService(service: Service, serviceType: Service["serviceType"]): Promise; addRegistry(registry: Registry, serviceType: Service["serviceType"]): Promise; @@ -182,15 +182,14 @@ class ServiceController implements IServiceController { return {}; } } - - async getGPUStats(serviceType: Service["serviceType"]): Promise> { + async getGPUStats(serviceType: Service["serviceType"]): Promise { // We check the env (browser or desktop) to determine serviceType if (serviceType === "docker") { return await this.dockerController.getGPUStats(); } else if (serviceType === "binary") { return await this.binariesController.getGPUStats(); } else { - return {}; + return {} as GPUStats; } } diff --git a/src/modules/service/types.ts b/src/modules/service/types.ts index 0d219885..159418cf 100644 --- a/src/modules/service/types.ts +++ b/src/modules/service/types.ts @@ -81,12 +81,24 @@ export type Stats = { storage_percentage: number; }; +type GPUInfos = { + gpu_name: string; + total_memory: number; + used_memory: number; + free_memory: number; + utilised_memory: number; + load: number; +}; + export type GPUStats = { - gpu_name: string | null; total_memory: number | null; used_memory: number | null; - memory_percentage: number | null; + free_memory: number | null; + average_utilised_memory: number | null; + average_load: number | null; + gpus: GPUInfos[]; }; + export type Message = { message: string; }; diff --git a/src/modules/settings/components/GPUResources.tsx b/src/modules/settings/components/GPUResources.tsx index 7da8b442..b522cc71 100644 --- a/src/modules/settings/components/GPUResources.tsx +++ b/src/modules/settings/components/GPUResources.tsx @@ -3,40 +3,41 @@ import useGPUStats from "shared/hooks/useGPUStats"; const GPUResources = () => { const { data } = useGPUStats(); + return ( <>

GPUs

- {data?.gpu_name ? ( -
-
- nvidia-logo -
-
-

{data.gpu_name}

-
    -
  • -
    - Memory  - - {data.used_memory} / {data.total_memory} GiB - -
    -
    -
    -
    -
  • -
+ {data?.gpus?.map((gpu) => { + return ( +
+
+ nvidia-logo +
+
+

{gpu.gpu_name}

+
    +
  • +
    + Memory  + + {gpu.used_memory} / {gpu.total_memory} GiB + +
    +
    +
    +
    +
  • +
+
-
- ) : ( -

No GPUs available

- )} + ); + }) ??

No GPUs available

}
);