clMathLibraries / clSPARSE

a software library containing Sparse functions written in OpenCL
Apache License 2.0
173 stars 60 forks source link

C# Wrapper #203

Closed TillAlex closed 7 years ago

TillAlex commented 7 years ago

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...

kknox commented 7 years ago

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

TillAlex commented 7 years ago

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.

kknox commented 7 years ago

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.

TillAlex commented 7 years ago

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...

TillAlex commented 7 years ago

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