Skip to content

Commit

Permalink
[DistGB] enable DistGraph to load graphbolt partitions (#7048)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhett-Ying authored Feb 1, 2024
1 parent 942b17a commit df6b325
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 62 deletions.
40 changes: 30 additions & 10 deletions python/dgl/distributed/dist_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,21 @@ class InitGraphRequest(rpc.Request):
with shared memory.
"""

def __init__(self, graph_name):
def __init__(self, graph_name, use_graphbolt):
self._graph_name = graph_name
self._use_graphbolt = use_graphbolt

def __getstate__(self):
return self._graph_name
return self._graph_name, self._use_graphbolt

def __setstate__(self, state):
self._graph_name = state
self._graph_name, self._use_graphbolt = state

def process_request(self, server_state):
if server_state.graph is None:
server_state.graph = _get_graph_from_shared_mem(self._graph_name)
server_state.graph = _get_graph_from_shared_mem(
self._graph_name, self._use_graphbolt
)
return InitGraphResponse(self._graph_name)


Expand Down Expand Up @@ -153,13 +156,15 @@ def _exist_shared_mem_array(graph_name, name):
return exist_shared_mem_array(_get_edata_path(graph_name, name))


def _get_graph_from_shared_mem(graph_name):
def _get_graph_from_shared_mem(graph_name, use_graphbolt):
"""Get the graph from the DistGraph server.
The DistGraph server puts the graph structure of the local partition in the shared memory.
The client can access the graph structure and some metadata on nodes and edges directly
through shared memory to reduce the overhead of data access.
"""
if use_graphbolt:
return gb.load_from_shared_memory(graph_name)
g, ntypes, etypes = heterograph_index.create_heterograph_from_shared_memory(
graph_name
)
Expand Down Expand Up @@ -524,6 +529,8 @@ class DistGraph:
part_config : str, optional
The path of partition configuration file generated by
:py:meth:`dgl.distributed.partition.partition_graph`. It's used in the standalone mode.
use_graphbolt : bool, optional
Whether to load GraphBolt partition. Default: False.
Examples
--------
Expand Down Expand Up @@ -557,9 +564,15 @@ class DistGraph:
manually setting up servers and trainers. The setup is not fully tested yet.
"""

def __init__(self, graph_name, gpb=None, part_config=None):
def __init__(
self, graph_name, gpb=None, part_config=None, use_graphbolt=False
):
self.graph_name = graph_name
self._use_graphbolt = use_graphbolt
if os.environ.get("DGL_DIST_MODE", "standalone") == "standalone":
assert (
use_graphbolt is False
), "GraphBolt is not supported in standalone mode."
assert (
part_config is not None
), "When running in the standalone model, the partition config file is required"
Expand Down Expand Up @@ -600,7 +613,9 @@ def __init__(self, graph_name, gpb=None, part_config=None):
self._init(gpb)
# Tell the backup servers to load the graph structure from shared memory.
for server_id in range(self._client.num_servers):
rpc.send_request(server_id, InitGraphRequest(graph_name))
rpc.send_request(
server_id, InitGraphRequest(graph_name, use_graphbolt)
)
for server_id in range(self._client.num_servers):
rpc.recv_response()
self._client.barrier()
Expand All @@ -625,7 +640,9 @@ def _init(self, gpb):
assert (
self._client is not None
), "Distributed module is not initialized. Please call dgl.distributed.initialize."
self._g = _get_graph_from_shared_mem(self.graph_name)
self._g = _get_graph_from_shared_mem(
self.graph_name, self._use_graphbolt
)
self._gpb = get_shared_mem_partition_book(self.graph_name)
if self._gpb is None:
self._gpb = gpb
Expand Down Expand Up @@ -682,10 +699,10 @@ def _init_edata_store(self):
self._edata_store[etype] = data

def __getstate__(self):
return self.graph_name, self._gpb
return self.graph_name, self._gpb, self._use_graphbolt

def __setstate__(self, state):
self.graph_name, gpb = state
self.graph_name, gpb, self._use_graphbolt = state
self._init(gpb)

self._init_ndata_store()
Expand Down Expand Up @@ -1230,6 +1247,9 @@ def find_edges(self, edges, etype=None):
tensor
The destination node ID array.
"""
assert (
self._use_graphbolt is False
), "find_edges is not supported in GraphBolt."
if etype is None:
assert (
len(self.etypes) == 1
Expand Down
Loading

0 comments on commit df6b325

Please sign in to comment.