@@ -415,8 +415,8 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size,
415415 unifiedMemoryProperties.flags .isUSMDeviceAllocation = false ;
416416 unifiedMemoryProperties.cacheRegion = MemoryPropertiesHelper::getCacheRegion (memoryProperties.allocationFlags );
417417
418- if (this ->usmHostAllocationsCacheEnabled ) {
419- void *allocationFromCache = this ->usmHostAllocationsCache . get (size, memoryProperties);
418+ if (this ->usmHostAllocationsCache ) {
419+ void *allocationFromCache = this ->usmHostAllocationsCache -> get (size, memoryProperties);
420420 if (allocationFromCache) {
421421 return allocationFromCache;
422422 }
@@ -428,7 +428,7 @@ void *SVMAllocsManager::createHostUnifiedMemoryAllocation(size_t size,
428428
429429 void *usmPtr = memoryManager->createMultiGraphicsAllocationInSystemMemoryPool (rootDeviceIndicesVector, unifiedMemoryProperties, allocData.gpuAllocations , externalHostPointer);
430430 if (!usmPtr) {
431- if (this ->usmHostAllocationsCacheEnabled ) {
431+ if (this ->usmHostAllocationsCache ) {
432432 this ->trimUSMHostAllocCache ();
433433 usmPtr = memoryManager->createMultiGraphicsAllocationInSystemMemoryPool (rootDeviceIndicesVector, unifiedMemoryProperties, allocData.gpuAllocations , externalHostPointer);
434434 }
@@ -492,9 +492,9 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
492492
493493 if (memoryProperties.memoryType == InternalMemoryType::deviceUnifiedMemory) {
494494 unifiedMemoryProperties.flags .isUSMDeviceAllocation = true ;
495- if (this ->usmDeviceAllocationsCacheEnabled &&
495+ if (this ->usmDeviceAllocationsCache &&
496496 false == memoryProperties.isInternalAllocation ) {
497- void *allocationFromCache = this ->usmDeviceAllocationsCache . get (size, memoryProperties);
497+ void *allocationFromCache = this ->usmDeviceAllocationsCache -> get (size, memoryProperties);
498498 if (allocationFromCache) {
499499 return allocationFromCache;
500500 }
@@ -508,7 +508,7 @@ void *SVMAllocsManager::createUnifiedMemoryAllocation(size_t size,
508508 GraphicsAllocation *unifiedMemoryAllocation = memoryManager->allocateGraphicsMemoryWithProperties (unifiedMemoryProperties, externalPtr);
509509 if (!unifiedMemoryAllocation) {
510510 if (memoryProperties.memoryType == InternalMemoryType::deviceUnifiedMemory &&
511- this ->usmDeviceAllocationsCacheEnabled ) {
511+ this ->usmDeviceAllocationsCache ) {
512512 this ->trimUSMDeviceAllocCache ();
513513 unifiedMemoryAllocation = memoryManager->allocateGraphicsMemoryWithProperties (unifiedMemoryProperties, externalPtr);
514514 }
@@ -642,14 +642,14 @@ bool SVMAllocsManager::freeSVMAlloc(void *ptr, bool blocking) {
642642 if (svmData) {
643643 if (InternalMemoryType::deviceUnifiedMemory == svmData->memoryType &&
644644 false == svmData->isInternalAllocation &&
645- this ->usmDeviceAllocationsCacheEnabled ) {
646- if (this ->usmDeviceAllocationsCache . insert (svmData->gpuAllocations .getDefaultGraphicsAllocation ()->getUnderlyingBufferSize (), ptr, svmData)) {
645+ this ->usmDeviceAllocationsCache ) {
646+ if (this ->usmDeviceAllocationsCache -> insert (svmData->gpuAllocations .getDefaultGraphicsAllocation ()->getUnderlyingBufferSize (), ptr, svmData)) {
647647 return true ;
648648 }
649649 }
650650 if (InternalMemoryType::hostUnifiedMemory == svmData->memoryType &&
651- this ->usmHostAllocationsCacheEnabled ) {
652- if (this ->usmHostAllocationsCache . insert (svmData->size , ptr, svmData)) {
651+ this ->usmHostAllocationsCache ) {
652+ if (this ->usmHostAllocationsCache -> insert (svmData->size , ptr, svmData)) {
653653 return true ;
654654 }
655655 }
@@ -672,14 +672,14 @@ bool SVMAllocsManager::freeSVMAllocDefer(void *ptr) {
672672 SvmAllocationData *svmData = getSVMAlloc (ptr);
673673 if (svmData) {
674674 if (InternalMemoryType::deviceUnifiedMemory == svmData->memoryType &&
675- this ->usmDeviceAllocationsCacheEnabled ) {
676- if (this ->usmDeviceAllocationsCache . insert (svmData->size , ptr, svmData)) {
675+ this ->usmDeviceAllocationsCache ) {
676+ if (this ->usmDeviceAllocationsCache -> insert (svmData->size , ptr, svmData)) {
677677 return true ;
678678 }
679679 }
680680 if (InternalMemoryType::hostUnifiedMemory == svmData->memoryType &&
681- this ->usmHostAllocationsCacheEnabled ) {
682- if (this ->usmHostAllocationsCache . insert (svmData->size , ptr, svmData)) {
681+ this ->usmHostAllocationsCache ) {
682+ if (this ->usmHostAllocationsCache -> insert (svmData->size , ptr, svmData)) {
683683 return true ;
684684 }
685685 }
@@ -752,16 +752,20 @@ void SVMAllocsManager::freeSVMAllocDeferImpl() {
752752}
753753
754754void SVMAllocsManager::cleanupUSMAllocCaches () {
755- this ->usmDeviceAllocationsCache .cleanup ();
756- this ->usmHostAllocationsCache .cleanup ();
755+ if (this ->usmDeviceAllocationsCache ) {
756+ this ->usmDeviceAllocationsCache ->cleanup ();
757+ }
758+ if (this ->usmHostAllocationsCache ) {
759+ this ->usmHostAllocationsCache ->cleanup ();
760+ }
757761}
758762
759763void SVMAllocsManager::trimUSMDeviceAllocCache () {
760- this ->usmDeviceAllocationsCache . trim ();
764+ this ->usmDeviceAllocationsCache -> trim ();
761765}
762766
763767void SVMAllocsManager::trimUSMHostAllocCache () {
764- this ->usmHostAllocationsCache . trim ();
768+ this ->usmHostAllocationsCache -> trim ();
765769}
766770
767771void *SVMAllocsManager::createZeroCopySvmAllocation (size_t size, const SvmAllocationProperties &svmProperties,
@@ -896,12 +900,13 @@ void SVMAllocsManager::freeZeroCopySvmAllocation(SvmAllocationData *svmData) {
896900}
897901
898902void SVMAllocsManager::initUsmDeviceAllocationsCache (Device &device) {
903+ this ->usmDeviceAllocationsCache .reset (new SvmAllocationCache);
899904 if (device.getMaxAllocationsSavedForReuseSize () > 0u ) {
900- this ->usmDeviceAllocationsCache . allocations .reserve (128u );
901- this ->usmDeviceAllocationsCache . svmAllocsManager = this ;
902- this ->usmDeviceAllocationsCache . memoryManager = memoryManager;
905+ this ->usmDeviceAllocationsCache -> allocations .reserve (128u );
906+ this ->usmDeviceAllocationsCache -> svmAllocsManager = this ;
907+ this ->usmDeviceAllocationsCache -> memoryManager = memoryManager;
903908 if (auto usmReuseCleaner = device.getExecutionEnvironment ()->unifiedMemoryReuseCleaner .get ()) {
904- usmReuseCleaner->registerSvmAllocationCache (& this ->usmDeviceAllocationsCache );
909+ usmReuseCleaner->registerSvmAllocationCache (this ->usmDeviceAllocationsCache . get () );
905910 }
906911 }
907912}
@@ -912,32 +917,33 @@ void SVMAllocsManager::initUsmHostAllocationsCache() {
912917 if (debugManager.flags .ExperimentalEnableHostAllocationCache .get () != -1 ) {
913918 fractionOfTotalMemoryForRecycling = 0.01 * std::min (100 , debugManager.flags .ExperimentalEnableHostAllocationCache .get ());
914919 }
915- this ->usmHostAllocationsCache .maxSize = static_cast <size_t >(fractionOfTotalMemoryForRecycling * totalSystemMemory);
916- if (this ->usmHostAllocationsCache .maxSize > 0u ) {
917- this ->usmHostAllocationsCache .allocations .reserve (128u );
918- this ->usmHostAllocationsCache .svmAllocsManager = this ;
919- this ->usmHostAllocationsCache .memoryManager = memoryManager;
920+ this ->usmHostAllocationsCache .reset (new SvmAllocationCache);
921+ this ->usmHostAllocationsCache ->maxSize = static_cast <size_t >(fractionOfTotalMemoryForRecycling * totalSystemMemory);
922+ if (this ->usmHostAllocationsCache ->maxSize > 0u ) {
923+ this ->usmHostAllocationsCache ->allocations .reserve (128u );
924+ this ->usmHostAllocationsCache ->svmAllocsManager = this ;
925+ this ->usmHostAllocationsCache ->memoryManager = memoryManager;
920926 if (auto usmReuseCleaner = this ->memoryManager ->peekExecutionEnvironment ().unifiedMemoryReuseCleaner .get ()) {
921- usmReuseCleaner->registerSvmAllocationCache (& this ->usmHostAllocationsCache );
927+ usmReuseCleaner->registerSvmAllocationCache (this ->usmHostAllocationsCache . get () );
922928 }
923929 }
924930}
925931
926932void SVMAllocsManager::initUsmAllocationsCaches (Device &device) {
927- this -> usmDeviceAllocationsCacheEnabled = NEO::ApiSpecificConfig::isDeviceAllocationCacheEnabled () && device.getProductHelper ().isDeviceUsmAllocationReuseSupported ();
933+ bool usmDeviceAllocationsCacheEnabled = NEO::ApiSpecificConfig::isDeviceAllocationCacheEnabled () && device.getProductHelper ().isDeviceUsmAllocationReuseSupported ();
928934 if (debugManager.flags .ExperimentalEnableDeviceAllocationCache .get () != -1 ) {
929- this -> usmDeviceAllocationsCacheEnabled = !!debugManager.flags .ExperimentalEnableDeviceAllocationCache .get ();
935+ usmDeviceAllocationsCacheEnabled = !!debugManager.flags .ExperimentalEnableDeviceAllocationCache .get ();
930936 }
931- if (this -> usmDeviceAllocationsCacheEnabled ) {
937+ if (usmDeviceAllocationsCacheEnabled) {
932938 device.getExecutionEnvironment ()->initializeUnifiedMemoryReuseCleaner (!device.isAnyDirectSubmissionEnabled (true ));
933939 this ->initUsmDeviceAllocationsCache (device);
934940 }
935941
936- this -> usmHostAllocationsCacheEnabled = NEO::ApiSpecificConfig::isHostAllocationCacheEnabled () && device.getProductHelper ().isHostUsmAllocationReuseSupported ();
942+ bool usmHostAllocationsCacheEnabled = NEO::ApiSpecificConfig::isHostAllocationCacheEnabled () && device.getProductHelper ().isHostUsmAllocationReuseSupported ();
937943 if (debugManager.flags .ExperimentalEnableHostAllocationCache .get () != -1 ) {
938- this -> usmHostAllocationsCacheEnabled = !!debugManager.flags .ExperimentalEnableHostAllocationCache .get ();
944+ usmHostAllocationsCacheEnabled = !!debugManager.flags .ExperimentalEnableHostAllocationCache .get ();
939945 }
940- if (this -> usmHostAllocationsCacheEnabled ) {
946+ if (usmHostAllocationsCacheEnabled) {
941947 device.getExecutionEnvironment ()->initializeUnifiedMemoryReuseCleaner (!device.isAnyDirectSubmissionEnabled (true ));
942948 this ->initUsmHostAllocationsCache ();
943949 }
0 commit comments