Skip to content

Add SciPy compatible connected_components - #4940

Merged
kmaehashi merged 8 commits into
cupy:masterfrom
anaruse:add_csgraph_connected_components
Apr 20, 2021
Merged

kmaehashi merged 8 commits into
cupy:masterfrom
anaruse:add_csgraph_connected_components

Conversation

@anaruse

@anaruse anaruse commented Mar 22, 2021 •

Copy link
Copy Markdown
Contributor

This PR adds SciPy compatible connected_components (cupyx.scipy.sparse.csgraph.connected_components) using libcugraph.

I think there are two main ways to use the functionality of cuGraph: 1) using the python APIs of cugraph, or 2) using the C++ APIs of libcugraph. I understand that you think the former method is better (#4219 (comment)), but cugraph has more dependent modules than libcugraph, so I think the latter is better for many CuPy users (Please see also #4219 (comment)).

As you can see from this PR, if you use libcugraph, you can use the feature of cuGraph via a python bindings to the libcugraph C++ APIs as well as cuTENSOR, NCCL, among others.

Libcugraph can be installed via conda as follows.

conda install -c rapidsai-nightly libcugraph

Current stable version of libcugraph 0.18, which can be installed from the rapidsai channel now, has an issue in the strongly connected components (SCC). It will be fixed in 0.19. So if you want to use the SCC, please install libcugraph 0.19 or above using rapidsai-nightly channel.

To enable libcugraph, set the environment variable CUGRAPH_PATH as below when you built CuPy from source.

CUGRAPH_PATH=/path/to/the/cugraph python setup.py install

This is related to #4054 and #4219.

@anaruse
anaruse marked this pull request as draft March 22, 2021 07:31
@anaruse anaruse changed the title Add SciPy compatible connected_components [WIP] Add SciPy compatible connected_components Mar 22, 2021
@kmaehashi kmaehashi self-assigned this Mar 23, 2021
@kmaehashi kmaehashi added cat:feature New features/APIs prio:medium to-be-backported Pull-requests to be backported to stable branch labels Mar 23, 2021
@anaruse
anaruse marked this pull request as ready for review March 29, 2021 13:33
@anaruse anaruse changed the title [WIP] Add SciPy compatible connected_components Add SciPy compatible connected_components Mar 29, 2021
@anaruse

anaruse commented Mar 29, 2021

Copy link
Copy Markdown
Contributor Author

@rlratzel

@kmaehashi kmaehashi added the blocking Issue/pull-request is mandatory for the upcoming release label Mar 30, 2021

@kmaehashi kmaehashi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for nits!

Comment thread cupy_setup_build.py Outdated
Comment on lines +514 to +519
cusparselt_path = os.environ.get('CUGRAPH_PATH', '')
for i in 'include', 'include/cugraph':
inc_path = os.path.join(cusparselt_path, i)
if os.path.exists(inc_path):
settings['include_dirs'].append(inc_path)
lib_path = os.path.join(cusparselt_path, 'lib')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cusparselt_path = os.environ.get('CUGRAPH_PATH', '')
for i in 'include', 'include/cugraph':
inc_path = os.path.join(cusparselt_path, i)
if os.path.exists(inc_path):
settings['include_dirs'].append(inc_path)
lib_path = os.path.join(cusparselt_path, 'lib')
cugraph_path = os.environ.get('CUGRAPH_PATH', '')
for i in 'include', 'include/cugraph':
inc_path = os.path.join(cugraph_path, i)
if os.path.exists(inc_path):
settings['include_dirs'].append(inc_path)
lib_path = os.path.join(cugraph_path, 'lib')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment thread cupy_setup_build.py

if module['name'] == 'cugraph':
cusparselt_path = os.environ.get('CUGRAPH_PATH', '')
for i in 'include', 'include/cugraph':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include include/cugraph as well?
I think just adding include dir to path list and using #include <cugraph/algorithms.hpp> from code looks better to avoid referencing the wrong header file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing that out. I agree with that it is not clean to include include/cugraph. Actually, I tried the method you pointed out before, but it gave me the following error.

In file included from cupy_backends/cuda/libs/../../cupy_cugraph.h:12:0,
                 from cupy_backends/cuda/libs/cugraph.cpp:674:
/home/anaruse/.pyenv/versions/miniconda3-4.7.12/envs/libcugraph-nightly/include/cugraph/algorithms.hpp:17:10: fatal error: experimental/graph.hpp: No such file or directory
 #include <experimental/graph.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1

This might be a problem with libcugraph, but I was able to solve it by adding include/cugraph, so I'm doing so now. Please let me know if you have any other good workarounds!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation, so the current cugraph seems to expect include/cugraph to be on the path. Sounds reasonable to merge as is 👍

@kmaehashi

Copy link
Copy Markdown
Member

pfnCI, test this please.

@kmaehashi kmaehashi added the st:test-and-merge (deprecated) Ready to merge after test pass. label Apr 20, 2021
@kmaehashi kmaehashi added this to the v10.0.0a1 milestone Apr 20, 2021
@chainer-ci

Copy link
Copy Markdown
Member

Jenkins CI test (for commit 1b27d46, target branch master) succeeded!

@kmaehashi
kmaehashi merged commit 3152723 into cupy:master Apr 20, 2021
chainer-ci pushed a commit to chainer-ci/cupy that referenced this pull request Apr 20, 2021
…nents

Add SciPy compatible connected_components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocking Issue/pull-request is mandatory for the upcoming release cat:feature New features/APIs prio:medium st:test-and-merge (deprecated) Ready to merge after test pass. to-be-backported Pull-requests to be backported to stable branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants