我正在将计算模型从Cuda转换为Metal。
我正在尝试从内核函数传递给函数的一些全局结构数组。
我收到以下错误:
- 候选函数不可行:第二个参数没有从'float3 device [32]'到'float3 *'(aka'vector_float3 *')的已知转换
对于testFunction。
这是示例代码:
#include <metal_stdlib>
using namespace metal;
struct DOBJ
{
int num_vertex; /* Number of vertcies */
float3 vert [32]; /* Rotated on CPU */
};
bool testFunction(
uint num_vertex_B,
float3 Vertex_B[32])
{
}
kernel void TestKernel( device DOBJ *VolumeObject )
{
int d_index = 5;
bool SP_Check = testFunction(
VolumeObject[d_index].num_vertex,
VolumeObject[d_index].vert );
}
Run Code Online (Sandbox Code Playgroud)
CUDA testFunction的原始格式具有以下格式:
__device__ bool testFunction(
uint num_vertex_B,
float3 *Vertex_B)
{
}
Run Code Online (Sandbox Code Playgroud)
我在程序中有大量遵循此结构的代码。如何正确格式化testFunction以接受Vertex_B?
在warrenm的评论之后,还有更多测试代码
float3 Vertex_B [5]为线程存储器而不是设备存储器编译。
#include <metal_stdlib>
using namespace metal;
struct DOBJ
{
int num_vertex; /* Number of vertcies */
float3 vert [32]; /* Rotated on CPU */
};
bool testFunction(uint num_vertex_B, device float3 *Vertex_B) { return false; }
bool testFunction(uint num_vertex_B, thread float3 *Vertex_B) { return false; }
bool testFunction2( uint num_vertex_B, float3 Vertex_B[5]) { return false; }
kernel void VolumeObject_InteractionPolyhedra( device DOBJ *VolumeObject )
{
int d_index = 5;
bool SP_Check = testFunction( VolumeObject[d_index].num_vertex, VolumeObject[d_index].vert);
// Compiler error: 1. Candidate function not viable: no known conversion from 'float3 device[32]' to 'float3 *' (aka 'vector_float3 *') for 2nd argument
// bool SP_Check2 = testFunction2( VolumeObject[d_index].num_vertex, VolumeObject[d_index].vert);
thread float3 *vertList;
bool SP_Check3 = testFunction( 5, vertList);
bool SP_Check4 = testFunction2( 5, vertList);
}
Run Code Online (Sandbox Code Playgroud)无法使用C或C ++(金属阴影语言是方言)中的值传递数组。但是,您的函数可以采用指向数组的指针参数,只要指针与原始缓冲区位于相同的地址空间中即可:
bool testFunction(uint num_vertex_B, device float3 *Vertex_B)
{
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
294 次 |
| 最近记录: |