-
Notifications
You must be signed in to change notification settings - Fork 114
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
[pstl-offload] Initial support for PSTL offload under Windows #1359
Conversation
7f64ad7
to
a1c0c20
Compare
8f9d9a6
to
31f9e14
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked all CMakeLists.txt
and ci.yml
files. Everything looks good besides some minor (probably, matter of personal taste) comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically went through the patch and I have some questions. I suggest to talk once again. I think Thursday should be ok.
|
||
if (__same_memory_page(__user_ptr, __header) && __header->_M_uniq_const == __uniq_type_const) | ||
{ | ||
if (__header->_M_requested_number_of_bytes == __new_size && (uintptr_t)__user_ptr % __alignment == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (__header->_M_requested_number_of_bytes == __new_size && (uintptr_t)__user_ptr % __alignment == 0) | |
if (__header->_M_requested_number_of_bytes == __new_size && (std::uintptr_t)__user_ptr % __alignment == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
017b9ab
to
7955c50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just getting my feet under me in reviewing this. Here are a few minor things to start with, but will review more in the coming days.
b2a118e
to
dfbeb5b
Compare
} | ||
return ::__pstl_offload::__internal_aligned_realloc(__ptr, __size, __alignment); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we care about supporting the following?
_aligned_recalloc
_aligned_offset_realloc
_aligned_offset_recalloc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic here is next: for TBBmalloc no one is asked about those functions for 10+ years, so we may want to ignore them as well.
From the different side, _recalloc
/_aligned_recalloc
is low hanging fruit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no strong feelings about what specific functions we support. I suppose the thing to do is to decide on them and document what is supported so it is not a guessing game for the user. Perhaps this becomes an issue to be resolved in a later doc specific PR. This is a fine resolution from my perspective without code changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. @rarutyun has a table with such functions for Linux, it might be complimented by Windows ones and releases as part of the product's documentation.
f7f7bbb
to
5de65c9
Compare
} | ||
|
||
|
||
std::size_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this function be static
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is exported and used in the public headers.
set(DETOURS_PATH ${PROJECT_BINARY_DIR}/src/project_detours-prefix/src/project_detours) | ||
ExternalProject_Add(project_detours | ||
GIT_REPOSITORY https://github.com/microsoft/Detours.git | ||
GIT_TAG 4b8c659f549b0ab21cf649377c7a84eb708f5e68 | ||
INSTALL_COMMAND "" | ||
CONFIGURE_COMMAND "" | ||
# use CL to add additional flags to the Detours build | ||
BUILD_COMMAND cd src && SET CL=/sdl | ||
COMMAND ${NMAKE_EXE} | ||
BUILD_IN_SOURCE on | ||
STEP_TARGETS build | ||
BUILD_BYPRODUCTS ${DETOURS_PATH}/lib.X64/detours.lib | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to mention the use of detours in our documentation (cmake readme and/or pstl section of the guide)?
Are there any license implications? (I assume not since its being used as an external project, but I don't know)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are license implications, I believe. @ValentinaKats promised to add them in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added Detours as a third party program to the third-party-program.txt file directly to this PR, b09be05.
Other than my comments, looks good to me. I would also ask somebody to review the infrastructure part. |
I've reviewed the infrastructure part, and it LGTM. I've reviewed the rest as well and looks good other than the documentation / licensing conversations still open (which can be address separately). It would be good to get final approval from @rarutyun after his comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can somebody put the approve from the infrastructure perspective? @danhoeflinger or @dmitriy-sobolev, could it be some of you? Or should it be someone else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for infrastructure part, (and normal part as well as far as I can see)
Decision to merge should of course wait for offline discussion.
067b695
b09be05
to
067b695
Compare
There are 4 groups of the changes: 1. Microsoft dynamic runtime is instrumented to intercept global memory releasing. Microsoft Detours is used for that. It downloaded and build from sources during pstloffload build step. Then statically linked to pstloffload.dll. 2. Allocation functions re-use. Under Windows, releasing of memory allocated by native aligned allocation functions must not be done by free/realloc, but by special _aligned_free/etc counterparts. Alignment 0 is used as a sign that common malloc etc should be called. 3. Tests changes. Link with release runtime is not supported for debug PSTL offload, so in debug testing skips iterator tests that requires that. 4. CI changes. pstloffload_smoke_tests group of tests created to run on checking.
Add Detours to third-party-programs.txt
This reverts commit e382ffa.
8618b85
to
622273b
Compare
// Under Windows, we must not use functions with explicit alignment for malloc replacement, as | ||
// an allocated memory would be released by free() replacement, that has no alignment argument. | ||
// Mark such allocations with special alignment. Use 0, as this is not valid alignment. | ||
static constexpr std::size_t __ignore_alignment = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make it inline
. Like:
static constexpr std::size_t __ignore_alignment = 0; | |
inline constexpr std::size_t __ignore_alignment = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -189,13 +200,24 @@ __internal_aligned_alloc(std::size_t __size, std::size_t __alignment) | |||
if (__sycl_device_shared_ptr __dev = __offload_policy_holder_type::__get_device_ptr(__offload_policy_holder)) | |||
{ | |||
void* __res = __allocate_shared_for_device(std::move(__dev), __size, __alignment); | |||
assert((std::uintptr_t(__res) & (__alignment - 1)) == 0); | |||
if (__res && __alignment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For everything but bool
I would recommend to not rely on implicit conversions to bool
. Readability-wise it gives you an idea what kind of variable you are checking right in the if-statement. The only place where conversion to bool worth it (in my opinion) is a generic code
if (__res && __alignment) | |
if (__res != nullptr && __alignment != 0) |
You can swap if you like. I mean nullptr != __res && 0 != alignment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Can it be part of code guideline, then?
void* __res = | ||
__original_aligned_alloc((__ignore_alignment == __alignment) ? alignof(std::max_align_t) : __alignment, __size); | ||
#endif | ||
if (__res && __alignment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There are 4 groups of the changes: