Ios 为什么我能';是否成功初始化MPS矩阵?

Ios 为什么我能';是否成功初始化MPS矩阵?,ios,objective-c,iphone,metal,metal-performance-shaders,Ios,Objective C,Iphone,Metal,Metal Performance Shaders,我想知道为什么我不能成功初始化MPSMatrix?对象方法initWith只返回一个nil(这意味着init失败)。我的代码如下所示,我想创建一个名为matrixA的MPSMatrix,但只得到一个nil id<MTLDevice> device = MTLCreateSystemDefaultDevice(); id<MTLCommandQueue> commandQueue = [device newCommandQueue]; id<MTLCommandBuf

我想知道为什么我不能成功初始化
MPSMatrix
?对象方法initWith只返回一个nil(这意味着init失败)。我的代码如下所示,我想创建一个名为matrixA的
MPSMatrix
,但只得到一个nil

id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<MTLCommandQueue> commandQueue = [device newCommandQueue];
id<MTLCommandBuffer> mpsBuffer = commandQueue.commandBuffer;
float arrayA[5*6] =
    {1,1,1,1,1,1,
     2,2,2,2,2,2,
     3,3,3,3,3,3,
     4,4,4,4,4,4,
     5,5,5,5,5,5};
float arrayB[6*5] =
    {1,1,1,1,1,
     2,2,2,2,2,
     3,3,3,3,3,
     4,4,4,4,4,
     5,5,5,5,5,
     6,6,6,6,6};
float arrayC[5*5] = {0};
id<MTLBuffer> bufferA = [device newBufferWithBytes:arrayA length:5*6*4 options:MTLResourceCPUCacheModeDefaultCache];
id<MTLBuffer> bufferB = [device newBufferWithBytes:arrayB length:6*5*4 options:MTLResourceCPUCacheModeDefaultCache];
id<MTLBuffer> bufferC = [device newBufferWithBytes:arrayC length:5*5*4 options:MTLResourceCPUCacheModeDefaultCache];

MPSMatrixDescriptor * descA = [MPSMatrixDescriptor matrixDescriptorWithDimensions:5 columns:6 rowBytes:6*4 dataType:MPSDataTypeFloat32];
MPSMatrixDescriptor * descB = [MPSMatrixDescriptor matrixDescriptorWithDimensions:6 columns:5 rowBytes:5*4 dataType:MPSDataTypeFloat32];
MPSMatrixDescriptor * descC = [MPSMatrixDescriptor matrixDescriptorWithDimensions:5 columns:5 rowBytes:5*4 dataType:MPSDataTypeFloat32];

MPSMatrix * matrixA = [[MPSMatrix alloc] initWithBuffer:bufferA descriptor:descA];
MPSMatrix * matrixB = [[MPSMatrix alloc] initWithBuffer:bufferB descriptor:descB];
MPSMatrix * matrixC = [[MPSMatrix alloc] initWithBuffer:bufferC descriptor:descC];
id device=MTLCreateSystemDefaultDevice();
id commandQueue=[device newCommandQueue];
id mpsBuffer=commandQueue.commandBuffer;
浮点数arrayA[5*6]=
{1,1,1,1,1,1,
2,2,2,2,2,2,
3,3,3,3,3,3,
4,4,4,4,4,4,
5,5,5,5,5,5};
浮动阵列B[6*5]=
{1,1,1,1,1,
2,2,2,2,2,
3,3,3,3,3,
4,4,4,4,4,
5,5,5,5,5,
6,6,6,6,6};
浮点数组[5*5]={0};
id bufferA=[device newBufferWithBytes:arrayA长度:5*6*4选项:MTLResourcePuccacheModeDefaultCache];
id bufferB=[设备newBufferWithBytes:arrayB长度:6*5*4选项:mtlResourcePuccacheModeDefaultCache];
id bufferC=[设备newBufferWithBytes:arrayC长度:5*5*4选项:mtlResourcePuccacheModeDefaultCache];
MPSMatrixDescriptor*descA=[MPSMatrixDescriptor MatrixDescriptor With Dimensions:5列:6行字节:6*4数据类型:MPSDataTypeFloat32];
MPSMatrixDescriptor*descB=[MPSMatrixDescriptor MatrixDescriptor with Dimensions:6列:5行字节:5*4数据类型:MPSDataTypeFloat32];
MPSMatrixDescriptor*descC=[MPSMatrixDescriptor MatrixDescriptor with Dimensions:5列:5行字节:5*4数据类型:MPSDataTypeFloat32];
MPSMatrix*matrixA=[[MPSMatrix alloc]initWithBuffer:bufferA描述符:descA];
MPSMatrix*matrixB=[[MPSMatrix alloc]initWithBuffer:bufferB描述符:descB];
MPSMatrix*matrixC=[[MPSMatrix alloc]initWithBuffer:bufferC描述符:descC];

<>代码> 我发现这是因为我调试的设备是5s,它只是部分支持金属性能着色器基础。它可以得到一个MPSMatrixDescriptor,但是它不能得到一个MPSMatrix。
叹息。

是。使用
MPSSupportsMTLDevice
确定MetalPerformanceShaders.framework是否支持MTL设备。事实上,我的iPadMini2也不支持MPS。详情如下:


要确定
MTL设备
是否支持MPS,可以调用
MPSSupportsMTL设备
功能。正如您所发现的,iphone5s的A7处理器不支持MPS。