numba / numba/pyculib

Problem setting matrixtype in pyculib.sparse.Sparse.matdescr

Open
#25 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
99
Forks
11
PR merge metrics
No merged PRs in 30d

Description

I have a problem with the matrix descriptor class, when giving parameters different from default ones :

``` python
>>> import pyculib
>>> handle = pyculib.sparse.Sparse()
>>> handle

>>> descr = handle.matdescr()
>>> descr.matrixtype
'G'
>>> descrS = handle.matdescr(matrixtype='S')
>>> descrS.matrixtype
Traceback (most recent call last):
File "", line 1, in
File "~/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/sparse/binding.py", line 201, in matrixtype
return MATRIXTYPECHAR[self._api.cusparseGetMatType(self._handle)]
File "~/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/utils/libutils.py", line 48, in wrapped
self.check_error(status)
File "~/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/utils/libutils.py", line 54, in check_error
raise self.ErrorType(status)
pyculib.sparse.binding.CuSparseError: CUSPARSE_STATUS_NOT_INITIALIZED

>>> descrT = handle.matdescr(matrixtype='T')
>>> descrT.matrixtype
Traceback (most recent call last):
File "", line 1, in
File "/home/matthieu/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/sparse/binding.py", line 201, in matrixtype
return MATRIXTYPECHAR[self._api.cusparseGetMatType(self._handle)]
File "/home/matthieu/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/utils/libutils.py", line 48, in wrapped
self.check_error(status)
File "/home/matthieu/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/utils/libutils.py", line 54, in check_error
raise self.ErrorType(status)
pyculib.sparse.binding.CuSparseError: CUSPARSE_STATUS_INVALID_VALUE

>>> descrH = handle.matdescr(matrixtype='H')
>>> descrH.matrixtype
Traceback (most recent call last):
File "", line 1, in
File "/home/matthieu/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/sparse/binding.py", line 201, in matrixtype
return MATRIXTYPECHAR[self._api.cusparseGetMatType(self._handle)]
File "/home/matthieu/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/utils/libutils.py", line 48, in wrapped
self.check_error(status)
File "/home/matthieu/anaconda3/envs/OTML/lib/python3.6/site-packages/pyculib/utils/libutils.py", line 54, in check_error
raise self.ErrorType(status)
pyculib.sparse.binding.CuSparseError: CUSPARSE_STATUS_ALLOC_FAILED

```

Any ideas of what could be happening ? I tried to debug it, but the function that returns the error is `self._api.cusparseGetMatType` and I can't access inside.

Other than that, I am also confused by the [matrix descriptor](https://docs.nvidia.com/cuda/cusparse/index.html#cusparsematrixtypet) documentation in CUDA. The text says:

> This type indicates the type of matrix stored in sparse storage. Notice that for symmetric, Hermitian and triangular matrices only their lower or upper part is assumed to be stored.
>
> The whole idea of matrix type and fill mode is to keep minimum storage for symmetric/Hermitian matrix, and also to take advantage of symmetric property on SpMV (Sparse Matrix Vector multiplication). To compute y=A\*x when A is symmetric and only lower triangular part is stored, two steps are needed. First step is to compute y=(L+D)\*x and second step is to compute y=L^T\*x + y. Given the fact that the transpose operation y=L^T\*x is 10x slower than non-transpose version y=L\*x, the symmetric property does not show up any performance gain. It is better for the user to extend the symmetric matrix to a general matrix and apply y=A\*x with matrix type CUSPARSE_MATRIX_TYPE_GENERAL.

Does that mean I should just use the General matrix type even if my matrix is symmetric ? But then why say that `The whole idea of matrix type and fill mode is to keep minimum storage for symmetric/Hermitian matrix, **and also to take advantage of symmetric property on SpMV**` ?

I know that this might be more a CUDA question than a pyculib, but maybe someone has the answer...

My config:

CUDA 8.0
Ubuntu 16.04
pyculib 1.0.2+2.g7ae9662
```
$ conda info
active environment : None
...
conda version : 4.5.12
conda-build version : 3.0.27
python version : 3.6.8.final.0
...
platform : linux-64
user-agent : conda/4.5.12 requests/2.18.4 CPython/3.6.8 Linux/4.4.0-141-generic ubuntu/16.04 glibc/2.23
UID:GID : 1000:1000
netrc file : None
offline mode : False
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with pyculib/sparse/binding.py, especially matdescr and the matrixtype property, then inspect error handling in pyculib/utils/libutils.py. Reproduce the descriptor calls with the reported CUDA 8.0 configuration and compare each requested matrix type with the CUDA API's accepted values; done means valid types behave consistently and invalid requests return an understandable result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.