我正在尝试在Metal上运行神经网络。
基本思想是数据复制。每个GPU线程为随机数据点运行一个版本的网络。
我已经编写了其他工作良好的着色器。
我还尝试在C++命令行应用程序中运行我的代码。那里没有错误。
我使用苹果文档将代码转换为Metal C ++,因为不支持来自C ++ 11的所有内容。
当它尝试将newComputePipelineStateWithFunction
分配给金属设备时,它在加载内核函数后崩溃。这意味着存在问题的代码在编译时未被捕获。
MCVE:
kernel void net(const device float *inputsVector [[ buffer(0) ]], // layout of net *
uint id [[ thread_position_in_grid ]]) {
uint floatSize = sizeof(tempFloat);
uint inputsVectorSize = sizeof(inputsVector) / floatSize;
float newArray[inputsVectorSize];
float test = inputsVector[id];
newArray[id] = test;
}
更新
这与动态数组有很大关系。
由于无法创建管线状态并且在实际着色器运行时不崩溃,因此必须是编码问题,而不是输入问题。
从动态数组中分配值到缓冲区会导致失败。