scikit-cuda icon indicating copy to clipboard operation
scikit-cuda copied to clipboard

cusparse.py is incomplete and won't import

Open brianthelion opened this issue 10 years ago • 7 comments

██ [ br@breach: scikits.cuda ] [ 19:38:38 ]
██ tail scikits/cuda/cusparse.py
                                            cusparseMatDescr,
                                            ctypes.c_void_p,
                                            ctypes.c_int,
                                            ctypes.c_void_p,
                                            ctypes.c_void_p,
                                            ctypes.c_void_p,
                                            ctypes.c_void_p]
def cusparseSdense2csr(handle, m, n, descrA, A, lda, 
                       nnzPerRow, csrValA, csrRowPtrA, csrColIndA):

brianthelion avatar Dec 19 '13 00:12 brianthelion

Sorry about the incomplete state of the cusparse wrappers; I'm in the process of rewriting them (and the other low-level NVIDIA library wrappers) using cffi (see the cffi branch of the source code).

lebedov avatar Jan 02 '14 22:01 lebedov

Hi @lebedov and @brianthelion.

I was recently in need of some CSR matrix-vector and matrix-matrix routines so I just wrapped these with CFFI last week, starting from the code that was in @lebedov's cffi branch, but was still testing it a bit before making a pull request. What I have so far is currently here: https://github.com/grlee77/scikits.cuda/tree/cusparse_cffi If you install scikits.cuda from that repository the cusparse python wrappers should get autogenerated the first time you import scikits.cuda.cusparse. There are some simple tests in tests/test_cusparse.py you can run to verify proper operation via nosetests test_cusparse.py at the terminal after installation.

There are many functions (>300 in CUDA v6.5!) so instead of trying to wrap them individually, I wrote a script to parse the cusparse_v2.h/cusparse.h header and autogenerate all the python wrappers for the interface. This process may not yet be robust across various platforms and library versions. I have only tested it with CUDA v6.5 on 64-bit linux, so it may still require a bit of tweaking for other versions/platforms.

I also implemented a higher level CSR object class and data type agnostic wrappers to some common functions such as csrmv and csrmm.

Here is a quick example using the CSR object interface:

One can make a cusparse CSR matrix, A_csr, from a numpy.ndarray, pycuda.gpuarray or scipy.sparse matrix A via:

handle = cusparseCreate()
A_csr = CSR.to_csr(A, handle)

and then multiply by a dense matrix, x on the gpu via:

y = A_csr.mv(x)

or multiple two CSR matrices A & B via

C = A_csr.gemm(B)

(under the hood .mv() will call the csrmv wrapper that selects between cusparseScsrmv, cusparseDcsrmv, cusparseCcsrmv, cusparseZcsrmv based on the input datatype.)

If you need to use BSR or HYB formats or any of the solver or preconditioner routines, for now you would have to use the lower level wrappers directly, which are all imported into the scikits.cuda.cusparse namespace, but have not yet been tested.

grlee77 avatar Dec 08 '14 16:12 grlee77

Hi, can I ask what the status of the cusparse wrappers is? I note they aren't covered in the documentation and I don't see objects to work with having installed from the main branch here.

Cheers

pearcemc avatar Jul 15 '15 15:07 pearcemc

The cusparse wrappers in the master branch are currently incomplete (and hence not listed in the docs), and I don't currently have time to transition the entire package to cffi. If there are specific missing cusparse functions that you need wrapped, feel free to mention them and I can add them.

lebedov avatar Jul 15 '15 18:07 lebedov

Hello @lebedov. I need cusparseSgtsv2StridedBatch and cusparseSgtsvInterleavedBatch wrapped (which probably also requires wrapping cusparseSgtsv2StridedBatch_bufferSizeExt): https://docs.nvidia.com/cuda/cusparse/index.html#gtsv2stridedbatch .

I expect these wouldn't be hard to wrap, because their arguments are actually just specially formatted dense matrices, so using them shouldn't depend on any other cuSPARSE functions. But I don't know where to start. Would you be able to wrap them quickly?

If you don't have the time, what's the best way for me to learn how to wrap them for skcuda? I see that, for example, s._libcusparse.cusparseDgtsv2StridedBatch is a well-defined function pointer. Is it as simple as defining restypes and argtypes? If so, is there a skcuda module that would be a best-practices example?

BTW: import skcuda.cusparse fails for me, at the import cuda line. There's no cuda. anywhere the module, so I assume this is an oversight. If I remove that line, I can import the module and run some of the simple functions within.

RyanGutenkunst avatar Apr 08 '20 23:04 RyanGutenkunst

Hi @RyanGutenkunst, I read your email on the pycuda mailing list and saw your message here. How about you open a new issue and we can discuss there? I haven't used cusparse.py but did (hand-)wrap a few functions for other skcuda modules before. Best, Kit

wingkitlee0 avatar Apr 09 '20 00:04 wingkitlee0

Hi @RyanGutenkunst, I read your email on the pycuda mailing list and saw your message here. How about you open a new issue and we can discuss there? I haven't used cusparse.py but did (hand-)wrap a few functions for other skcuda modules before. Best, Kit

Thanks Kit, Opened a new issue: #296 .

RyanGutenkunst avatar Apr 09 '20 01:04 RyanGutenkunst