fix: retain typed Vision compute device references
This commit is contained in:
1 parent
baa6cb22c9
commit
b22eaf9715
2 files changed
+7
-4
No files matched your search
@@ -13,10 +13,13 @@ print("Vision supported revisions: \(VNRecognizeTextRequest.supportedRevisions)"
|
||||
|
||||
func assignCPU(_ request: VNRecognizeTextRequest) throws {
|
||||
if #available(macOS 14.0, *) {
|
||||
let stages = try request.supportedComputeStageDevices()
|
||||
let stages = try request.supportedComputeStageDevices
|
||||
for (stage, devices) in stages {
|
||||
print("compute stage \(stage): \(devices)")
|
||||
if let cpu = devices.first(where: { $0 is MLCPUComputeDevice }) {
|
||||
if let cpu = devices.first(where: {
|
||||
if case .cpu(_) = $0 { return true }
|
||||
return false
|
||||
}) {
|
||||
request.setComputeDevice(cpu, for: stage)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,12 +129,12 @@ fn configure_cpu(request: &VNRecognizeTextRequest) -> Result<(), String> {
|
||||
.map_err(|error| format!("读取 OCR 计算设备失败: {error}"))?;
|
||||
let mut assigned = false;
|
||||
for stage in stages.allKeys().iter() {
|
||||
if let Some(devices) = stages.objectForKey(stage) {
|
||||
if let Some(devices) = stages.objectForKey(&stage) {
|
||||
if let Some(cpu) = devices
|
||||
.iter()
|
||||
.find(|device| device.isKindOfClass(MLCPUComputeDevice::class()))
|
||||
{
|
||||
request.setComputeDevice_forComputeStage(Some(cpu), stage);
|
||||
request.setComputeDevice_forComputeStage(Some(&cpu), &stage);
|
||||
assigned = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user