forked from huggingface/swift-coreml-diffusers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCapabilities.swift
48 lines (40 loc) · 1.22 KB
/
Capabilities.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Capabilities.swift
// Diffusion-macOS
//
// Created by Pedro Cuenca on 20/2/23.
// See LICENSE at https://github.com/huggingface/swift-coreml-diffusers/LICENSE
//
import Foundation
let runningOnMac = true
let deviceHas6GBOrMore = true
let deviceHas8GBOrMore = true
let BENCHMARK = false
let deviceSupportsQuantization = {
if #available(macOS 14, *) {
return true
} else {
return false
}
}()
#if canImport(MLCompute)
import MLCompute
let _hasANE = MLCDevice.ane() != nil
#else
let _hasANE = false
#endif
final class Capabilities {
static let hasANE = _hasANE
// According to my tests this is a good proxy to estimate whether CPU+GPU
// or CPU+NE works better. Things may become more complicated if we
// choose all compute units.
static var performanceCores: Int = {
var ncores: Int32 = 0
var bytes = MemoryLayout<Int32>.size
// In M1/M2 perflevel0 refers to the performance cores and perflevel1 are the efficiency cores
// In Intel there's only one performance level
let result = sysctlbyname("hw.perflevel0.physicalcpu", &ncores, &bytes, nil, 0)
guard result == 0 else { return 0 }
return Int(ncores)
}()
}