| 574 | } |
| 575 | |
| 576 | static PyObject* tensor__mul__method(TensorObject* self, |
| 577 | PyObject* args, |
| 578 | PyObject* kwargs) { |
| 579 | phi::RecordEvent pythonc_record_event( |
| 580 | "__mul__ pybind_patch_func", phi::TracerEventType::UserDefined, 1); |
| 581 | |
| 582 | EAGER_TRY |
| 583 | VLOG(6) << "Running Eager tensor__mul__method"; |
| 584 | |
| 585 | SetPythonStack(); |
| 586 | |
| 587 | // Set Device ID |
| 588 | auto place = egr::Controller::Instance().GetExpectedPlace(); |
| 589 | SetDevice(place); |
| 590 | |
| 591 | Tensor ret; |
| 592 | |
| 593 | Tensor self_tensor = self->tensor; |
| 594 | PyObject* other_obj = PyTuple_GET_ITEM(args, 0); |
| 595 | |
| 596 | // 1. scalar exists cases |
| 597 | if (PyFloat_Check(other_obj) || PyCheckInteger(other_obj) || |
| 598 | IsNumpyType(other_obj)) { |
| 599 | if (PyFloat_Check(other_obj)) { |
| 600 | if (_supported_int_dtype_.find(self_tensor.dtype()) != |
| 601 | _supported_int_dtype_.end()) { |
| 602 | eager_gil_scoped_release guard; |
| 603 | self_tensor = cast_ad_func(self_tensor, DataType::FLOAT32); |
| 604 | } |
| 605 | } else if (PyCheckInteger(other_obj) && |
| 606 | self_tensor.dtype() == DataType::BOOL) { |
| 607 | eager_gil_scoped_release guard; |
| 608 | self_tensor = cast_ad_func(self_tensor, DataType::INT64); |
| 609 | } |
| 610 | |
| 611 | double other = CastPyArg2Double(other_obj, "__mul__", 0); |
| 612 | { |
| 613 | eager_gil_scoped_release guard; |
| 614 | ret = CallScalarFunction(self_tensor, other, "mul"); |
| 615 | } |
| 616 | return ToPyObject(ret); |
| 617 | } else if (PyComplex_Check(other_obj)) { |
| 618 | if (is_support_complex(self_tensor.dtype()) == false) { |
| 619 | eager_gil_scoped_release guard; |
| 620 | self_tensor = cast_ad_func( |
| 621 | self_tensor, promoteTypes(self_tensor.dtype(), DataType::COMPLEX64)); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | // 2. create or get tensor for other_obj |
| 626 | // if lhs or rhs input is tensor, we need to inplace cast it to dist_tensor |
| 627 | // if one of the input is numpy or scalar, no need to do inplace cast. |
| 628 | Tensor other_tensor; |
| 629 | if (PyCheckTensor(other_obj)) { |
| 630 | auto& self_tensor_ref_addr = self->tensor; |
| 631 | auto& other_tensor_ref_addr = CastPyArg2Tensor(other_obj, 0); |
| 632 | const phi::distributed::ProcessMesh* mesh = nullptr; |
| 633 | if (InputsContainDistTensor( |
nothing calls this directly
no test coverage detected