在这里,我在使用 managedCUDA 时遇到了一些麻烦,
我有一个用 CUDA C/C++ 编写的应用程序,我想使用 managedCUDA 启动它。
从我的问题开始:我收到此错误:
Ungandled 异常:System.ArgumentException:对象包含非原始或非 blittable 数据。
它发生在我做了一个variable.CopyToDevice(otherVariable)
我寻找什么是non-primitive
什么,什么是non-blittable
因为non-primitive
我得到了:
非原始类型(或)用户定义
例如:类、结构、枚举、接口、委托、数组。
因为non-blittable
我得到了:
下表列出了 System 命名空间中的*非 blittable 类型。> 委托,它们是引用静态方法或 > 类实例的数据结构,也是不可 blittable 的。
*表列表:System.Array、System.Boolean、System.Char、System.Class、>System.Object、System.Mdarray、System.String、Systeme.Valuetype、Systeme.Szarray
所以这是我的代码示例:
using ManagedCuda;
using ManagedCuda.BasicTypes;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace Code
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
struct Cartesian
{
// all in is public
/* some double and Global variables */
/* some function (Cartesian, void, double, LatLonAlt type) */
}
[StructLayout(LayoutKind.Sequential)]
struct LatLonAlt
{
// all in is public
/* some double, Cartesian and Global variables */
/* some function (LatLonAlt, void, Cartesian type) */
}
[StructLayout(LayoutKind.Sequential)]
struct Global
{
/* some function (double, Cartesian, int, void type) */
}
[StructLayout(LayoutKind.Sequential)]
struct Propagator
{
// all in is public
/* some double, int and Global variables */
/* some function (void, Cartesian, double type) */
}
[StructLayout(LayoutKind.Sequential)]
struct EarthCoordinates
{
// all in is publis
/* some Cartesian, double, LatLonAlt, bool and Global variables */
/* one EarthCoordinates "constructor" and one Cartesian function */
}
static void Main(string[] args)
{
Propagator[] host_prop = new Propagator[180];
initPropagator(ref host_prop);
CudaDeviceVariable<Propagator> dev_prop = new CudaDeviceVariable<Propagator>(180);
dev_prop.CopyToDevice(host_prop);
EarthCoordinates[] earthStation = new EarthCoordinates[1];
initEarthCoordinates(ref earthStation);
CudaDeviceVariable<EarthCoordinates> dev_station = new CudaDeviceVariable<EarthCoordinates>(1);
dev_station.CopyToDevice(earthStation);
}
}
}
该错误未显示在行上:dev_prop.CopyToDevice(host_prop);
似乎 Global 不是问题,也不是 Propagator 是一个结构的事实
但是就行了:dev_station.CopyToDevice(earthStation);
如您所见,我对两个变量都做了“相同”的事情,所以这不是我进行导致错误的方式。我猜它来自包含其他结构对象的 EarthCoordinates 结构,可能是这个,这就是问题所在。
所以,知道我正在使用 managedCUDA 并且我不能像在 CUDA C/C++ 中那样做,我不知道如何解决这个错误。那么有什么办法可以让这个工作?
谢谢大家 !!