Skip to content

Commit

Permalink
Correctly compare Stream IValues (#47303)
Browse files Browse the repository at this point in the history
Summary:
Stream IValue equality comparison was comparing wrong object.

Pull Request resolved: #47303

Test Plan:
Added a new C++ test

Fixes #{issue number}

Reviewed By: bdhirsh

Differential Revision: D24752434

Pulled By: gmagogsfm

fbshipit-source-id: 78bc7a812740485ebbc7cf0c06c2e671a7ccd26f
  • Loading branch information
tugsbayasgalan authored and facebook-github-bot committed Nov 7, 2020
1 parent 25d1fb5 commit 3f9697b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion aten/src/ATen/core/ivalue.cpp
Expand Up @@ -273,7 +273,7 @@ IValue IValue::equals(const IValue& rhs) const {
case Tag::Tuple:
return rhs.isTuple() && *lhs.toTuple() == *rhs.toTuple();
case Tag::Stream:
return rhs.isStream() && lhs.toStream() == lhs.toStream();
return rhs.isStream() && lhs.toStream() == rhs.toStream();
case Tag::Device:
return rhs.isDevice() && lhs.toDevice() == rhs.toDevice();
case Tag::GenericList:
Expand Down
12 changes: 12 additions & 0 deletions aten/src/ATen/test/ivalue_test.cpp
Expand Up @@ -259,6 +259,18 @@ TEST(IValueTest, ListNestedEquality) {
EXPECT_NE(c2, c3);
}

TEST(IValueTest, StreamEquality) {
at::Device device1 = at::Device(kCUDA, 0);
at::Device device2 = at::Device(kCUDA, 1);
c10::Stream stream1 = c10::Stream(c10::Stream::Default::DEFAULT, device1);
c10::Stream stream2 = c10::Stream(c10::Stream::Default::DEFAULT, device2);
IValue lhs(stream1);
IValue rhs_different(stream2);
IValue rhs_same(stream1);
EXPECT_FALSE(lhs.equals(rhs_different).toBool());
EXPECT_TRUE(lhs.equals(rhs_same).toBool());
}

TEST(IValueTest, EnumEquality) {
auto cu = std::make_shared<CompilationUnit>();
IValue int_ivalue_1(1);
Expand Down

0 comments on commit 3f9697b

Please sign in to comment.