Skip to content

Commit

Permalink
[Misc] clang-format auto fix. (dmlc#4810)
Browse files Browse the repository at this point in the history
* [Misc] clang-format auto fix.

* manual

* manual

Co-authored-by: Steve <[email protected]>
  • Loading branch information
frozenbugs and Steve authored Nov 4, 2022
1 parent 401e127 commit 8f0df39
Show file tree
Hide file tree
Showing 40 changed files with 2,253 additions and 2,452 deletions.
15 changes: 8 additions & 7 deletions src/graph/serialize/zerocopy_serializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace dgl {

using dgl::runtime::NDArray;

NDArray CreateNDArrayFromRawData(std::vector<int64_t> shape, DGLDataType dtype,
DGLContext ctx, void* raw) {
NDArray CreateNDArrayFromRawData(
std::vector<int64_t> shape, DGLDataType dtype, DGLContext ctx, void* raw) {
return NDArray::CreateFromRaw(shape, dtype, ctx, raw, true);
}

Expand All @@ -25,9 +25,9 @@ void StreamWithBuffer::PushNDArray(const NDArray& tensor) {
int ndim = tensor->ndim;
this->WriteArray(tensor->shape, ndim);
CHECK(tensor.IsContiguous())
<< "StreamWithBuffer only supports contiguous tensor";
<< "StreamWithBuffer only supports contiguous tensor";
CHECK_EQ(tensor->byte_offset, 0)
<< "StreamWithBuffer only supports zero byte offset tensor";
<< "StreamWithBuffer only supports zero byte offset tensor";
int type_bytes = tensor->dtype.bits / 8;
int64_t num_elems = 1;
for (int i = 0; i < ndim; ++i) {
Expand All @@ -40,7 +40,8 @@ void StreamWithBuffer::PushNDArray(const NDArray& tensor) {
// If the stream is for remote communication or the data is not stored in
// shared memory, serialize the data content as a buffer.
this->Write<bool>(false);
// If this is a null ndarray, we will not push it into the underlying buffer_list
// If this is a null ndarray, we will not push it into the underlying
// buffer_list
if (data_byte_size != 0) {
buffer_list_.emplace_back(tensor, tensor->data, data_byte_size);
}
Expand Down Expand Up @@ -90,8 +91,8 @@ NDArray StreamWithBuffer::PopNDArray() {
// Mean this is a null ndarray
ret = CreateNDArrayFromRawData(shape, dtype, cpu_ctx, nullptr);
} else {
ret = CreateNDArrayFromRawData(shape, dtype, cpu_ctx,
buffer_list_.front().data);
ret = CreateNDArrayFromRawData(
shape, dtype, cpu_ctx, buffer_list_.front().data);
buffer_list_.pop_front();
}
return ret;
Expand Down
39 changes: 20 additions & 19 deletions src/graph/shared_mem_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ using namespace dgl::aten;
namespace dgl {

template <>
NDArray SharedMemManager::CopyToSharedMem<NDArray>(const NDArray &data,
std::string name) {
NDArray SharedMemManager::CopyToSharedMem<NDArray>(
const NDArray &data, std::string name) {
DGLContext ctx = {kDGLCPU, 0};
std::vector<int64_t> shape(data->shape, data->shape + data->ndim);
strm_->Write(data->ndim);
Expand All @@ -46,42 +46,44 @@ NDArray SharedMemManager::CopyToSharedMem<NDArray>(const NDArray &data,
return data;
} else {
auto nd =
NDArray::EmptyShared(graph_name_ + name, shape, data->dtype, ctx, true);
NDArray::EmptyShared(graph_name_ + name, shape, data->dtype, ctx, true);
nd.CopyFrom(data);
return nd;
}
}

template <>
CSRMatrix SharedMemManager::CopyToSharedMem<CSRMatrix>(const CSRMatrix &csr,
std::string name) {
CSRMatrix SharedMemManager::CopyToSharedMem<CSRMatrix>(
const CSRMatrix &csr, std::string name) {
auto indptr_shared_mem = CopyToSharedMem(csr.indptr, name + "_indptr");
auto indices_shared_mem = CopyToSharedMem(csr.indices, name + "_indices");
auto data_shared_mem = CopyToSharedMem(csr.data, name + "_data");
strm_->Write(csr.num_rows);
strm_->Write(csr.num_cols);
strm_->Write(csr.sorted);
return CSRMatrix(csr.num_rows, csr.num_cols, indptr_shared_mem,
indices_shared_mem, data_shared_mem, csr.sorted);
return CSRMatrix(
csr.num_rows, csr.num_cols, indptr_shared_mem, indices_shared_mem,
data_shared_mem, csr.sorted);
}

template <>
COOMatrix SharedMemManager::CopyToSharedMem<COOMatrix>(const COOMatrix &coo,
std::string name) {
COOMatrix SharedMemManager::CopyToSharedMem<COOMatrix>(
const COOMatrix &coo, std::string name) {
auto row_shared_mem = CopyToSharedMem(coo.row, name + "_row");
auto col_shared_mem = CopyToSharedMem(coo.col, name + "_col");
auto data_shared_mem = CopyToSharedMem(coo.data, name + "_data");
strm_->Write(coo.num_rows);
strm_->Write(coo.num_cols);
strm_->Write(coo.row_sorted);
strm_->Write(coo.col_sorted);
return COOMatrix(coo.num_rows, coo.num_cols, row_shared_mem, col_shared_mem,
data_shared_mem, coo.row_sorted, coo.col_sorted);
return COOMatrix(
coo.num_rows, coo.num_cols, row_shared_mem, col_shared_mem,
data_shared_mem, coo.row_sorted, coo.col_sorted);
}

template <>
bool SharedMemManager::CreateFromSharedMem<NDArray>(NDArray *nd,
std::string name) {
bool SharedMemManager::CreateFromSharedMem<NDArray>(
NDArray *nd, std::string name) {
int ndim;
DGLContext ctx = {kDGLCPU, 0};
DGLDataType dtype;
Expand All @@ -98,15 +100,14 @@ bool SharedMemManager::CreateFromSharedMem<NDArray>(NDArray *nd,
if (is_null) {
*nd = NDArray::Empty(shape, dtype, ctx);
} else {
*nd =
NDArray::EmptyShared(graph_name_ + name, shape, dtype, ctx, false);
*nd = NDArray::EmptyShared(graph_name_ + name, shape, dtype, ctx, false);
}
return true;
}

template <>
bool SharedMemManager::CreateFromSharedMem<COOMatrix>(COOMatrix *coo,
std::string name) {
bool SharedMemManager::CreateFromSharedMem<COOMatrix>(
COOMatrix *coo, std::string name) {
CreateFromSharedMem(&coo->row, name + "_row");
CreateFromSharedMem(&coo->col, name + "_col");
CreateFromSharedMem(&coo->data, name + "_data");
Expand All @@ -118,8 +119,8 @@ bool SharedMemManager::CreateFromSharedMem<COOMatrix>(COOMatrix *coo,
}

template <>
bool SharedMemManager::CreateFromSharedMem<CSRMatrix>(CSRMatrix *csr,
std::string name) {
bool SharedMemManager::CreateFromSharedMem<CSRMatrix>(
CSRMatrix *csr, std::string name) {
CreateFromSharedMem(&csr->indptr, name + "_indptr");
CreateFromSharedMem(&csr->indices, name + "_indices");
CreateFromSharedMem(&csr->data, name + "_data");
Expand Down
3 changes: 1 addition & 2 deletions src/graph/shared_mem_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const size_t SHARED_MEM_METAINFO_SIZE_MAX = 1024 * 32;
class SharedMemManager : public dmlc::Stream {
public:
explicit SharedMemManager(std::string graph_name, dmlc::Stream* strm)
: graph_name_(graph_name),
strm_(strm) {}
: graph_name_(graph_name), strm_(strm) {}

template <typename T>
T CopyToSharedMem(const T& data, std::string name);
Expand Down
62 changes: 32 additions & 30 deletions src/graph/subgraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ namespace dgl {
HeteroSubgraph InEdgeGraphRelabelNodes(
const HeteroGraphPtr graph, const std::vector<IdArray>& vids) {
CHECK_EQ(vids.size(), graph->NumVertexTypes())
<< "Invalid input: the input list size must be the same as the number of vertex types.";
<< "Invalid input: the input list size must be the same as the number of "
"vertex types.";
std::vector<IdArray> eids(graph->NumEdgeTypes());
DGLContext ctx = aten::GetContextOf(vids);
for (dgl_type_t etype = 0; etype < graph->NumEdgeTypes(); ++etype) {
Expand All @@ -29,9 +30,11 @@ HeteroSubgraph InEdgeGraphRelabelNodes(

HeteroSubgraph InEdgeGraphNoRelabelNodes(
const HeteroGraphPtr graph, const std::vector<IdArray>& vids) {
// TODO(mufei): This should also use EdgeSubgraph once it is supported for CSR graphs
// TODO(mufei): This should also use EdgeSubgraph once it is supported for CSR
// graphs
CHECK_EQ(vids.size(), graph->NumVertexTypes())
<< "Invalid input: the input list size must be the same as the number of vertex types.";
<< "Invalid input: the input list size must be the same as the number of "
"vertex types.";
std::vector<HeteroGraphPtr> subrels(graph->NumEdgeTypes());
std::vector<IdArray> induced_edges(graph->NumEdgeTypes());
DGLContext ctx = aten::GetContextOf(vids);
Expand All @@ -43,30 +46,28 @@ HeteroSubgraph InEdgeGraphNoRelabelNodes(
if (aten::IsNullArray(vids[dst_vtype])) {
// create a placeholder graph
subrels[etype] = UnitGraph::Empty(
relgraph->NumVertexTypes(),
graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype),
graph->DataType(), ctx);
induced_edges[etype] = IdArray::Empty({0}, graph->DataType(), graph->Context());
relgraph->NumVertexTypes(), graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype), graph->DataType(), ctx);
induced_edges[etype] =
IdArray::Empty({0}, graph->DataType(), graph->Context());
} else {
const auto& earr = graph->InEdges(etype, {vids[dst_vtype]});
subrels[etype] = UnitGraph::CreateFromCOO(
relgraph->NumVertexTypes(),
graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype),
earr.src,
earr.dst);
relgraph->NumVertexTypes(), graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype), earr.src, earr.dst);
induced_edges[etype] = earr.id;
}
}
HeteroSubgraph ret;
ret.graph = CreateHeteroGraph(graph->meta_graph(), subrels, graph->NumVerticesPerType());
ret.graph = CreateHeteroGraph(
graph->meta_graph(), subrels, graph->NumVerticesPerType());
ret.induced_edges = std::move(induced_edges);
return ret;
}

HeteroSubgraph InEdgeGraph(
const HeteroGraphPtr graph, const std::vector<IdArray>& vids, bool relabel_nodes) {
const HeteroGraphPtr graph, const std::vector<IdArray>& vids,
bool relabel_nodes) {
if (relabel_nodes) {
return InEdgeGraphRelabelNodes(graph, vids);
} else {
Expand All @@ -77,7 +78,8 @@ HeteroSubgraph InEdgeGraph(
HeteroSubgraph OutEdgeGraphRelabelNodes(
const HeteroGraphPtr graph, const std::vector<IdArray>& vids) {
CHECK_EQ(vids.size(), graph->NumVertexTypes())
<< "Invalid input: the input list size must be the same as the number of vertex types.";
<< "Invalid input: the input list size must be the same as the number of "
"vertex types.";
std::vector<IdArray> eids(graph->NumEdgeTypes());
DGLContext ctx = aten::GetContextOf(vids);
for (dgl_type_t etype = 0; etype < graph->NumEdgeTypes(); ++etype) {
Expand All @@ -95,9 +97,11 @@ HeteroSubgraph OutEdgeGraphRelabelNodes(

HeteroSubgraph OutEdgeGraphNoRelabelNodes(
const HeteroGraphPtr graph, const std::vector<IdArray>& vids) {
// TODO(mufei): This should also use EdgeSubgraph once it is supported for CSR graphs
// TODO(mufei): This should also use EdgeSubgraph once it is supported for CSR
// graphs
CHECK_EQ(vids.size(), graph->NumVertexTypes())
<< "Invalid input: the input list size must be the same as the number of vertex types.";
<< "Invalid input: the input list size must be the same as the number of "
"vertex types.";
std::vector<HeteroGraphPtr> subrels(graph->NumEdgeTypes());
std::vector<IdArray> induced_edges(graph->NumEdgeTypes());
DGLContext ctx = aten::GetContextOf(vids);
Expand All @@ -109,30 +113,28 @@ HeteroSubgraph OutEdgeGraphNoRelabelNodes(
if (aten::IsNullArray(vids[src_vtype])) {
// create a placeholder graph
subrels[etype] = UnitGraph::Empty(
relgraph->NumVertexTypes(),
graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype),
graph->DataType(), ctx);
induced_edges[etype] = IdArray::Empty({0}, graph->DataType(), graph->Context());
relgraph->NumVertexTypes(), graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype), graph->DataType(), ctx);
induced_edges[etype] =
IdArray::Empty({0}, graph->DataType(), graph->Context());
} else {
const auto& earr = graph->OutEdges(etype, {vids[src_vtype]});
subrels[etype] = UnitGraph::CreateFromCOO(
relgraph->NumVertexTypes(),
graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype),
earr.src,
earr.dst);
relgraph->NumVertexTypes(), graph->NumVertices(src_vtype),
graph->NumVertices(dst_vtype), earr.src, earr.dst);
induced_edges[etype] = earr.id;
}
}
HeteroSubgraph ret;
ret.graph = CreateHeteroGraph(graph->meta_graph(), subrels, graph->NumVerticesPerType());
ret.graph = CreateHeteroGraph(
graph->meta_graph(), subrels, graph->NumVerticesPerType());
ret.induced_edges = std::move(induced_edges);
return ret;
}

HeteroSubgraph OutEdgeGraph(
const HeteroGraphPtr graph, const std::vector<IdArray>& vids, bool relabel_nodes) {
const HeteroGraphPtr graph, const std::vector<IdArray>& vids,
bool relabel_nodes) {
if (relabel_nodes) {
return OutEdgeGraphRelabelNodes(graph, vids);
} else {
Expand Down
Loading

0 comments on commit 8f0df39

Please sign in to comment.