cupy / cupy

NumPy & SciPy for GPU
https://cupy.dev
MIT License
9.37k stars 843 forks source link

Sparse matrix creation via `(data, (row, col))` constructor incurs synchronization #5813

Open kmaehashi opened 3 years ago

kmaehashi commented 3 years ago

https://jenkins.preferred.jp/job/chainer/job/cupy_stable/TEST=cupy-py36,label=mn1-p100/691/testReport/junit/tests.cupy_tests.test_cusparse/TestSparseMatrixConversion/test_denseToSparse__param_17__density_0_5__format__coo___shape__4__3___/

tests.cupy_tests.test_cusparse.TestSparseMatrixConversion.test_denseToSparse[_param_17_{density=0.5, format='coo', shape=(4, 3)}] (from pytest)

Error message:

OverflowError: Python int too large to convert to C long

Stacktrace:

self = <<cupy_tests.test_cusparse.TestSparseMatrixConversion object at 0x7fe0000a0b00>  parameter: {'density': 0.5, 'format': 'coo', 'shape': (4, 3)}>
dtype = <class 'numpy.float32'>

    @testing.for_dtypes('fdFD')
    def test_denseToSparse(self, dtype):
        if not cusparse.check_availability('denseToSparse'):
            pytest.skip('denseToSparse is not available')
        x = cupy.random.uniform(0, 1, self.shape).astype(dtype)
        x[x < self.density] = 0
>       y = cusparse.denseToSparse(x, format=self.format)

dtype      = <class 'numpy.float32'>
self       = <<cupy_tests.test_cusparse.TestSparseMatrixConversion object at 0x7fe0000a0b00>  parameter: {'density': 0.5, 'format': 'coo', 'shape': (4, 3)}>
x          = array([[0.       , 0.       , 0.       ],
       [0.       , 0.       , 0.       ],
       [0.       , 0.       , 0.       ],
       [0.6650874, 0.       , 0.       ]], dtype=float32)

cupy_tests/test_cusparse.py:856: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/home/user/.local/lib/python3.6/site-packages/cupy/cusparse.py:1691: in denseToSparse
    y = cupyx.scipy.sparse.coo_matrix((data, (row, col)), shape=x.shape)
        algo       = 0
        buff       = array([0, 0, 0, ..., 2, 0, 0], dtype=int8)
        buff_size  = 1563
        col        = array([0], dtype=int32)
        data       = array([-2.4840681e+33], dtype=float32)
        desc_x     = <cupy.cusparse.DnMatDescriptor object at 0x7fe0000a0080>
        desc_y     = <cupy.cusparse.SpMatDescriptor object at 0x7fe0000a0278>
        format     = 'coo'
        handle     = 996993600
        nnz        = 1
        num_cols_tmp = array(3)
        num_rows_tmp = array(4)
        row        = array([0], dtype=int32)
        x          = array([[0.       , 0.       , 0.       ],
       [0.       , 0.       , 0.       ],
       [0.       , 0.       , 0.       ],
       [0.6650874, 0.       , 0.       ]], dtype=float32)
        y          = <cupyx.scipy.sparse.coo.coo_matrix object at 0x7fe0000a0358>
/home/user/.local/lib/python3.6/site-packages/cupyx/scipy/sparse/coo.py:82: in __init__
    elif _util.isshape(arg1):
        arg1       = (array([-2.4840681e+33], dtype=float32), (array([0], dtype=int32), array([0], dtype=int32)))
        copy       = False
        dtype      = None
        self       = <cupyx.scipy.sparse.coo.coo_matrix object at 0x7fe0000a08d0>
        shape      = (4, 3)
/home/user/.local/lib/python3.6/site-packages/cupyx/scipy/sparse/_util.py:24: in isshape
    return isintlike(m) and isintlike(n)
        m          = array([-2.4840681e+33], dtype=float32)
        n          = (array([0], dtype=int32), array([0], dtype=int32))
        x          = (array([-2.4840681e+33], dtype=float32), (array([0], dtype=int32), array([0], dtype=int32)))
