Skip to content

Commit

Permalink
[feat][cmake] Support compiling on aarch64 cpu.
Browse files Browse the repository at this point in the history
Signed-off-by: Ketor <d.ketor@gmail.com>
  • Loading branch information
ketor authored and rock-git committed Apr 10, 2024
1 parent 39d0afe commit 3007af7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 77 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -g3 -ggdb")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g3 -ggdb")

message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
message(${CMAKE_HOST_SYSTEM_NAME})
message(${CMAKE_HOST_SYSTEM_PROCESSOR})

# xdprocks
if(XDPROCKS_PATH)
Expand Down Expand Up @@ -645,4 +647,4 @@ endif()
if(BUILD_PYTHON_SDK)
message(STATUS "Build python sdk")
add_subdirectory(src/pysdk)
endif()
endif()
2 changes: 1 addition & 1 deletion cmake/libunwind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SET(LIBUNWIND_INSTALL_DIR ${THIRD_PARTY_PATH}/install/libunwind)
SET(LIBUNWIND_INCLUDE_DIR "${LIBUNWIND_INSTALL_DIR}/include" CACHE PATH "libunwind include directory." FORCE)
SET(LIBUNWIND_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind.a" CACHE FILEPATH "libunwind library." FORCE)
SET(LIBUNWIND_GENERIC_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind-generic.a" CACHE FILEPATH "libunwind generic library." FORCE)
SET(LIBUNWIND_ARCH_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind-x86_64.a" CACHE FILEPATH "libunwind x86_64 library." FORCE)
SET(LIBUNWIND_ARCH_LIBRARIES "${LIBUNWIND_INSTALL_DIR}/lib/libunwind-${CMAKE_HOST_SYSTEM_PROCESSOR}.a" CACHE FILEPATH "libunwind library." FORCE)

FILE(WRITE ${LIBUNWIND_BUILD_DIR}/copy_repo.sh
"mkdir -p ${LIBUNWIND_BUILD_DIR} && cp -rf ${LIBUNWIND_SOURCES_DIR}/* ${LIBUNWIND_BUILD_DIR}/")
Expand Down
2 changes: 1 addition & 1 deletion contrib/bdb
Submodule bdb updated 2 files
+1,037 −747 dist/config.guess
+1,462 −1,262 dist/config.sub
6 changes: 3 additions & 3 deletions src/sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ set(SDK_LIBS
# ${LZ4_LIBRARIES}
# ${ZSTD_LIBRARIES}
${FMT_LIBRARIES}
${ZLIB_LIBRARIES}
# ${ZLIB_LIBRARIES}
${OPENSSL_LIBRARIES}
${CRYPTO_LIBRARIES}
${GLOG_LIBRARIES}
Expand All @@ -93,14 +93,14 @@ set(SDK_LIBS
)

if(BRPC_ENABLE_CPU_PROFILER)
set(SDK_LIBS ${SDK_LIBS} ${GPERFTOOLS_LIBRARIES} ${LIBUNWIND_LIBRARIES})
set(SDK_LIBS ${SDK_LIBS} ${GPERFTOOLS_LIBRARIES} ${LIBUNWIND_LIBRARIES})
endif()

if(ENABLE_COVERAGE)
set(SDK_LIBS ${SDK_LIBS} ${GCOV_LIBRAR})
endif()

set(SDK_LIBS ${SDK_LIBS} dl Threads::Threads)
set(SDK_LIBS ${SDK_LIBS} ${ZLIB_LIBRARIES} dl Threads::Threads)

target_link_libraries(sdk
PRIVATE
Expand Down
103 changes: 32 additions & 71 deletions src/serial/record_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,17 @@
#include <vector>

#include "common/logging.h"
#include "counter.h"

namespace dingodb {

// TODO cast and decode function not good, optimize on 0.8.0 or later

using CastAndDecodeOrSkipFuncPointer = void (*)(
const std::shared_ptr<BaseSchema>& schema,
Buf* key_buf,
Buf* value_buf,
std::vector<std::any>& record,
int record_index,
bool skip
);
using CastAndDecodeOrSkipFuncPointer = void (*)(const std::shared_ptr<BaseSchema>& schema, Buf* key_buf, Buf* value_buf,
std::vector<std::any>& record, int record_index, bool skip);

template <typename T>
void CastAndDecodeOrSkip(
const std::shared_ptr<BaseSchema>& schema,
Buf* key_buf,
Buf* value_buf,
std::vector<std::any>& record,
int record_index,
bool skip
) {

void CastAndDecodeOrSkip(const std::shared_ptr<BaseSchema>& schema, Buf* key_buf, Buf* value_buf,
std::vector<std::any>& record, int record_index, bool skip) {
auto dingo_schema = std::dynamic_pointer_cast<DingoSchema<std::optional<T>>>(schema);
if (skip) {
if (schema->IsKey()) {
Expand All @@ -55,28 +41,27 @@ void CastAndDecodeOrSkip(
record.at(record_index) = dingo_schema->DecodeKey(key_buf);
} else {
if (value_buf->IsEnd()) {
record.at(record_index) = std::optional<T>(std::nullopt);
record.at(record_index) = std::optional<T>(std::nullopt);
} else {
record.at(record_index) = dingo_schema->DecodeValue(value_buf);
record.at(record_index) = dingo_schema->DecodeValue(value_buf);
}
}
}

}

CastAndDecodeOrSkipFuncPointer cast_and_decode_or_skip_func_ptrs[] = {
CastAndDecodeOrSkip<bool>,
CastAndDecodeOrSkip<int32_t>,
CastAndDecodeOrSkip<float>,
CastAndDecodeOrSkip<int64_t>,
CastAndDecodeOrSkip<double>,
CastAndDecodeOrSkip<std::shared_ptr<std::string>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<bool>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<int32_t>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<float>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<int64_t>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<double>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<std::string>>>,
CastAndDecodeOrSkip<bool>,
CastAndDecodeOrSkip<int32_t>,
CastAndDecodeOrSkip<float>,
CastAndDecodeOrSkip<int64_t>,
CastAndDecodeOrSkip<double>,
CastAndDecodeOrSkip<std::shared_ptr<std::string>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<bool>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<int32_t>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<float>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<int64_t>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<double>>>,
CastAndDecodeOrSkip<std::shared_ptr<std::vector<std::string>>>,
};

RecordDecoder::RecordDecoder(int schema_version, std::shared_ptr<std::vector<std::shared_ptr<BaseSchema>>> schemas,
Expand Down Expand Up @@ -113,25 +98,14 @@ bool RecordDecoder::CheckReverseTag(Buf* buf) const {
return false;
}

bool RecordDecoder::CheckSchemaVersion(Buf* buf) const {
return buf->ReadInt() <= schema_version_;
}

void DecodeOrSkip(
const std::shared_ptr<BaseSchema>& schema,
Buf* key_buf,
Buf* value_buf,
std::vector<std::any>& record,
int record_index,
bool skip
) {
cast_and_decode_or_skip_func_ptrs[static_cast<int>(schema->GetType())](
schema, key_buf, value_buf, record, record_index, skip
);
bool RecordDecoder::CheckSchemaVersion(Buf* buf) const { return buf->ReadInt() <= schema_version_; }

void DecodeOrSkip(const std::shared_ptr<BaseSchema>& schema, Buf* key_buf, Buf* value_buf,
std::vector<std::any>& record, int record_index, bool skip) {
cast_and_decode_or_skip_func_ptrs[static_cast<int>(schema->GetType())](schema, key_buf, value_buf, record,
record_index, skip);
}


int RecordDecoder::Decode(const std::string& key, const std::string& value, std::vector<std::any>& record) {
Buf* key_buf = new Buf(key, this->le_);
Buf* value_buf = new Buf(value, this->le_);
Expand Down Expand Up @@ -202,13 +176,8 @@ int RecordDecoder::Decode(const pb::common::KeyValue& key_value, std::vector<std
return Decode(key_value.key(), key_value.value(), record);
}

inline bool IsSkipOnly(
const std::vector<std::pair<int, int>>& indexed_mapping_index,
int& n,
int& m,
int& record_index
) {

inline bool IsSkipOnly(const std::vector<std::pair<int, int>>& indexed_mapping_index, int& n, int& m,
int& record_index) {
int first = indexed_mapping_index[n].first;
int second = indexed_mapping_index[n].second;
DINGO_LOG(DEBUG) << "(" << first << ", " << second << ", " << m << "," << n << ") ";
Expand All @@ -219,17 +188,10 @@ inline bool IsSkipOnly(
} else {
return true;
}

}


int RecordDecoder::Decode(
const std::string& key,
const std::string& value,
const std::vector<int>& column_indexes,
std::vector<std::any>& record
) {

int RecordDecoder::Decode(const std::string& key, const std::string& value, const std::vector<int>& column_indexes,
std::vector<std::any>& record) {
Buf key_buf(key, this->le_);
Buf value_buf(value, this->le_);
if (!CheckPrefix(&key_buf) || !CheckReverseTag(&key_buf) || !CheckSchemaVersion(&value_buf)) {
Expand All @@ -243,6 +205,7 @@ int RecordDecoder::Decode(
std::vector<std::pair<int, int>> col_index_mapping;

// index
col_index_mapping.reserve(column_indexes.size());
for (int i = 0; i < column_indexes.size(); i++) {
col_index_mapping.push_back(std::make_pair(column_indexes[i], i));
}
Expand All @@ -251,21 +214,19 @@ int RecordDecoder::Decode(
std::sort(col_index_mapping.begin(), col_index_mapping.end());

// sort end indexed_mapping_index and mapping_index
DINGO_LOG(DEBUG) << "indexed_mapping_index: ";
DINGO_LOG(DEBUG) << "indexed_mapping_index: ";
for (auto p : col_index_mapping) {
DINGO_LOG(DEBUG) << "(" << p.first << ", " << p.second << ") ";
}

int record_index = 0;
for (auto iter = schemas_->begin(); iter != schemas_->end(); ++iter) {

for (auto& bs : *schemas_) {
if (column_indexes.size() == n) {
return 0;
}
const auto& bs = *iter;
if (bs) {

DecodeOrSkip(bs, &key_buf, &value_buf, record, record_index, IsSkipOnly(col_index_mapping, n, m, record_index));
bool is_skip = IsSkipOnly(col_index_mapping, n, m, record_index);
DecodeOrSkip(bs, &key_buf, &value_buf, record, record_index, is_skip);
}
}
return 0;
Expand Down

0 comments on commit 3007af7

Please sign in to comment.