Skip to content

[SYCL] Fix library destructor priority value #3054

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 3 commits into from
Jan 21, 2021

Conversation

alexbatashev
Copy link
Contributor

No description provided.

@alexbatashev alexbatashev requested a review from a team as a code owner January 19, 2021 08:09
__attribute__((destructor(65535))) static void syclUnload() { shutdown(); }
// Setting minimal priority on destructor ensures it runs after all other global
// destructors. Priorities 0-100 are reserved by the compiler.
__attribute__((destructor(101))) static void syclUnload() { shutdown(); }
Copy link
Contributor

@romanovvlad romanovvlad Jan 19, 2021

Choose a reason for hiding this comment

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

What about setting something like 110 to let other libraries to have a destructor which works after SYCL one.
@smaslov-intel @alexbatashev What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, I think

// destructors. Priorities 0-100 are reserved by the compiler. The priority
// value 110 allows SYCL users to run their destructors after runtime library
// deinitialization.
__attribute__((destructor(110))) static void syclUnload() { shutdown(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we document it somewhere what priority are for what? And how it interacts with no priority specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I conducted a small experiment:

#include <iostream>

__attribute__((destructor(101))) static void syclUnload101() {
    std::cout << "101\n";
}

__attribute__((destructor(102))) static void syclUnload102() {
    std::cout << "102\n";
}

__attribute__((destructor(110))) static void syclUnload110() {
    std::cout << "110\n";
}

__attribute__((destructor(105))) static void syclUnload105() {
    std::cout << "105\n";
}

__attribute__((destructor)) static void syclUnload() {
    std::cout << "default\n";
}

int main() {
    std::cout << "Hi\n";
    return 0;
}

The result is the same for both GCC and Clang:

Hi
default
110
105
102
101

@romanovvlad romanovvlad merged commit fed2d47 into intel:sycl Jan 21, 2021
@alexbatashev alexbatashev deleted the update_sycl_destructor_priority branch July 28, 2021 06:44
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.

3 participants