kunzmi / managedCuda

ManagedCUDA aims an easy integration of NVidia's CUDA in .net applications written in C#, Visual Basic or any other .net language.
Other
440 stars 79 forks source link

Moving towards Net Standard #41

Closed kaby76 closed 7 years ago

kaby76 commented 7 years ago

Is it possible to have ManagedCUDA target Net Standard, or to make some changes in the source so I can create a private build of ManagedCUDA that targeting Net Standard? I need a Net Standard library because my code is in Net Standard, and Net Framework libraries cannot link with Net Standard libs and apps.

I made some changes in a forked repository as a prototype ( https://github.com/kaby76/managedCuda ). (1) There's a dependency on serialization that I commented out, but it should be ifdef'ed. Unfortunately, Net Standard does not support binary serialization. (2) Array.LongLength is not supported in Net Standard either. I wrote an extension method that appears to work. I tested the changes and they work for me.

kunzmi commented 7 years ago

Hmm, that's not that simple to judge. Serialization is probably not that necessary in managedCuda but the guidelines are (for normal .net) to make exceptions serializable (e.g. for remoting). One can find arguments for both, to keep it and to remove it entirely. Ifdef every Cudalike-exception might be a solution if it doesn't make the code to messy. More challenging is the Array.LongLength property. In normal .net the internal size is stored with an int --> no issues here, but the mono framework supports also arrays larger than 2GB, hence the simple cast in your extension method would break this support on mono. And finally I found that, after googling a bit, all these interfaces are probably coming some day to .net Standard. If I got it right, serialization is already available (by extensions), and the LongLength property is already implemented but throws an exception. Might it come in future? I guess its not worth the effort if .net Standard will support the missing features in future.

kaby76 commented 7 years ago

True, ManagedCUDA would likely require no changes under Net Standard 2.0. Using VS2017.3/Net Standard/Core 2.0 Preview 1, I tested a simple example calling LongLength and it compiles fine. I hadn't tried serialization, but I suspect it would work, too. More importantly, while Net Standard 2.0 assemblies can reference any version of Net Framework, Net Framework 4 to 4.6 assemblies cannot reference Net Standard 2.0. I decided instead to write a SWIG-generated wrapper for the CUDA Driver API for my needs, compiled to Net Standard 1.1, which would be compatible with a few more Net Framework versions. Not sure if it’s all worth the effort, though. Regards, Ken.