Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
**/__pycache__/

# build dir
**/dist/
graph-learn/dist/
dynamic_graph_service/dist/
**/build/
**/built/
**/cmake-build/
Expand Down
9 changes: 8 additions & 1 deletion graphlearn/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
graph_learn.egg-info/
dist/
examples/tf/*.tar.gz
examples/tf/*.tar.gz

# clangd
.cache/

# core dump
/core

38 changes: 35 additions & 3 deletions graphlearn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ option (GPU
"Enable gpu"
OFF)

option (WITH_VINEYARD
"Enable vineyard"
OFF)

option (VINEYARD_USE_OID
"Use OID when work with vineyard graphs"
ON)

set (GL_CXX_DIALECT
"c++11"
CACHE
Expand Down Expand Up @@ -247,6 +255,17 @@ else ()
set (GL_KNN_FILES)
endif ()

## contrib vineyard
if (WITH_VINEYARD)
message(INFO "Graph-learn is built with vineyard support.")
find_package (vineyard)
include_directories (SYSTEM ${VINEYARD_INCLUDE_DIRS})
add_definitions (-DWITH_VINEYARD)
if (VINEYARD_USE_OID)
add_definitions (-DVINEYARD_USE_OID)
endif ()
endif ()

## cxx flags
if (DEBUG)
set (GL_MODE_FLAGS -DDEBUG -g)
Expand Down Expand Up @@ -285,12 +304,16 @@ set (GL_CXX_FLAGS
-fPIC
-fvisibility-inlines-hidden
-pthread
-mavx
-msse4.2
-msse4.1
# fixme: check format security
-Wno-format-security)

if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
set (GL_CXX_FLAGS ${GL_CXX_FLAGS}
-mavx
-msse4.2
-msse4.1)
endif ()

if (APPLE)
set (GL_CXX_FLAGS ${GL_CXX_FLAGS} -Wno-deprecated-declarations)
endif ()
Expand Down Expand Up @@ -338,6 +361,11 @@ if (KNN)
PUBLIC -lm -lquadmath -lgfortran)
endif ()

if (WITH_VINEYARD)
target_include_directories (graphlearn_shared PUBLIC ${VINEYARD_INCLUDE_DIRS})
target_link_libraries (graphlearn_shared PUBLIC ${VINEYARD_LIBRARIES})
endif ()

if (GPU)
set (CUDA_PATH /usr/local/cuda-10.0)

Expand Down Expand Up @@ -404,6 +432,10 @@ if (TESTING)
${GL_KNN_DIR}/*.cpp)
add_gl_tests (${KNN_TEST_FILES})
endif ()

if (WITH_VINEYARD)
target_compile_options(vineyard_storage_unittest PRIVATE "-std=c++14")
endif ()
endif()

# python
Expand Down
6 changes: 5 additions & 1 deletion graphlearn/python/c/py_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ void init_client_module(py::module& m) {
return self.Sampling(req, res);
},
py::arg("request"),
py::arg("response"));
py::arg("response"))
.def("get_own_servers",
[](Client& self) {
return py::cast(self.GetOwnServers());
});

m.def("del_op_request", [](OpRequest* req) { delete req; });
m.def("del_op_response", [](OpResponse* res) { delete res; });
Expand Down
14 changes: 11 additions & 3 deletions graphlearn/python/c/py_export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ PYBIND11_MODULE(pywrap_graphlearn, m) {
// getters
m.def("get_tracker_mode", &GetGlobalFlagTrackerMode);

m.def("set_vineyard_graph_id", &SetGlobalFlagVineyardGraphID);
m.def("set_vineyard_ipc_socket", &SetGlobalFlagVineyardIPCSocket);

py::enum_<error::Code>(m, "ErrorCode")
.value("OK", error::Code::OK)
.value("CANCELLED", error::Code::CANCELLED)
Expand Down Expand Up @@ -201,7 +204,9 @@ PYBIND11_MODULE(pywrap_graphlearn, m) {
.def_readwrite("id_type", &io::NodeSource::id_type)
.def_readwrite("format", &io::NodeSource::format)
.def_readwrite("attr_info", &io::NodeSource::attr_info)
.def_readwrite("option", &io::NodeSource::option);
.def_readwrite("option", &io::NodeSource::option)
.def_readwrite("view_type", &io::NodeSource::view_type)
.def_readwrite("use_attrs", &io::NodeSource::use_attrs);

py::class_<io::EdgeSource>(m, "EdgeSource")
.def(py::init<>())
Expand All @@ -212,7 +217,9 @@ PYBIND11_MODULE(pywrap_graphlearn, m) {
.def_readwrite("format", &io::EdgeSource::format)
.def_readwrite("direction", &io::EdgeSource::direction)
.def_readwrite("attr_info", &io::EdgeSource::attr_info)
.def_readwrite("option", &io::EdgeSource::option);
.def_readwrite("option", &io::EdgeSource::option)
.def_readwrite("view_type", &io::EdgeSource::view_type)
.def_readwrite("use_attrs", &io::EdgeSource::use_attrs);

py::class_<Status>(m, "Status")
.def("ok", &Status::ok)
Expand Down Expand Up @@ -243,7 +250,8 @@ PYBIND11_MODULE(pywrap_graphlearn, m) {
&NewRpcClient,
py::return_value_policy::take_ownership,
py::arg("server_id") = -1,
py::arg("server_own") = false);
py::arg("server_own") = false,
py::arg("client_own") = true);

init_client_module(m);

Expand Down
8 changes: 7 additions & 1 deletion graphlearn/python/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ def set_neg_sampler_retry_times(times):
pywrap.set_neg_sampler_retry_times(times)

def set_field_delimiter(delimiter="\t"):
pywrap.set_field_delimiter(delimiter)
pywrap.set_field_delimiter(delimiter)

def set_vineyard_graph_id(graph_id):
pywrap.set_vineyard_graph_id(graph_id)

def set_vineyard_ipc_socket(ipc_socket):
pywrap.set_vineyard_ipc_socket(ipc_socket)
4 changes: 4 additions & 0 deletions graphlearn/src/common/base/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ DEFINE_INT32_GLOBAL_FLAG(NegativeSamplingRetryTimes, 5)
DEFINE_INT32_GLOBAL_FLAG(IgnoreInvalid, 1) // 1 is True, 0 is False.
DEFINE_INT32_GLOBAL_FLAG(LocalShardCount, 8)
DEFINE_STRING_GLOBAL_FLAG(FieldDelimiter, "\t")
DEFINE_INT64_GLOBAL_FLAG(VineyardGraphID, 0)
DEFINE_STRING_GLOBAL_FLAG(VineyardIPCSocket, "/var/run/vineyard.sock")

// Define the setters
DEFINE_SET_INT32_GLOBAL_FLAG(DeployMode)
Expand Down Expand Up @@ -142,6 +144,8 @@ DEFINE_SET_INT32_GLOBAL_FLAG(NegativeSamplingRetryTimes)
DEFINE_SET_INT32_GLOBAL_FLAG(IgnoreInvalid)
DEFINE_SET_INT32_GLOBAL_FLAG(LocalShardCount)
DEFINE_SET_STRING_GLOBAL_FLAG(FieldDelimiter)
DEFINE_SET_INT64_GLOBAL_FLAG(VineyardGraphID)
DEFINE_SET_STRING_GLOBAL_FLAG(VineyardIPCSocket)

// Define the getters
/// Only export flags that are needed by system.
Expand Down
2 changes: 1 addition & 1 deletion graphlearn/src/common/base/progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct Progress {
if (count > stage * grading) {
char buffer[100];
snprintf(buffer, sizeof(buffer),
"Progress of %s: %ld", key.c_str(), stage * grading);
"Progress of %s: %lld", key.c_str(), stage * grading);
USER_LOG(buffer);
++stage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class DynamicWorkerThreadPool : public ThreadPoolBase {
int AddTask(Callback* callback) override;
void WaitForIdle() override;

int GetQueueLength();
int GetThreadNum() const;
int GetBusyThreadNum() const;
int GetQueueLength() override;
int GetThreadNum() const override;
int GetBusyThreadNum() const override;

protected:
void SetIdleThresholdInMs(int ms);
Expand Down
2 changes: 1 addition & 1 deletion graphlearn/src/contrib/knn/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool BuildKnnIndex(io::NodeStorage* storage, const IndexOption& option) {
}

index->Train(n, vectors.data());
index->Add(n, vectors.data(), storage->GetIds()->data());
index->Add(n, vectors.data(), storage->GetIds().data());

op::KnnIndexManager::Instance()->Add(storage->GetSideInfo()->type, index);
return true;
Expand Down
8 changes: 6 additions & 2 deletions graphlearn/src/core/graph/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ class Graph {
#undef DECLARE_METHOD
};

Graph* CreateLocalGraph();
Graph* CreateRemoteGraph();
Graph* CreateLocalGraph(const std::string& type,
const std::string& view_type,
const std::string& use_attrs);
Graph* CreateRemoteGraph(const std::string& type,
const std::string& view_type,
const std::string& use_attrs);

} // namespace graphlearn

Expand Down
17 changes: 14 additions & 3 deletions graphlearn/src/core/graph/graph_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include "common/base/macros.h"
#include "common/base/progress.h"
#include "common/threading/sync/cond.h"
#include "core/graph/storage/storage_mode.h"
#include "core/io/element_value.h"
#include "core/io/edge_loader.h"
#include "core/io/node_loader.h"
Expand Down Expand Up @@ -186,7 +187,12 @@ Status GraphStore::Init(
const std::vector<io::NodeSource>& nodes) {

for (const auto& e : edges) {
graphs_->LookupOrCreate(e.edge_type);
std::string decorated_edge_view = e.src_id_type + "|" + e.dst_id_type;
if (!e.view_type.empty()) {
decorated_edge_view += "|" + e.view_type;
}
graphs_->LookupOrCreate(e.edge_type, decorated_edge_view, e.use_attrs);

auto it = e_types_.find(e.edge_type);
if (it == e_types_.end()) {
e_types_.insert({e.edge_type, 1});
Expand All @@ -195,7 +201,7 @@ Status GraphStore::Init(
}
}
for (const auto& n : nodes) {
noders_->LookupOrCreate(n.id_type);
noders_->LookupOrCreate(n.id_type, n.view_type, n.use_attrs);
n_types_.insert({n.id_type, 1});
}
return Status::OK();
Expand All @@ -205,6 +211,11 @@ Status GraphStore::Load(
const std::vector<io::EdgeSource>& edges,
const std::vector<io::NodeSource>& nodes) {
Init(edges, nodes);

if (io::IsVineyardStorageEnabled()) {
return Status::OK();
}

Initializer<io::EdgeSource,
io::EdgeLoader,
io::EdgeValue,
Expand Down Expand Up @@ -301,7 +312,7 @@ void GraphStore::BuildLocalCount() {
for (auto it = n_types_.begin(); it != n_types_.end(); ++it) {
Noder* noder = noders_->LookupOrCreate(it->first);
::graphlearn::io::NodeStorage* storage = noder->GetLocalStorage();
local_count_.push_back(storage->GetIds()->size() * it->second);
local_count_.push_back(storage->GetIds().Size() * it->second);
}
}

Expand Down
10 changes: 7 additions & 3 deletions graphlearn/src/core/graph/heter_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace graphlearn {
template <class T>
class HeterDispatcher {
public:
typedef T* (*TypeCreator)();
typedef T* (*TypeCreator)(const std::string& type,
const std::string& view_type,
const std::string& use_attrs);

public:
explicit HeterDispatcher(TypeCreator creator)
Expand All @@ -39,14 +41,16 @@ class HeterDispatcher {
}
}

T* LookupOrCreate(const std::string& type) {
T* LookupOrCreate(const std::string& type,
const std::string& view_type="",
const std::string& use_attrs="") {
ScopedLocker<std::mutex> _(&mtx_);
auto it = holder_.find(type);
if (it != holder_.end()) {
return it->second;
}

T* t = creator_();
T* t = creator_(type, view_type, use_attrs);
holder_[type] = t;
return t;
}
Expand Down
12 changes: 8 additions & 4 deletions graphlearn/src/core/graph/local_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ namespace graphlearn {

class LocalGraph : public Graph {
public:
LocalGraph() {
storage_ = CreateGraphStorage();
LocalGraph(const std::string& type,
const std::string& view_type,
const std::string& use_attrs) {
storage_ = CreateGraphStorage(type, view_type, use_attrs);
}

virtual ~LocalGraph() {
Expand Down Expand Up @@ -91,8 +93,10 @@ class LocalGraph : public Graph {
io::GraphStorage* storage_;
};

Graph* CreateLocalGraph() {
return new LocalGraph();
Graph* CreateLocalGraph(const std::string& type,
const std::string& view_type,
const std::string& use_attrs) {
return new LocalGraph(type, view_type, use_attrs);
}

} // namespace graphlearn
12 changes: 8 additions & 4 deletions graphlearn/src/core/graph/local_noder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ namespace graphlearn {

class LocalNoder : public Noder {
public:
LocalNoder() {
storage_ = CreateNodeStorage();
LocalNoder(const std::string& type,
const std::string& view_type,
const std::string& use_attrs) {
storage_ = CreateNodeStorage(type, view_type, use_attrs);
}

virtual ~LocalNoder() {
Expand Down Expand Up @@ -103,8 +105,10 @@ class LocalNoder : public Noder {
io::NodeStorage* storage_;
};

Noder* CreateLocalNoder() {
return new LocalNoder();
Noder* CreateLocalNoder(const std::string& type,
const std::string& view_type,
const std::string& use_attrs) {
return new LocalNoder(type, view_type, use_attrs);
}

} // namespace graphlearn
8 changes: 6 additions & 2 deletions graphlearn/src/core/graph/noder.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ class Noder {
#undef DECLARE_METHOD
};

Noder* CreateLocalNoder();
Noder* CreateRemoteNoder();
Noder* CreateLocalNoder(const std::string& type,
const std::string& view_type,
const std::string& use_attrs);
Noder* CreateRemoteNoder(const std::string& type,
const std::string& view_type,
const std::string& use_attrs);

} // namespace graphlearn

Expand Down
Loading