MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / EmitTransferElements

Method EmitTransferElements

tensorflow/compiler/xla/service/cpu/ir_emitter.cc:2727–2761  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2725}
2726
2727void IrEmitter::EmitTransferElements(llvm::Value* target, llvm::Value* source,
2728 int64 element_count,
2729 PrimitiveType primitive_type,
2730 const llvm_ir::IrArray& target_array,
2731 const llvm_ir::IrArray& source_array) {
2732 unsigned primitive_type_size =
2733 ShapeUtil::ByteSizeOfPrimitiveType(primitive_type);
2734 unsigned element_alignment = tensorflow::MathUtil::GCD<unsigned>(
2735 primitive_type_size, MinimumAlignmentForPrimitiveType(primitive_type));
2736 llvm::Type* primitive_ptr_type = llvm::PointerType::getUnqual(
2737 llvm_ir::PrimitiveTypeToIrType(primitive_type, module_));
2738
2739 if (element_count == 1) {
2740 auto* load_instruction =
2741 AlignedLoad(BitCast(source, primitive_ptr_type), element_alignment);
2742 source_array.AnnotateLoadStoreInstructionWithMetadata(load_instruction);
2743 auto* store_instruction =
2744 AlignedStore(load_instruction, BitCast(target, primitive_ptr_type),
2745 element_alignment);
2746 target_array.AnnotateLoadStoreInstructionWithMetadata(store_instruction);
2747 } else {
2748 auto* memcpy_instruction = MemCpy(
2749 target, /*DstAlign=*/element_alignment, source,
2750 /*SrcAlign=*/element_alignment, element_count * primitive_type_size);
2751
2752 // The memcpy does the load and the store internally. The aliasing related
2753 // metadata has to reflect that.
2754 std::map<int, llvm::MDNode*> merged_metadata =
2755 llvm_ir::MergeMetadata(&module_->getContext(), source_array.metadata(),
2756 target_array.metadata());
2757 for (const auto& kind_md_pair : merged_metadata) {
2758 memcpy_instruction->setMetadata(kind_md_pair.first, kind_md_pair.second);
2759 }
2760 }
2761}
2762
2763Status IrEmitter::HandleConcatenate(HloInstruction* concatenate) {
2764 absl::Span<HloInstruction* const> operands(concatenate->operands());

Callers

nothing calls this directly

Calls 7

ByteSizeOfPrimitiveTypeFunction · 0.85
PrimitiveTypeToIrTypeFunction · 0.85
BitCastFunction · 0.85
MergeMetadataFunction · 0.85
getContextMethod · 0.80
metadataMethod · 0.80

Tested by

no test coverage detected