我在将包含多个数组的结构分配给 GPU 时遇到了一些问题。在第二个代码块中,我遇到以下错误:
SimpleDataStructure[] dev_SDS = _gpu.CopyToDevice(SDS);
有谁知道为什么?从我可以看到 CopyToDevice() 不支持将结构作为参数。我可能会遗漏一些东西,所以无论如何我都会感谢一些帮助。
结构声明:
[Cudafy]
public struct SimpleDataStructure
{
public float[] AreaCode;
public float[] Number;
public SimpleDataStructure(int x)
{
AreaCode = new float[x];
Number = new float[x];
}
}
在我的类中的方法中编写代码:
Public class TaskManager
{
private static GPGPU _gpu;
private SimpleDataStructure SDS;
public void PreparationForTasks()
{
DataRetrieval();
SDS = new SimpleDataStructure(_entity.Data.Count - 1);
CudafyModule km = CudafyTranslator.Cudafy();
_gpu = CudafyHost.GetDevice(eGPUType.Cuda);
_gpu.LoadModule(km);
//Loaded SimpleDataStructure into same module.
km = CudafyTranslator.Cudafy(typeof(SimpleDataStructure));
_gpu.LoadModule(km, false);
//Getting error on following line.
SimpleDataStructure[] dev_SDS = _gpu.CopyToDevice(SDS);
dim3 grid = new dim3(10, 10, 1);
dim3 block = new dim3(8, 8, 1);
_gpu.Launch(grid, block, "WorkerKernelOnGPU", dev_SDS);
SimpleDataStructure result_SDS = new SimpleDataStructure(100);
_gpu.CopyFromDevice(dev_SDS, result_SDS);
}
//.....
}