Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct some uses of wrong variable types preventing QLever from running on ARM #116

Merged
merged 2 commits into from Aug 30, 2018
Merged

Conversation

niklas88
Copy link
Member

@niklas88 niklas88 commented Aug 29, 2018

To improve the portability and type correctness of the QLever code base I'm trying to get it running on my Raspberry Pi (ARM) as well as an Odroid C1 (ARM64). I find that most issues this uncovers look like they are worth doing right even on x86_64

Note: With the current state of this PR everything compiles and it can built some kind of index. However there are still problems with SCANs which break most queries (at least on ARM, haven't tested ARM64 yet). Also convertIndexWordToFloat() seems to be broken on 32 bit ARM.

  • Most are uses of size_t where we really want Id (uint64_t) which on ARM are incompatible
  • Also use explicitly sized types for versions and magic numbers
  • In MmapVector we were also using -someSizeT as an off_t which somehow
    doesn't work on ARM. I guess the compiler tries to do it as an unary
    minus before converting to off_t

@@ -153,7 +154,7 @@ using IndexMetaDataMmapView = IndexMetaData<
MetaDataWrapperDense<ad_utility::MmapVectorView<FullRelationMetaData>>>;

// constants for Magic Numbers to separate different types of MetaData;
const size_t MAGIC_NUMBER_MMAP_META_DATA = static_cast<size_t>(-1);
const size_t MAGIC_NUMBER_SPARSE_META_DATA = static_cast<size_t>(-2);
const uint64_t MAGIC_NUMBER_MMAP_META_DATA = std::numeric_limits<uint64_t>::max();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has wrong formatting

@@ -252,8 +252,8 @@ class MmapVector {
std::string _filename = "";
AccessPattern _pattern = AccessPattern::None;
static constexpr float ResizeFactor = 1.5;
static constexpr int MagicNumber = 7601577;
static constexpr int Version = 0;
static constexpr uint64_t MagicNumber = 7601577;
Copy link
Member Author

@niklas88 niklas88 Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the index format, will change to use uint32_t here which should be compatible

@@ -77,14 +80,14 @@ void MmapVector<T>::readMetaDataFromEnd() {
template <class T>
void MmapVector<T>::mapForReading() {
// open to get valid file descriptor
FILE* fp = fopen(_filename.c_str(), "r");
int orig_fd = ::open(_filename.c_str(), O_RDONLY);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to make things more similar to the write case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agreed.

* These break building QLever on ARM where size_t is incompatible with
  Id (uint64_t)
* Most are uses of size_t where we really want Id
* Also use explicitly sized types for versions and magic numbers
* In MmapVector we were also using -someSizeT as an off_t which somehow
  doesn't work on ARM. I guess the compiler tries to do it as an unary
  minus before converting to off_t
@niklas88 niklas88 requested a review from joka921 August 29, 2018 13:48
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, As far as I see you only avoided casts between size_t and Id. This is completely in my interest too

@@ -43,6 +43,8 @@ void MmapVector<T>::writeMetaDataToEnd() {
ofs.write((char*)&_bytesize, sizeof(_bytesize));
ofs.write((char*)&MagicNumber, sizeof(MagicNumber));
ofs.write((char*)&Version, sizeof(Version));
ofs.flush();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this pattern over and over again in the code:
Usage of explicit open() and close() for ad_utility::File and std::fstream.
But actually I think this not necessary when the file class is only used locally and the flush and close are done automagically by the destructor. So wouldn't it be more C++ to let RAII do its job here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I played around with this searching for a bug that broke the MmapVectorTest. Ultimately it was something else. So yeah makes sense to let that happen implicitly

@@ -77,14 +80,14 @@ void MmapVector<T>::readMetaDataFromEnd() {
template <class T>
void MmapVector<T>::mapForReading() {
// open to get valid file descriptor
FILE* fp = fopen(_filename.c_str(), "r");
int orig_fd = ::open(_filename.c_str(), O_RDONLY);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally agreed.

@@ -588,22 +588,20 @@ string decodeUrl(const string& url) {
} else if (h1 >= 'a' && h1 <= 'f') {
h1 = h1 - 'a' + 10;
} else {
h1 = -1;
decoded += '%';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this indeed valid URL encoding? As I see it you interpret % as % when the next character cannot be interpreted as HEX. Is there a reason for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, you just refactored the original behaviour. I'm still not sure whether this is within the specification.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither am I. It's a bit hackish too.

@niklas88 niklas88 merged commit 67a43ec into ad-freiburg:master Aug 30, 2018
@niklas88 niklas88 deleted the arm_cleanups branch October 31, 2018 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants