Skip to content

Commit

Permalink
refactor(flex): Refactor CMakeLists.txt to support be imported by fin…
Browse files Browse the repository at this point in the history
…d_package (alibaba#3478)

Co-authored-by: xiaolei.zl <[email protected]>
  • Loading branch information
luoxiaojian and zhanglei1949 authored Jan 12, 2024
1 parent e67f8d7 commit 982de58
Show file tree
Hide file tree
Showing 99 changed files with 1,003 additions and 1,081 deletions.
65 changes: 63 additions & 2 deletions flex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ option(BUILD_DOC "Whether to build doc" ON)
option(BUILD_ODPS_FRAGMENT_LOADER "Whether to build odps fragment loader" ON)
option(MONITOR_SESSIONS "Whether monitor sessions" OFF)


# ------------------------------------------------------------------------------
# cmake configs
# ------------------------------------------------------------------------------

include(CheckLibraryExists)
include(GNUInstallDirs)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# reference: https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

if (MONITOR_SESSIONS)
message("Monitor sessions is enabled")
add_definitions(-DMONITOR_SESSIONS)
Expand All @@ -32,10 +47,23 @@ endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)

set(DEFAULT_BUILD_TYPE "Release")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE
STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "-g3 -O0")
if (APPLE)
set(CMAKE_MACOSX_RPATH ON)
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wl,-rpath,$ORIGIN")
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -fPIC")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g")

add_compile_definitions(FLEX_VERSION="${FLEX_VERSION}")

Expand Down Expand Up @@ -122,6 +150,23 @@ if (BUILD_ODPS_FRAGMENT_LOADER)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/third_party/odps/include)
endif()

macro(install_flex_target target)
install(TARGETS ${target}
EXPORT flex-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endmacro()

macro(install_without_export_flex_target target)
install(TARGETS ${target}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endmacro()

add_subdirectory(utils)
add_subdirectory(codegen)
add_subdirectory(storages)
Expand All @@ -131,6 +176,22 @@ if (BUILD_TEST)
add_subdirectory(tests)
endif()


configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flex-config.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/flex-config.cmake @ONLY)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/flex-config-version.in.cmake
${CMAKE_CURRENT_BINARY_DIR}/flex-config-version.cmake @ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/flex-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/flex-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/flex)

install(EXPORT flex-targets
FILE flex-targets.cmake
NAMESPACE flex::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/flex)

