| 191 | } |
| 192 | |
| 193 | Maybe<void> LocalTensor::load() { |
| 194 | TENSOR_OFFLOAD_CHECK(true, "loaded"); |
| 195 | |
| 196 | // Load cpu to cuda. |
| 197 | int64_t device_id = JUST(this->device())->device_id(); |
| 198 | std::shared_ptr<Tensor> cpu_tensor = std::make_shared<LocalTensor>(offloaded_impl_); |
| 199 | auto loaded_tensor = JUST(functional::Copy(cpu_tensor, "cuda", device_id, |
| 200 | /*pin_memory=*/JUST(cpu_tensor->is_pinned()))); |
| 201 | JUST(vm::CurrentRankSync()); |
| 202 | JUST(set_data(loaded_tensor)); |
| 203 | |
| 204 | // Release cpu memory. |
| 205 | cpu_tensor.reset(); |
| 206 | offloaded_impl_.reset(); |
| 207 | auto* vm = JUST(SingletonMaybe<VirtualMachine>()); |
| 208 | JUST(vm->ShrinkAllMem()); |
| 209 | |
| 210 | is_offloaded_ = false; |
| 211 | return Maybe<void>::Ok(); |
| 212 | } |
| 213 | |
| 214 | std::shared_ptr<Tensor> GlobalTensor::contiguous() const { |
| 215 | std::shared_ptr<Tensor> tensor = std::const_pointer_cast<Tensor>(shared_from_this()); |
no test coverage detected