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

Remove square from block list #229

Merged
merged 6 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions aten/src/ATen/mps/MPSDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ static inline MTLLanguageVersion getMetalLanguageVersion(const id<MTLDevice>& de
static bool _macos_13_0_plus = [mpsCD instancesRespondToSelector:@selector(cumulativeSumWithTensor:axis:name:)] == YES;
static bool _macos_13_1_plus = [mpsCD instancesRespondToSelector:@selector(
sampleGridWithSourceTensor:coordinateTensor:layout:normalizeCoordinates:relativeCoordinates:alignCorners:paddingMode:samplingMode:constantValue:name:)] == YES;
static bool _macos_13_2_plus = [mpsCD instancesRespondToSelector:@selector(convolution3DWithSourceTensor:weightsTensor:descriptor:name:)] == YES;

switch (subVersion) {
case 0: return _macos_13_0_plus;
case 1: return _macos_13_1_plus;
case 2: return _macos_13_2_plus;
default: return false;
}
}
Expand Down
6 changes: 5 additions & 1 deletion aten/src/ATen/native/mps/operations/BinaryOps.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
void binaryOpTensor(const Tensor& self, const Tensor& other, const Scalar& alpha,
const Tensor& output_, std::string op_name, BinaryOpBlock binaryBlock)
{
TORCH_CHECK(!(op_name == "power" && !is_macos_13_or_newer(2) &&
(self.scalar_type() == ScalarType::Long ||
(other.scalar_type() == ScalarType::Long && (self.scalar_type() != ScalarType::Half && self.scalar_type() != ScalarType::Float)))),
"MPS: ", op_name, " op with int64 input is supported natively starting from macOS 13.2");
MPSStream* mpsStream = getCurrentMPSStream();

const bool is_self_scalar = self.dim() == 0;
Expand Down Expand Up @@ -246,7 +250,7 @@ void add_sub_template(const Tensor& self, const Tensor& other, const Scalar& alp
#define CREATE_MPS_STRUCTURED_BINARY_OP_FUNC(func_out, func_stub, other_type) \
TORCH_IMPL_FUNC(func_out) (const Tensor& self, const other_type& other, const Tensor& output) { \
TORCH_CHECK(!(self.scalar_type() == ScalarType::Long && \
(std::string(#func_stub) == "power" || std::string(#func_stub) == "atan2")), \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check for self is still needed (for macOS under 13.2). Otherwise, passing a long input would crash on older OSes. e.g:

import torch


device="mps"
a = torch.tensor([1, 2, 3], dtype=torch.int64, device=device)
b = torch.tensor(5, dtype=torch.uint8, device=device)
x = torch.pow(a, b)
print(x)

std::string(#func_stub) == "atan2"), \
"MPS does not support ", #func_stub, " op with int64 input") \
mps::binaryOp##other_type(self, other, Scalar(1.0), output, #func_stub, \
^BinaryOpFn(cachedGraph, primaryCastTensor, secondaryCastTensor) { \
Expand Down
3 changes: 1 addition & 2 deletions test/test_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9034,7 +9034,7 @@ class TestConsistency(TestCase):
'i64',
'u8'],
'sqrt': ['b8', 'f32', 'i16', 'i32', 'i64', 'u8'],
'square': ['f16', 'f32'],
'square': ['b8', 'f16', 'f32', 'i16', 'i32', 'i64', 'u8'],
'squeeze': ['b8', 'f16', 'f32', 'i16', 'i32', 'i64', 'u8'],
'stack': ['b8', 'f16', 'f32', 'i16', 'i32', 'i64', 'u8'],
'std': ['f16', 'f32'],
Expand Down Expand Up @@ -9280,7 +9280,6 @@ class TestConsistency(TestCase):
'nn.functional.interpolatearea': [torch.float32],
'resize_as_': [torch.float16, torch.float32],
'topk': [torch.int16, torch.int32, torch.int64, torch.uint8],
'square': [torch.bool, torch.int16, torch.int32, torch.int64, torch.uint8],

# Functions with correctness issues
'unique': [torch.bool, torch.float16, torch.float32, torch.int16, torch.int32, torch.int64, torch.uint8],
Expand Down