-
Notifications
You must be signed in to change notification settings - Fork 0
Code review for tryGetSourceBasedKernel
#2
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
Code review for tryGetSourceBasedKernel
#2
Conversation
Self, std::move(OwnerBundle), | ||
ArgMask, UrProgram, CacheMutex); | ||
Self, OwnerBundle, ArgMask, | ||
UrProgram, CacheMutex); | ||
} | ||
return nullptr; |
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 this return
is ever returned in future, then we might have double move from the same object. The version on the right avoids that possibility entirely.
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.
And what's wrong with double move from the same object? std::move()
is just a cast, and OwnerBundle
became empty only when move ctor for MKernelBundleImpl
is executed. And if the move ctor is executed, we must leave the loop.
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.
And if the move ctor is executed, we must leave the loop.
Only now. If that logic changes, the moves must be updated and it's very easy to miss that. With this approach this mistake won't be possible.
It's also one less thing to focus on if there is any bug (hypothetically) in that area.
@@ -629,7 +627,7 @@ class kernel_bundle_impl | |||
getSyclObjImpl(DevImg); | |||
if (std::shared_ptr<kernel_impl> PotentialKernelImpl = | |||
// move is performed only when SourceBasedKernel is not null | |||
DevImgImpl->tryGetSourceBasedKernel(Name, MContext, std::move(Self), | |||
DevImgImpl->tryGetSourceBasedKernel(Name, MContext, *this, |
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 comment is necessary to explain that there is no double-move here anymore. Also, no "optimization" of moving Self
out of the loop anymore (one less thing to explain to the reader).
@@ -964,7 +960,7 @@ class kernel_bundle_impl | |||
getSyclObjImpl(DevImg); | |||
if (std::shared_ptr<kernel_impl> SourceBasedKernel = | |||
// move is performed only when SourceBasedKernel is not null | |||
DevImgImpl->tryGetSourceBasedKernel(Name, MContext, std::move(Self), | |||
DevImgImpl->tryGetSourceBasedKernel(Name, MContext, *this, |
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.
Likewise.
Fixes #123300 What is seen ``` clang-repl> int x = 42; clang-repl> auto capture = [&]() { return x * 2; }; In file included from <<< inputs >>>:1: input_line_4:1:17: error: non-local lambda expression cannot have a capture-default 1 | auto capture = [&]() { return x * 2; }; | ^ zsh: segmentation fault clang-repl --Xcc="-v" (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8) * frame #0: 0x0000000107b4f8b8 libclang-cpp.19.1.dylib`clang::IncrementalParser::CleanUpPTU(clang::PartialTranslationUnit&) + 988 frame #1: 0x0000000107b4f1b4 libclang-cpp.19.1.dylib`clang::IncrementalParser::ParseOrWrapTopLevelDecl() + 416 frame #2: 0x0000000107b4fb94 libclang-cpp.19.1.dylib`clang::IncrementalParser::Parse(llvm::StringRef) + 612 frame intel#3: 0x0000000107b52fec libclang-cpp.19.1.dylib`clang::Interpreter::ParseAndExecute(llvm::StringRef, clang::Value*) + 180 frame intel#4: 0x0000000100003498 clang-repl`main + 3560 frame intel#5: 0x000000018d39a0e0 dyld`start + 2360 ``` Though the error is justified, we shouldn't be interested in exiting through a segfault in such cases. The issue is that empty named decls weren't being taken care of resulting into this assert https://github.com/llvm/llvm-project/blob/c1a229252617ed58f943bf3f4698bd8204ee0f04/clang/include/clang/AST/DeclarationName.h#L503 Can also be seen when the example is attempted through xeus-cpp-lite. 
With non -O0, the call stack is not preserved, like malloc_shared will be inlined, the call stack would be like ``` #0 in int* sycl::_V1::malloc_host<int>(unsigned long, sycl::_V1::context const&, sycl::_V1::property_list const&, sycl::_V1::detail::code_location const&) /tmp/syclws/include/sycl/usm.hpp:215:27 #1 in ?? (/lib/x86_64-linux-gnu/libc.so.6+0x757867a2a1c9) #2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x757867a2a28a) ``` instead of ``` #0 in int* sycl::_V1::malloc_host<int>(unsigned long, sycl::_V1::context const&, sycl::_V1::property_list const&, sycl::_V1::detail::code_location const&) /tmp/syclws/include/sycl/usm.hpp:215:27 #1 in int* sycl::_V1::malloc_host<int>(unsigned long, sycl::_V1::queue const&, sycl::_V1::property_list const&, sycl::_V1::detail::code_location const&) /tmp/syclws/include/sycl/usm.hpp:223:10 #2 in main /tmp/syclws/llvm/sycl/test-e2e/MemorySanitizer/track-origins/check_host_usm_initialized_on_host.cpp:15:17 intel#3 in ?? (/lib/x86_64-linux-gnu/libc.so.6+0x7a67f842a1c9) intel#4 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x7a67f842a28a) ``` Also, add env to every %{run} directive to make sure they are not affected by system env.
No description provided.