c# - Passing an array within a structure in CUDAfy -


using vs 2012, .net 4.5, 64bit , cudafy 1.12 , have following proof of concept

using system; using system.runtime.interopservices; using cudafy; using cudafy.host; using cudafy.translator;  namespace test { [cudafy(ecudafytype.struct)] [structlayout(layoutkind.sequential)] public struct childstruct {     [marshalas(unmanagedtype.lparray)]     public float[] farray;     public long farraylength; }  [cudafy(ecudafytype.struct)] [structlayout(layoutkind.sequential)] public struct parentstruct {     public childstruct child; }  public class program {     [cudafy]     public static void kernelfunction(gthread gthread, parentstruct parent)     {         long length = parent.child.farraylength;     }      public static void main(string[] args)     {         var module = cudafytranslator.cudafy(           eplatform.x64, earchitecture.sm_35,           new[] {typeof(childstruct), typeof(parentstruct), typeof(program)});         var dev = cudafyhost.getdevice();         dev.loadmodule(module);          float[] hostfloat = new float[10];         (int = 0; < hostfloat.length; i++) { hostfloat[i] = i; }          parentstruct parent = new parentstruct         {             child = new childstruct             {                 farray = dev.allocate(hostfloat),                 farraylength = hostfloat.length             }         };          dev.launch(1, 1, kernelfunction, parent);          console.readline();     } } } 

when program runs, getting following error on dev.launch:

type 'test.parentstruct' cannot marshaled unmanaged structure; no meaningful size or offset can computed.

if remove float array childstruct, works expected.

having worked in c/c++/cli , cuda c in past, aware of nature of error. solutions error suggest setting struct size manually using size parameter of marshalas, not possible due variety of types within struct.

i looked @ generated .cu file , generating float array float * expected.

is there way pass array within struct kernel? , if there isn't best second alternative? problem doesn't exist in cuda c , exists because marshaling clr.

i spent time reading source code of cudafy see if there solution problem.

cudafy trying make things simple .net developers , shield them away intptr , other pointer concepts. however, level of abstraction makes hard think of answer problem without major refactor way library works.

not being able send float array within struct show stopper. ended doing pinvoke cuda runtime , not using cudafy.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -