Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/memory/hipMemPoolMaxAlloc.cc
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

74 lines
2.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
/* Test Case Description:
Stress test for memory pool allocations. Allocates blocks from 1% to 50%
of total device memory in 2% increments, verifies pool attributes
(UsedMemCurrent, ReservedMemCurrent) after all allocations, then frees
all blocks and verifies memory returns to zero.
*/
#include <hip_test_common.hh>
HIP_TEST_CASE(Unit_hipMemPoolMaxAlloc) {
int device = 0;
HIP_CHECK(hipSetDevice(device));
hipMemPool_t pool;
HIP_CHECK(hipDeviceGetDefaultMemPool(&pool, device));
uint64_t threshold = 0;
HIP_CHECK(hipMemPoolSetAttribute(pool, hipMemPoolAttrReleaseThreshold, &threshold));
std::size_t free{}, total{};
HIP_CHECK(hipMemGetInfo(&free, &total));
const std::size_t memBudget = total;
hipStream_t stream = nullptr;
constexpr int kStartPct = 1;
constexpr int kEndPct = 50;
constexpr int kStepPct = 2;
constexpr int kMaxAllocs = (kEndPct - kStartPct) / kStepPct + 1;
const std::size_t memLimit = (memBudget / 100) * 60;
void* ptrs[kMaxAllocs] = {};
std::size_t sizes[kMaxAllocs] = {};
std::size_t expectedTotal = 0;
// Allocate all blocks, stop when cumulative usage would exceed 60% of device memory
int numAllocs = 0;
for (int pct = kStartPct; pct <= kEndPct; pct += kStepPct) {
std::size_t allocSize = (memBudget / 100) * pct;
if (expectedTotal + allocSize > memLimit) break;
sizes[numAllocs] = allocSize;
expectedTotal += allocSize;
HIP_CHECK(hipMallocAsync(&ptrs[numAllocs], sizes[numAllocs], stream));
HIP_CHECK(hipStreamSynchronize(stream));
numAllocs++;
}
// Verify pool reports expected usage after all allocations
uint64_t usedMem = 0;
uint64_t reservedMem = 0;
HIP_CHECK(hipMemPoolGetAttribute(pool, hipMemPoolAttrUsedMemCurrent, &usedMem));
HIP_CHECK(hipMemPoolGetAttribute(pool, hipMemPoolAttrReservedMemCurrent, &reservedMem));
REQUIRE(usedMem >= expectedTotal);
REQUIRE(reservedMem >= expectedTotal);
// Free all blocks
for (int i = 0; i < numAllocs; i++) {
HIP_CHECK(hipFreeAsync(ptrs[i], stream));
HIP_CHECK(hipStreamSynchronize(stream));
}
// Verify pool reports zero usage after all frees
HIP_CHECK(hipMemPoolGetAttribute(pool, hipMemPoolAttrUsedMemCurrent, &usedMem));
HIP_CHECK(hipMemPoolGetAttribute(pool, hipMemPoolAttrReservedMemCurrent, &reservedMem));
REQUIRE(usedMem == 0);
REQUIRE(reservedMem == 0);
}