| 25 | namespace oneflow { |
| 26 | |
| 27 | void AutoMemcpy(ep::Stream* stream, void* dst, const void* src, size_t sz, |
| 28 | const MemoryCase& dst_mem_case, const MemoryCase& src_mem_case) { |
| 29 | ep::primitive::MemcpyKind kind{}; |
| 30 | if (stream->device_type() == DeviceType::kCPU) { |
| 31 | CHECK(memory::IsHostMem(src_mem_case)); |
| 32 | if (dst_mem_case.device_type() != DeviceType::kMeta) { CHECK(memory::IsHostMem(dst_mem_case)); } |
| 33 | kind = ep::primitive::MemcpyKind::kDtoD; |
| 34 | } else { |
| 35 | if (memory::IsHostMem(src_mem_case)) { |
| 36 | CHECK(!memory::IsHostMem(dst_mem_case)); |
| 37 | kind = ep::primitive::MemcpyKind::kHtoD; |
| 38 | } else if (memory::IsHostMem(dst_mem_case)) { |
| 39 | CHECK(!memory::IsHostMem(src_mem_case)); |
| 40 | kind = ep::primitive::MemcpyKind::kDtoH; |
| 41 | } else { |
| 42 | kind = ep::primitive::MemcpyKind::kDtoD; |
| 43 | } |
| 44 | } |
| 45 | std::unique_ptr<ep::primitive::Memcpy> primitive = |
| 46 | ep::primitive::NewPrimitive<ep::primitive::MemcpyFactory>(stream->device_type(), kind); |
| 47 | CHECK(primitive); |
| 48 | primitive->Launch(stream, dst, src, sz); |
| 49 | } |
| 50 | |
| 51 | void AutoMemcpy(ep::Stream* stream, Blob* dst, const Blob* src) { |
| 52 | const size_t body_bytes = src->ByteSizeOfBlobBody(); |
no test coverage detected