/home/user/.local/lib/python3.6/site-packages/cupyx/scipy/sparse/_util.py:11: in isintlike
    return bool(int(x) == x)
        x          = array([-2.4840681e+33], dtype=float32)
cupy/_core/core.pyx:1060: in cupy._core.core.ndarray.__richcmp__
    ???
        CUDARuntimeError = <class 'cupy_backends.cuda.api.runtime.CUDARuntimeError'>
        ElementwiseKernel = <class 'cupy._core._kernel.ElementwiseKernel'>
        __builtins__ = <builtins>
        __doc__    = None
        __file__   = '/home/user/.local/lib/python3.6/site-packages/cupy/_core/core.cpython-36m-x86_64-linux-gnu.so'
        __loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef71a1b38>
        __name__   = 'cupy._core.core'
        __package__ = 'cupy._core'
        __pyx_capi__ = {'_convert_object_with_cuda_array_interface': <capsule object "struct __pyx_obj_4cupy_5_core_4core_ndarray *(PyObject ..._core_4core_ndarray *(struct __pyx_obj_4cupy_5_core_4core_ndarray *, int __pyx_skip_dispatch)" at 0x7fdef71ddea0>, ...}
        __spec__   = ModuleSpec(name='cupy._core.core', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef71a1b38>, origin='/home/user/.local/lib/python3.6/site-packages/cupy/_core/core.cpython-36m-x86_64-linux-gnu.so')
        __test__   = {'ndarray.__getitem__ (line 1324)': 'x.__getitem__(y) <==> x[y]\n\n        Supports both basic and advanced indexing.\...  >>> array2 = cupy.fromDlpack(dltensor)\n            >>> cupy.testing.assert_array_equal(array1, array2)\n\n        '}
        _convert_object_with_cuda_array_interface = <built-in function _convert_object_with_cuda_array_interface>
        _cucomplex_include_pattern = re.compile('\\s*#\\s*include\\s*<\\s*cuComplex\\.h\\s*>')
        _cucomplex_include_tokens = ['', '#', 'include', '<', 'cuComplex\\.h', '>']
        _cupy_header_list = ['cupy/complex.cuh', 'cupy/carray.cuh', 'cupy/atomics.cuh']
        _get_header_dir_path = <built-in function _get_header_dir_path>
        _get_header_source = <built-in function _get_header_source>
        _get_header_source_map = <built-in function _get_header_source_map>
        _internal_ascontiguousarray = <built-in function _internal_ascontiguousarray>
        _internal_asfortranarray = <built-in function _internal_asfortranarray>
        _round_ufunc = <ufunc 'cupy_round'>
        _util      = <module 'cupy._util' from '/home/user/.local/lib/python3.6/site-packages/cupy/_util.cpython-36m-x86_64-linux-gnu.so'>
        array      = <built-in function array>
        ascontiguousarray = <built-in function ascontiguousarray>
        asfortranarray = <built-in function asfortranarray>
        compile_with_cache = <built-in function compile_with_cache>
        create_ufunc = <built-in function create_ufunc>
        cuda       = <module 'cupy.cuda' from '/home/user/.local/lib/python3.6/site-packages/cupy/cuda/__init__.py'>
        cupy       = <module 'cupy' from '/home/user/.local/lib/python3.6/site-packages/cupy/__init__.py'>
        divmod     = <ufunc 'cupy_divmod'>
        elementwise_copy = <ufunc 'cupy_copy'>
        flags      = <module 'cupy._core.flags' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/flags.cpython-36m-x86_64-linux-gnu.so'>
        functools  = <module 'functools' from '/usr/lib/python3.6/functools.py'>
        memory_module = <module 'cupy.cuda.memory' from '/home/user/.local/lib/python3.6/site-packages/cupy/cuda/memory.cpython-36m-x86_64-linux-gnu.so'>
        ndarray    = <class 'cupy._core.core.ndarray'>
        numpy      = <module 'numpy' from '/home/user/.local/lib/python3.6/site-packages/numpy/__init__.py'>
        os         = <module 'os' from '/usr/lib/python3.6/os.py'>
        pickle     = <module 'pickle' from '/usr/lib/python3.6/pickle.py'>
        re         = <module 're' from '/usr/lib/python3.6/re.py'>
        syncdetect = <module 'cupy._core.syncdetect' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/syncdetect.py'>
        sys        = <module 'sys' (built-in)>
        ufunc      = <class 'cupy._core._kernel.ufunc'>
        warnings   = <module 'warnings' from '/usr/lib/python3.6/warnings.py'>
