MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / tensor__mul__method

Function tensor__mul__method

paddle/fluid/pybind/eager_math_op_patch.cc:576–707  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

574}
575
576static 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(

Callers

nothing calls this directly

Calls 15

SetPythonStackFunction · 0.85
InstanceFunction · 0.85
CastPyArg2DoubleFunction · 0.85
CallScalarFunctionFunction · 0.85
is_support_complexFunction · 0.85
promoteTypesFunction · 0.85
PyCheckTensorFunction · 0.85
InputsContainDistTensorFunction · 0.85
PyObject_CheckStringFunction · 0.85
CastPyArg2ScalarFunction · 0.85
multiply_ad_funcFunction · 0.85

Tested by

no test coverage detected