Here I come with some trouble using managedCUDA,
I got an application written in CUDA C/C++ and I wanted to launch it using managedCUDA.
To begin with my problem : I got this error :
Ungandled Exception: System.ArgumentException: Object contains non-primitive or non-blittable data.
It occured on a line where I made a variable.CopyToDevice(otherVariable)
I search for what is non-primitive
and what is non-blittable
For non-primitive
I got :
non-primitive types (or) User Defined
Ex: class , struct , enum , interface, delegate, array.
For non-blittable
I got :
The following table lists* non-blittable types from the System namespace. >Delegates, which are data structures that refer to a static method or to a >class instance, are also non-blittable.
*table list : System.Array, System.Boolean, System.Char, System.Class, >System.Object, System.Mdarray, System.String, Systeme.Valuetype, Systeme.Szarray
So here is a sample of my code :
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);
}
}
}
The error did not shows up on the line : dev_prop.CopyToDevice(host_prop);
Seems that Global isn't the problem, neither the fact that Propagator is a struct
But on the line : dev_station.CopyToDevice(earthStation);
As you can see I did the "same" thing for both variables so, that's not how I proceed that cause the error. I'm guessing it come from EarthCoordinates struct that contain other struct object, and it may be this, that is the problem..
So, knowing I'm using managedCUDA and I can't really do as in CUDA C/C++, I don't have any idea how to solve this error.. So is there any way to make this work ?
Thanks to all !!
Ok so, after some digging, I figured out that the problem simply come from the boolean value... So I changed it into an int (0/false - 1/true) and the copy work again !