Skip to content
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
26 changes: 26 additions & 0 deletions test/cpp/test_aten_xla_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3011,6 +3011,32 @@ TEST_F(AtenXlaTensorTest, TestFloor) {
});
}

TEST_F(AtenXlaTensorTest, TestFloorDivide) {
for (torch::ScalarType scalar_type1 : {torch::kFloat, torch::kInt}) {
torch::Tensor a =
isFloatingType(scalar_type1)
? torch::rand({3, 4}, torch::TensorOptions(scalar_type1)) - 0.5f
: torch::randint(0, 100, {3, 4},
torch::TensorOptions(scalar_type1));
for (torch::ScalarType scalar_type2 : {torch::kFloat, torch::kInt}) {
torch::Tensor b =
isFloatingType(scalar_type2)
? torch::rand({3, 4}, torch::TensorOptions(scalar_type2)) + 0.5f
: torch::randint(1, 100, {3, 4},
torch::TensorOptions(scalar_type2));
torch::Tensor c = torch::floor_divide(a, b);
ForEachDevice([&](const torch::Device& device) {
torch::Tensor xla_a = CopyToDevice(a, device);
torch::Tensor xla_b = CopyToDevice(b, device);
torch::Tensor xla_c = torch::floor_divide(xla_a, xla_b);
AllClose(c, xla_c);
});
}
}
ExpectCounterNotChanged("aten::.*", cpp_test::GetIgnoredCounters());
ExpectCounterChanged("xla::div", cpp_test::GetIgnoredCounters());
}

TEST_F(AtenXlaTensorTest, TestRound) {
torch::Tensor a = torch::cat(
{torch::randn({8}, torch::TensorOptions(torch::kFloat)) * 100.0,
Expand Down
6 changes: 6 additions & 0 deletions torch_xla/csrc/aten_xla_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,12 @@ at::Tensor XLANativeFunctions::flip(const at::Tensor& self,
XLATensor::flip(bridge::GetXlaTensor(self), XlaHelpers::I64List(dims)));
}

at::Tensor XLANativeFunctions::floor_divide(const at::Tensor& self,
const at::Tensor& other) {
return torch_xla::XLANativeFunctions::div(self, other,
/*rounding_mode=*/"floor");
}

at::Tensor XLANativeFunctions::fmod(const at::Tensor& self,
const at::Tensor& other) {
XLA_FN_COUNTER("xla::");
Expand Down
1 change: 1 addition & 0 deletions xla_native_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ supported:
- fill_.Scalar
- fill_.Tensor
- flip
- floor_divide
- fmod.Scalar
- fmod.Tensor
- gather
Expand Down