Skip to content

Conversation

@jinge90
Copy link
Contributor

@jinge90 jinge90 commented Jul 20, 2021

This PR adds memset and memcmp in libdevice. Latest llvm-spirv can handle
llvm.memset intrinsic, so we just rely on "__builtin_memset" which is the
same way as memcpy. For memcmp, there is no support we can rely on in latest
llvm-spirv, so libdevice provides a simple implementation.

Signed-off-by: gejin ge.jin@intel.com

This PR adds memset and memcmp in libdevice. Latest llvm-spirv can handle
llvm.memset intrinsic, so we just rely on "__builtin_memset" which is the
same way as memcpy. For memcmp, there is no support we can rely on in latest
memcpy, so libdevice provides a simple implementation.

Signed-off-by: gejin <ge.jin@intel.com>
@jinge90
Copy link
Contributor Author

jinge90 commented Jul 20, 2021

Test for memcpy, memset, memcmp is in intel/llvm-test-suite#371

Signed-off-by: gejin <ge.jin@intel.com>
@jinge90 jinge90 requested a review from bader July 20, 2021 03:11
@jinge90
Copy link
Contributor Author

jinge90 commented Jul 21, 2021

/summary:run

@jinge90
Copy link
Contributor Author

jinge90 commented Jul 26, 2021

Hi, all.
Could you help review this PR?
Thanks very much.

AlexeySachkov
AlexeySachkov previously approved these changes Jul 26, 2021
gmlueck
gmlueck previously approved these changes Jul 26, 2021
@jinge90
Copy link
Contributor Author

jinge90 commented Jul 29, 2021

Hi, @vzakhari @kbobrovs @mlychkov @intel/llvm-reviewers-runtime
Could you help review this patch?
Thanks very much.

s-kanaev
s-kanaev previously approved these changes Jul 29, 2021
Copy link
Contributor

@s-kanaev s-kanaev left a comment

Choose a reason for hiding this comment

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

RT change LGTM

mlychkov
mlychkov previously approved these changes Aug 2, 2021
@bader
Copy link
Contributor

bader commented Aug 2, 2021

@vzakhari, could you take a look, please?

==========================

.. code:
void *__devicelib_memcpy(void *dest, const void *src, size_t n);
Copy link
Contributor

Choose a reason for hiding this comment

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

does this work for any combination of address spaces pointed to by dest and src? Might be worth adding a note. Std C library is not concerned with address spaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @kbobrovs
I think no matter what combination of address spaces pointed to by dest and src is, it should work if we can "read" from src and "write" to "dest". Is this correct?
Thanks very much.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know. I would expect this to work with any combination. My point that such details should be added to the user API description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it will only work for __generic address space pointers. Is there a way in DPC++ to specify __generic pointer explicitly?

Copy link
Contributor

@kbobrovs kbobrovs Aug 3, 2021

Choose a reason for hiding this comment

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

By default, function pointer arguments are generic. But users needs to understand if he/she can do e.g.

int arr[100]; // local variable in a function, resides in the private address space
...
auto *s1 = local_accessor.get_pointer();
auto *s2 = &arr[0];
__devicelib_memcpy(s1, s2, 100);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, @kbobrovs and @vzakhari
__devicelib_memcpy is called by memcpy whose input pointer parameter is standard C/C++ pointer with address space.
So, if developer calls memcpy in SYCL device, the pointer is a generic_space pointer. And no matter where the input generic pointer points to, developers should ensure that they have access to the memory.
I also created a PR for memory function test: intel/llvm-test-suite#371 which includes some basic tests and alignment test, I will update it to add some tests covering different address space memory.
Thanks very much.

@vzakhari
Copy link
Contributor

vzakhari commented Aug 2, 2021

LGTM except for the alignment issue that Konst pointed out.

@jinge90 jinge90 dismissed stale reviews from mlychkov, s-kanaev, gmlueck, and AlexeySachkov via ea32ef8 August 3, 2021 08:34
Signed-off-by: gejin <ge.jin@intel.com>
AlexeySachkov
AlexeySachkov previously approved these changes Aug 3, 2021
==========================

.. code:
void *__devicelib_memcpy(void *dest, const void *src, size_t n);
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it will only work for __generic address space pointers. Is there a way in DPC++ to specify __generic pointer explicitly?

Copy link
Contributor

@kbobrovs kbobrovs left a comment

Choose a reason for hiding this comment

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

I think this patch is still missing couple of things:

  • documenting behavior when when pointers to various address spaces are used as arguments
  • tests for different address space combinations
    (will be on vacation next 3 weeks, feel free to proceed w/o my approval)

Signed-off-by: gejin <ge.jin@intel.com>
@jinge90
Copy link
Contributor Author

jinge90 commented Aug 4, 2021

/summary:run

Copy link
Contributor

@s-kanaev s-kanaev left a comment

Choose a reason for hiding this comment

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

RT changes LGTM

@jinge90
Copy link
Contributor Author

jinge90 commented Aug 6, 2021

/summary:run

@jinge90
Copy link
Contributor Author

jinge90 commented Aug 6, 2021

Hi, @AlexeySachkov
Could you review and approve again?
Thanks very much.

@jinge90
Copy link
Contributor Author

jinge90 commented Aug 6, 2021

I think this patch is still missing couple of things:

  • documenting behavior when when pointers to various address spaces are used as arguments
  • tests for different address space combinations
    (will be on vacation next 3 weeks, feel free to proceed w/o my approval)

Hi, @bader
Could you help review this patch?
Thanks very much.

@bader bader merged commit 349c798 into intel:sycl Aug 9, 2021
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.

8 participants