Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REVIEW] Bug ext python test #105

Merged
merged 33 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7370343
fixed flake8 warnings and errors
seunghwak Feb 28, 2019
446873a
fixed pylint errors and warnings (except for ones related to missing …
seunghwak Mar 1, 2019
9742127
temporarily suppress deprecation warning (python 3.7) in importing ne…
seunghwak Mar 1, 2019
cce4912
fixed a segmentation fault error when invoking view_edge_list on an e…
seunghwak Mar 1, 2019
b1f4e02
fixed a 'terminate called after throwing an instance of 'thrust::syst…
seunghwak Mar 2, 2019
0b9f2ff
fixed memory leaks in class Graph
seunghwak Mar 5, 2019
169b6fe
modified test_grmat.py to execute a test case in pytest (this just te…
seunghwak Mar 5, 2019
35c7ff6
set the seed value for a random number generator to eliminate non-det…
seunghwak Mar 5, 2019
d1f460e
fixed a problem in gdf_col_delete (accessing memory after deallocatio…
seunghwak Mar 5, 2019
a4840f8
additional flake8 fixes
seunghwak Mar 5, 2019
2167980
update comments on disabling free on un-owned memory
seunghwak Mar 5, 2019
d29186a
CHANGELOG.md
seunghwak Mar 5, 2019
af9d966
fixed flake8 warnings and errors
seunghwak Feb 28, 2019
d867ce9
fixed pylint errors and warnings (except for ones related to missing …
seunghwak Mar 1, 2019
ee5926a
temporarily suppress deprecation warning (python 3.7) in importing ne…
seunghwak Mar 1, 2019
bf6a8e0
fixed a segmentation fault error when invoking view_edge_list on an e…
seunghwak Mar 1, 2019
8335790
fixed a 'terminate called after throwing an instance of 'thrust::syst…
seunghwak Mar 2, 2019
7398072
fixed memory leaks in class Graph
seunghwak Mar 5, 2019
dcb7a1f
modified test_grmat.py to execute a test case in pytest (this just te…
seunghwak Mar 5, 2019
5c89201
set the seed value for a random number generator to eliminate non-det…
seunghwak Mar 5, 2019
2dc4b0a
fixed a problem in gdf_col_delete (accessing memory after deallocatio…
seunghwak Mar 5, 2019
91f8011
additional flake8 fixes
seunghwak Mar 5, 2019
b7f3c65
update comments on disabling free on un-owned memory
seunghwak Mar 5, 2019
e18ece0
CHANGELOG.md
seunghwak Mar 5, 2019
0e7c12d
minor fixes for merge
seunghwak Mar 5, 2019
6c1d8eb
additional minor fixes for merging
seunghwak Mar 5, 2019
44082ff
additional minor fixes for merging
seunghwak Mar 5, 2019
e0185c5
Merge branch 'bug_ext_python_test' of https://github.com/seunghwak/cu…
seunghwak Mar 5, 2019
6633372
Merge branch 'bug_ext_python_test' of https://github.com/seunghwak/cu…
seunghwak Mar 5, 2019
1efc5a0
Merge branch 'bug_ext_python_test' of https://github.com/seunghwak/cu…
seunghwak Mar 5, 2019
9da6b38
removed prints for debugging
seunghwak Mar 5, 2019
35d6f22
resolve additional merge conflicts
seunghwak Mar 5, 2019
aa60d2b
Merge remote-tracking branch 'origin/branch-0.6' into bug_ext_python_…
seunghwak Mar 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
- PR #95 Code clean up
- PR #96 Relocated mmio.c and mmio.h (external files) to thirdparty/mmio
- PR #97 Updated python tests to speed them up
- PR #105 Updated ptyhton code to follow PEP8 (fixed flake8 complaints)
BradReesWork marked this conversation as resolved.
Show resolved Hide resolved

## Bug Fixes

- PR #48 ABI Fixes
- PR #72 Bug fix for segfault issue getting transpose from adjacency list
- PR #105 Bug fix for memory leaks and python test failures


# cuGraph 0.5.0 (28 Jan 2019)
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/rmm_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class rmm_allocator : public thrust::device_malloc_allocator<T>
~rmm_allocator() {}

private:
cudaStream_t stream;
cudaStream_t stream;
};

using rmm_temp_allocator = rmm_allocator<char>; // Use this alias for thrust::cuda::par(allocator).on(stream)
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct gdf_graph{
gdf_dynamic *dynAdjList; //dynamic
gdf_graph_properties *prop;
gdf_graph() : edgeList(nullptr), adjList(nullptr), transposedAdjList(nullptr), dynAdjList(nullptr), prop(nullptr) {}
~gdf_graph() {
~gdf_graph() {
if (edgeList)
delete edgeList;
if (adjList)
Expand Down
63 changes: 37 additions & 26 deletions cpp/src/cugraph.cu
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ void gdf_col_delete(gdf_column* col) {
{
ALLOC_FREE_TRY(col->data, nullptr);
}
#if 1
// If delete col is executed, the memory pointed by col is no longer valid and
// can be used in another memory allocation, so executing col->data = nullptr
// after delete col is dangerous, also, col = nullptr has no effect here (the
// address is passed by value, for col = nullptr should work, the input
// parameter should be gdf_column*& col (or alternatively, gdf_column** col and
// *col = nullptr also work)
col->data = nullptr;
delete col;
#else
delete col;
col->data = nullptr;
col = nullptr;
}
col = nullptr;
#endif
}
}

void gdf_col_release(gdf_column* col) {
delete col;
delete col;
}

void cpy_column_view(const gdf_column *in, gdf_column *out) {
Expand Down Expand Up @@ -284,8 +295,8 @@ gdf_error gdf_pagerank_impl (gdf_graph *graph,

gdf_error gdf_add_adj_list(gdf_graph *graph)
{
if (graph->adjList != nullptr)
return GDF_SUCCESS;
if (graph->adjList != nullptr)
return GDF_SUCCESS;

GDF_REQUIRE( graph->edgeList != nullptr , GDF_INVALID_API_CALL);
GDF_REQUIRE( graph->adjList == nullptr , GDF_INVALID_API_CALL);
Expand All @@ -304,8 +315,8 @@ gdf_error gdf_add_adj_list(gdf_graph *graph)

gdf_error gdf_add_transpose(gdf_graph *graph)
{
if (graph->edgeList == nullptr)
gdf_add_edge_list(graph);
if (graph->edgeList == nullptr)
gdf_add_edge_list(graph);
if (graph->edgeList->edge_data != nullptr) {
switch (graph->edgeList->edge_data->dtype) {
case GDF_FLOAT32: return gdf_add_transpose_impl<float>(graph);
Expand Down Expand Up @@ -349,23 +360,23 @@ gdf_error gdf_pagerank(gdf_graph *graph, gdf_column *pagerank, float alpha, floa
}

gdf_error gdf_bfs(gdf_graph *graph, gdf_column *distances, gdf_column *predecessors, int start_node, bool directed) {
GDF_REQUIRE(graph->adjList != nullptr, GDF_VALIDITY_UNSUPPORTED);
GDF_REQUIRE(graph->adjList->offsets->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);
GDF_REQUIRE(graph->adjList->indices->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);
GDF_REQUIRE(distances->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);
GDF_REQUIRE(predecessors->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);

int n = graph->adjList->offsets->size - 1;
int e = graph->adjList->indices->size;
int* offsets_ptr = (int*)graph->adjList->offsets->data;
int* indices_ptr = (int*)graph->adjList->indices->data;
int* distances_ptr = (int*)distances->data;
int* predecessors_ptr = (int*)predecessors->data;
int alpha = 15;
int beta = 18;

cugraph::Bfs<int> bfs(n, e, offsets_ptr, indices_ptr, directed, alpha, beta);
bfs.configure(distances_ptr, predecessors_ptr, nullptr);
bfs.traverse(start_node);
return GDF_SUCCESS;
GDF_REQUIRE(graph->adjList != nullptr, GDF_VALIDITY_UNSUPPORTED);
GDF_REQUIRE(graph->adjList->offsets->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);
GDF_REQUIRE(graph->adjList->indices->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);
GDF_REQUIRE(distances->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);
GDF_REQUIRE(predecessors->dtype == GDF_INT32, GDF_UNSUPPORTED_DTYPE);

int n = graph->adjList->offsets->size - 1;
int e = graph->adjList->indices->size;
int* offsets_ptr = (int*)graph->adjList->offsets->data;
int* indices_ptr = (int*)graph->adjList->indices->data;
int* distances_ptr = (int*)distances->data;
int* predecessors_ptr = (int*)predecessors->data;
int alpha = 15;
int beta = 18;

cugraph::Bfs<int> bfs(n, e, offsets_ptr, indices_ptr, directed, alpha, beta);
bfs.configure(distances_ptr, predecessors_ptr, nullptr);
bfs.traverse(start_node);
return GDF_SUCCESS;
}
13 changes: 12 additions & 1 deletion cpp/src/tests/test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,19 @@ void gdf_col_delete(gdf_column* col) {
cudaStream_t stream{nullptr};
if(col->data)
ALLOC_FREE_TRY(col->data, stream);
#if 1
// If delete col is executed, the memory pointed by col is no longer valid and
// can be used in another memory allocation, so executing col->data = nullptr
// after delete col is dangerous, also, col = nullptr has no effect here (the
// address is passed by value, for col = nullptr should work, the input
// parameter should be gdf_column*& col (or alternatively, gdf_column** col and
// *col = nullptr also work)
col->data = nullptr;
delete col;
#else
delete col;
col->data = nullptr;
col = nullptr;
col = nullptr;
#endif
}
}
64 changes: 37 additions & 27 deletions python/cugraph/bfs/test_bfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import cugraph
import cudf
import queue
import time
from scipy.io import mmread
import pytest

import numpy as np
import pytest
from scipy.io import mmread

def ReadMtxFile(mmFile):
print('Reading ' + str(mmFile) + '...')
return mmread(mmFile).asfptype()
import cudf
import cugraph


def cugraph_Call(M, start_vertex):
def read_mtx_file(mm_file):
print('Reading ' + str(mm_file) + '...')
return mmread(mm_file).asfptype()


def cugraph_call(M, start_vertex):
# Device data
M = M.tocsr()
sources = cudf.Series(M.indptr)
destinations = cudf.Series(M.indices)
values = cudf.Series(M.data)

G = cugraph.Graph()
G.add_adj_list(sources, destinations, values)

t1 = time.time()
df = cugraph.bfs(G, start_vertex)
t2 = time.time() - t1
Expand All @@ -43,41 +46,48 @@ def cugraph_Call(M, start_vertex):
return df['distance'].to_array()


def base_Call(M, start_vertex):
intMax = 2147483647
def base_call(M, start_vertex):
int_max = 2**31 - 1

M = M.tocsr()

offsets = M.indptr
indices = M.indices
num_verts = len(offsets) - 1
dist = np.zeros(num_verts, dtype=np.int32)

for i in range(num_verts):
dist[i] = intMax
import queue
dist[i] = int_max

q = queue.Queue()
q.put(start_vertex)
dist[start_vertex] = 0
while(not q.empty()):
u = q.get()
for iCol in range(offsets[u],offsets[u + 1]):
v = indices[iCol]
if (dist[v] == intMax):
for i_col in range(offsets[u], offsets[u + 1]):
v = indices[i_col]
if (dist[v] == int_max):
dist[v] = dist[u] + 1
q.put(v)

return dist

datasets = ['/datasets/networks/dolphins.mtx',

DATASETS = ['/datasets/networks/dolphins.mtx',
'/datasets/networks/karate.mtx',
'/datasets/networks/polbooks.mtx',
'/datasets/golden_data/graphs/dblp.mtx']

@pytest.mark.parametrize('graph_file', datasets)

@pytest.mark.parametrize('graph_file', DATASETS)
def test_bfs(graph_file):
M = read_mtx_file(graph_file)

base_dist = base_call(M, 0)
cugraph_dist = cugraph_call(M, 0)

# Calculating mismatch

M = ReadMtxFile(graph_file)
base_dist = base_Call(M, 0)
dist = cugraph_Call(M, 0)

assert len(base_dist) == len(dist)
for i in range(len(dist)):
assert base_dist[i] == dist[i]
assert len(base_dist) == len(cugraph_dist)
for i in range(len(cugraph_dist)):
assert base_dist[i] == cugraph_dist[i]
22 changes: 11 additions & 11 deletions python/cugraph/graph/c_graph.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from libcpp cimport bool

cdef extern from "cudf.h":

ctypedef enum gdf_error:
ctypedef enum gdf_error:
pass

ctypedef enum gdf_dtype:
Expand All @@ -13,9 +13,9 @@ cdef extern from "cudf.h":
GDF_INT64,
GDF_FLOAT32,
GDF_FLOAT64,
GDF_DATE32,
GDF_DATE64,
GDF_TIMESTAMP,
GDF_DATE32,
GDF_DATE64,
GDF_TIMESTAMP,
GDF_CATEGORY,
GDF_STRING,
N_GDF_TYPES
Expand All @@ -24,18 +24,18 @@ cdef extern from "cudf.h":
ctypedef size_t gdf_size_type

struct gdf_column_:
void *data
void *data
gdf_valid_type *valid
gdf_size_type size
gdf_size_type size
gdf_dtype dtype
gdf_size_type null_count

ctypedef gdf_column_ gdf_column

cdef gdf_error gdf_column_view_augmented(gdf_column *column,
void *data,
cdef gdf_error gdf_column_view_augmented(gdf_column *column,
void *data,
gdf_valid_type *valid,
gdf_size_type size,
gdf_size_type size,
gdf_dtype dtype,
gdf_size_type null_count)

Expand All @@ -60,13 +60,13 @@ cdef extern from "cugraph.h":
gdf_adj_list *transposedAdjList


cdef gdf_error gdf_edge_list_view(gdf_graph *graph,
cdef gdf_error gdf_edge_list_view(gdf_graph *graph,
const gdf_column *source_indices,
const gdf_column *destination_indices,
const gdf_column *edge_data)
cdef gdf_error gdf_add_edge_list(gdf_graph *graph)
cdef gdf_error gdf_delete_edge_list(gdf_graph *graph)
cdef gdf_error gdf_adj_list_view (gdf_graph *graph,
cdef gdf_error gdf_adj_list_view (gdf_graph *graph,
const gdf_column *offsets,
const gdf_column *indices,
const gdf_column *edge_data)
Expand Down
Loading