@@ -712,9 +712,6 @@ size_t GPUReconstruction::AllocateRegisteredMemory(int16_t ires, GPUOutputContro
712712
713713void * GPUReconstruction::AllocateDirectMemory (size_t size, int32_t type)
714714{
715- if (type != GPUMemoryResource::MEMORY_HOST && (!IsGPU () || type != GPUMemoryResource::MEMORY_GPU)) {
716- throw std::runtime_error (" Requested invalid memory typo for unmanaged allocation" );
717- }
718715 if (GetProcessingSettings ().memoryAllocationStrategy == GPUMemoryResource::ALLOCATION_INDIVIDUAL) {
719716 char * retVal = new (std::align_val_t (GPUCA_BUFFER_ALIGNMENT)) char [size];
720717 if ((type & GPUMemoryResource::MEMORY_STACK)) {
@@ -723,25 +720,35 @@ void* GPUReconstruction::AllocateDirectMemory(size_t size, int32_t type)
723720 mDirectMemoryChunks .emplace_back (retVal, alignedDeleter ());
724721 }
725722 return retVal;
723+ }
724+
725+ if ((type & ~(GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_GPU | GPUMemoryResource::MEMORY_STACK)) || ((type & GPUMemoryResource::MEMORY_HOST) && (type & GPUMemoryResource::MEMORY_GPU))) {
726+ throw std::runtime_error (" Requested invalid memory typo for direct allocation" );
727+ }
728+ if (mVolatileMemoryStart && !mDeviceMemoryAsVolatile && (type & GPUMemoryResource::MEMORY_GPU) && !(type & GPUMemoryResource::MEMORY_STACK)) {
729+ GPUError (" Must not allocate direct memory while volatile chunks are allocated" );
730+ throw std::bad_alloc ();
731+ }
732+
733+ void *& pool = (type & GPUMemoryResource::MEMORY_GPU) ? mDeviceMemoryPool : mHostMemoryPool ;
734+ void *& poolend = (type & GPUMemoryResource::MEMORY_GPU) ? mDeviceMemoryPoolEnd : mHostMemoryPoolEnd ;
735+ char * retVal;
736+ if ((type & GPUMemoryResource::MEMORY_STACK)) {
737+ poolend = (char *)poolend - size;
738+ poolend = (char *)poolend - GPUProcessor::getAlignmentMod<GPUCA_MEMALIGN>(poolend);
739+ retVal = (char *)poolend;
726740 } else {
727- if (mVolatileMemoryStart && !mDeviceMemoryAsVolatile && (type & GPUMemoryResource::MEMORY_GPU) && !(type & GPUMemoryResource::MEMORY_STACK)) {
728- GPUError (" Must not allocate direct memory while volatile chunks are allocated" );
729- throw std::bad_alloc ();
730- }
731- void *& pool = type == GPUMemoryResource::MEMORY_GPU ? mDeviceMemoryPool : mHostMemoryPool ;
732- void *& poolend = type == GPUMemoryResource::MEMORY_GPU ? mDeviceMemoryPoolEnd : mHostMemoryPoolEnd ;
733- char * retVal;
734741 GPUProcessor::computePointerWithAlignment (pool, retVal, size);
735- if (pool > poolend) {
736- GPUError (" Insufficient unmanaged memory: missing %ld bytes" , ptrDiff (pool, poolend));
737- throw std::bad_alloc ();
738- }
739- UpdateMaxMemoryUsed ();
740- if (GetProcessingSettings ().allocDebugLevel >= 2 ) {
741- std::cout << " Allocated (unmanaged " << (type == GPUMemoryResource::MEMORY_GPU ? " gpu" : " host" ) << " ): " << size << " - available: " << ptrDiff (poolend, pool) << " \n " ;
742- }
743- return retVal;
744742 }
743+ if (pool > poolend) {
744+ GPUError (" Insufficient unmanaged memory: missing %ld bytes" , ptrDiff (pool, poolend));
745+ throw std::bad_alloc ();
746+ }
747+ UpdateMaxMemoryUsed ();
748+ if (GetProcessingSettings ().allocDebugLevel >= 2 ) {
749+ std::cout << " Allocated (unmanaged " << (type == GPUMemoryResource::MEMORY_GPU ? " gpu" : " host" ) << " ): " << size << " - available: " << ptrDiff (poolend, pool) << " \n " ;
750+ }
751+ return retVal;
745752}
746753
747754void * GPUReconstruction::AllocateVolatileDeviceMemory (size_t size)
0 commit comments