@@ -78,17 +78,14 @@ namespace rocr {
7878namespace AMD {
7979// Anonymous namespace.
8080namespace {
81+
82+ const std::array<std::function<hsa_status_t (std::unique_ptr<core::Driver>&)>,
8183#if _WIN32
82- constexpr size_t num_drivers = 0 ;
84+ 0
8385#elif __linux__
84- constexpr size_t num_drivers = 2
85- #ifdef HSAKMT_VIRTIO_ENABLED
86- + 1
87- #endif
88- ;
86+ static_cast <size_t >(core::DriverType::NUM_DRIVER_TYPES)
8987#endif
90-
91- const std::array<std::function<hsa_status_t (std::unique_ptr<core::Driver>&)>, num_drivers>
88+ >
9289 discover_driver_funcs = {
9390#ifdef __linux__
9491 KfdDriver::DiscoverDriver,
@@ -121,22 +118,22 @@ bool InitializeDriver(std::unique_ptr<core::Driver>& driver) {
121118 return true ;
122119}
123120
124- void DiscoverCpu (HSAuint32 node_id, HsaNodeProperties& node_prop) {
125- CpuAgent* cpu = new CpuAgent (node_id, node_prop);
121+ void DiscoverCpu (HSAuint32 node_id, HsaNodeProperties& node_prop, core::DriverType driver_type ) {
122+ CpuAgent* cpu = new CpuAgent (node_id, node_prop, driver_type );
126123 cpu->Enable ();
127124 core::Runtime::runtime_singleton_->RegisterAgent (cpu, true );
128125}
129126
130127GpuAgent* DiscoverGpu (HSAuint32 node_id, HsaNodeProperties& node_prop, bool xnack_mode,
131- bool enabled) {
128+ bool enabled, core::DriverType driver_type ) {
132129 GpuAgent* gpu = nullptr ;
133130 if (node_prop.NumFComputeCores == 0 ) {
134131 // Ignore non GPUs.
135132 return nullptr ;
136133 }
137134 try {
138135 gpu = new GpuAgent (node_id, node_prop, xnack_mode,
139- core::Runtime::runtime_singleton_->gpu_agents ().size ());
136+ core::Runtime::runtime_singleton_->gpu_agents ().size (), driver_type );
140137
141138 const HsaVersionInfo& kfd_version = core::Runtime::runtime_singleton_->KfdVersion ().version ;
142139
@@ -163,7 +160,7 @@ GpuAgent* DiscoverGpu(HSAuint32 node_id, HsaNodeProperties& node_prop, bool xnac
163160 node_prop.Capability .ui32 .SRAM_EDCSupport = 1 ;
164161 delete gpu;
165162 gpu = new GpuAgent (node_id, node_prop, xnack_mode,
166- core::Runtime::runtime_singleton_->gpu_agents ().size ());
163+ core::Runtime::runtime_singleton_->gpu_agents ().size (), driver_type );
167164 }
168165 }
169166 } catch (const hsa_exception& e) {
@@ -268,24 +265,29 @@ void SurfaceGpuList(std::vector<int32_t>& gpu_list, bool xnack_mode, bool enable
268265 const int32_t invalidIdx = -1 ;
269266 int32_t list_sz = gpu_list.size ();
270267 HsaNodeProperties node_prop = {0 };
271- const auto & gpu_driver = core::Runtime::runtime_singleton_->AgentDriver (core::DriverType::KFD);
272- for (int32_t idx = 0 ; idx < list_sz; idx++) {
273- if (gpu_list[idx] == invalidIdx) {
274- break ;
268+ for (const auto & gpu_driver : core::Runtime::runtime_singleton_->AgentDrivers ()) {
269+ if (!core::Runtime::IsGPUDriver (gpu_driver->kernel_driver_type_ )) {
270+ continue ;
275271 }
276272
277- // Obtain properties of the node
278- hsa_status_t ret = gpu_driver.GetNodeProperties (node_prop, gpu_list[idx]);
279- assert (ret == HSA_STATUS_SUCCESS && " Error in getting Node Properties" );
273+ for (int32_t idx = 0 ; idx < list_sz; idx++) {
274+ if (gpu_list[idx] == invalidIdx) {
275+ break ;
276+ }
280277
281- // disable interrupt signal for DTIF platform
282- if (core::Runtime::runtime_singleton_-> flag (). enable_dtif ())
283- core::g_use_interrupt_wait = false ;
278+ // Obtain properties of the node
279+ hsa_status_t ret = gpu_driver-> GetNodeProperties (node_prop, gpu_list[idx]);
280+ assert (ret == HSA_STATUS_SUCCESS && " Error in getting Node Properties " ) ;
284281
285- // Instantiate a Gpu device. The IO links
286- // of this node have already been registered
287- assert ((node_prop.NumFComputeCores != 0 ) && " Improper node used for GPU device discovery." );
288- DiscoverGpu (gpu_list[idx], node_prop, xnack_mode, enabled);
282+ // disable interrupt signal for DTIF platform
283+ if (core::Runtime::runtime_singleton_->flag ().enable_dtif ())
284+ core::g_use_interrupt_wait = false ;
285+
286+ // Instantiate a Gpu device. The IO links
287+ // of this node have already been registered
288+ assert ((node_prop.NumFComputeCores != 0 ) && " Improper node used for GPU device discovery." );
289+ DiscoverGpu (gpu_list[idx], node_prop, xnack_mode, enabled, gpu_driver->kernel_driver_type_ );
290+ }
289291 }
290292}
291293
@@ -346,7 +348,7 @@ bool BuildTopology() {
346348 // / @todo: Add support for AIEs.
347349 // Query if env ROCR_VISIBLE_DEVICES is defined. If defined
348350 // determine number and order of GPU devices to be surfaced.
349- if (filter && driver-> kernel_driver_type_ == core::DriverType::KFD ) {
351+ if (filter && ( core::Runtime::IsGPUDriver (driver-> kernel_driver_type_ )) ) {
350352 rvdFilter.BuildRvdTokenList ();
351353 rvdFilter.BuildDeviceUuidList (node_props_vec);
352354 visibleCnt = rvdFilter.BuildUsrDeviceList ();
@@ -361,7 +363,7 @@ bool BuildTopology() {
361363 for (auto & node_props : node_props_vec) {
362364 if (node_props.NumCPUCores ) {
363365 // Node has CPU cores so instantiate a CPU agent.
364- DiscoverCpu (node_id, node_props);
366+ DiscoverCpu (node_id, node_props, driver-> kernel_driver_type_ );
365367 }
366368
367369 if (node_props.NumNeuralCores ) {
0 commit comments