| 381 | } // namespace |
| 382 | |
| 383 | Status LiteralBase::Piece::CopyFrom(const LiteralBase::Piece& src) { |
| 384 | CHECK(subshape_ != nullptr); |
| 385 | CHECK(src.subshape_ != nullptr); |
| 386 | if (ShapeUtil::Equal(subshape(), src.subshape())) { |
| 387 | // If the layouts are equal it's faster just to memcpy. |
| 388 | memcpy(buffer(), src.buffer(), src.size_bytes()); |
| 389 | } else { |
| 390 | TF_RET_CHECK(ShapeUtil::Compatible(src.subshape(), subshape())); |
| 391 | std::vector<int64> origin(subshape().rank(), 0); |
| 392 | switch (subshape().element_type()) { |
| 393 | #define COPY_ELEMENTS(XLA_T, NATIVE_T) \ |
| 394 | case (XLA_T): \ |
| 395 | CopyElementsBetween<NATIVE_T>(data<NATIVE_T>(), src.data<NATIVE_T>(), \ |
| 396 | subshape(), src.subshape()); \ |
| 397 | break; |
| 398 | COPY_ELEMENTS(U8, uint8); |
| 399 | COPY_ELEMENTS(U16, uint16); |
| 400 | COPY_ELEMENTS(U32, uint32); |
| 401 | COPY_ELEMENTS(U64, uint64); |
| 402 | COPY_ELEMENTS(S8, int8); |
| 403 | COPY_ELEMENTS(S16, int16); |
| 404 | COPY_ELEMENTS(S32, int32); |
| 405 | COPY_ELEMENTS(S64, int64); |
| 406 | COPY_ELEMENTS(F16, half); |
| 407 | COPY_ELEMENTS(BF16, bfloat16); |
| 408 | COPY_ELEMENTS(F32, float); |
| 409 | COPY_ELEMENTS(F64, double); |
| 410 | COPY_ELEMENTS(C64, complex64); |
| 411 | COPY_ELEMENTS(C128, complex128); |
| 412 | COPY_ELEMENTS(PRED, bool); |
| 413 | #undef COPY_ELEMENTS |
| 414 | default: |
| 415 | return Unimplemented( |
| 416 | "Copying a Literal object with element type %s is not implemented.", |
| 417 | PrimitiveType_Name(subshape().element_type())); |
| 418 | } |
| 419 | } |
| 420 | return Status::OK(); |
| 421 | } |
| 422 | |
| 423 | Status MutableLiteralBase::CopyFrom(const LiteralSlice& src_literal, |
| 424 | const ShapeIndex& dest_shape_index, |