Update the MemoryPool by defining the max pool size, and use it when adding a new entry to the pool (#44)

* Update the MemoryPool by defining the max pool size, and use it when adding a new entry to the pool

* Fix finding the gfx942_mi300x
Этот коммит содержится в:
Aryan Salmanpour
2024-07-19 19:04:31 -04:00
коммит произвёл GitHub
родитель c3d07f42a0
Коммит 6d7d72c6da
2 изменённых файлов: 24 добавлений и 23 удалений
+22 -22
Просмотреть файл
@@ -32,10 +32,11 @@ THE SOFTWARE.
* @return None
*/
RocJpegVaapiMemoryPool::RocJpegVaapiMemoryPool() {
std::vector<uint32_t> surface_formats = {VA_FOURCC_RGBA, VA_FOURCC_RGBP, VA_FOURCC_444P, VA_FOURCC_422V, ROCJPEG_FOURCC_YUYV, VA_FOURCC_NV12, VA_FOURCC_Y800};
std::vector<uint32_t> surface_formats = {VA_FOURCC_RGBA, VA_FOURCC_RGBP, VA_FOURCC_444P, VA_FOURCC_422V, ROCJPEG_FOURCC_YUYV, VA_FOURCC_NV12, VA_FOURCC_Y800};
for (auto surface_format : surface_formats) {
mem_pool_[surface_format] = std::vector<RocJpegVaapiMemPoolEntry>();
}
max_pool_size_ = 2;
}
/**
@@ -84,10 +85,8 @@ void RocJpegVaapiMemoryPool::ReleaseResources() {
}
}
void RocJpegVaapiMemoryPool::SetPoolSize(int32_t max_pool_size) {
for (auto& pair : mem_pool_) {
pair.second.reserve(max_pool_size);
}
void RocJpegVaapiMemoryPool::SetPoolSize(uint32_t max_pool_size) {
max_pool_size_ = max_pool_size;
}
void RocJpegVaapiMemoryPool::SetVaapiDisplay(const VADisplay& va_display) {
@@ -107,20 +106,20 @@ void RocJpegVaapiMemoryPool::SetVaapiDisplay(const VADisplay& va_display) {
* @return The status of the operation. Returns ROCJPEG_STATUS_SUCCESS if the operation is successful.
*/
RocJpegStatus RocJpegVaapiMemoryPool::AddPoolEntry(uint32_t surface_format, const RocJpegVaapiMemPoolEntry& pool_entry) {
auto& entires = mem_pool_[surface_format];
if (entires.size() < entires.capacity()) {
entires.push_back(pool_entry);
auto& entries = mem_pool_[surface_format];
if (entries.size() < max_pool_size_) {
entries.push_back(pool_entry);
} else {
if (entires.front().va_context_id != 0) {
CHECK_VAAPI(vaDestroyContext(va_display_, entires.front().va_context_id));
entires.front().va_context_id = 0;
if (entries.front().va_context_id != 0) {
CHECK_VAAPI(vaDestroyContext(va_display_, entries.front().va_context_id));
entries.front().va_context_id = 0;
}
if (!entires.front().va_surface_ids.empty()) {
CHECK_VAAPI(vaDestroySurfaces(va_display_, entires.front().va_surface_ids.data(), entires.front().va_surface_ids.size()));
std::fill(entires.front().va_surface_ids.begin(), entires.front().va_surface_ids.end(), 0);
if (!entries.front().va_surface_ids.empty()) {
CHECK_VAAPI(vaDestroySurfaces(va_display_, entries.front().va_surface_ids.data(), entries.front().va_surface_ids.size()));
std::fill(entries.front().va_surface_ids.begin(), entries.front().va_surface_ids.end(), 0);
}
if (!entires.front().hip_interops.empty()) {
for(auto& hip_interop_entry : entires.front().hip_interops) {
if (!entries.front().hip_interops.empty()) {
for(auto& hip_interop_entry : entries.front().hip_interops) {
if (hip_interop_entry.hip_mapped_device_mem != nullptr)
CHECK_HIP(hipFree(hip_interop_entry.hip_mapped_device_mem));
if (hip_interop_entry.hip_ext_mem != nullptr)
@@ -128,8 +127,8 @@ RocJpegStatus RocJpegVaapiMemoryPool::AddPoolEntry(uint32_t surface_format, cons
memset((void*)&hip_interop_entry, 0, sizeof(hip_interop_entry));
}
}
entires.erase(entires.begin());
entires.push_back(pool_entry);
entries.erase(entries.begin());
entries.push_back(pool_entry);
}
return ROCJPEG_STATUS_SUCCESS;
}
@@ -312,15 +311,16 @@ RocJpegStatus RocJpegVappiDecoder::InitializeDecoder(std::string device_name, st
if (is_gfx942_detected) {
std::string mi300a = "MI300A";
size_t found_mi300a = device_name.find(mi300a);
if (found_mi300a != std::string::npos) {
gcn_arch_name_base_temp = (found_mi300a != std::string::npos) ? gcn_arch_name_base_temp + "_mi300a"
: gcn_arch_name_base_temp + "_mi300x";
}
gcn_arch_name_base_temp = (found_mi300a != std::string::npos) ? gcn_arch_name_base_temp + "_mi300a"
: gcn_arch_name_base_temp + "_mi300x";
}
auto it = vcn_jpeg_spec_.find(gcn_arch_name_base_temp);
if (it != vcn_jpeg_spec_.end()) {
current_vcn_jpeg_spec_ = it->second;
} else {
ERR("ERROR: didn't find the jpeg spec for " + gcn_arch_name_base_temp);
return ROCJPEG_STATUS_NOT_INITIALIZED;
}
std::vector<int> visible_devices;
GetVisibleDevices(visible_devices);
+2 -1
Просмотреть файл
@@ -140,7 +140,7 @@ class RocJpegVaapiMemoryPool {
* @brief Sets the maximum size of the memory pool.
* @param max_pool_size The maximum size of the memory pool.
*/
void SetPoolSize(int32_t max_pool_size);
void SetPoolSize(uint32_t max_pool_size);
/**
* @brief Sets the VADisplay for the memory pool.
@@ -183,6 +183,7 @@ class RocJpegVaapiMemoryPool {
private:
VADisplay va_display_; // The VADisplay associated with the memory pool.
uint32_t max_pool_size_; // The maximum pool size of the memory pool (mem_pool_) per entry.
std::unordered_map<uint32_t, std::vector<RocJpegVaapiMemPoolEntry>> mem_pool_; // The memory pool.
};