diff options
| author | anatawa12 <anatawa12@icloud.com> | 2025-01-14 19:36:35 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-14 10:36:35 +0000 |
| commit | 6820878676f5f531bc596076ed5c5ea022051631 (patch) | |
| tree | 26c9b7e4ef768a13f0073fcf724d6b79bad95ad3 /packages/backend/src/core/AiService.ts | |
| parent | fix(frontend): コンポーネントのインポート忘れ (#15274) (diff) | |
| download | misskey-6820878676f5f531bc596076ed5c5ea022051631.tar.gz misskey-6820878676f5f531bc596076ed5c5ea022051631.tar.bz2 misskey-6820878676f5f531bc596076ed5c5ea022051631.zip | |
fix: unable to use AiService on arm64 (#15261)
Diffstat (limited to 'packages/backend/src/core/AiService.ts')
| -rw-r--r-- | packages/backend/src/core/AiService.ts | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/backend/src/core/AiService.ts b/packages/backend/src/core/AiService.ts index ad852fdd6e..33ddabb5e0 100644 --- a/packages/backend/src/core/AiService.ts +++ b/packages/backend/src/core/AiService.ts @@ -15,7 +15,7 @@ import { bindThis } from '@/decorators.js'; const _filename = fileURLToPath(import.meta.url); const _dirname = dirname(_filename); -const REQUIRED_CPU_FLAGS = ['avx2', 'fma']; +const REQUIRED_CPU_FLAGS_X64 = ['avx2', 'fma']; let isSupportedCpu: undefined | boolean = undefined; @Injectable() @@ -31,8 +31,7 @@ export class AiService { public async detectSensitive(path: string): Promise<nsfw.predictionType[] | null> { try { if (isSupportedCpu === undefined) { - const cpuFlags = await this.getCpuFlags(); - isSupportedCpu = REQUIRED_CPU_FLAGS.every(required => cpuFlags.includes(required)); + isSupportedCpu = await this.computeIsSupportedCpu(); } if (!isSupportedCpu) { @@ -64,6 +63,22 @@ export class AiService { } } + private async computeIsSupportedCpu(): Promise<boolean> { + switch (process.arch) { + case 'x64': { + const cpuFlags = await this.getCpuFlags(); + return REQUIRED_CPU_FLAGS_X64.every(required => cpuFlags.includes(required)); + } + case 'arm64': { + // As far as I know, no required CPU flags for ARM64. + return true; + } + default: { + return false; + } + } + } + @bindThis private async getCpuFlags(): Promise<string[]> { const str = await si.cpuFlags(); |