Skip to content

[SYCL] Reduce number of getenv calls to improve performance of short-running parallel_for kernels on Windows. #4321

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 10 commits into from
Aug 19, 2021

Conversation

rdeodhar
Copy link
Contributor

@rdeodhar rdeodhar commented Aug 11, 2021

This change avoids repeated calls to getenv when launching parallel_for kernels.

Signed-off-by: rdeodhar rajiv.deodhar@intel.com

@romanovvlad romanovvlad requested a review from s-kanaev August 12, 2021 10:31
std::string KName = typeid(NameT *).name();
using KI = detail::KernelInfo<KernelName>;
bool DisableRounding =
(getenv("SYCL_DISABLE_PARALLEL_FOR_RANGE_ROUNDING") != nullptr) ||
Copy link
Contributor

@s-kanaev s-kanaev Aug 12, 2021

Choose a reason for hiding this comment

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

This environment variable is documented.
I don't know if there are users of this environment variable.
Anyway, I believe, it should become deprecated first with or without any effect. It can be removed being deprecated for at least one update. @bader , could you, please, confirm it?
Also, if the reason for eliminating of this env var is reducing host overhead, one could employ SYCLConfig class from source/detail/config.hpp.

Comment on lines 809 to 819

// Check whether rounding trace has been requested.
// Call getenv only once.
static bool RoundingTraceChecked = false;
static bool RoundingTrace = false;
if (!RoundingTraceChecked) {
RoundingTrace =
getenv("SYCL_PARALLEL_FOR_RANGE_ROUNDING_TRACE") != nullptr;
RoundingTraceChecked = true;
}
if (RoundingTrace)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitely a subject of thread-unsafety pattern.
It's more convenient to use SYCLConfig class.
If needed its thread-safety can be handled in distinct patch.

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, I'll switch to using the SYCLConfig infrastructure, preserve all existing env vars, and see if that is efficient enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The SYCLConfig features are available from the SYCL library. They don't seem to be directly available in the headers, e.g. handler.hpp. Will need to go from header into library to use SYCLConfig.

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 change has been made in environment variables supported.
Use of getenv has been minimized, which reduces overhead when short-running kernels are executed on Windows. (Execution time of getenv appears to be greater than two orders of magnitude higher on Windows than Linux).
Thread safety is not an issue since values are only written by the processing of env var settings, and any concurrent writes will write the same values.

@rdeodhar rdeodhar marked this pull request as ready for review August 14, 2021 05:42
@rdeodhar rdeodhar requested a review from a team as a code owner August 14, 2021 05:42
@rdeodhar rdeodhar changed the title [SYCL] Deleted unused code and reduced number of getenv calls. [SYCL] Reduce number of getenv calls to improve performance of short-running kernels on Windows. Aug 14, 2021
@rdeodhar rdeodhar changed the title [SYCL] Reduce number of getenv calls to improve performance of short-running kernels on Windows. [SYCL] Reduce number of getenv calls to improve performance of short-running parallel_for kernels on Windows. Aug 14, 2021
vladimirlaz
vladimirlaz previously approved these changes Aug 17, 2021
Copy link
Contributor

@vladimirlaz vladimirlaz left a comment

Choose a reason for hiding this comment

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

LGTM

@vladimirlaz vladimirlaz requested a review from s-kanaev August 19, 2021 07:48
@romanovvlad romanovvlad merged commit 9c2acd9 into intel:sycl Aug 19, 2021
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