Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,15 @@ static void copyH2H(SYCLMemObjI *SYCLMemObj, char *SrcMem,
PI_INVALID_OPERATION);
}

DstOffset[0] *= DstElemSize;
SrcOffset[0] *= SrcElemSize;
SrcMem += SrcOffset[0] * SrcElemSize;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious.
Why only SrcOffset[0] is involved? Is multidimensional offset "merged" into singledimensional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the checks at lines 353-355 in this file make this line 361 correct. If Dim > 1, then the statement is SrcMem += 0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly speaking it is hard to believe that std::memcpy() does not check src==dst case and does something wrong in such case.

Why did you decide fixing this, did you really noticed unexpected behavior when src==dst?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@v-klochkov I have indeed encountered such behaviour when linking with Intel's implementation of memcpy (_intel_fast_memcpy).

DstMem += DstOffset[0] * DstElemSize;

if (SrcMem == DstMem)
return;

size_t BytesToCopy =
SrcAccessRange[0] * SrcElemSize * SrcAccessRange[1] * SrcAccessRange[2];

std::memcpy(DstMem + DstOffset[0], SrcMem + SrcOffset[0], BytesToCopy);
std::memcpy(DstMem, SrcMem, BytesToCopy);
}

// Copies memory between: host and device, host and host,
Expand Down