Update memory allocation guide in using pool apis
This is to allow allocations in system memory that exceed sizes
reported by a CPU device
Change-Id: I3d10d192aafcefbe4107f69b7c5e30bf7f836619
[ROCm/ROCR-Runtime commit: 3201f68f72]
Этот коммит содержится в:
@@ -341,7 +341,7 @@ static hsa_status_t DumpSegment(const pool_info_t *pool_i,
|
||||
std::string const *ind_lvl) {
|
||||
hsa_status_t err;
|
||||
|
||||
fprintf(stdout, "%s%-25s", ind_lvl->c_str(), "Pool Segment:");
|
||||
fprintf(stdout, "%s%-28s", ind_lvl->c_str(), "Pool Segment:");
|
||||
std::string seg_str = "";
|
||||
std::string tmp_str;
|
||||
|
||||
@@ -412,6 +412,11 @@ hsa_status_t AcquirePoolInfo(hsa_amd_memory_pool_t pool,
|
||||
&pool_i->accessible_by_all);
|
||||
RET_IF_HSA_COMMON_ERR(err);
|
||||
|
||||
err = hsa_amd_memory_pool_get_info(pool,
|
||||
HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE,
|
||||
&pool_i->aggregate_alloc_max);
|
||||
RET_IF_HSA_COMMON_ERR(err);
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -422,25 +427,30 @@ hsa_status_t DumpMemoryPoolInfo(const pool_info_t *pool_i,
|
||||
DumpSegment(pool_i, &ind_lvl);
|
||||
|
||||
std::string sz_str = std::to_string(pool_i->size / 1024) + "KB";
|
||||
fprintf(stdout, "%s%-25s%-35s\n", ind_lvl.c_str(), "Pool Size:",
|
||||
fprintf(stdout, "%s%-28s%-36s\n", ind_lvl.c_str(), "Pool Size:",
|
||||
sz_str.c_str());
|
||||
|
||||
fprintf(stdout, "%s%-25s%-35s\n", ind_lvl.c_str(), "Pool Allocatable:",
|
||||
fprintf(stdout, "%s%-28s%-36s\n", ind_lvl.c_str(), "Pool Allocatable:",
|
||||
(pool_i->alloc_allowed ? "TRUE" : "FALSE"));
|
||||
|
||||
std::string gr_str = std::to_string(pool_i->alloc_granule / 1024) + "KB";
|
||||
fprintf(stdout, "%s%-25s%-35s\n", ind_lvl.c_str(), "Pool Alloc Granule:",
|
||||
fprintf(stdout, "%s%-28s%-36s\n", ind_lvl.c_str(), "Pool Alloc Granule:",
|
||||
gr_str.c_str());
|
||||
|
||||
|
||||
std::string al_str =
|
||||
std::to_string(pool_i->alloc_alignment / 1024) + "KB";
|
||||
fprintf(stdout, "%s%-25s%-35s\n", ind_lvl.c_str(), "Pool Alloc Alignment:",
|
||||
fprintf(stdout, "%s%-28s%-36s\n", ind_lvl.c_str(), "Pool Alloc Alignment:",
|
||||
al_str.c_str());
|
||||
|
||||
fprintf(stdout, "%s%-25s%-35s\n", ind_lvl.c_str(), "Pool Acessible by all:",
|
||||
fprintf(stdout, "%s%-28s%-36s\n", ind_lvl.c_str(), "Pool Acessible by all:",
|
||||
(pool_i->accessible_by_all ? "TRUE" : "FALSE"));
|
||||
|
||||
std::string agg_str =
|
||||
std::to_string(pool_i->aggregate_alloc_max / 1024) + "KB";
|
||||
fprintf(stdout, "%s%-28s%-36s\n", ind_lvl.c_str(), "Pool Aggregate Alloc Size:",
|
||||
agg_str.c_str());
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,12 +88,14 @@ typedef struct pool_info_t_ {
|
||||
size_t alloc_alignment;
|
||||
bool accessible_by_all;
|
||||
uint32_t global_flag;
|
||||
uint64_t aggregate_alloc_max;
|
||||
inline bool operator==(const pool_info_t_ &a) {
|
||||
if (a.segment == segment && a.size == size
|
||||
&& a.alloc_allowed == alloc_allowed
|
||||
&& a.alloc_granule == alloc_granule
|
||||
&& a.alloc_alignment == alloc_alignment
|
||||
&& a.accessible_by_all == accessible_by_all
|
||||
&& a.aggregate_alloc_max == aggregate_alloc_max
|
||||
&& a.global_flag == global_flag )
|
||||
return true;
|
||||
else
|
||||
|
||||
@@ -197,7 +197,7 @@ void MemoryTest::MaxSingleAllocationTest(hsa_agent_t ag,
|
||||
}
|
||||
// Do everything in "granule" units
|
||||
auto gran_sz = pool_i.alloc_granule;
|
||||
auto pool_sz = pool_i.size / gran_sz;
|
||||
auto pool_sz = pool_i.aggregate_alloc_max / gran_sz;
|
||||
|
||||
// Neg. test: Try to allocate more than the pool size
|
||||
err = TestAllocate(pool, pool_sz*gran_sz + gran_sz);
|
||||
|
||||
+11
-10
@@ -179,7 +179,7 @@ static void PrintAgentNameAndType(hsa_agent_t agent) {
|
||||
static const int kMemoryAllocSize = 1024;
|
||||
|
||||
// This test verify that hsa_memory_allocate can't allocate
|
||||
// memory more than POOL_INFO_SIZE
|
||||
// memory more than HSA_AMD_MEMORY_POOL_INFO_ALLOC_MAX_SIZE
|
||||
void MemoryAllocateNegativeTest::MaxMemoryAllocateTest(hsa_agent_t agent,
|
||||
hsa_amd_memory_pool_t pool) {
|
||||
hsa_status_t err;
|
||||
@@ -193,19 +193,20 @@ void MemoryAllocateNegativeTest::MaxMemoryAllocateTest(hsa_agent_t agent,
|
||||
}
|
||||
|
||||
// Determine if allocation is allowed in this pool
|
||||
bool alloc = false;
|
||||
err = hsa_amd_memory_pool_get_info(pool,
|
||||
HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED, &alloc);
|
||||
if (!pool_i.alloc_allowed || pool_i.alloc_granule == 0) {
|
||||
if (verbosity() > 0) {
|
||||
std::cout << " Test not applicable. Skipping." << std::endl;
|
||||
std::cout << kSubTestSeparator << std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (alloc) {
|
||||
size_t max_size;
|
||||
err = hsa_amd_memory_pool_get_info(pool, HSA_AMD_MEMORY_POOL_INFO_SIZE,
|
||||
&max_size);
|
||||
char *memoryPtr;
|
||||
err = hsa_amd_memory_pool_allocate(pool, (max_size + 16), 0,
|
||||
auto gran_sz = pool_i.alloc_granule;
|
||||
size_t max_size = pool_i.aggregate_alloc_max;
|
||||
err = hsa_amd_memory_pool_allocate(pool, (max_size + gran_sz), 0,
|
||||
reinterpret_cast<void**>(&memoryPtr));
|
||||
ASSERT_EQ(err, HSA_STATUS_ERROR_INVALID_ALLOCATION);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user