Skip to content
Merged
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
37 changes: 23 additions & 14 deletions GPU/GPUTracking/Base/GPUReconstruction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ int32_t GPUReconstruction::Init()
return retVal;
}
mNStreams = std::max(mNStreams, mSlaves[i]->mNStreams);
mHostMemorySize = std::max(mHostMemorySize, mSlaves[i]->mHostMemorySize);
mHostMemorySize += mSlaves[i]->mHostMemorySize;
mDeviceMemorySize = std::max(mDeviceMemorySize, mSlaves[i]->mDeviceMemorySize);
}
if (InitDevice()) {
Expand Down Expand Up @@ -269,7 +269,7 @@ int32_t GPUReconstruction::InitPhaseBeforeDevice()
detMode = true;
#endif
if (GetProcessingSettings().deterministicGPUReconstruction == -1) {
mProcessingSettings->deterministicGPUReconstruction = detMode ? 1 : (GetProcessingSettings().debugLevel >= 6);
mProcessingSettings->deterministicGPUReconstruction = detMode ? 1 : GetProcessingSettings().debugLevel >= 6;
}
if (GetProcessingSettings().deterministicGPUReconstruction) {
if (!detMode) {
Expand Down Expand Up @@ -375,7 +375,7 @@ int32_t GPUReconstruction::InitPhaseBeforeDevice()
return 1;
}
mChains[i]->RegisterPermanentMemoryAndProcessors();
size_t memPrimary, memPageLocked;
size_t memPrimary = 0, memPageLocked = 0;
mChains[i]->MemorySize(memPrimary, memPageLocked);
if (!IsGPU() || mOutputControl.useInternal()) {
memPageLocked = memPrimary;
Expand Down Expand Up @@ -584,7 +584,7 @@ size_t GPUReconstruction::AllocateRegisteredMemoryHelper(GPUMemoryResource* res,
GPUError("Insufficient reuse memory %lu < %lu (%s) (%s)", mMemoryResources[res->mReuse].mSize, retVal, res->mName, device);
throw std::bad_alloc();
}
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << "Reused (" << device << ") " << res->mName << ": " << retVal << "\n";
}
return retVal;
Expand Down Expand Up @@ -619,7 +619,7 @@ size_t GPUReconstruction::AllocateRegisteredMemoryHelper(GPUMemoryResource* res,
std::cerr << "Memory pool size exceeded (" << device << ") (" << res->mName << ": " << (memorypoolend ? (memorysize + ptrDiff(memorypool, memorypoolend)) : ptrDiff(memorypool, memorybase)) << " > " << memorysize << "\n";
throw std::bad_alloc();
}
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << "Allocated (" << device << ") " << res->mName << ": " << retVal << " - available: " << (memorypoolend ? ptrDiff(memorypoolend, memorypool) : (memorysize - ptrDiff(memorypool, memorybase))) << "\n";
}
return retVal;
Expand All @@ -644,7 +644,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
}
res->mPtr = GPUProcessor::alignPointer<constants::GPU_BUFFER_ALIGNMENT>(res->mPtrDevice);
res->SetPointers(res->mPtr);
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << (res->mReuse >= 0 ? "Reused " : "Allocated ") << res->mName << ": " << res->mSize << " (individual" << ((res->mType & GPUMemoryResource::MEMORY_STACK) ? " stack" : "") << ")\n";
}
if (res->mType & GPUMemoryResource::MEMORY_STACK) {
Expand All @@ -670,7 +670,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
res->mSize = std::max((size_t)res->SetPointers((void*)1) - 1, res->mOverrideSize);
res->mPtr = control->allocator(CAMath::nextMultipleOf<constants::GPU_BUFFER_ALIGNMENT>(res->mSize));
res->mSize = std::max<size_t>(ptrDiff(res->SetPointers(res->mPtr), res->mPtr), res->mOverrideSize);
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << "Allocated (from callback) " << res->mName << ": " << res->mSize << "\n";
}
} else {
Expand Down Expand Up @@ -766,7 +766,7 @@ void* GPUReconstruction::AllocateDirectMemory(size_t size, int32_t type)
throw std::bad_alloc();
}
UpdateMaxMemoryUsed();
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << "Allocated (direct " << ((type & GPUMemoryResource::MEMORY_GPU) ? "gpu" : "host") << "): " << size << " - available: " << ptrDiff(poolend, pool) << "\n";
}
return retVal;
Expand All @@ -788,7 +788,7 @@ void* GPUReconstruction::AllocateVolatileDeviceMemory(size_t size)
throw std::bad_alloc();
}
UpdateMaxMemoryUsed();
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << "Allocated (volatile GPU): " << size << " - available: " << ptrDiff(mDeviceMemoryPoolEnd, mDeviceMemoryPool) << "\n";
}
return retVal;
Expand Down Expand Up @@ -818,7 +818,7 @@ void GPUReconstruction::ReturnVolatileDeviceMemory()
mDeviceMemoryPool = mVolatileMemoryStart;
mVolatileMemoryStart = nullptr;
}
if (GetProcessingSettings().allocDebugLevel >= 2) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent) {
std::cout << "Freed (volatile GPU) - available: " << ptrDiff(mDeviceMemoryPoolEnd, mDeviceMemoryPool) << "\n";
}
}
Expand Down Expand Up @@ -875,7 +875,7 @@ void GPUReconstruction::FreeRegisteredMemory(int16_t ires)

