gpt4 book ai didi

ios - Metal IOS 简单直通计算内核在 iphone 5s 上耗时 10 毫秒

转载 作者:行者123 更新时间:2023-12-01 15:58:39 24 4
gpt4 key购买 nike

我创建了简单的直通计算内核

kernel void filter(texture2d<float, access::read> inTexture [[texture(0)]],
texture2d<float, access::write> outTexture [[texture(1)]],
uint2 gridPos [[ thread_position_in_grid ]]) {
float4 color = inTexture.read(gridPos);
outTexture.write(color, gridPos);
}

测量执行时间
[self.timer start];
[commandBuffer commit];
[commandBuffer waitUntilCompleted];
CGFloat ms = [self.timer elapse];

Timer 类的工作方式如下:
- (void)start {
self.startMach = mach_absolute_time();
}

- (CGFloat)elapse {
uint64_t end = mach_absolute_time();
uint64_t elapsed = end - self.startMach;
uint64_t nanosecs = elapsed * self.info.numer / self.info.denom;
uint64_t millisecs = nanosecs / 1000000;

return millisecs;
}

dispatch 电话:
static const NSUInteger kGroupSize = 16;
- (MTLSize)threadGroupSize {
return MTLSizeMake(kGroupSize, kGroupSize, 1);
}

- (MTLSize)threadGroupsCount:(MTLSize)threadGroupSize {
return MTLSizeMake(self.provider.texture.width / kGroupSize,
self.provider.texture.height / kGroupSize, 1);
}

[commandEncoder dispatchThreadgroups:threadgroups
threadsPerThreadgroup:threadgroupSize];

在 512x512 rgba 图像上给我 13 毫秒的时间,如果我执行更多的传球,它会线性增长。

它是否正确?实时应用程序的开销似乎太大了。

最佳答案

众所周知,计算内核在 A7 处理器上具有相当高的开销。不过要考虑的一件事是,这基本上是您可以运行的最不讨人喜欢的测试:一次性线程组调度可能需要大约 2 毫秒才能被调度,但后续调度的调度可以快一个数量级。此外,延迟隐藏在这里的可能性很小。在实践中,一个更复杂的内核可能不会花费更长的时间来执行,如果你可以将它与你可能正在做的任何渲染交错,你可能会发现性能是可以接受的。

关于ios - Metal IOS 简单直通计算内核在 iphone 5s 上耗时 10 毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38360750/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com