cupy/_core/core.pyx:1499: in cupy._core.core.ndarray.__array_ufunc__
    ???
        CUDARuntimeError = <class 'cupy_backends.cuda.api.runtime.CUDARuntimeError'>
        ElementwiseKernel = <class 'cupy._core._kernel.ElementwiseKernel'>
        __builtins__ = <builtins>
        __doc__    = None
        __file__   = '/home/user/.local/lib/python3.6/site-packages/cupy/_core/core.cpython-36m-x86_64-linux-gnu.so'
        __loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef71a1b38>
        __name__   = 'cupy._core.core'
        __package__ = 'cupy._core'
        __pyx_capi__ = {'_convert_object_with_cuda_array_interface': <capsule object "struct __pyx_obj_4cupy_5_core_4core_ndarray *(PyObject ..._core_4core_ndarray *(struct __pyx_obj_4cupy_5_core_4core_ndarray *, int __pyx_skip_dispatch)" at 0x7fdef71ddea0>, ...}
        __spec__   = ModuleSpec(name='cupy._core.core', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef71a1b38>, origin='/home/user/.local/lib/python3.6/site-packages/cupy/_core/core.cpython-36m-x86_64-linux-gnu.so')
        __test__   = {'ndarray.__getitem__ (line 1324)': 'x.__getitem__(y) <==> x[y]\n\n        Supports both basic and advanced indexing.\...  >>> array2 = cupy.fromDlpack(dltensor)\n            >>> cupy.testing.assert_array_equal(array1, array2)\n\n        '}
        _convert_object_with_cuda_array_interface = <built-in function _convert_object_with_cuda_array_interface>
        _cucomplex_include_pattern = re.compile('\\s*#\\s*include\\s*<\\s*cuComplex\\.h\\s*>')
        _cucomplex_include_tokens = ['', '#', 'include', '<', 'cuComplex\\.h', '>']
        _cupy_header_list = ['cupy/complex.cuh', 'cupy/carray.cuh', 'cupy/atomics.cuh']
        _get_header_dir_path = <built-in function _get_header_dir_path>
        _get_header_source = <built-in function _get_header_source>
        _get_header_source_map = <built-in function _get_header_source_map>
        _internal_ascontiguousarray = <built-in function _internal_ascontiguousarray>
        _internal_asfortranarray = <built-in function _internal_asfortranarray>
        _round_ufunc = <ufunc 'cupy_round'>
        _util      = <module 'cupy._util' from '/home/user/.local/lib/python3.6/site-packages/cupy/_util.cpython-36m-x86_64-linux-gnu.so'>
        array      = <built-in function array>
        ascontiguousarray = <built-in function ascontiguousarray>
        asfortranarray = <built-in function asfortranarray>
        compile_with_cache = <built-in function compile_with_cache>
        create_ufunc = <built-in function create_ufunc>
        cuda       = <module 'cupy.cuda' from '/home/user/.local/lib/python3.6/site-packages/cupy/cuda/__init__.py'>
        cupy       = <module 'cupy' from '/home/user/.local/lib/python3.6/site-packages/cupy/__init__.py'>
        divmod     = <ufunc 'cupy_divmod'>
        elementwise_copy = <ufunc 'cupy_copy'>
        flags      = <module 'cupy._core.flags' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/flags.cpython-36m-x86_64-linux-gnu.so'>
        functools  = <module 'functools' from '/usr/lib/python3.6/functools.py'>
        memory_module = <module 'cupy.cuda.memory' from '/home/user/.local/lib/python3.6/site-packages/cupy/cuda/memory.cpython-36m-x86_64-linux-gnu.so'>
        ndarray    = <class 'cupy._core.core.ndarray'>
        numpy      = <module 'numpy' from '/home/user/.local/lib/python3.6/site-packages/numpy/__init__.py'>
        os         = <module 'os' from '/usr/lib/python3.6/os.py'>
        pickle     = <module 'pickle' from '/usr/lib/python3.6/pickle.py'>
        re         = <module 're' from '/usr/lib/python3.6/re.py'>
        syncdetect = <module 'cupy._core.syncdetect' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/syncdetect.py'>
        sys        = <module 'sys' (built-in)>
        ufunc      = <class 'cupy._core._kernel.ufunc'>
        warnings   = <module 'warnings' from '/usr/lib/python3.6/warnings.py'>
