-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Specialization constants: fix scope, allow redefinition and AOT. #1633
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
Conversation
Link to the spec proposal: |
- Specialization constants are now per-program, as the implemented spec requires. - Program's specialization constant set is added to the program compilation cache key, it gets recompiled on new specialization constant combination. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
d5133e3
to
ed05d8e
Compare
…x it. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
ed05d8e
to
cba353c
Compare
sycl/source/detail/program_impl.cpp
Outdated
|
||
auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms(); | ||
|
||
for (SCItTy SCIt = SCRange.begin(); SCIt != SCRange.end(); SCIt++) { |
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 (SCItTy SCIt = SCRange.begin(); SCIt != SCRange.end(); SCIt++) { | |
for (SCItTy &SCIt: SCRange) { |
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.
OK, but I'll avoid reference to iterator
// RUN: env SYCL_PI_TRACE=2 %CPU_RUN_PLACEHOLDER %t.out 2>&1 %CPU_CHECK_PLACEHOLDER | ||
// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER | ||
// RUN: env SYCL_PI_TRACE=2 %ACC_RUN_PLACEHOLDER %t.out 2>&1 %ACC_CHECK_PLACEHOLDER | ||
// TODO the test currently fails on devices these devices: |
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.
// TODO the test currently fails on devices these devices: | |
// TODO the test currently fails on these configurations: |
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.
right, I think I've pushed a fix already
class spec_constant_impl { | ||
public: | ||
spec_constant_impl(unsigned int ID) : ID(ID), Size(0), Bytes{0} {} | ||
spec_constant_impl() = default; |
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.
Please, initialize member to some default value(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.
ok
if (DbgProgMgr > 0) | ||
std::cerr << ">>> WARNING: flushSpecConstants requested on a " | ||
"program w/o known binary image\n"; | ||
return; // program origin is unknown |
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 think we should throw exception here.
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.
ok
if (DbgProgMgr > 0) | ||
std::cerr << ">>> ProgramManager::flushSpecConstants: binary image " | ||
<< &Img->getRawData() << " doesn't support spec constants\n"; | ||
// this device binary image does not support runtime setting of |
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 throw exception somewhere if user sets spec constant for an image which doesn't support this feature?
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. But exception can't be thrown here - the implemented spec has some gaps here.
What can happen in practice is AOT compilation, after which spec constants can't be set. On the other hand, we don't want to throw or change the program depending on JIT vs AOT scenario. Defaults will be used instead.
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.
added a comment
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.
So, there will be no diagnostic if a user uses AOT compiled binary but sets specialization constant. Is there any plan to address this problem?
SC.set(ValSize, ValAddr); | ||
} | ||
|
||
void program_impl::flush_spec_constants(const RTDeviceBinaryImage &Img, |
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.
Suggest moving functionality of this function to program_manager.cpp:991 to avoid dealing with RTDeviceBeinaryImage outside of program_manager.
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.
What is the problem with dealing with RTDeviceBeinaryImage outside of program_manager?
Or do you mean incurred dependence on program_manager.h everywhere RTDeviceBeinaryImage is used? That can be fixed by extracting BinaryImage infra into a separate header.
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 think it would be nice if program_manager abstracts away low level image details from other parts of the SYCL.
Is there any reason for this function to be a method of program class?
This comment doesn't block PR approval.
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.
Spec constants are now bound to a program_impl, this is the main reason. But I agree that it is better keep as few inter-dependencies as possible. Anyway, upcoming modules implementation will require significant refactoring in this area - let's revisit this design question as a part of modules design, not to refactor twice. Do you agree?
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.
Ok.
return getOrBuild<PiProgramT, compile_program_error>( | ||
Cache, KeyT(std::move(SpecConsts), KSId), AcquireF, GetF, BuildF); |
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 these programs (i.e. with specialization consts) be cached at all?
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.
Yes. Why it should not?
@@ -184,7 +184,7 @@ RetT *waitUntilBuilt(KernelProgramCache &Cache, | |||
/// cache. Accepts nothing. Return pointer to built entity. | |||
template <typename RetT, typename ExceptionT, typename KeyT, typename AcquireFT, | |||
typename GetCacheFT, typename BuildFT> | |||
RetT *getOrBuild(KernelProgramCache &KPCache, const KeyT &CacheKey, | |||
RetT *getOrBuild(KernelProgramCache &KPCache, KeyT &&CacheKey, |
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.
Why do you need universal reference for CacheKey
here?
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.
to avoid copying of the CacheKey when working with the cache map, as the key now includes the spec constant set.
Co-authored-by: Romanov Vlad <[email protected]>
Co-authored-by: Romanov Vlad <[email protected]>
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
59f389f
to
11df804
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.
Ok to me.
requires.
compilation cache key, it gets recompiled on new specialization
constant combination.
Signed-off-by: Konstantin S Bobrovsky [email protected]