-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Usm allocator refactor #7785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@igchor : rather than adding new stuff into L0 Plugin, could you first move the USM allocator into Unified Runtime please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update after #7820 is merged
d84b2d9
to
a78068d
Compare
Done. |
@rdeodhar : please help review the change to USM allocator |
|
||
// Generate buckets sized such as: 64, 96, 128, 192, ..., CutOff. | ||
// Powers of 2 and the value halfway between the powers of 2. | ||
auto Size1 = USMSettings.MinBucketSize[MemHandle->getMemType()]; | ||
auto Size1 = params.MinBucketSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this affect performance during this period of transition, if MinBucketSize may be different depending on the memory type? See here
MinBucketSize[MemType::Host] = 64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in fact, my goal was to keep the original behavior intact. This assignment is just in a different place: https://github.com/intel/llvm/blob/51609155370086670b74ba99f3724d3d8d340852/sycl/plugins/unified_runtime/ur/usm_allocator_config.cpp
In the original implementation, those variables (MinBucketSize, Capacity, itp.) were stored in a single global structure and indexed using [getMemType()]
. I have moved those variables to a separate class: USMAllocatorParameters
and I'm now passing instance of this class to the USMAllocContext as you can see here: https://github.com/intel/llvm/blob/51609155370086670b74ba99f3724d3d8d340852/sycl/plugins/level_zero/pi_level_zero.cpp#L844
Basically, instead of having Structure of Arrays:
class SetLimits() {
...
size_t MinBucketSize[MemType::All];
};
we now have Array of Structs:
class USMAllocatorParameters {
...
size_t MinBucketSize;
} configs[MemType::All];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this is to split the pool management logic from reading/setting the configuration since this might differ for other adapters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @igchor.
size_t SlabMinSize() { | ||
return USMSettings.SlabMinSize[(*MemHandle).getMemType()]; | ||
}; | ||
size_t SlabMinSize() { return params.SlabMinSize; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment about performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my previous answer
if (OwnAllocCtx.getParams().limits->TotalSize.compare_exchange_strong( | ||
PoolSize, NewPoolSize)) { | ||
if (chunkedBucket) | ||
++chunkedSlabsInPool; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is this protected now that the lock at the beginning of this function was removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My assumption was that the PoolLock
was here only to protect CurPoolSize
update (since this is a global variable, shared between all instances of USMAllocContext. This would match the comment: https://github.com/intel/llvm/blob/sycl/sycl/plugins/unified_runtime/ur/usm_allocator.cpp#L62 Now, instead of this lock I just rely on CAS to update the value.
As for the remaining variables (e.g. chunkedSlabsInPool) they should be protected by BucketLock which must be taken before calling CanPool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @igchor. if that's the case, then yes, we would be ok.
@@ -885,11 +622,11 @@ size_t Bucket::Capacity() { | |||
if (getSize() <= ChunkCutOff()) | |||
return 1; | |||
else | |||
return USMSettings.Capacity[getMemType()]; | |||
return OwnAllocCtx.getParams().Capacity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how we will handle different values for Capacity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my previous answer
This is the first step to make USMAllocator generic and usable for different plugins/adapters. This commit makes USMAllocator unaware of memory type on which it is operating. User of USMAllocator is responsible for setting appropriate options for each instance of USMAllocator.
all memory types when MemType::All is specified. Previously, SharedReadyOnly was not updated in MemParser.
since TotalSize is now updated atomically, there is no need for additional lock. All other (per-bucket) stats are protected by a per-bucket lock.
5160915
to
e684a78
Compare
e684a78
to
a684627
Compare
@intel/llvm-gatekeepers @againull @smaslov-intel is there something pending to merge this? |
@smaslov-intel requested changes. He must approve before it can be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think this is good to go in. |
Approval from @intel/llvm-reviewers-runtime team is required. |
This commit makes USMAllocator unaware of the memory type on which it is operating. The user of USMAllocator is responsible
for setting appropriate options for each instance of USMAllocator.
This is the first step to making USMAllocator generic. In the next step, I'd like to start integration with Unified Memory Allocation (oneMemory). USMAllocator would be used as a heap manager by UMA.