Skip to content
Open
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
1 change: 1 addition & 0 deletions GPU/GPUTracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ if(GPUCA_QA)
endif()

target_link_libraries(${targetName} PRIVATE TBB::tbb)
target_link_libraries(${targetName} PUBLIC Boost::headers)

target_compile_options(${targetName} PRIVATE -Wno-instantiation-after-specialization)

Expand Down
1 change: 1 addition & 0 deletions GPU/GPUTracking/Definitions/GPUSettingsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ AddOption(debugLevel, int32_t, -1, "debug", 'd', "Set debug level (-2 = silent,
AddOption(allocDebugLevel, int32_t, 0, "allocDebug", 0, "Some debug output for memory allocations (without messing with normal debug level)")
AddOption(debugMask, uint32_t, (1 << 18) - 1, "debugMask", 0, "Mask for debug output dumps to file")
AddOption(debugLogSuffix, std::string, "", "debugSuffix", 0, "Suffix for debug log files with --debug 6")
AddOption(debugDumpChecksum, bool, false, "", 0, "Dump the only the checkusm instead of the full file with --debug 6")

Copy link
Copy Markdown
Collaborator

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 :)

AddOption(debugFileHexFloat, int32_t, -1, "", 0, "Use hex format to print floats to debug dump file")
AddOption(debugCSV, std::string, "", "", 0, "CSV filename to append the benchmark results. Verbosity determined by parameter --debug.")
AddOption(debugMarkdown, bool, false, "", 0, "Print the results of standlaone benchmarks in markdown format")
Expand Down
21 changes: 18 additions & 3 deletions GPU/GPUTracking/Global/GPUChainTracking.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ using namespace o2::gpu;
using namespace o2::tpc;
using namespace o2::trd;

GPUChainTracking::GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits, uint32_t maxTRDTracklets) : GPUChain(rec), mIOPtrs(processors()->ioPtrs), mInputsHost(new GPUTrackingInputProvider), mInputsShadow(new GPUTrackingInputProvider), mClusterNativeAccess(new ClusterNativeAccess), mTriggerBuffer(new GPUTriggerOutputs), mMaxTPCHits(maxTPCHits), mMaxTRDTracklets(maxTRDTracklets), mDebugFile(new std::ofstream)
GPUChainTracking::GPUChainTracking(GPUReconstruction* rec, uint32_t maxTPCHits, uint32_t maxTRDTracklets) : GPUChain(rec), mIOPtrs(processors()->ioPtrs), mInputsHost(new GPUTrackingInputProvider), mInputsShadow(new GPUTrackingInputProvider), mClusterNativeAccess(new ClusterNativeAccess), mTriggerBuffer(new GPUTriggerOutputs), mMaxTPCHits(maxTPCHits), mMaxTRDTracklets(maxTRDTracklets), mDebugFile(new std::ostream(nullptr))
{
ClearIOPointers();
mFlatObjectsShadow.mChainTracking = this;
Expand Down Expand Up @@ -386,7 +386,17 @@ int32_t GPUChainTracking::Init()

if (GetProcessingSettings().debugLevel >= 6) {
std::string filename = std::string(mRec->IsGPU() ? "GPU" : "CPU") + (mRec->slaveId() != -1 ? (std::string("_slave") + std::to_string(mRec->slaveId())) : std::string(mRec->slavesExist() ? "_master" : "")) + GetProcessingSettings().debugLogSuffix + ".out";
mDebugFile->open(filename.c_str());

bool hashOnly = GetProcessingSettings().debugDumpChecksum;

std::streambuf* backing = nullptr;
if (!hashOnly) {
mDebugFileBuffer.open(filename.c_str(), std::ios::out);
backing = &mDebugFileBuffer;
}

mDebugFileStream = HashStreamBuf(hashOnly, backing);
mDebugFile->rdbuf(&mDebugFileStream);
if (GetProcessingSettings().debugFileHexFloat >= 1 || (GetProcessingSettings().debugFileHexFloat == -1 && GetProcessingSettings().deterministicGPUReconstruction)) {
*mDebugFile << std::hexfloat;
}
Expand Down Expand Up @@ -475,7 +485,12 @@ int32_t GPUChainTracking::Finalize()
GetQA()->DrawQAHistograms();
}
if (GetProcessingSettings().debugLevel >= 6) {
mDebugFile->close();
mDebugFile->flush();
mDebugFileBuffer.close();

if (GetProcessingSettings().debugDumpChecksum) {
GPUInfo("Debug hash: %lX", mDebugFileStream.hash());
}
}
if (mCompressionStatistics) {
mCompressionStatistics->Finish();
Expand Down
5 changes: 4 additions & 1 deletion GPU/GPUTracking/Global/GPUChainTracking.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "GPUDataTypesIO.h"
#include "GPUDataTypesConfig.h"
#include "GPUCommonAlignedAlloc.h"
#include "utils/HashStreamBuf.h"
#include <atomic>
#include <mutex>
#include <functional>
Expand Down Expand Up @@ -286,7 +287,9 @@ class GPUChainTracking : public GPUChain
uint32_t mMaxTRDTracklets = 0;

// Debug
std::unique_ptr<std::ofstream> mDebugFile;
std::filebuf mDebugFileBuffer;
HashStreamBuf mDebugFileStream;
std::unique_ptr<std::ostream> mDebugFile;

// Synchronization and Locks
eventStruct* mEvents = nullptr;
Expand Down
1 change: 1 addition & 0 deletions GPU/GPUTracking/Standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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++?
Otherwise, the Boost dependency should be optional, and the functionality disabled if boost is not found.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 xxhash.h (single header library, C implementation) for the hashing algorithm and get rid of the boost dependency. But I'm not sure what the policy is on including external sources directly in O2.


if(GPUCA_CONFIG_FMT)
find_package(fmt REQUIRED HINTS $ENV{FMT_ROOT})
Expand Down
98 changes: 98 additions & 0 deletions GPU/GPUTracking/utils/HashStreamBuf.h
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;
};
Loading