| 589 | } |
| 590 | |
| 591 | bool Variable::copyToDevicePtr(void* devicePtr, int memoryType) { |
| 592 | if (nullptr != mFrom->get()) { |
| 593 | MNN_ERROR("Can't copyToDevicePtr to no-input op\n"); |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | auto inside = mFrom->inside(); |
| 598 | auto originTensor = inside->mOutputTensors[mFromIndex]; |
| 599 | |
| 600 | auto bn = TensorUtils::getDescribeOrigin(originTensor)->getBackend(); |
| 601 | if(bn == nullptr) { |
| 602 | MNN_ERROR("Error: Varp copyToDevicePtr can't find backend\n"); |
| 603 | return false; |
| 604 | } |
| 605 | |
| 606 | MNN::Tensor tempTensor(originTensor->dimensions(), originTensor->getDimensionType()); |
| 607 | tempTensor.setDevicePtr(devicePtr, memoryType); |
| 608 | |
| 609 | TensorUtils::getDescribeOrigin(originTensor)->getBackend()->onCopyBuffer(originTensor, &tempTensor); |
| 610 | // Sync the result |
| 611 | tempTensor.wait(Tensor::MAP_TENSOR_READ, true); |
| 612 | return true; |
| 613 | } |
| 614 | |
| 615 | const std::string& Variable::name() const { |
| 616 | return mFrom->outputName(mFromIndex); |