cupy/_core/_kernel.pyx:1119: in cupy._core._kernel.ufunc.__call__
    ???
        ElementwiseKernel = <class 'cupy._core._kernel.ElementwiseKernel'>
        ParameterInfo = <class 'cupy._core._kernel.ParameterInfo'>
        _ArgInfo   = <class 'cupy._core._kernel._ArgInfo'>
        _Op        = <class 'cupy._core._kernel._Op'>
        _Ops       = <class 'cupy._core._kernel._Ops'>
        _TypeMap   = <class 'cupy._core._kernel._TypeMap'>
        __builtins__ = <builtins>
        __doc__    = None
        __file__   = '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_kernel.cpython-36m-x86_64-linux-gnu.so'
        __loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef7068fd0>
        __name__   = 'cupy._core._kernel'
        __package__ = 'cupy._core'
        __pyx_capi__ = {'_broadcast': <capsule object "PyObject *(PyObject *, PyObject *, int, __pyx_t_4cupy_5_core_7_carray_shape_t &)" at 0...at 0x7fdef705ba80>, '_get_kernel_params': <capsule object "PyObject *(PyObject *, PyObject *)" at 0x7fdef705bab0>, ...}
        __pyx_unpickle_ElementwiseKernel = <built-in function __pyx_unpickle_ElementwiseKernel>
        __pyx_unpickle_ParameterInfo = <built-in function __pyx_unpickle_ParameterInfo>
        __pyx_unpickle__ArgInfo = <built-in function __pyx_unpickle__ArgInfo>
        __pyx_unpickle__Op = <built-in function __pyx_unpickle__Op>
        __pyx_unpickle__Ops = <built-in function __pyx_unpickle__Ops>
        __pyx_unpickle__TypeMap = <built-in function __pyx_unpickle__TypeMap>
        __pyx_unpickle_ufunc = <built-in function __pyx_unpickle_ufunc>
        __spec__   = ModuleSpec(name='cupy._core._kernel', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef7068fd0>, origin='/home/user/.local/lib/python3.6/site-packages/cupy/_core/_kernel.cpython-36m-x86_64-linux-gnu.so')
        __test__   = {}
        _decide_params_type = <cyfunction _decide_params_type at 0x7fdef7063a70>
        _fusion_thread_local = <module 'cupy._core._fusion_thread_local' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_fusion_thread_local.cpython-36m-x86_64-linux-gnu.so'>
        _get_elementwise_kernel = <cyfunction _get_elementwise_kernel at 0x7fdef7063b38>
        _get_param_info = <cyfunction _get_param_info at 0x7fdef70639a8>
        _get_typename = <built-in function get_typename>
        _util      = <module 'cupy._util' from '/home/user/.local/lib/python3.6/site-packages/cupy/_util.cpython-36m-x86_64-linux-gnu.so'>
        compiler   = <module 'cupy.cuda.compiler' from '/home/user/.local/lib/python3.6/site-packages/cupy/cuda/compiler.py'>
        create_ufunc = <built-in function create_ufunc>
        numpy      = <module 'numpy' from '/home/user/.local/lib/python3.6/site-packages/numpy/__init__.py'>
        string     = <module 'string' from '/usr/lib/python3.6/string.py'>
        ufunc      = <class 'cupy._core._kernel.ufunc'>
        warnings   = <module 'warnings' from '/usr/lib/python3.6/warnings.py'>
