Repository navigation
GPU/Standalone: Compute checksum of dumped data #15908
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,7 @@ elseif(GPUCA_BUILD_EVENT_DISPLAY) | |
| message(FATAL_ERROR "Cannot build event display without ROOT") | ||
| endif() | ||
| find_package(Microsoft.GSL REQUIRED HINTS "$ENV{MS_GSL_ROOT}/share/cmake") | ||
| find_package(Boost 1.88 REQUIRED) # boost/hash2 (HashStreamBuf.h) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The standalone benchmark should not be force to depend on boost. Isn't there a way to do this with modern C++?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not aware of anything in the C++ standard library that provides this. We could just include |
||
|
|
||
| if(GPUCA_CONFIG_FMT) | ||
| find_package(fmt REQUIRED HINTS $ENV{FMT_ROOT}) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright 2019-2026 CERN and copyright holders of ALICE O2. | ||
| // See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. | ||
| // All rights not expressly granted are reserved. | ||
| // | ||
| // This software is distributed under the terms of the GNU General Public | ||
| // License v3 (GPL Version 3), copied verbatim in the file "COPYING". | ||
| // | ||
| // In applying this license CERN does not waive the privileges and immunities | ||
| // granted to it by virtue of its status as an Intergovernmental Organization | ||
| // or submit itself to any jurisdiction. | ||
|
|
||
| /// \file HashStreamBuf.h | ||
| /// \author Felix Weiglhofer | ||
| /// \brief Stream buffer that supports on the fly hashing with an optional backing file buffer, | ||
| // if we want to access the hash and file contents at the same time. | ||
|
|
||
| #include <boost/hash2/xxhash.hpp> | ||
|
|
||
| #include <cstdint> | ||
| #include <streambuf> | ||
| #include <ostream> | ||
|
|
||
| class HashStreamBuf : public std::streambuf | ||
| { | ||
| public: | ||
| HashStreamBuf() = default; | ||
|
|
||
| HashStreamBuf(bool doHash, | ||
| std::streambuf* backing = nullptr, | ||
| uint64_t seed = 0) | ||
| : mBacking(backing), | ||
| mHash(seed), | ||
| mDoHash(doHash) | ||
| { | ||
| } | ||
|
|
||
| // Returns the hash without modifying the current hashing state. | ||
| uint64_t hash() const | ||
| { | ||
| auto copy = mHash; | ||
| return copy.result(); | ||
| } | ||
|
|
||
| protected: | ||
| std::streamsize xsputn(const char* data, | ||
| std::streamsize size) override | ||
| { | ||
| if (size <= 0) { | ||
| size = 0; | ||
| } | ||
|
|
||
| if (mBacking) { | ||
| // Only hash bytes that were successfully written | ||
| // to the backing stream. | ||
| size = mBacking->sputn(data, size); | ||
| } | ||
|
|
||
| if (mDoHash) { | ||
| mHash.update(data, static_cast<size_t>(size)); | ||
| } | ||
| return size; | ||
| } | ||
|
|
||
| int_type overflow(int_type ch) override | ||
| { | ||
| if (traits_type::eq_int_type(ch, traits_type::eof())) | ||
| return traits_type::not_eof(ch); | ||
|
|
||
| const char c = traits_type::to_char_type(ch); | ||
|
|
||
| if (mBacking) { | ||
| const auto result = mBacking->sputc(c); | ||
|
|
||
| if (traits_type::eq_int_type(result, | ||
| traits_type::eof())) { | ||
| return traits_type::eof(); | ||
| } | ||
| } | ||
|
|
||
| mHash.update(&c, 1); | ||
|
|
||
| return ch; | ||
| } | ||
|
|
||
| int sync() override | ||
| { | ||
| int s = 0; | ||
| if (mBacking) { | ||
| s = mBacking->pubsync(); | ||
| } | ||
| return s; | ||
| } | ||
|
|
||
| private: | ||
| std::streambuf* mBacking = nullptr; | ||
| boost::hash2::xxhash_64 mHash; | ||
| bool mDoHash = false; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the english in the description :)