Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/runtime/metal/metal_device_api.mm
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ int GetWarpSize(id<MTLDevice> dev) {

void MetalWorkspace::FreeDataSpace(Device dev, void* ptr) {
AUTORELEASEPOOL {
// need to make sure buffer is not in use in command buffer
// before set the purgeable state to empty
// otherwise can cause issues sometimes
this->StreamSync(dev, nullptr);
// MTLBuffer PurgeableState should be set to empty before manual
// release in order to prevent memory leak
[(id<MTLBuffer>)ptr setPurgeableState:MTLPurgeableStateEmpty];
Expand Down Expand Up @@ -336,6 +340,10 @@ int GetWarpSize(id<MTLDevice> dev) {
if (temp_buffer_[dev.device_id] == nil || temp_buffer_[dev.device_id].length < size) {
id<MTLDevice> mtl_dev = MetalWorkspace::Global()->GetDevice(dev);
if (temp_buffer_[dev.device_id] != nil) {
// need to make sure buffer is not in use in command buffer
// before set the purgeable state to empty
// otherwise can cause issues sometimes
MetalWorkspace::Global()->StreamSync(dev, nullptr);
[temp_buffer_[dev.device_id] setPurgeableState:MTLPurgeableStateEmpty];
[temp_buffer_[dev.device_id] release];
}
Expand Down