-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][Level Zero] Enable multi-CCS support. #4038
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f3c884d
[DPC++] enable multi-context (c-slice) support.
rbegam d5f4387
fix sub sub device count.
rbegam 607746e
remove SubSubDevicesCount.
rbegam beb8763
clang formatted.
rbegam e5b85fb
clang format.
rbegam 00aef90
inlining.
rbegam 89fdf06
clang formatted.
rbegam d388a8b
update pi_level_zero.cpp.
rbegam 485ecaf
clang formatted.
rbegam fa22bcd
update max sub-device count.
rbegam 6ff74c2
add comments.
rbegam 0d9dfa6
add index.
rbegam a52ca46
update context initialization.
rbegam bf50ccd
clang formatted.
rbegam 33c4449
add comments.
rbegam 306cc9f
fix pre-commit fail.
rbegam 37b114e
update comments.
rbegam 3527982
clang formatted.
rbegam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,12 @@ static const pi_uint32 ZeSerialize = [] { | |
return SerializeModeValue; | ||
}(); | ||
|
||
static const bool CopyEngineRequested = [] { | ||
const char *CopyEngine = std::getenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE"); | ||
bool UseCopyEngine = (!CopyEngine || (std::stoi(CopyEngine) != 0)); | ||
return UseCopyEngine; | ||
}(); | ||
|
||
// This class encapsulates actions taken along with a call to Level Zero API. | ||
class ZeCall { | ||
private: | ||
|
@@ -529,7 +535,8 @@ createEventAndAssociateQueue(pi_queue Queue, pi_event *Event, | |
return PI_SUCCESS; | ||
} | ||
|
||
pi_result _pi_device::initialize() { | ||
pi_result _pi_device::initialize(int SubSubDeviceOrdinal, | ||
int SubSubDeviceIndex) { | ||
uint32_t numQueueGroups = 0; | ||
ZE_CALL(zeDeviceGetCommandQueueGroupProperties, | ||
(ZeDevice, &numQueueGroups, nullptr)); | ||
|
@@ -542,44 +549,54 @@ pi_result _pi_device::initialize() { | |
(ZeDevice, &numQueueGroups, QueueProperties.data())); | ||
|
||
int ComputeGroupIndex = -1; | ||
for (uint32_t i = 0; i < numQueueGroups; i++) { | ||
if (QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) { | ||
ComputeGroupIndex = i; | ||
break; | ||
} | ||
} | ||
// How is it possible that there are no "compute" capabilities? | ||
if (ComputeGroupIndex < 0) { | ||
return PI_ERROR_UNKNOWN; | ||
} | ||
ZeComputeQueueGroupIndex = ComputeGroupIndex; | ||
ZeComputeQueueGroupProperties = QueueProperties[ComputeGroupIndex]; | ||
|
||
int CopyGroupIndex = -1; | ||
const char *CopyEngine = std::getenv("SYCL_PI_LEVEL_ZERO_USE_COPY_ENGINE"); | ||
bool UseCopyEngine = (!CopyEngine || (std::stoi(CopyEngine) != 0)); | ||
if (UseCopyEngine) { | ||
// Initialize a sub-sub-device with its own ordinal and index | ||
if (SubSubDeviceOrdinal >= 0) { | ||
ComputeGroupIndex = SubSubDeviceOrdinal; | ||
ZeComputeEngineIndex = SubSubDeviceIndex; | ||
} else { // This is a root or a sub-device | ||
for (uint32_t i = 0; i < numQueueGroups; i++) { | ||
if (((QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) == 0) && | ||
(QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY)) { | ||
CopyGroupIndex = i; | ||
if (QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) { | ||
ComputeGroupIndex = i; | ||
break; | ||
} | ||
} | ||
if (CopyGroupIndex < 0) | ||
zePrint("NOTE: blitter/copy engine is not available though it was " | ||
"requested\n"); | ||
else | ||
zePrint("NOTE: blitter/copy engine is available\n"); | ||
} | ||
ZeCopyQueueGroupIndex = CopyGroupIndex; | ||
if (CopyGroupIndex >= 0) { | ||
ZeCopyQueueGroupProperties = QueueProperties[CopyGroupIndex]; | ||
// How is it possible that there are no "compute" capabilities? | ||
if (ComputeGroupIndex < 0) { | ||
return PI_ERROR_UNKNOWN; | ||
} | ||
|
||
// The index for a root or a sub-device is always 0. | ||
ZeComputeEngineIndex = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This deserves a comment why we are using "0" and how it scales to HW |
||
|
||
int CopyGroupIndex = -1; | ||
if (CopyEngineRequested) { | ||
for (uint32_t i = 0; i < numQueueGroups; i++) { | ||
if (((QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) == 0) && | ||
(QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY)) { | ||
CopyGroupIndex = i; | ||
break; | ||
} | ||
} | ||
if (CopyGroupIndex < 0) | ||
zePrint("NOTE: blitter/copy engine is not available though it was " | ||
smaslov-intel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"requested\n"); | ||
else | ||
zePrint("NOTE: blitter/copy engine is available\n"); | ||
} | ||
|
||
ZeCopyQueueGroupIndex = CopyGroupIndex; | ||
if (CopyGroupIndex >= 0) { | ||
ZeCopyQueueGroupProperties = QueueProperties[CopyGroupIndex]; | ||
} | ||
} | ||
|
||
ZeComputeQueueGroupIndex = ComputeGroupIndex; | ||
ZeComputeQueueGroupProperties = QueueProperties[ComputeGroupIndex]; | ||
|
||
// Cache device properties | ||
ZeDeviceProperties = {}; | ||
ZE_CALL(zeDeviceGetProperties, (ZeDevice, &ZeDeviceProperties)); | ||
|
@@ -598,7 +615,7 @@ pi_result _pi_context::initialize() { | |
pi_device Device = SingleRootDevice ? SingleRootDevice : Devices[0]; | ||
ZeStruct<ze_command_queue_desc_t> ZeCommandQueueDesc; | ||
ZeCommandQueueDesc.ordinal = Device->ZeComputeQueueGroupIndex; | ||
ZeCommandQueueDesc.index = 0; | ||
ZeCommandQueueDesc.index = Device->ZeComputeEngineIndex; | ||
ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_SYNCHRONOUS; | ||
ZE_CALL( | ||
zeCommandListCreateImmediate, | ||
|
@@ -1547,6 +1564,50 @@ pi_result _pi_platform::populateDeviceCacheIfNeeded() { | |
delete[] ZeSubdevices; | ||
return Result; | ||
} | ||
|
||
// collect all the ordinals for the sub-sub-devices | ||
std::vector<int> Ordinals; | ||
|
||
uint32_t numQueueGroups = 0; | ||
ZE_CALL(zeDeviceGetCommandQueueGroupProperties, | ||
(PiSubDevice->ZeDevice, &numQueueGroups, nullptr)); | ||
if (numQueueGroups == 0) { | ||
return PI_ERROR_UNKNOWN; | ||
} | ||
std::vector<ze_command_queue_group_properties_t> QueueProperties( | ||
numQueueGroups); | ||
ZE_CALL( | ||
zeDeviceGetCommandQueueGroupProperties, | ||
(PiSubDevice->ZeDevice, &numQueueGroups, QueueProperties.data())); | ||
|
||
for (uint32_t i = 0; i < numQueueGroups; i++) { | ||
if (QueueProperties[i].flags & | ||
ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE && | ||
QueueProperties[i].numQueues > 1) { | ||
Ordinals.push_back(i); | ||
} | ||
} | ||
|
||
// Create PI sub-sub-devices with the sub-device for all the ordinals. | ||
// Each {ordinal, index} points to a specific CCS which constructs | ||
// a sub-sub-device at this point. | ||
for (uint32_t J = 0; J < Ordinals.size(); ++J) { | ||
for (uint32_t K = 0; K < QueueProperties[Ordinals[J]].numQueues; | ||
++K) { | ||
std::unique_ptr<_pi_device> PiSubSubDevice( | ||
new _pi_device(ZeSubdevices[I], this, PiSubDevice.get())); | ||
pi_result Result = PiSubSubDevice->initialize(Ordinals[J], K); | ||
if (Result != PI_SUCCESS) { | ||
return Result; | ||
} | ||
|
||
// save pointers to sub-sub-devices for quick retrieval in the | ||
// future. | ||
PiSubDevice->SubDevices.push_back(PiSubSubDevice.get()); | ||
PiDevicesCache.push_back(std::move(PiSubSubDevice)); | ||
} | ||
} | ||
|
||
// save pointers to sub-devices for quick retrieval in the future. | ||
Device->SubDevices.push_back(PiSubDevice.get()); | ||
PiDevicesCache.push_back(std::move(PiSubDevice)); | ||
|
@@ -1777,17 +1838,23 @@ pi_result piDeviceGetInfo(pi_device Device, pi_device_info ParamName, | |
case PI_DEVICE_INFO_VERSION: | ||
return ReturnValue(Device->Platform->ZeDriverApiVersion.c_str()); | ||
case PI_DEVICE_INFO_PARTITION_MAX_SUB_DEVICES: { | ||
uint32_t ZeSubDeviceCount = 0; | ||
ZE_CALL(zeDeviceGetSubDevices, (ZeDevice, &ZeSubDeviceCount, nullptr)); | ||
return ReturnValue(pi_uint32{ZeSubDeviceCount}); | ||
pi_result Res = Device->Platform->populateDeviceCacheIfNeeded(); | ||
if (Res != PI_SUCCESS) { | ||
return Res; | ||
} | ||
return ReturnValue(pi_uint32{(unsigned int)(Device->SubDevices.size())}); | ||
} | ||
case PI_DEVICE_INFO_REFERENCE_COUNT: | ||
return ReturnValue(pi_uint32{Device->RefCount}); | ||
case PI_DEVICE_INFO_PARTITION_PROPERTIES: { | ||
// SYCL spec says: if this SYCL device cannot be partitioned into at least | ||
// two sub devices then the returned vector must be empty. | ||
uint32_t ZeSubDeviceCount = 0; | ||
ZE_CALL(zeDeviceGetSubDevices, (ZeDevice, &ZeSubDeviceCount, nullptr)); | ||
pi_result Res = Device->Platform->populateDeviceCacheIfNeeded(); | ||
if (Res != PI_SUCCESS) { | ||
return Res; | ||
} | ||
|
||
uint32_t ZeSubDeviceCount = Device->SubDevices.size(); | ||
if (ZeSubDeviceCount < 2) { | ||
return ReturnValue(pi_device_partition_property{0}); | ||
} | ||
|
@@ -2402,7 +2469,7 @@ pi_result piQueueCreate(pi_context Context, pi_device Device, | |
ZeDevice = Device->ZeDevice; | ||
ZeStruct<ze_command_queue_desc_t> ZeCommandQueueDesc; | ||
ZeCommandQueueDesc.ordinal = Device->ZeComputeQueueGroupIndex; | ||
ZeCommandQueueDesc.index = 0; | ||
ZeCommandQueueDesc.index = Device->ZeComputeEngineIndex; | ||
ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS; | ||
|
||
ZE_CALL(zeCommandQueueCreate, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.