cupy/_core/_kernel.pyx:108: in cupy._core._kernel._preprocess_args
    ???
        ElementwiseKernel = <class 'cupy._core._kernel.ElementwiseKernel'>
        ParameterInfo = <class 'cupy._core._kernel.ParameterInfo'>
        _ArgInfo   = <class 'cupy._core._kernel._ArgInfo'>
        _Op        = <class 'cupy._core._kernel._Op'>
        _Ops       = <class 'cupy._core._kernel._Ops'>
        _TypeMap   = <class 'cupy._core._kernel._TypeMap'>
        __builtins__ = <builtins>
        __doc__    = None
        __file__   = '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_kernel.cpython-36m-x86_64-linux-gnu.so'
        __loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef7068fd0>
        __name__   = 'cupy._core._kernel'
        __package__ = 'cupy._core'
        __pyx_capi__ = {'_broadcast': <capsule object "PyObject *(PyObject *, PyObject *, int, __pyx_t_4cupy_5_core_7_carray_shape_t &)" at 0...at 0x7fdef705ba80>, '_get_kernel_params': <capsule object "PyObject *(PyObject *, PyObject *)" at 0x7fdef705bab0>, ...}
        __pyx_unpickle_ElementwiseKernel = <built-in function __pyx_unpickle_ElementwiseKernel>
        __pyx_unpickle_ParameterInfo = <built-in function __pyx_unpickle_ParameterInfo>
        __pyx_unpickle__ArgInfo = <built-in function __pyx_unpickle__ArgInfo>
        __pyx_unpickle__Op = <built-in function __pyx_unpickle__Op>
        __pyx_unpickle__Ops = <built-in function __pyx_unpickle__Ops>
        __pyx_unpickle__TypeMap = <built-in function __pyx_unpickle__TypeMap>
        __pyx_unpickle_ufunc = <built-in function __pyx_unpickle_ufunc>
        __spec__   = ModuleSpec(name='cupy._core._kernel', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef7068fd0>, origin='/home/user/.local/lib/python3.6/site-packages/cupy/_core/_kernel.cpython-36m-x86_64-linux-gnu.so')
        __test__   = {}
        _decide_params_type = <cyfunction _decide_params_type at 0x7fdef7063a70>
        _fusion_thread_local = <module 'cupy._core._fusion_thread_local' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_fusion_thread_local.cpython-36m-x86_64-linux-gnu.so'>
        _get_elementwise_kernel = <cyfunction _get_elementwise_kernel at 0x7fdef7063b38>
        _get_param_info = <cyfunction _get_param_info at 0x7fdef70639a8>
        _get_typename = <built-in function get_typename>
        _util      = <module 'cupy._util' from '/home/user/.local/lib/python3.6/site-packages/cupy/_util.cpython-36m-x86_64-linux-gnu.so'>
        compiler   = <module 'cupy.cuda.compiler' from '/home/user/.local/lib/python3.6/site-packages/cupy/cuda/compiler.py'>
        create_ufunc = <built-in function create_ufunc>
        numpy      = <module 'numpy' from '/home/user/.local/lib/python3.6/site-packages/numpy/__init__.py'>
        string     = <module 'string' from '/usr/lib/python3.6/string.py'>
        ufunc      = <class 'cupy._core._kernel.ufunc'>
        warnings   = <module 'warnings' from '/usr/lib/python3.6/warnings.py'>
cupy/_core/_scalar.pyx:340: in cupy._core._scalar.scalar_to_numpy_scalar
    ???
        CScalar    = <class 'cupy._core._scalar.CScalar'>
        __builtins__ = <builtins>
        __doc__    = None
        __file__   = '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_scalar.cpython-36m-x86_64-linux-gnu.so'
        __loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef719f0f0>
        __name__   = 'cupy._core._scalar'
        __package__ = 'cupy._core'
        __pyx_capi__ = {'get_typename': <capsule object "PyObject *(PyObject *, int __pyx_skip_dispatch)" at 0x7fdef705b8d0>, 'scalar_to_c_sc...object "PyObject *(PyObject *)" at 0x7fdef705b960>, 'scalar_type_set': <capsule object "PyObject *" at 0x7fdef705b900>}
        __spec__   = ModuleSpec(name='cupy._core._scalar', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef719f0f0>, origin='/home/user/.local/lib/python3.6/site-packages/cupy/_core/_scalar.cpython-36m-x86_64-linux-gnu.so')
        __test__   = {}
        _dtype_module = <module 'cupy._core._dtype' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_dtype.cpython-36m-x86_64-linux-gnu.so'>
        _python_scalar_to_numpy_scalar = <built-in function _python_scalar_to_numpy_scalar>
        get_typename = <built-in function get_typename>
        numpy      = <module 'numpy' from '/home/user/.local/lib/python3.6/site-packages/numpy/__init__.py'>
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   OverflowError: Python int too large to convert to C long

CScalar    = <class 'cupy._core._scalar.CScalar'>
__builtins__ = <builtins>
__doc__    = None
__file__   = '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_scalar.cpython-36m-x86_64-linux-gnu.so'
__loader__ = <_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef719f0f0>
__name__   = 'cupy._core._scalar'
__package__ = 'cupy._core'
__pyx_capi__ = {'get_typename': <capsule object "PyObject *(PyObject *, int __pyx_skip_dispatch)" at 0x7fdef705b8d0>, 'scalar_to_c_sc...object "PyObject *(PyObject *)" at 0x7fdef705b960>, 'scalar_type_set': <capsule object "PyObject *" at 0x7fdef705b900>}
__spec__   = ModuleSpec(name='cupy._core._scalar', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7fdef719f0f0>, origin='/home/user/.local/lib/python3.6/site-packages/cupy/_core/_scalar.cpython-36m-x86_64-linux-gnu.so')
__test__   = {}
_dtype_module = <module 'cupy._core._dtype' from '/home/user/.local/lib/python3.6/site-packages/cupy/_core/_dtype.cpython-36m-x86_64-linux-gnu.so'>
_python_scalar_to_numpy_scalar = <built-in function _python_scalar_to_numpy_scalar>
get_typename = <built-in function get_typename>
numpy      = <module 'numpy' from '/home/user/.local/lib/python3.6/site-packages/numpy/__init__.py'>

cupy/_core/_scalar.pyx:127: OverflowError
kmaehashi commented 2 years ago

This happened again: https://ci.preferred.jp/cupy.linux.cuda11x-cuda-python/93968/

FAILED cupy_tests/test_cusparse.py::TestSparseMatrixConversion::test_denseToSparse[_param_15_{density=0.5, format='coo', shape=(3, 4)}]
01:00:58.626466 STDOUT 1593] | _ TestSparseMatrixConversion.test_denseToSparse[_param_15_{density=0.5, format='coo', shape=(3, 4)}] _ |  
01:00:58.626469 STDOUT 1593] |   |  
01:00:58.626475 STDOUT 1593] | self = <<cupy_tests.test_cusparse.TestSparseMatrixConversion object at 0x7fea8d89a800>  parameter: {'density': 0.5, 'format': 'coo', 'shape': (3, 4)}> |  
01:00:58.626580 STDOUT 1593] | dtype = <class 'numpy.float32'> |  
01:00:58.626585 STDOUT 1593] |   |  
01:00:58.626612 STDOUT 1593] | @skip_HIP_0_size_matrix() |  
01:00:58.626614 STDOUT 1593] | @testing.for_dtypes('fdFD') |  
01:00:58.626619 STDOUT 1593] | def test_denseToSparse(self, dtype): |  
01:00:58.626706 STDOUT 1593] | if not cusparse.check_availability('denseToSparse'): |  
01:00:58.626710 STDOUT 1593] | pytest.skip('denseToSparse is not available') |  
01:00:58.626721 STDOUT 1593] | x = cupy.random.uniform(0, 1, self.shape).astype(dtype) |  
01:00:58.626760 STDOUT 1593] | x[x < self.density] = 0 |  
01:00:58.626770 STDOUT 1593] | >       y = cusparse.denseToSparse(x, format=self.format) |  
01:00:58.626776 STDOUT 1593] |   |  
01:00:58.626802 STDOUT 1593] | dtype      = <class 'numpy.float32'> |  
01:00:58.626805 STDOUT 1593] | self       = <<cupy_tests.test_cusparse.TestSparseMatrixConversion object at 0x7fea8d89a800>  parameter: {'density': 0.5, 'format': 'coo', 'shape': (3, 4)}> |  
01:00:58.626859 STDOUT 1593] | x          = array([[0.        , 0.        , 0.        , 0.        ], |  
01:00:58.626862 STDOUT 1593] | [0.        , 0.86181563, 0.        , 0.        ], |  
01:00:58.626867 STDOUT 1593] | [0.        , 0.        , 0.        , 0.        ]], dtype=float32) |  
01:00:58.626910 STDOUT 1593] |   |  
01:00:58.626912 STDOUT 1593] | cupy_tests/test_cusparse.py:930: |  
01:00:58.626917 STDOUT 1593] | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |  
01:00:58.626947 STDOUT 1593] | /root/.local/lib/python3.10/site-packages/cupy/cusparse.py:1742: in denseToSparse |  
01:00:58.626950 STDOUT 1593] | y = cupyx.scipy.sparse.coo_matrix((data, (row, col)), shape=x.shape) |  
01:00:58.626954 STDOUT 1593] | algo       = 0 |  
01:00:58.626987 STDOUT 1593] | buff       = array([0, 0, 0, ..., 0, 0, 0], dtype=int8) |  
01:00:58.626990 STDOUT 1593] | buff_size  = 1431 |  
01:00:58.626995 STDOUT 1593] | col        = array([0], dtype=int32) |  
01:00:58.627032 STDOUT 1593] | data       = array([9.034914e+23], dtype=float32) |  
01:00:58.627034 STDOUT 1593] | desc_x     = <cupy.cusparse.DnMatDescriptor object at 0x7fea8d89a8f0> |  
01:00:58.627039 STDOUT 1593] | desc_y     = <cupy.cusparse.SpMatDescriptor object at 0x7fea8d89ab90> |  
01:00:58.627074 STDOUT 1593] | format     = 'coo' |  
01:00:58.627076 STDOUT 1593] | handle     = 94564811359120 |  
01:00:58.627082 STDOUT 1593] | nnz        = 1 |  
01:00:58.627119 STDOUT 1593] | num_cols_tmp = array(4) |  
01:00:58.627122 STDOUT 1593] | num_rows_tmp = array(3) |  
01:00:58.627126 STDOUT 1593] | row        = array([0], dtype=int32) |  
01:00:58.627157 STDOUT 1593] | x          = array([[0.        , 0.        , 0.        , 0.        ], |  
01:00:58.627159 STDOUT 1593] | [0.        , 0.86181563, 0.        , 0.        ], |  
01:00:58.627167 STDOUT 1593] | [0.        , 0.        , 0.        , 0.        ]], dtype=float32) |  
01:00:58.960171 STDOUT 1593] | y          = <cupyx.scipy.sparse.coo.coo_matrix object at 0x7fea8d89ab60> |  
01:00:58.960267 STDOUT 1593] | /root/.local/lib/python3.10/site-packages/cupyx/scipy/sparse/coo.py:83: in __init__ |  
01:00:58.960271 STDOUT 1593] | elif _util.isshape(arg1): |  
01:00:58.960276 STDOUT 1593] | arg1       = (array([9.034914e+23], dtype=float32), (array([0], dtype=int32), array([0], dtype=int32))) |  
01:00:58.960358 STDOUT 1593] | copy       = False |  
01:00:58.960360 STDOUT 1593] | dtype      = None |  
01:00:58.960364 STDOUT 1593] | self       = <cupyx.scipy.sparse.coo.coo_matrix object at 0x7fea8d89abf0> |  
01:00:58.960408 STDOUT 1593] | shape      = (3, 4) |  
01:00:58.960410 STDOUT 1593] | /root/.local/lib/python3.10/site-packages/cupyx/scipy/sparse/_util.py:24: in isshape |  
01:00:58.960413 STDOUT 1593] | return isintlike(m) and isintlike(n) |  
01:00:58.960437 STDOUT 1593] | m          = array([9.034914e+23], dtype=float32) |  
01:00:58.960440 STDOUT 1593] | n          = (array([0], dtype=int32), array([0], dtype=int32)) |  
01:00:58.960443 STDOUT 1593] | x          = (array([9.034914e+23], dtype=float32), (array([0], dtype=int32), array([0], dtype=int32))) |  
01:00:58.960466 STDOUT 1593] | /root/.local/lib/python3.10/site-packages/cupyx/scipy/sparse/_util.py:11: in isintlike |  
01:00:58.960468 STDOUT 1593] | return bool(int(x) == x) |  
01:00:58.960470 STDOUT 1593] | x          = array([9.034914e+23], dtype=float32) |  
01:00:58.960488 STDOUT 1593] | cupy/_core/core.pyx:1130: in cupy._core.core.ndarray.__richcmp__ |  
01:00:58.960492 STDOUT 1593] | ??? |  
01:00:58.960502 STDOUT 1593] | cupy/_core/core.pyx:1596: in cupy._core.core.ndarray.__array_ufunc__ |  
01:00:58.960518 STDOUT 1593] | ??? |  
01:00:58.960519 STDOUT 1593] | cupy/_core/_kernel.pyx:1171: in cupy._core._kernel.ufunc.__call__ |  
01:00:58.960522 STDOUT 1593] | ??? |  
01:00:58.960545 STDOUT 1593] | cupy/_core/_kernel.pyx:129: in cupy._core._kernel._preprocess_args |  
01:00:58.960546 STDOUT 1593] | ??? |  
01:00:58.960549 STDOUT 1593] | cupy/_core/_scalar.pyx:340: in cupy._core._scalar.scalar_to_numpy_scalar |  
01:00:58.960570 STDOUT 1593] | ??? |  
01:00:58.960571 STDOUT 1593] | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |  
01:00:58.960574 STDOUT 1593] |   |  
01:00:58.960619 STDOUT 1593] | >   ??? |  
01:00:58.960622 STDOUT 1593] | E   OverflowError: Python int too large to convert to C long |  
01:00:58.960627 STDOUT 1593] |   |  
01:00:58.960668 STDOUT 1593] |   |  
01:00:58.960670 STDOUT 1593] | cupy/_core/_scalar.pyx:127: OverflowError
kmaehashi commented 2 years ago

Ah, ok got it. The data is initially created with cupy.empty here: https://github.com/cupy/cupy/blob/1b12a402e666d0662a3203e8169efbd3c4c6d3ec/cupy/cusparse.py#L1741-L1742

and when that random value exceeds 2**64, the above error happens, because the value it is tested whether it is a shape-like:

https://github.com/cupy/cupy/blob/1b12a402e666d0662a3203e8169efbd3c4c6d3ec/cupyx/scipy/sparse/coo.py#L83 https://github.com/cupy/cupy/blob/1b12a402e666d0662a3203e8169efbd3c4c6d3ec/cupyx/scipy/sparse/_util.py#L9-L13

kmaehashi commented 2 years ago

Minimum reproducer:

>>> z = cupy.array([9.034914e+23], dtype=cupy.float32)
>>> int(z) == z
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cupy/_core/core.pyx", line 1130, in cupy._core.core.ndarray.__richcmp__
    return numpy.equal(self, other)
  File "cupy/_core/core.pyx", line 1596, in cupy._core.core.ndarray.__array_ufunc__
    ])
  File "cupy/_core/_kernel.pyx", line 1147, in cupy._core._kernel.ufunc.__call__
    return _fusion_thread_local.call_ufunc(self, *args, **kwargs)
  File "cupy/_core/_kernel.pyx", line 128, in cupy._core._kernel._preprocess_args
    else:  # scalars or invalid args
  File "cupy/_core/_scalar.pyx", line 340, in cupy._core._scalar.scalar_to_numpy_scalar
    return _python_scalar_to_numpy_scalar(x)
  File "cupy/_core/_scalar.pyx", line 127, in cupy._core._scalar._python_scalar_to_numpy_scalar
    return numpy_type(x)
OverflowError: Python int too large to convert to C long

The *_matrix constructor needs to be fixed to avoid unnecessary computation/synchronization when creating a spmat from (data, (row, col)).