Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCL] Fix host-to-host copy during copyback #1692

Merged
merged 2 commits into from
May 16, 2020

Conversation

sergey-semenov
Copy link
Contributor

Copyback is performed unconditionally during buffer destruction, so
it's possible for it to perform a copy from and to the same host
pointer. This patch adds a check for this scenario so that we don't rely
on undefined behaviour of std::memcpy.

Signed-off-by: Sergey Semenov sergey.semenov@intel.com

Copyback is performed unconditionally during buffer destruction, so
it's possible for it to perform a copy from and to the same host
pointer. This patch adds a check for this scenario so that we don't rely
on undefined behaviour of std::memcpy.

Signed-off-by: Sergey Semenov <sergey.semenov@intel.com>
Signed-off-by: Sergey Semenov <sergey.semenov@intel.com>
@sergey-semenov sergey-semenov requested a review from a team as a code owner May 15, 2020 09:33
@sergey-semenov sergey-semenov requested a review from v-klochkov May 15, 2020 09:33
@@ -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).

@bader bader merged commit 4bf22cc into intel:sycl May 16, 2020
@sergey-semenov sergey-semenov deleted the fixcopyback branch May 18, 2020 08:48
alexbatashev pushed a commit to alexbatashev/llvm that referenced this pull request May 18, 2020
…_docs

* origin/sycl: (1867 commits)
  [SYCL] Implement USM vars and placeholder accessors passed to reduction (intel#1657)
  [SYCL] Fix post-commit testing (intel#1705)
  [SYCL][NFC] Remove multi_ptr<const void, Space>::operator multi_ptr<const void, Space> (intel#1702)
  [Doc] Readme update. (intel#1701)
  Support function pointers in cast instructions
  Adjust FPGA IVDep translation for embedded loops
  [SYCL] Fix host-to-host copy during copyback (intel#1692)
  [SYCL] Add information about dependencies used in CI
  [SYCL] Add runtime support for fsycl-id-queries-fit-in-int (intel#1685)
  Revert "Revert "[llvm][NFC] Cleanup uses of std::function in Inlining-related APIs""
  StoreInst should store Align, not MaybeAlign
  [clang][slh] Add test for SLH feature checking macro
  [NFC] Deduplicate comment in PromoteMemoryToRegister.cpp
  [WebAssembly] Optimize splats of bitcasted vectors
  [LLD][ELF] Use offset in thin archives to disambiguate thinLTO members
  [AArch64][SVE] Implement AArch64ISD::SETCC_PRED
  [SVE] Restore broken LLVM-C ABI compatability
  IR: Remove extra name mangling from llvm.ptrmask
  [NFC] Whitespace fix inside OptParserEmitter
  [compiler-rt][CMAKE] Only add cmake link flags in standalone build
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants