Skip to content

Commit 97bfeed

Browse files
authored
Added guards for preventing k-truss execution on CUDA 11.4 systems (#1773)
Added guards for preventing k-truss execution on CUDA 11.4 systems and the appropriate user-friendly messaging, along with a new unit test. Also updated the k-truss notebook with a note about the unsupported CUDA version and a comment to skip automated tests on CUDA 11.4, along with updates to the notebook skip mechanism to also look at CUDA version. Tested on a CUDA 11.2 system by changing the unsupported version to 11.2 to verify correct behavior. Behavior on a CUDA 11.4 systems should be to allow cugraph to be imported as always, but if the user calls k_truss or kturss_subgraph, a NotImplementedError exception with "is not currently supported in CUDA 11.4 environments" message is raised. If the user directly imports the module (ie. from cugraph.community.ktruss_subgraph import k_truss), the exception is raised immediately. Behavior on non-CUDA 11.4 systems should be exactly the same as prior to this change.
1 parent f7c22a6 commit 97bfeed

File tree

5 files changed

+87
-10
lines changed

5 files changed

+87
-10
lines changed

ci/gpu/notebook_list.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717

1818
from numba import cuda
1919

20+
cuda_version_string = ".".join([str(n) for n in cuda.runtime.get_version()])
2021
#
2122
# Not strictly true... however what we mean is
2223
# Pascal or earlier
2324
#
2425
pascal = False
25-
2626
device = cuda.get_current_device()
2727
# check for the attribute using both pre and post numba 0.53 names
2828
cc = getattr(device, 'COMPUTE_CAPABILITY', None) or \
@@ -45,6 +45,12 @@
4545
print(f'SKIPPING {filename} (does not run on Pascal)', file=sys.stderr)
4646
skip = True
4747
break;
48+
elif re.search('# Does not run on CUDA ', line) and \
49+
(cuda_version_string in line):
50+
print(f'SKIPPING {filename} (does not run on CUDA {cuda_version_string})',
51+
file=sys.stderr)
52+
skip = True
53+
break;
4854

4955
if not skip:
5056
print(filename)

notebooks/cores/ktruss.ipynb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@
55
"metadata": {},
66
"source": [
77
"# K-Truss\n",
8+
"# Does not run on CUDA 11.4\n",
89
"\n",
910
"\n",
1011
"In this notebook, we will use cuGraph to identify the K-Truss clusters in a test graph \n",
1112
"\n",
1213
"Notebook Credits\n",
1314
"* Original Authors: Bradley Rees\n",
1415
"* Created: 10/28/2019\n",
15-
"* Last Edit: 08/16/2020\n",
16-
"\n",
17-
"RAPIDS Versions: 0.13\n",
18-
"\n",
19-
"Test Hardware\n",
20-
"* GV100 32G, CUDA 10.2\n",
21-
"\n",
16+
"* Last Edit: 08/13/2021\n",
2217
"\n",
2318
"\n",
2419
"## Introduction\n",
2520
"\n",
2621
"Compute the k-truss of the graph G. A K-Truss is a relaxed cliques where every vertex is supported by at least k-2 triangle.\n",
22+
"NOTE: k-truss is currently not supported on CUDA 11.4 systems.\n",
2723
"\n",
2824
"Ref:\n",
2925
"\n",

python/cugraph/community/__init__.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,38 @@
2323
)
2424
from cugraph.community.subgraph_extraction import subgraph
2525
from cugraph.community.triangle_count import triangles
26-
from cugraph.community.ktruss_subgraph import ktruss_subgraph
27-
from cugraph.community.ktruss_subgraph import k_truss
2826
from cugraph.community.egonet import ego_graph
2927
from cugraph.community.egonet import batched_ego_graphs
28+
29+
# FIXME: special case for ktruss on CUDA 11.4: an 11.4 bug causes ktruss to
30+
# crash in that environment. Allow ktruss to import on non-11.4 systems, but
31+
# replace ktruss with a __UnsupportedModule instance, which lazily raises an
32+
# exception when referenced.
33+
from numba import cuda
34+
__cuda_version = cuda.runtime.get_version()
35+
__ktruss_unsupported_cuda_version = (11, 4)
36+
37+
class __UnsupportedModule:
38+
def __init__(self, exception):
39+
self.__exception = exception
40+
41+
def __getattr__(self, attr):
42+
raise self.__exception
43+
44+
def __call__(self, *args, **kwargs):
45+
raise self.__exception
46+
47+
48+
if __cuda_version != __ktruss_unsupported_cuda_version:
49+
from cugraph.community.ktruss_subgraph import ktruss_subgraph
50+
from cugraph.community.ktruss_subgraph import k_truss
51+
else:
52+
__kuvs = ".".join([str(n) for n in __ktruss_unsupported_cuda_version])
53+
k_truss = __UnsupportedModule(
54+
NotImplementedError("k_truss is not currently supported in CUDA"
55+
f" {__kuvs} environments.")
56+
)
57+
ktruss_subgraph = __UnsupportedModule(
58+
NotImplementedError("ktruss_subgraph is not currently supported in CUDA"
59+
f" {__kuvs} environments.")
60+
)

python/cugraph/community/ktruss_subgraph.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@
1616
from cugraph.utilities import check_nx_graph
1717
from cugraph.utilities import cugraph_to_nx
1818

19+
# FIXME: special case for ktruss on CUDA 11.4: an 11.4 bug causes ktruss to
20+
# crash in that environment. Allow ktruss to import on non-11.4 systems, but
21+
# raise an exception if ktruss is directly imported on 11.4.
22+
from numba import cuda
23+
__cuda_version = cuda.runtime.get_version()
24+
__ktruss_unsupported_cuda_version = (11, 4)
25+
if __cuda_version == __ktruss_unsupported_cuda_version:
26+
__kuvs = ".".join([str(n) for n in __ktruss_unsupported_cuda_version])
27+
raise NotImplementedError("k_truss is not currently supported in CUDA"
28+
f" {__kuvs} environments.")
29+
1930

2031
def k_truss(G, k):
2132
"""
2233
Returns the K-Truss subgraph of a graph for a specific k.
2334
35+
NOTE: this function is currently not available on CUDA 11.4 systems.
36+
2437
The k-truss of a graph is a subgraph where each edge is part of at least
2538
(k−2) triangles. K-trusses are used for finding tighlty knit groups of
2639
vertices in a graph. A k-truss is a relaxation of a k-clique in the graph
@@ -60,6 +73,8 @@ def ktruss_subgraph(G, k, use_weights=True):
6073
"""
6174
Returns the K-Truss subgraph of a graph for a specific k.
6275
76+
NOTE: this function is currently not available on CUDA 11.4 systems.
77+
6378
The k-truss of a graph is a subgraph where each edge is part of at least
6479
(k−2) triangles. K-trusses are used for finding tighlty knit groups of
6580
vertices in a graph. A k-truss is a relaxation of a k-clique in the graph

python/cugraph/tests/test_k_truss_subgraph.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from cugraph.tests import utils
2020

2121
import numpy as np
22+
from numba import cuda
2223

2324
# Temporarily suppress warnings till networkX fixes deprecation warnings
2425
# (Using or importing the ABCs from 'collections' instead of from
@@ -73,6 +74,31 @@ def compare_k_truss(k_truss_cugraph, k, ground_truth_file):
7374
return True
7475

7576

77+
__cuda_version = cuda.runtime.get_version()
78+
__unsupported_cuda_version = (11, 4)
79+
80+
81+
# FIXME: remove when ktruss is supported on CUDA 11.4
82+
def test_unsupported_cuda_version():
83+
"""
84+
Ensures the proper exception is raised when ktruss is called in an
85+
unsupported env, and not when called in a supported env.
86+
"""
87+
k = 5
88+
cu_M = utils.read_csv_file(utils.DATASETS_KTRUSS[0][0])
89+
G = cugraph.Graph()
90+
G.from_cudf_edgelist(cu_M, source="0", destination="1", edge_attr="2")
91+
92+
if __cuda_version == __unsupported_cuda_version:
93+
with pytest.raises(NotImplementedError):
94+
cugraph.k_truss(G, k)
95+
else:
96+
cugraph.k_truss(G, k)
97+
98+
99+
@pytest.mark.skipif((__cuda_version == __unsupported_cuda_version),
100+
reason="skipping on unsupported CUDA "
101+
f"{__unsupported_cuda_version} environment.")
76102
@pytest.mark.parametrize("graph_file, nx_ground_truth", utils.DATASETS_KTRUSS)
77103
def test_ktruss_subgraph_Graph(graph_file, nx_ground_truth):
78104
gc.collect()
@@ -86,6 +112,9 @@ def test_ktruss_subgraph_Graph(graph_file, nx_ground_truth):
86112
compare_k_truss(k_subgraph, k, nx_ground_truth)
87113

88114

115+
@pytest.mark.skipif((__cuda_version == __unsupported_cuda_version),
116+
reason="skipping on unsupported CUDA "
117+
f"{__unsupported_cuda_version} environment.")
89118
@pytest.mark.parametrize("graph_file, nx_ground_truth", utils.DATASETS_KTRUSS)
90119
def test_ktruss_subgraph_Graph_nx(graph_file, nx_ground_truth):
91120
gc.collect()

0 commit comments

Comments
 (0)