-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
dbb9a21
commit 9d904b0
Showing
4 changed files
with
56 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,27 @@ | ||
from fastapi import APIRouter | ||
from gpustat import GPUStatCollection | ||
|
||
from app.api.v1.schemas.system import ( | ||
GpuInfoPayload, | ||
GpuInfosResponse, | ||
LibraryInfo, | ||
GpusInfoResponse, | ||
ServerInfoPayload, | ||
ServerInfoResponse, | ||
) | ||
from app.services.system import system_service | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/server-info", response_model=ServerInfoResponse) | ||
def get_server_info() -> ServerInfoResponse: | ||
installed_libraries = system_service.get_installed_libraries() | ||
|
||
server_info = ServerInfoPayload(installed_libraries=[LibraryInfo(name="netspresso", version="1.14.0")]) | ||
server_info = ServerInfoPayload(installed_libraries=installed_libraries) | ||
|
||
return ServerInfoResponse(data=server_info) | ||
|
||
|
||
@router.get("/gpu-info", response_model=GpuInfosResponse) | ||
def get_gpu_infos() -> GpuInfosResponse: | ||
|
||
stats = GPUStatCollection.new_query() | ||
|
||
gpu_infos = [ | ||
GpuInfoPayload( | ||
index=gpu.index, | ||
uuid=gpu.uuid, | ||
name=gpu.name, | ||
temperature_gpu=gpu.temperature, | ||
fan_speed=gpu.fan_speed, | ||
utilization_gpu=gpu.utilization, | ||
utilization_enc=gpu.utilization_enc, | ||
utilization_dec=gpu.utilization_dec, | ||
power_draw=gpu.power_draw, | ||
enforced_power_limit=gpu.power_limit, | ||
memory_used=gpu.memory_used, | ||
memory_total=gpu.memory_total, | ||
processes=list(gpu.processes), | ||
) | ||
for gpu in stats.gpus | ||
] | ||
|
||
return GpuInfosResponse(data=gpu_infos) | ||
@router.get("/gpus-info", response_model=GpusInfoResponse) | ||
def get_gpus_info() -> GpusInfoResponse: | ||
|
||
gpus_info = system_service.get_gpus_info() | ||
|
||
return GpusInfoResponse(data=gpus_info) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import List | ||
|
||
from gpustat import GPUStatCollection | ||
|
||
from app.api.v1.schemas.system import GpuInfoPayload, LibraryInfo | ||
from netspresso.clients.utils.system import get_package_version | ||
|
||
|
||
class SystemService: | ||
def get_installed_libraries(self) -> List[LibraryInfo]: | ||
LIBRARY_KEYS = ["netspresso"] | ||
|
||
installed_libraries = [ | ||
LibraryInfo(name=library_name, version=get_package_version(package_name=library_name)) | ||
for library_name in LIBRARY_KEYS | ||
] | ||
|
||
return installed_libraries | ||
|
||
def get_gpus_info(self) -> List[GpuInfoPayload]: | ||
stats = GPUStatCollection.new_query() | ||
|
||
gpus_info = [ | ||
GpuInfoPayload( | ||
index=gpu.index, | ||
uuid=gpu.uuid, | ||
name=gpu.name, | ||
temperature_gpu=gpu.temperature, | ||
fan_speed=gpu.fan_speed, | ||
utilization_gpu=gpu.utilization, | ||
utilization_enc=gpu.utilization_enc, | ||
utilization_dec=gpu.utilization_dec, | ||
power_draw=gpu.power_draw, | ||
enforced_power_limit=gpu.power_limit, | ||
memory_used=gpu.memory_used, | ||
memory_total=gpu.memory_total, | ||
processes=list(gpu.processes), | ||
) | ||
for gpu in stats.gpus | ||
] | ||
|
||
return gpus_info | ||
|
||
|
||
system_service = SystemService() |