Used only to retrieve tensors from remote processes.
| 41 | |
| 42 | // Used only to retrieve tensors from remote processes. |
| 43 | class StarRecvTensorCall : public BaseRecvTensorCall { |
| 44 | public: |
| 45 | StarRecvTensorCall() : wi_(nullptr), dst_device_(nullptr) {} |
| 46 | |
| 47 | void Init(WorkerInterface* wi, int64 step_id, StringPiece key, |
| 48 | AllocatorAttributes alloc_attrs, Device* dst_device, |
| 49 | const Rendezvous::Args& recv_args, Rendezvous::DoneCallback done) { |
| 50 | wi_ = wi; |
| 51 | star_wi_ = dynamic_cast<StarWorkerInterface*>(wi_); |
| 52 | alloc_attrs_ = alloc_attrs; |
| 53 | dst_device_ = dst_device; |
| 54 | recv_args_ = recv_args; |
| 55 | done_ = std::move(done); |
| 56 | req_.set_step_id(step_id); |
| 57 | req_.set_rendezvous_key(key.data(), key.size()); |
| 58 | } |
| 59 | |
| 60 | void Reset(WorkerCacheInterface* wc) { |
| 61 | wc->ReleaseWorker(src_worker_, wi_); |
| 62 | wi_ = nullptr; |
| 63 | star_wi_ = nullptr; |
| 64 | alloc_attrs_ = AllocatorAttributes(); |
| 65 | dst_device_ = nullptr; |
| 66 | // We don't clear opts_ and assume that Init will set up the state for |
| 67 | // opts_ appropriately. |
| 68 | req_.Clear(); |
| 69 | resp_.Clear(); |
| 70 | { |
| 71 | mutex_lock l(mu_); |
| 72 | status_ = Status::OK(); |
| 73 | } |
| 74 | done_ = nullptr; |
| 75 | } |
| 76 | |
| 77 | ~StarRecvTensorCall() override { |
| 78 | // Since only the StarRecvTensorFreeList will delete an |
| 79 | // StarRecvTensorCall, and it always sets this->wi_ to null when |
| 80 | // a call object is released to it, we can assert that this->wi_ is |
| 81 | // always null at the point of deletion. |
| 82 | CHECK_EQ(static_cast<WorkerInterface*>(nullptr), wi_) |
| 83 | << "Leaking WorkerInterface in StarRecvTensorCall destructor."; |
| 84 | } |
| 85 | |
| 86 | void Start(std::function<void()> recv_done) override { |
| 87 | StartRTCall(std::move(recv_done)); |
| 88 | } |
| 89 | |
| 90 | void StartAbort(const Status& s) override { |
| 91 | { |
| 92 | mutex_lock l(mu_); |
| 93 | status_.Update(s); |
| 94 | } |
| 95 | opts_.StartCancel(); |
| 96 | } |
| 97 | |
| 98 | Status status() const override { |
| 99 | mutex_lock l(mu_); |
| 100 | return status_; |