Use the correct offset when creating render nodes on each partition mode on MI300 (#310)

* Use the correct offset when creating render nodes on each partition mode on MI300

* Use the correct offset when creating render nodes on each partition mode on MI300

* code clean up
This commit is contained in:
Aryan Salmanpour
2024-04-09 18:17:02 -04:00
committed by GitHub
szülő f8bf587f92
commit f2d1ad75eb
2 fájl változott, egészen pontosan 35 új sor hozzáadva és 20 régi sor törölve
@@ -76,7 +76,6 @@ rocDecStatus VaapiVideoDecoder::InitializeDecoder(std::string device_name, std::
std::vector<int> visible_devices;
GetVisibleDevices(visible_devices);
int num_render_cards_per_socket = 1;
int offset = 0;
if (gcn_arch_name_base.compare("gfx940") == 0 ||
gcn_arch_name_base.compare("gfx941") == 0 ||
@@ -85,17 +84,21 @@ rocDecStatus VaapiVideoDecoder::InitializeDecoder(std::string device_name, std::
GetCurrentComputePartition(current_compute_partitions);
if (current_compute_partitions.empty()) {
//if the current_compute_partitions is empty then the default SPX mode is assumed.
num_render_cards_per_socket = 8;
if (decoder_create_info_.device_id < visible_devices.size()) {
offset = visible_devices[decoder_create_info_.device_id] * 7;
} else {
offset = decoder_create_info_.device_id * 7;
}
} else {
GetNumRenderCardsPerDevice(device_name, decoder_create_info_.device_id, visible_devices, current_compute_partitions, num_render_cards_per_socket, offset);
GetDrmNodeOffset(device_name, decoder_create_info_.device_id, visible_devices, current_compute_partitions, offset);
}
}
std::string drm_node = "/dev/dri/renderD";
if (decoder_create_info_.device_id < visible_devices.size()) {
drm_node += std::to_string(128 + offset + visible_devices[decoder_create_info_.device_id] * num_render_cards_per_socket);
drm_node += std::to_string(128 + offset + visible_devices[decoder_create_info_.device_id]);
} else {
drm_node += std::to_string(128 + offset + decoder_create_info_.device_id * num_render_cards_per_socket);
drm_node += std::to_string(128 + offset + decoder_create_info_.device_id);
}
rocdec_status = InitVAAPI(drm_node);
if (rocdec_status != ROCDEC_SUCCESS) {
@@ -463,34 +466,43 @@ void VaapiVideoDecoder::GetCurrentComputePartition(std::vector<ComputePartition>
}
}
void VaapiVideoDecoder::GetNumRenderCardsPerDevice(std::string device_name, uint8_t device_id, std::vector<int>& visible_devices,
std::vector<ComputePartition> &current_compute_partitions,
int &num_render_cards_per_socket, int &offset) {
offset = 0;
void VaapiVideoDecoder::GetDrmNodeOffset(std::string device_name, uint8_t device_id, std::vector<int>& visible_devices,
std::vector<ComputePartition> &current_compute_partitions, int &offset) {
if (!current_compute_partitions.empty()) {
switch (current_compute_partitions[0]) {
case kSpx:
num_render_cards_per_socket = 8;
if (device_id < visible_devices.size()) {
offset = visible_devices[device_id] * 7;
} else {
offset = device_id * 7;
}
break;
case kDpx:
num_render_cards_per_socket = 4;
if (device_id < visible_devices.size()) {
offset = (visible_devices[device_id] / 2) * 6;
} else {
offset = (device_id / 2) * 6;
}
break;
case kTpx:
num_render_cards_per_socket = 2;
// Please note that although there are only 6 XCCs per socket on MI300A,
// there are two dummy render nodes added by the driver.
// This needs to be taken into account when creating drm_node on each socket in TPX mode.
if (device_id < visible_devices.size()) {
offset = (visible_devices[device_id] / 3) * 2;
offset = (visible_devices[device_id] / 3) * 5;
} else {
offset = (device_id / 3) * 2;
offset = (device_id / 3) * 5;
}
break;
case kQpx:
num_render_cards_per_socket = 2;
if (device_id < visible_devices.size()) {
offset = (visible_devices[device_id] / 4) * 4;
} else {
offset = (device_id / 4) * 4;
}
break;
case kCpx:
num_render_cards_per_socket = 1;
// Please note that both MI300A and MI300X have the same gfx_arch_name which is
// gfx942. Therefore we cannot use the gfx942 to identify MI300A.
// instead use the device name and look for MI300A
@@ -499,7 +511,11 @@ void VaapiVideoDecoder::GetNumRenderCardsPerDevice(std::string device_name, uint
std::string mi300a = "MI300A";
size_t found_mi300a = device_name.find(mi300a);
if (found_mi300a != std::string::npos) {
offset = (device_id / 6) * 2;
if (device_id < visible_devices.size()) {
offset = (visible_devices[device_id] / 6) * 2;
} else {
offset = (device_id / 6) * 2;
}
}
break;
}
@@ -89,7 +89,6 @@ private:
rocDecStatus DestroyDataBuffers();
void GetVisibleDevices(std::vector<int>& visible_devices);
void GetCurrentComputePartition(std::vector<ComputePartition> &currnet_compute_partitions);
void GetNumRenderCardsPerDevice(std::string device_name, uint8_t device_id, std::vector<int>& visible_devices,
std::vector<ComputePartition> &current_compute_partitions,
int &num_render_cards_per_socket, int &offset);
void GetDrmNodeOffset(std::string device_name, uint8_t device_id, std::vector<int>& visible_devices,
std::vector<ComputePartition> &current_compute_partitions, int &offset);
};