Skip to content

[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

Merged
merged 6 commits into from
May 8, 2020

Conversation

kbobrovs
Copy link
Contributor

@kbobrovs kbobrovs commented May 2, 2020

  • 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]

@kbobrovs kbobrovs requested a review from a team as a code owner May 2, 2020 03:22
@kbobrovs
Copy link
Contributor Author

kbobrovs commented May 4, 2020

- 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]>
@kbobrovs kbobrovs force-pushed the spec-const-redefine branch from d5133e3 to ed05d8e Compare May 6, 2020 00:03
@kbobrovs kbobrovs force-pushed the spec-const-redefine branch from ed05d8e to cba353c Compare May 6, 2020 00:22

auto LockGuard = Ctx->getKernelProgramCache().acquireCachedPrograms();

for (SCItTy SCIt = SCRange.begin(); SCIt != SCRange.end(); SCIt++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (SCItTy SCIt = SCRange.begin(); SCIt != SCRange.end(); SCIt++) {
for (SCItTy &SCIt: SCRange) {

Copy link
Contributor Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// TODO the test currently fails on devices these devices:
// TODO the test currently fails on these configurations:

Copy link
Contributor Author

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;
Copy link
Contributor

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).

Copy link
Contributor Author

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
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 we should throw exception here.

Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment

Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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 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.

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok.

@romanovvlad romanovvlad requested a review from s-kanaev May 7, 2020 10:39
Comment on lines +413 to +414
return getOrBuild<PiProgramT, compile_program_error>(
Cache, KeyT(std::move(SpecConsts), KSId), AcquireF, GetF, BuildF);
Copy link
Contributor

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?

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@kbobrovs kbobrovs force-pushed the spec-const-redefine branch from 59f389f to 11df804 Compare May 7, 2020 21:42
@kbobrovs kbobrovs requested review from romanovvlad and s-kanaev May 7, 2020 22:20
Copy link
Contributor

@romanovvlad romanovvlad left a comment

Choose a reason for hiding this comment

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

Ok to me.

@pvchupin pvchupin merged commit c22e34b into intel:sycl May 8, 2020
@kbobrovs kbobrovs deleted the spec-const-redefine branch July 30, 2020 12:31
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