file(GLOB_RECURSE FILES_NEED_LINT
"engines/*.cc"
"engines/*.h"
Expand Down
36 changes: 6 additions & 30 deletions flex/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,29 @@ find_package(Hiactor)
if(Hiactor_FOUND)
add_executable(rt_server rt_server.cc)
target_link_libraries(rt_server flex_utils flex_rt_mutable_graph flex_graph_db flex_server)

install(TARGETS rt_server
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_without_export_flex_target(rt_server)
endif()

if(Hiactor_FOUND)
include_directories(../engines/http_server)
add_executable(rt_bench rt_bench.cc)
target_link_libraries(rt_bench flex_utils flex_rt_mutable_graph flex_graph_db flex_server)

install(TARGETS rt_bench
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_without_export_flex_target(rt_bench)
endif()

add_executable(rt_admin rt_admin.cc)
target_link_libraries(rt_admin flex_utils flex_rt_mutable_graph flex_graph_db)

install(TARGETS rt_admin
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_without_export_flex_target(rt_admin)

add_executable(flex_analytical_engine flex_analytical_engine.cc)
target_link_libraries(flex_analytical_engine flex_immutable_graph flex_bsp ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES})

install(TARGETS flex_analytical_engine
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_without_export_flex_target(flex_analytical_engine)

if(BUILD_HQPS)
if(Hiactor_FOUND)
add_executable(interactive_server interactive_server.cc)
target_link_libraries(interactive_server flex_utils flex_graph_db flex_server hqps_plan_proto flex_utils ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES})

install(TARGETS interactive_server
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_without_export_flex_target(interactive_server)
endif()
# install the script
install(PROGRAMS load_plan_and_gen.sh DESTINATION bin)
Expand All @@ -54,8 +34,4 @@ endif()
include_directories(${Boost_INCLUDE_DIRS})
add_executable(bulk_loader bulk_loader.cc)
target_link_libraries(bulk_loader flex_rt_mutable_graph flex_utils ${GLOG_LIBRARIES} ${GFLAGS_LIBRARIES} ${Boost_LIBRARIES})

install(TARGETS bulk_loader
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_without_export_flex_target(bulk_loader)
6 changes: 3 additions & 3 deletions flex/bin/rt_bench.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class Req {
std::vector<char> tmp(size);
size_t index = 0;
while (fi.read(buffer.data(), size)) {
auto len = fi.gcount();
for (size_t i = 0; i < len; ++i) {
std::streamsize len = fi.gcount();
for (std::streamsize i = 0; i < len; ++i) {
if (index >= 4 && tmp[index - 1] == '#') {
if (tmp[index - 4] == 'e' && tmp[index - 3] == 'o' &&
tmp[index - 2] == 'r') {
Expand Down Expand Up @@ -118,7 +118,7 @@ class Req {
"IC9", "IC10", "IC11", "IC12", "IC13", "IC14", "IS1", "IS2",
"IS3", "IS4", "IS5", "IS6", "IS7", "IU1", "IU2", "IU3",
"IU4", "IU5", "IU6", "IU7", "IU8"};
for (auto i = 0; i < vec.size(); ++i) {
for (size_t i = 0; i < vec.size(); ++i) {
size_t sz = ts[i].size();
if (sz > 0) {
std::cout << queries[i] << "; mean: " << vec[i] * 1. / count[i]
Expand Down
6 changes: 1 addition & 5 deletions flex/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS})

add_executable(gen_code_from_plan gen_code_from_plan.cc)
target_link_libraries(gen_code_from_plan hqps_plan_proto ${GLOG_LIBRARIES} ${Boost_LIBRARIES})

install(TARGETS gen_code_from_plan
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install_flex_target(gen_code_from_plan)
36 changes: 19 additions & 17 deletions flex/codegen/src/building_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct TagIndMapping {
return -1;
}
print_debug_info();
CHECK(tag_id < tag_id_2_tag_inds_.size())
CHECK(tag_id < (int) tag_id_2_tag_inds_.size())
<< "tag id: " << tag_id << " not found";
return tag_id_2_tag_inds_[tag_id];
}
Expand All @@ -78,7 +78,7 @@ struct TagIndMapping {
if (it == tag_ind_2_tag_ids_.end()) {
auto new_tag_ind = tag_ind_2_tag_ids_.size();
tag_ind_2_tag_ids_.emplace_back(tag_id);
auto old_size = tag_id_2_tag_inds_.size();
auto old_size = (int32_t) tag_id_2_tag_inds_.size();
if (tag_id + 1 > old_size) {
tag_id_2_tag_inds_.resize(tag_id + 1);
for (auto i = old_size; i < tag_id; ++i) {
Expand All @@ -100,8 +100,8 @@ struct TagIndMapping {
*std::max_element(tag_id_2_tag_inds_.begin(), tag_id_2_tag_inds_.end());
auto max_tag_id =
*std::max_element(tag_ind_2_tag_ids_.begin(), tag_ind_2_tag_ids_.end());
CHECK(max_ind + 1 == tag_ind_2_tag_ids_.size());
CHECK(max_tag_id + 1 == tag_id_2_tag_inds_.size());
CHECK(max_ind + 1 == (int32_t) tag_ind_2_tag_ids_.size());
CHECK(max_tag_id + 1 == (int32_t) tag_id_2_tag_inds_.size());
}

void print_debug_info() const {
Expand Down Expand Up @@ -129,14 +129,15 @@ class BuildingContext {
std::string query_name = "Query0",
std::string ctx_prefix = "")
: storage_backend_(storage_type),
app_base_header_(APP_BASE_HEADER),
query_name_(query_name),
ctx_id_(0),
var_id_(0),
query_name_(query_name),
expr_id_(0),
expr_var_id_(0),
mapper_var_id_(0),
expr_id_(0),
lambda_func_id_(0),
ctx_prefix_(ctx_prefix),
app_base_header_(APP_BASE_HEADER),
alias_size_(0) {
if (storage_type == StorageBackend::kGrape) {
graph_header_ = GRAPE_INTERFACE_HEADER;
Expand All @@ -151,16 +152,17 @@ class BuildingContext {
std::string query_name = "Query0",
std::string ctx_prefix = "")
: storage_backend_(storage_type),
graph_interface_(graph_interface),
graph_header_(graph_header),
app_base_header_(APP_BASE_HEADER),
query_name_(query_name),
ctx_id_(0),
var_id_(0),
query_name_(query_name),
expr_id_(0),
expr_var_id_(0),
mapper_var_id_(0),
expr_id_(0),
lambda_func_id_(0),
ctx_prefix_(ctx_prefix),
app_base_header_(APP_BASE_HEADER),
graph_interface_(graph_interface),
graph_header_(graph_header),
alias_size_(0) {}

// int32_t GetCurrentCtxId() const { return ctx_id_; }
Expand Down Expand Up @@ -351,7 +353,7 @@ class BuildingContext {
void SetAliasType(int32_t alias, int32_t type,
std::vector<int32_t>& label_list) {
auto index = tag_index_[alias];
if (tag_type_.size() <= index) {
if ((int32_t) tag_type_.size() <= index) {
tag_type_.resize(index + 1);
}
tag_type_[index].first = type;
Expand All @@ -365,7 +367,7 @@ class BuildingContext {
}

int32_t SetAlias(int32_t cur_alias) {
if (cur_alias >= tag_index_.size()) {
if (cur_alias >= (int32_t) tag_index_.size()) {
tag_index_.resize(cur_alias + 1, -1);
}
if (tag_index_[cur_alias] != -1) {
Expand Down Expand Up @@ -402,7 +404,7 @@ class BuildingContext {
}
}

void SetOutput(int32_t index, std::vector<codegen::DataType>& output) {
void SetOutput(size_t index, std::vector<codegen::DataType>& output) {
if (cur_outputs_.size() <= index) {
cur_outputs_.resize(index + 1);
}
Expand Down Expand Up @@ -432,10 +434,10 @@ class BuildingContext {
int32_t expr_var_id_;
int32_t mapper_var_id_;
int32_t lambda_func_id_;
std::string ctx_prefix_;
std::string app_base_header_;
std::string graph_interface_;
std::string graph_header_;
std::string app_base_header_;
std::string ctx_prefix_;

std::vector<codegen::ParamConst> parameter_vars_;
std::vector<std::string> expr_code_;
Expand Down
26 changes: 12 additions & 14 deletions flex/codegen/src/codegen_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ std::string generate_arg_list(std::string arg_name, int32_t size) {
if (size > 1) {
arg_ss << "(";
}
for (auto i = 0; i < size; i++) {
for (int32_t i = 0; i < size; i++) {
arg_ss << arg_name << i;
if (i < size - 1) {
arg_ss << ", ";
Expand All @@ -103,7 +103,7 @@ std::string generate_output_list(std::string input_name, int32_t input_size,
std::stringstream result_ss;
result_ss << "(" << result_name;
if (contain_head) {
for (auto i = 1; i < input_size; i++) {
for (int32_t i = 1; i < input_size; i++) {
if (i == alias_index) {
result_ss << ", " << result_name;
} else {
Expand All @@ -114,7 +114,7 @@ std::string generate_output_list(std::string input_name, int32_t input_size,
result_ss << ", " << result_name;
}
} else {
for (auto i = 0; i < input_size; i++) {
for (int32_t i = 0; i < input_size; i++) {
if (i == alias_index) {
result_ss << ", " << result_name;
} else {
Expand Down Expand Up @@ -154,7 +154,7 @@ template <typename T>
void intersection(std::vector<T>& v1, const std::vector<T>& v2) {
std::vector<T> res;
for (auto num : v1) {
for (int i = 0; i < v2.size(); i++) {
for (size_t i = 0; i < v2.size(); i++) {
if (num == v2[i]) {
res.push_back(num);
break;
Expand All @@ -164,20 +164,18 @@ void intersection(std::vector<T>& v1, const std::vector<T>& v2) {
res.swap(v1);
}

static std::vector<std::string> add_quotes(
const std::vector<std::string>& strs) {
std::vector<std::string> add_quotes(const std::vector<std::string>& strs) {
std::vector<std::string> res;
for (auto& str : strs) {
res.emplace_back("\"" + str + "\"");
}
return res;
}

static std::string with_quote(std::string res) { return "\"" + res + "\""; }
std::string with_quote(std::string res) { return "\"" + res + "\""; }

static std::string make_named_property(
const std::vector<std::string>& prop_names,
const std::vector<std::string>& prop_types) {
std::string make_named_property(const std::vector<std::string>& prop_names,
const std::vector<std::string>& prop_types) {
std::stringstream ss;
auto quoted_prop_names = add_quotes(prop_names);
std::string prop_names_str = gs::to_string(quoted_prop_names);
Expand All @@ -190,14 +188,14 @@ static std::string make_named_property(
return ss.str();
}

static std::string make_inner_id_property(int tag_id, std::string prop_type) {
std::string make_inner_id_property(int tag_id, std::string prop_type) {
std::stringstream ss;
ss << INNER_ID_PROPERTY_NAME << "<" << tag_id << ">{}";
return ss.str();
}

static codegen::ParamConst variable_to_param_const(const common::Variable& var,
BuildingContext& ctx) {
codegen::ParamConst variable_to_param_const(const common::Variable& var,
BuildingContext& ctx) {
codegen::ParamConst param_const;
if (var.has_property()) {
auto& var_property = var.property();
Expand Down Expand Up @@ -242,7 +240,7 @@ static codegen::ParamConst variable_to_param_const(const common::Variable& var,
return param_const;
}

static std::string interval_to_str(const common::Extract::Interval& interval) {
std::string interval_to_str(const common::Extract::Interval& interval) {
switch (interval) {
case common::Extract::Interval::Extract_Interval_YEAR:
return "Interval::YEAR";
Expand Down
2 changes: 1 addition & 1 deletion flex/codegen/src/graph_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static std::string common_data_type_pb_2_str(
return single_common_data_type_pb_2_str(data_types[0]);
}
ss << "std::tuple<";
for (auto i = 0; i < data_types.size(); ++i) {
for (size_t i = 0; i < data_types.size(); ++i) {
ss << single_common_data_type_pb_2_str(data_types[i]);
if (i + 1 < data_types.size()) {
ss << ", ";
Expand Down
Loading

0 comments on commit 982de58

Please sign in to comment.