Skip to content
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

Fix the crash with Scalar pool on discrete memory devices #102

Merged
merged 1 commit into from
Sep 7, 2022
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
17 changes: 13 additions & 4 deletions aten/src/ATen/native/mps/OperationUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,19 @@ MPSScalar getMPSScalar(const Scalar& scalar, ScalarType type) {
}

MPSGraphTensorData* getMPSGraphTensorFromScalar(MPSStream* mpsStream, MPSScalar& scalar) {
scalar.buffer = at::mps::allocate_scalar_buffer(&scalar.value, scalar.size);
MPSGraphTensorData* result = [[[MPSGraphTensorData alloc] initWithMTLBuffer: scalar.getMTLBuffer()
shape: @[@1]
dataType: getMPSScalarType(scalar.type)] autorelease];
MPSGraphTensorData *result = nullptr;
// Scalar pools are only supported on devices with unified memory
if (mpsStream->device().hasUnifiedMemory) {
scalar.buffer = at::mps::allocate_scalar_buffer(&scalar.value, scalar.size);
result = [[[MPSGraphTensorData alloc] initWithMTLBuffer: scalar.getMTLBuffer()
shape: @[@1]
dataType: getMPSScalarType(scalar.type)] autorelease];
} else {
MPSNDArrayDescriptor *tensorDesc = [MPSNDArrayDescriptor descriptorWithDataType:getMPSScalarType(scalar.type) shape:@[@1]];
MPSNDArray *tensorNDArray = [[[MPSNDArray alloc] initWithDevice:mpsStream->device() descriptor:tensorDesc] autorelease];
[tensorNDArray writeBytes:&scalar.value strideBytes:nil];
result = [[[MPSGraphTensorData alloc] initWithMPSNDArray:tensorNDArray] autorelease];
}
return result;
}

Expand Down