Restrict stack usage in interop map to a more reasonable level.
Change-Id: I663f262a391d1e7f8a6fc3028ea9acbe37d8bcf0
This commit is contained in:
@@ -562,6 +562,7 @@ hsa_status_t hsa_amd_interop_map_buffer(uint32_t num_agents,
|
||||
uint32_t flags, size_t* size,
|
||||
void** ptr, size_t* metadata_size,
|
||||
const void** metadata) {
|
||||
static const int tinyArraySize=8;
|
||||
IS_OPEN();
|
||||
IS_BAD_PTR(agents);
|
||||
IS_BAD_PTR(size);
|
||||
@@ -569,9 +570,9 @@ hsa_status_t hsa_amd_interop_map_buffer(uint32_t num_agents,
|
||||
if (flags != 0) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
if (num_agents == 0) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
core::Agent* short_agents[64];
|
||||
core::Agent* short_agents[tinyArraySize];
|
||||
core::Agent** core_agents = short_agents;
|
||||
if (num_agents > 64) {
|
||||
if (num_agents > tinyArraySize) {
|
||||
core_agents = new core::Agent* [num_agents];
|
||||
if (core_agents == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
|
||||
}
|
||||
@@ -586,7 +587,7 @@ hsa_status_t hsa_amd_interop_map_buffer(uint32_t num_agents,
|
||||
num_agents, core_agents, interop_handle, flags, size, ptr, metadata_size,
|
||||
metadata);
|
||||
|
||||
if (num_agents > 64) delete[] core_agents;
|
||||
if (num_agents > tinyArraySize) delete[] core_agents;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -590,16 +590,17 @@ hsa_status_t Runtime::InteropMap(uint32_t num_agents, Agent** agents,
|
||||
int interop_handle, uint32_t flags,
|
||||
size_t* size, void** ptr,
|
||||
size_t* metadata_size, const void** metadata) {
|
||||
static const int tinyArraySize=8;
|
||||
HsaGraphicsResourceInfo info;
|
||||
|
||||
HSAuint32 short_nodes[64];
|
||||
HSAuint32 short_nodes[tinyArraySize];
|
||||
HSAuint32* nodes = short_nodes;
|
||||
if (num_agents > 64) {
|
||||
if (num_agents > tinyArraySize) {
|
||||
nodes = new HSAuint32[num_agents];
|
||||
if (nodes == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
|
||||
}
|
||||
MAKE_SCOPE_GUARD([&]() {
|
||||
if (num_agents > 64) delete[] nodes;
|
||||
if (num_agents > tinyArraySize) delete[] nodes;
|
||||
});
|
||||
|
||||
for (int i = 0; i < num_agents; i++)
|
||||
|
||||
Reference in New Issue
Block a user