Skip to content

[SYCL][L0][PI] Modify SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE environment variable to allow user a finer control over copy engines #4333

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 9 commits into from
Aug 18, 2021

Conversation

asudarsa
Copy link
Contributor

Signed-off-by: Arvind Sudarsanam [email protected]

…ontrol over copy engines

Signed-off-by: Arvind Sudarsanam <[email protected]>
| `SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE_FOR_D2D_COPY` (experimental) | Integer | Allows the use of copy engine, if available in the device, in Level Zero plugin for device to device copy operations. The default is 0. This option is experimental and will be removed once heuristics are added to make a decision about use of copy engine for device to device copy operations. |
| `SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE_RANGE` | Any(\*) | This environment variable enables users to select a desired range of copy engines to use for copy operations. The value of this environment variable is a pair of the form "lower_index:upper_index" where the indices point to copy engines in a list of all available copy engines.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just extend existing SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE to [optionally] take a range now? The current 0/1 values would continue mean disable/enable all. Explain the lower/upper bounds of the range. Also since the size of the list is not known to the user it is good to have "1" to mean 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.

I updated this in the latest commit. Can you please check it and see if it's missing something? Thanks.

@@ -60,12 +60,28 @@ static const bool UseCopyEngineForD2DCopy = [] {
return (CopyEngineForD2DCopy && (std::stoi(CopyEngineForD2DCopy) != 0));
}();

// TODO: Add support for non-zero values of SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE
Copy link
Contributor

Choose a reason for hiding this comment

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

But you already support 1-digit non-zero values below. Comment outdated? Also why need this check for exactly 1 symbol?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the unnecessary check and the comment. Thanks

if (CopyEngineRange[0] == '0')
return std::pair<int, int>(-1, -1);
else
return std::pair<int, int>(0, 8);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid hardcoding 8 here, e.g. have -1 mean no upper bound

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 replaced this with INT_MAX. That's the right value to use as we want to use ALL copy engines here.

return std::pair<int, int>(0, 8);
}
int LowerCopyEngineIndex = (CopyEngineRange) ? (CopyEngineRange[0] - '0') : 0;
int UpperCopyEngineIndex = (CopyEngineRange) ? (CopyEngineRange[2] - '0') : 8;
Copy link
Contributor

Choose a reason for hiding this comment

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

the access CopyEngineRange[2] can be past the allocated string, please check
also check full syntax "a:b"

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 modified the logic here. Please check.

@@ -1056,6 +1072,11 @@ _pi_queue::getZeCopyCommandQueue(int *CopyQueueIndex,
int *CopyQueueGroupIndex) {
assert(CopyQueueIndex);
int n = ZeCopyCommandQueues.size();
int LowerCopyQueueIndex = getRangeOfAllowedCopyEngines.first;
int UpperCopyQueueIndex = getRangeOfAllowedCopyEngines.second;
LowerCopyQueueIndex = std::max(0, LowerCopyQueueIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

This will compute to "0" if LowerCopyQueueIndex == -1, why is this OK?

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 added a check to see if LowerCopyQueueIndex is greater than UpperCopyQueueIndex and return nullptr if that's the case.

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 an additional subtle check on top of this questionable computation. Why don't you just check for -1 range and return -1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address this in next patch. Thanks.

@@ -2572,24 +2596,34 @@ pi_result piQueueCreate(pi_context Context, pi_device Device,
&ZeCommandQueueDesc, // TODO: translate properties
&ZeComputeCommandQueue));

// Create additional queues to link copy engines and push them into
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the comment to line 2621

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reordered comments.

Copy link
Contributor

@smaslov-intel smaslov-intel left a comment

Choose a reason for hiding this comment

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

Please address comments

@asudarsa asudarsa changed the title [SYCL][L0][PI] Add a new environment variable to allow user a finer control over copy engines [SYCL][L0][PI] Modify SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE environment variable to allow user a finer control over copy engines Aug 17, 2021
// available copy engines can be used.
static const std::pair<int, int> getRangeOfAllowedCopyEngines = [] {
std::string CopyEngineRange =
std::getenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE");
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 you cannot create a string from a null pointer, so have to check that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. That could be the reason for the failures I am seeing as well. Will correct this.

Copy link
Contributor

@smaslov-intel smaslov-intel left a comment

Choose a reason for hiding this comment

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

Please address more comments

@@ -1089,7 +1089,8 @@ _pi_queue::getZeCopyCommandQueue(int *CopyQueueIndex,
int n = ZeCopyCommandQueues.size();
int LowerCopyQueueIndex = getRangeOfAllowedCopyEngines.first;
int UpperCopyQueueIndex = getRangeOfAllowedCopyEngines.second;
LowerCopyQueueIndex = std::max(0, LowerCopyQueueIndex);
LowerCopyQueueIndex =
(LowerCopyQueueIndex == -1) ? -1 : std::max(0, LowerCopyQueueIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

if your range is [-1:-1] then the check at line 1098 is not going to evaluate to "true"

smaslov-intel
smaslov-intel previously approved these changes Aug 17, 2021
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

Please, add tests for this code.

Comment on lines 86 to 87
else
return std::pair<int, int>(-1, -1); // No copy engines will be used.
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
else
return std::pair<int, int>(-1, -1); // No copy engines will be used.
return std::pair<int, int>(-1, -1); // No copy engines will be used.

Comment on lines 75 to 77
if (!EnvVar) {
return std::pair<int, int>(0, INT_MAX);
}
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
if (!EnvVar) {
return std::pair<int, int>(0, INT_MAX);
}
if (!EnvVar)
return std::pair<int, int>(0, INT_MAX);

Comment on lines 89 to 91
int LowerCopyEngineIndex = std::stoi(CopyEngineRange.substr(0, pos));
int UpperCopyEngineIndex = std::stoi(CopyEngineRange.substr(pos + 1));
return std::pair<int, int>(LowerCopyEngineIndex, UpperCopyEngineIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at surrounding code it seems like there must be additional check for invalid values.
From my understanding, the requirement is: -1 <= LowerCopyEngineIndex <= UpperCopyEngineIndex <= INT_MAX.

  • <= INT_MAX is validated by std::stoi, but we must explicitly check other limitations.
  • LowerCopyEngineIndex <= UpperCopyEngineIndex is also tested at one place, although I would check it right here.
  • -1 <= LowerCopyEngineIndex - is not checked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in next patch. Thanks

@asudarsa
Copy link
Contributor Author

asudarsa commented Aug 17, 2021

The test failing in linux build is passing locally. I have restarted the test. I see that this test is failing for other PRs as well.

@bader bader merged commit 3828df5 into sycl Aug 18, 2021
@bader bader deleted the add_new_link_engine_option branch August 18, 2021 07:35
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