Skip to content

Commit

Permalink
fix: add compatible check
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Mar 14, 2024
1 parent 6313ad3 commit 0f11ce2
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions web/screens/Settings/CoreExtensions/TensorRtExtensionItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { useCallback, useEffect, useState } from 'react'

import { Compatibility, InstallationState, abortDownload } from '@janhq/core'
import {
Compatibility,
GpuSetting,
InstallationState,
abortDownload,
systemInformations,
} from '@janhq/core'
import {
Button,
Progress,
Expand Down Expand Up @@ -31,6 +37,7 @@ const TensorRtExtensionItem: React.FC<Props> = ({ item }) => {
const [installState, setInstallState] =
useState<InstallationState>('NotRequired')
const installingExtensions = useAtomValue(installingExtensionAtom)
const [isGpuSupported, setIsGpuSupported] = useState<boolean>(false)

const isInstalling = installingExtensions.some(
(e) => e.extensionId === item.name
Expand All @@ -41,6 +48,32 @@ const TensorRtExtensionItem: React.FC<Props> = ({ item }) => {
?.percentage ?? -1
: -1

useEffect(() => {
const getSystemInfos = async () => {
const info = await systemInformations()
if (!info) {
setIsGpuSupported(false)
return
}

const gpuSettings: GpuSetting | undefined = info.gpuSetting
if (!gpuSettings || gpuSettings.gpus.length === 0) {
setIsGpuSupported(false)
return
}

const arch = gpuSettings.gpus[0].arch
if (!arch) {
setIsGpuSupported(false)
return
}

const supportedGpuArch = ['turing', 'ampere', 'ada']
setIsGpuSupported(supportedGpuArch.includes(arch))
}
getSystemInfos()
}, [])

useEffect(() => {
const getExtensionInstallationState = async () => {
const extension = extensionManager.get(item.name ?? '')
Expand Down Expand Up @@ -92,7 +125,8 @@ const TensorRtExtensionItem: React.FC<Props> = ({ item }) => {
{item.description}
</p>
</div>
{!compatibility || compatibility['platform']?.includes('win32') ? (
{(!compatibility || compatibility['platform']?.includes(PLATFORM)) &&
isGpuSupported ? (
<InstallStateIndicator
installProgress={progress}
installState={installState}
Expand All @@ -109,18 +143,25 @@ const TensorRtExtensionItem: React.FC<Props> = ({ item }) => {
</TooltipTrigger>
<TooltipPortal>
<TooltipContent side="top">
<span>
Only available on{' '}
{compatibility.platform
?.map((e: string) =>
e === 'win32'
? 'Windows'
: e === 'linux'
? 'Linux'
: 'MacOS'
)
.join(', ')}
</span>
{compatibility ? (
<span>
Only available on{' '}
{compatibility?.platform
?.map((e: string) =>
e === 'win32'
? 'Windows'
: e === 'linux'
? 'Linux'
: 'MacOS'
)
.join(', ')}
</span>
) : (
<span>
{' '}
Your GPUs do not support to run this extension.{' '}
</span>
)}
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
Expand Down

0 comments on commit 0f11ce2

Please sign in to comment.