Skip to content

Commit

Permalink
GPU: Require correct buffer alignment (after fixed in FMQ)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrohr committed Jan 25, 2021
1 parent 0e2410a commit db8a940
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion GPU/GPUTracking/Base/GPUReconstruction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,10 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
if (res->mType & GPUMemoryResource::MEMORY_STACK) {
mNonPersistentIndividualAllocations.emplace_back(res);
}
if ((size_t)res->mPtr % GPUCA_BUFFER_ALIGNMENT) {
GPUError("Got buffer with insufficient alignment");
throw std::bad_alloc();
}
}
} else {
if (res->mPtr != nullptr) {
Expand All @@ -557,7 +561,7 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
if (control && control->useExternal()) {
if (control->allocator) {
res->mSize = std::max((size_t)res->SetPointers((void*)1) - 1, res->mOverrideSize);
res->mPtr = control->allocator(res->mSize);
res->mPtr = control->allocator(CAMath::nextMultipleOf<GPUCA_BUFFER_ALIGNMENT>(res->mSize));
res->mSize = std::max<size_t>((char*)res->SetPointers(res->mPtr) - (char*)res->mPtr, res->mOverrideSize);
} else {
void* dummy = nullptr;
Expand All @@ -566,6 +570,10 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
} else {
res->mSize = AllocateRegisteredMemoryHelper(res, res->mPtr, recPool->mHostMemoryPool, recPool->mHostMemoryBase, recPool->mHostMemorySize, &GPUMemoryResource::SetPointers, recPool->mHostMemoryPoolEnd);
}
if ((size_t)res->mPtr % GPUCA_BUFFER_ALIGNMENT) {
GPUError("Got buffer with insufficient alignment");
throw std::bad_alloc();
}
}
if (IsGPU() && (res->mType & GPUMemoryResource::MEMORY_GPU)) {
if (res->mProcessor->mLinkedProcessor == nullptr) {
Expand All @@ -580,6 +588,10 @@ void GPUReconstruction::AllocateRegisteredMemoryInternal(GPUMemoryResource* res,
GPUError("Inconsistent device memory allocation (%s: device %lu vs %lu)", res->mName, size, res->mSize);
throw std::bad_alloc();
}
if ((size_t)res->mPtrDevice % GPUCA_BUFFER_ALIGNMENT) {
GPUError("Got buffer with insufficient alignment");
throw std::bad_alloc();
}
}
UpdateMaxMemoryUsed();
}
Expand Down

0 comments on commit db8a940

Please sign in to comment.