C# Wrapper
TillAlex opened this issue · 5 comments
Did anyone successfuly wrap clSparse for C#? I'm just trying to but I'm constantly getting SEHExceptions for some functions (e.g. clsparseSdense2csr), while others work ok (e.g. clsparseSnrm2).
My feeling is that my C# definition of some of the APIs structs differ in padding/alignment from their c counterparts. Perhaps anyone can tell me what is the size of clsparseCsrMatrix and cldenseMatrix structs in c...
I have never attempted to create a wrapper for clsparse, so I am interested in your experiences. I don't know the size of the structs offhand, but you can find their definitions here
More and more functions are working now, but still some are crashing. One problem about wrapping c structs is that you have to know their exact layout. I can't see it from their definitions... It would be very helpful to know the result of sizeof for these structs to know if they are tightly packed or not. If their size does not match the sum of their components wrapping is a bit more complicated.
I think the layout of structs are dependent on the compiler used to compile the library. I don't think i can give you a definitive answer. What you can try to do is to compile the sample-spmv sample and put in a few sizeof() operators to get the answer for your compiler. These structs are meant to be POD types.
It seems that struct sizes are not the problem. At least all functions not using Coo matrices work now... I'll see if I can find the reason...
One more thing:
I'm using clBLAS, clFFT and clSparse from C# and created wrappers for those three. The clFFT part covers almost the complete API, while the clBLAS and clSparse only cover the basic initialization, teardown and some of the math functions. I do not have the time to publish this work myself, but if anybody is interested in open maintining a wrapper project or using my code I'm willing to share it...
I found that the crashes I was experiencing were coming from the library itself and were not connected to the wrapper itself. Therefor, I will close this issue now.
If anybody is interested in the .NET wrapper the code can be found here:
https://github.com/clSharp/clMathLibraries-dotnet