@@ -86,57 +86,29 @@ Expected<int32_t> LevelZeroPluginTy::findDevices() {
8686 return A.IsDiscrete ;
8787 });
8888
89- struct DeviceInfoTy {
90- L0DeviceIdTy Id;
91- L0ContextTy *Driver;
92- bool isRoot () const { return Id.SubId < 0 && Id.CCSId < 0 ; }
93- };
94-
95- llvm::SmallVector<DeviceInfoTy> DevicesToAdd;
96-
9789 for (size_t RootId = 0 ; RootId < RootDevices.size (); RootId++) {
9890 const auto zeDevice = RootDevices[RootId].zeDevice ;
9991 auto *RootDriver = RootDevices[RootId].Driver ;
100- DevicesToAdd.push_back (
101- {{zeDevice, static_cast <int32_t >(RootId), -1 , -1 }, RootDriver});
102- }
103- NumDevices = DevicesToAdd.size ();
104- auto DeviceId = 0 ;
105- for (auto &DeviceInfo : DevicesToAdd) {
106- auto RootId = DeviceInfo.Id .RootId ;
107- auto SubId = DeviceInfo.Id .SubId ;
108- auto CCSId = DeviceInfo.Id .CCSId ;
109- auto zeDevice = DeviceInfo.Id .zeId ;
110- auto *Driver = DeviceInfo.Driver ;
111-
112- std::string IdStr = std::to_string (RootId) +
113- (SubId < 0 ? " " : " ." + std::to_string (SubId)) +
114- (CCSId < 0 ? " " : " ." + std::to_string (CCSId));
115-
116- L0Devices.push_back (new L0DeviceTy (*this , DeviceId, getNumRootDevices (),
117- zeDevice, *Driver, std::move (IdStr),
118- CCSId < 0 ? 0 : CCSId /* ComputeIndex */
119- ));
120- DeviceId++;
92+ DetectedDevices.push_back (DeviceInfoTy{
93+ {zeDevice, static_cast <int32_t >(RootId), -1 , -1 }, RootDriver});
12194 }
95+ int32_t NumDevices = DetectedDevices.size ();
12296
123- DP (" Found %" PRIu32 " root devices, %" PRIu32 " total devices.\n " ,
124- getNumRootDevices (), NumDevices);
97+ DP (" Found %" PRIu32 " devices.\n " , NumDevices);
12598 DP (" List of devices (DeviceID[.SubID[.CCSID]])\n " );
126- for (auto &l0Device : L0Devices) {
127- DP (" -- %s\n " , l0Device->getZeIdCStr ());
128- (void )l0Device; // silence warning
99+ for (auto &DeviceInfo : DetectedDevices) {
100+ (void )DeviceInfo; // to avoid unused variable warning in non-debug builds
101+ DP (" -- Device %" PRIu32 " %s%s (zeDevice=%p) from Driver %p\n " ,
102+ DeviceInfo.Id .RootId ,
103+ (DeviceInfo.Id .SubId < 0
104+ ? " "
105+ : (" ." + std::to_string (DeviceInfo.Id .SubId )).c_str ()),
106+ (DeviceInfo.Id .CCSId < 0
107+ ? " "
108+ : (" ." + std::to_string (DeviceInfo.Id .CCSId )).c_str ()),
109+ DPxPTR (DeviceInfo.Id .zeId ), DPxPTR (DeviceInfo.Id .Driver ));
129110 }
130-
131- if (getDebugLevel () > 0 ) {
132- DP (" Root Device Information\n " );
133- for (uint32_t I = 0 ; I < getNumRootDevices (); I++) {
134- auto &l0Device = getDeviceFromId (I);
135- l0Device.reportDeviceInfo ();
136- }
137- }
138-
139- return getNumRootDevices ();
111+ return NumDevices;
140112}
141113
142114Expected<int32_t > LevelZeroPluginTy::initImpl () {
@@ -163,7 +135,25 @@ Error LevelZeroPluginTy::deinitImpl() {
163135GenericDeviceTy *LevelZeroPluginTy::createDevice (GenericPluginTy &Plugin,
164136 int32_t DeviceId,
165137 int32_t NumDevices) {
166- return &getDeviceFromId (DeviceId);
138+ auto &DeviceInfo = DetectedDevices[DeviceId];
139+ auto RootId = DeviceInfo.Id .RootId ;
140+ auto SubId = DeviceInfo.Id .SubId ;
141+ auto CCSId = DeviceInfo.Id .CCSId ;
142+ auto zeDevice = DeviceInfo.Id .zeId ;
143+ auto *zeDriver = DeviceInfo.Driver ;
144+
145+ std::string IdStr = std::to_string (RootId) +
146+ (SubId < 0 ? " " : " ." + std::to_string (SubId)) +
147+ (CCSId < 0 ? " " : " ." + std::to_string (CCSId));
148+
149+ auto *NewDevice = new L0DeviceTy (
150+ static_cast <LevelZeroPluginTy &>(Plugin), DeviceId, NumDevices, zeDevice,
151+ *zeDriver, std::move (IdStr), CCSId < 0 ? 0 : CCSId /* ComputeIndex */ );
152+ if (NewDevice && getDebugLevel () > 0 ) {
153+ DP (" Device %" PRIi32 " information\n " , DeviceId);
154+ NewDevice->reportDeviceInfo ();
155+ }
156+ return NewDevice;
167157}
168158
169159GenericGlobalHandlerTy *LevelZeroPluginTy::createGlobalHandler () {
0 commit comments