void GPUReconstruction::FreeRegisteredMemory(GPUMemoryResource* res)
{
if (GetProcessingSettings().allocDebugLevel >= 2 && (res->mPtr || res->mPtrDevice)) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent && (res->mPtr || res->mPtrDevice)) {
std::cout << "Freeing " << res->mName << ": size " << res->mSize << " (reused " << res->mReuse << ")\n";
}
if (GetProcessingSettings().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL && res->mReuse < 0) {
Expand Down Expand Up @@ -904,7 +904,7 @@ void GPUReconstruction::PopNonPersistentMemory(RecoStep step, uint64_t tag, cons
if (tag != 0 && std::get<4>(mNonPersistentMemoryStack.back()) != tag) {
GPUFatal("Tag mismatch when popping non persistent memory from stack : pop %s vs on stack %s", qTag2Str(tag).c_str(), qTag2Str(std::get<4>(mNonPersistentMemoryStack.back())).c_str());
}
if (!proc && (GetProcessingSettings().debugLevel >= 3 || GetProcessingSettings().allocDebugLevel) && (IsGPU() || GetProcessingSettings().forceHostMemoryPoolSize)) {
if (!proc && (GetProcessingSettings().debugLevel >= 3 || GetProcessingSettings().allocDebugLevel) && !GetProcessingSettings().debugSilent && (IsGPU() || GetProcessingSettings().forceHostMemoryPoolSize)) {
printf("Allocated memory after %30s (%8s) (Stack %zu): ", gpudatatypes::RECO_STEP_NAMES[getRecoStepNum(step, true)], qTag2Str(std::get<4>(mNonPersistentMemoryStack.back())).c_str(), mNonPersistentMemoryStack.size());
PrintMemoryOverview();
printf("%76s", "");
Expand All @@ -915,7 +915,7 @@ void GPUReconstruction::PopNonPersistentMemory(RecoStep step, uint64_t tag, cons
if (proc && res->mProcessor != proc) {
continue;
}
if (GetProcessingSettings().allocDebugLevel >= 2 && (res->mPtr || res->mPtrDevice)) {
if (GetProcessingSettings().allocDebugLevel >= 2 && !GetProcessingSettings().debugSilent && (res->mPtr || res->mPtrDevice)) {
std::cout << "Freeing NonPersistent " << res->mName << ": size " << res->mSize << " (reused " << res->mReuse << ")\n";
}
if (res->mReuse < 0) {
Expand Down Expand Up @@ -1345,11 +1345,20 @@ void GPUReconstruction::SetInputControl(void* ptr, size_t size) { mInputControl.
GPUReconstruction::DeviceType GPUReconstruction::GetDeviceType() const { return (DeviceType)GetDeviceBackendSettings().deviceType; }
const GPUParam& GPUReconstruction::GetParam() const { return mHostConstantMem->param; }
void GPUReconstruction::SetResetTimers(bool reset) { mProcessingSettings->resetTimers = reset; }
void GPUReconstruction::SetDebugLevelTmp(int32_t level) { mProcessingSettings->debugLevel = level; }
GPUParam& GPUReconstruction::param() { return mHostConstantMem->param; }
const GPUTrackingInOutPointers GPUReconstruction::GetIOPtrs() const { return mHostConstantMem->ioPtrs; }
const GPUCalibObjectsConst& GPUReconstruction::GetCalib() const { return processors()->calibObjects; }

void GPUReconstruction::SetDebugLevelTmp(int32_t level, int32_t silent)
{
if (level > -100) {
mProcessingSettings->debugLevel = level;
}
if (silent > -100) {
mProcessingSettings->debugSilent = silent;
}
}

ThrustVolatileAllocator::ThrustVolatileAllocator(GPUReconstruction* r)
{
mAlloc = [&r](size_t n) { return (char*)r->AllocateVolatileDeviceMemory(n); };
Expand Down
5 changes: 3 additions & 2 deletions GPU/GPUTracking/Base/GPUReconstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class GPUReconstruction
// Getters / setters for parameters
DeviceType GetDeviceType() const;
bool IsGPU() const { return GetDeviceType() != DeviceType::INVALID_DEVICE && GetDeviceType() != DeviceType::CPU; }
virtual bool backendSupportsRTC() const { return false; }
const GPUParam& GetParam() const;
const GPUConstantMem& GetConstantMem() const { return *mHostConstantMem; }
const GPUTrackingInOutPointers GetIOPtrs() const;
Expand All @@ -216,8 +217,8 @@ class GPUReconstruction
bool IsInitialized() const { return mInitialized; }
void SetSettings(float solenoidBzNominalGPU, const GPURecoStepConfiguration* workflow = nullptr);
void SetSettings(const GPUSettingsGRP* grp, const GPUSettingsRec* rec = nullptr, const GPUSettingsProcessing* proc = nullptr, const GPURecoStepConfiguration* workflow = nullptr);
void SetResetTimers(bool reset); // May update also after Init()
void SetDebugLevelTmp(int32_t level); // Temporarily, before calling SetSettings()
void SetResetTimers(bool reset); // May update also after Init()
void SetDebugLevelTmp(int32_t level = -100, int32_t silent = -100); // Temporarily, before calling SetSettings()
void UpdateSettings(const GPUSettingsGRP* g, const GPUSettingsProcessing* p = nullptr, const GPUSettingsRecDynamic* d = nullptr);
void UpdateDynamicSettings(const GPUSettingsRecDynamic* d);
void SetOutputControl(const GPUOutputControl& v) { mOutputControl = v; }
Expand Down
11 changes: 6 additions & 5 deletions GPU/GPUTracking/Base/GPUReconstructionCPU.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ int32_t GPUReconstructionCPU::RunChains()
mStatNEvents++;
mNEventsProcessed++;

if (GetProcessingSettings().debugLevel >= 3 || GetProcessingSettings().allocDebugLevel) {
if ((GetProcessingSettings().debugLevel >= 3 || GetProcessingSettings().allocDebugLevel) && !GetProcessingSettings().debugSilent) {
GPUInfo("Allocated memory when starting processing %34s", "");
PrintMemoryOverview();
}
Expand All @@ -314,7 +314,7 @@ int32_t GPUReconstructionCPU::RunChains()
ClearAllocatedMemory();
}
mStatCPUTime += (double)(std::clock() - cpuTimerStart) / CLOCKS_PER_SEC;
if (GetProcessingSettings().debugLevel >= 3 || GetProcessingSettings().allocDebugLevel) {
if ((GetProcessingSettings().debugLevel >= 3 || GetProcessingSettings().allocDebugLevel) && !GetProcessingSettings().debugSilent) {
GPUInfo("Allocated memory when ending processing %36s", "");
PrintMemoryOverview();
}
Expand All @@ -327,7 +327,7 @@ int32_t GPUReconstructionCPU::RunChains()
double kernelTotal = 0;
std::vector<double> kernelStepTimes(gpudatatypes::N_RECO_STEPS, 0.);

debugWriter writer(GetProcessingSettings().debugCSV, GetProcessingSettings().debugMarkdown, mStatNEvents);
debugWriter writer(GetProcessingSettings().debugCSV, GetProcessingSettings().debugMarkdown, mStatNEvents, GetProcessingSettings().debugSilent);

if (GetProcessingSettings().debugLevel >= 1) {
writer.header();
Expand Down Expand Up @@ -357,6 +357,7 @@ int32_t GPUReconstructionCPU::RunChains()
}
}
}
mStatKernelTime = kernelTotal * 1000000. / mStatNEvents; // Average kernel time per run in us, like mStatWallTime, only with debugLevel >= 1
if (GetProcessingSettings().recoTaskTiming) {
for (int32_t i = 0; i < gpudatatypes::N_RECO_STEPS; i++) {
if (kernelStepTimes[i] != 0. || mTimersRecoSteps[i].timerTotal.GetElapsedTime() != 0.) {
Expand Down Expand Up @@ -385,7 +386,7 @@ int32_t GPUReconstructionCPU::RunChains()
}
double gpu_time = GetProcessingSettings().debugLevel >= 1 ? kernelTotal : -1.0;
writer.row(' ', 0, "Wall", gpu_time, mStatCPUTime, mTimerTotal.GetElapsedTime(), 0, nEventReport);
} else if (GetProcessingSettings().debugLevel >= 0) {
} else if (GetProcessingSettings().debugLevel >= 0 && !GetProcessingSettings().debugSilent) {
GPUInfo("Total Wall Time: %10.0f us%s", mStatWallTime, nEventReport.c_str());
}
if (GetProcessingSettings().resetTimers) {
Expand All @@ -399,7 +400,7 @@ int32_t GPUReconstructionCPU::RunChains()
}
if (GetProcessingSettings().memoryStat) {
PrintMemoryStatistics();
} else if (GetProcessingSettings().debugLevel >= 2) {
} else if (GetProcessingSettings().debugLevel >= 2 && !GetProcessingSettings().debugSilent) {
PrintMemoryOverview();
}

Expand Down
3 changes: 2 additions & 1 deletion GPU/GPUTracking/Base/GPUReconstructionCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ class GPUReconstructionCPU : public GPUReconstructionProcessing::KernelInterface
void runKernelInterface(krnlSetup&& setup, Args const&... args);

struct debugWriter {
debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents);
debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents, bool silent);
void header();
void row(char type, uint32_t count, std::string name, double gpu_time, double cpu_time, double total_time, std::size_t memSize, std::string nEventReport = "");

private:
std::ofstream streamCSV;
bool mMarkdown;
bool mSilent;
uint32_t mStatNEvents;
};
};
Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline void GPUReconstructionCPU::runKernelInterface(krnlSetup&& setup, Args con
if (nThreads > constants::GPU_MAX_THREADS) {
throw std::runtime_error("GPU_MAX_THREADS exceeded");
}
if (GetProcessingSettings().debugLevel >= 3) {
if (GetProcessingSettings().debugLevel >= 3 && !GetProcessingSettings().debugSilent) {
GPUInfo("Running kernel %s (Stream %d, Index %d, Grid %d/%d) on %s", GetKernelName<S, I>(), stream, setup.y.index, nBlocks, nThreads, cpuFallback == 2 ? "CPU (forced)" : (cpuFallback ? "CPU (fallback)" : mDeviceName.c_str()));
}
if (nThreads == 0 || nBlocks == 0) {
Expand Down
4 changes: 2 additions & 2 deletions GPU/GPUTracking/Base/GPUReconstructionDebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ bool GPUReconstruction::triggerDebugDump()
return false;
}

GPUReconstructionCPU::debugWriter::debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents) : mMarkdown{markdown}, mStatNEvents{statNEvents}
GPUReconstructionCPU::debugWriter::debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents, bool silent) : mMarkdown{markdown}, mSilent{silent}, mStatNEvents{statNEvents}
{
if (!filenameCSV.empty()) {
streamCSV.open(filenameCSV, std::ios::out | std::ios::app);
Expand Down Expand Up @@ -277,7 +277,7 @@ void GPUReconstructionCPU::debugWriter::row(char type, uint32_t count, std::stri
std::cout << " | | |";
}
std::cout << std::endl;
} else {
} else if (!mSilent) {
if (name.substr(0, 3) == "GPU") {
char bandwidth[256] = "";
if (memSize && mStatNEvents && gpu_time != 0.0) {
Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUTracking/Base/GPUReconstructionDeviceBase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ size_t GPUReconstructionDeviceBase::TransferMemoryInternal(GPUMemoryResource* re
}
return 0;
}
if (GetProcessingSettings().debugLevel >= 3 && (strcmp(res->Name(), "ErrorCodes") || GetProcessingSettings().debugLevel >= 4)) {
if (GetProcessingSettings().debugLevel >= 3 && !GetProcessingSettings().debugSilent && (strcmp(res->Name(), "ErrorCodes") || GetProcessingSettings().debugLevel >= 4)) {
GPUInfo("Copying to %s: %s - %ld bytes", toGPU ? "GPU" : "Host", res->Name(), (int64_t)res->Size());
}
return GPUMemCpy(dst, src, res->Size(), stream, toGPU, ev, evList, nEvents);
Expand Down
10 changes: 5 additions & 5 deletions GPU/GPUTracking/Base/GPUReconstructionIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ inline uint32_t GPUReconstruction::DumpData(FILE* fp, const T* const* entries, c
fwrite(entries[i], sizeof(*entries[i]), num[i], fp);
}
}
if (GetProcessingSettings().debugLevel >= 2) {
if (GetProcessingSettings().debugLevel >= 2 && !GetProcessingSettings().debugSilent) {
GPUInfo("Dumped %u %s", numTotal, IOTYPENAMES[type]);
}
return numTotal;
Expand Down Expand Up @@ -107,7 +107,7 @@ inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, s
}
numTotal += num[i];
}
if (GetProcessingSettings().debugLevel >= 2) {
if (GetProcessingSettings().debugLevel >= 2 && !GetProcessingSettings().debugSilent) {
GPUInfo("Read %zu %s", numTotal, IOTYPENAMES[type]);
}
return numTotal;
Expand Down Expand Up @@ -147,7 +147,7 @@ inline std::unique_ptr<T> GPUReconstruction::ReadFlatObjectFromFile(const char*
r = fread((void*)retVal.get(), 1, size[0], fp);
r = fread(buf, 1, size[1], fp);
fclose(fp);
if (GetProcessingSettings().debugLevel >= 2) {
if (GetProcessingSettings().debugLevel >= 2 && !GetProcessingSettings().debugSilent) {
GPUInfo("Read %zu bytes from %s", r, file);
}
retVal->clearInternalBufferPtr();
Expand Down Expand Up @@ -197,7 +197,7 @@ inline std::unique_ptr<T> GPUReconstruction::ReadStructFromFile(const char* file
GPUError("ERROR reading %s, read %zu (%zu expected)", file, r, size);
throw std::runtime_error("invalid size");
}
if (GetProcessingSettings().debugLevel >= 2) {
if (GetProcessingSettings().debugLevel >= 2 && !GetProcessingSettings().debugSilent) {
GPUInfo("Read %zu bytes from %s", r, file);
}
if (errorOnMissing) {
Expand Down Expand Up @@ -255,7 +255,7 @@ inline aligned_unique_buffer_ptr<T> GPUReconstruction::ReadDynamicStructFromFile
GPUError("ERROR in %s: File Read error: %zu (%zu expected)", file, r, dynsize - sizeof(T));
throw std::runtime_error("invalid size");
}
if (GetProcessingSettings().debugLevel >= 2) {
if (GetProcessingSettings().debugLevel >= 2 && !GetProcessingSettings().debugSilent) {
GPUInfo("Read %zu bytes from %s", r + dynsize, file);
}
return newObj;
Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUTracking/Base/GPUReconstructionProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void GPUReconstructionProcessing::SetNActiveThreads(int32_t n)
{
mActiveHostKernelThreads = std::max(1, n < 0 ? mMaxHostThreads : std::min(n, mMaxHostThreads));
mThreading->activeThreads = std::make_unique<tbb::task_arena>(mActiveHostKernelThreads);
if (GetProcessingSettings().debugLevel >= 3) {
if (GetProcessingSettings().debugLevel >= 3 && !GetProcessingSettings().debugSilent) {
GPUInfo("Set number of active parallel kernels threads on host to %d (%d requested)", mActiveHostKernelThreads, n);
}
}
Expand Down
Loading