-
Notifications
You must be signed in to change notification settings - Fork 787
[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
Conversation
…ontrol over copy engines Signed-off-by: Arvind Sudarsanam <[email protected]>
sycl/doc/EnvironmentVariables.md
Outdated
| `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. |
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.
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.
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 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 |
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.
But you already support 1-digit non-zero values below. Comment outdated? Also why need this check for exactly 1 symbol?
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.
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); |
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.
Can we avoid hardcoding 8 here, e.g. have -1 mean no upper bound
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 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; |
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.
the access CopyEngineRange[2] can be past the allocated string, please check
also check full syntax "a:b"
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 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); |
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.
This will compute to "0" if LowerCopyQueueIndex == -1, why is this OK?
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 added a check to see if LowerCopyQueueIndex is greater than UpperCopyQueueIndex and return nullptr if that's the case.
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.
This is an additional subtle check on top of this questionable computation. Why don't you just check for -1 range and return -1?
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.
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 |
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.
Move the comment to line 2621
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.
Reordered comments.
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 address comments
// 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"); |
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 you cannot create a string from a null pointer, so have to check that case.
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.
That's right. That could be the reason for the failures I am seeing as well. Will correct this.
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 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); |
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.
if your range is [-1:-1] then the check at line 1098 is not going to evaluate to "true"
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, add tests for this code.
else | ||
return std::pair<int, int>(-1, -1); // No copy engines will be used. |
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.
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. |
if (!EnvVar) { | ||
return std::pair<int, int>(0, INT_MAX); | ||
} |
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.
if (!EnvVar) { | |
return std::pair<int, int>(0, INT_MAX); | |
} | |
if (!EnvVar) | |
return std::pair<int, int>(0, INT_MAX); | |
int LowerCopyEngineIndex = std::stoi(CopyEngineRange.substr(0, pos)); | ||
int UpperCopyEngineIndex = std::stoi(CopyEngineRange.substr(pos + 1)); | ||
return std::pair<int, int>(LowerCopyEngineIndex, UpperCopyEngineIndex); |
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.
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
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.
Addressed in next patch. Thanks
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. |
Signed-off-by: Arvind Sudarsanam [email protected]