!41323 Fix PyNative coredump

Merge pull request !41323 from caifubi/master-pynative-op-compile-refactor
This commit is contained in:
i-robot 2022-09-05 01:44:35 +00:00 committed by Gitee
commit 5a0b0bca90
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 19 additions and 0 deletions

View File

@ -793,6 +793,18 @@ void MindRTBackend::DispatchOpTask(bool single_op_cache_hit, VectorRef *outputs,
MS_EXCEPTION_IF_NULL(graph);
const auto &output_nodes = op_compiler_info->graph_output_nodes_;
auto input_tensors = op_run_info->base_op_run_info.input_tensor;
for (auto &input_tensor : input_tensors) {
MS_EXCEPTION_IF_NULL(input_tensor);
auto data = input_tensor->data_ptr();
if (data != nullptr && data->is_from_numpy()) {
// Convert python tensor to cpp tensor
py::gil_scoped_acquire gil;
input_tensor->AssignValue(tensor::Tensor(*input_tensor, input_tensor->data_type()));
data = nullptr;
}
}
runtime::UpdateDeviceAddress(graph, GetTensorWithoutValueMask(op_run_info), op_compiler_info->device_context_);
UpdateOutput(output_nodes, outputs);

View File

@ -179,6 +179,8 @@ class TensorDataNumpy : public TensorData {
bool has_sub_data() const override { return false; }
bool is_from_numpy() const override { return true; }
/// To string.
std::string ToString(const TypeId, const ShapeVector &, bool use_comma) const override {
if (use_comma) {

View File

@ -99,6 +99,11 @@ class MS_CORE_API TensorData {
/// \return True if this tensor data has sub data, otherwise false.
virtual bool has_sub_data() const = 0;
/// \brief Get whether this tensor data is from numpy.
///
/// \return Whether this tensor data is from numpy.
virtual bool is_from_numpy() const { return false; }
/// \brief Whether the data are equal.
///
/// \param[in] other Another TensorData.