Add InterProcess memory sharing support.

Support is disabled pending KFD / Thunk readiness.

Change-Id: I55def748e3d56cbfcfa6e24983a0ab78567aa81d


[ROCm/ROCR-Runtime commit: 8081758a55]
Este commit está contenido en:
Sean Keely
2016-11-10 02:51:19 -06:00
padre c9e78a451b
commit 2e8c176e11
Se han modificado 9 ficheros con 260 adiciones y 5 borrados
@@ -360,6 +360,9 @@ void HsaApiTable::UpdateAmdExts() {
amd_ext_api.hsa_amd_interop_unmap_buffer_fn = AMD::hsa_amd_interop_unmap_buffer;
amd_ext_api.hsa_amd_pointer_info_fn = AMD::hsa_amd_pointer_info;
amd_ext_api.hsa_amd_pointer_info_set_userdata_fn = AMD::hsa_amd_pointer_info_set_userdata;
amd_ext_api.hsa_amd_ipc_memory_create_fn = AMD::hsa_amd_ipc_memory_create;
amd_ext_api.hsa_amd_ipc_memory_attach_fn = AMD::hsa_amd_ipc_memory_attach;
amd_ext_api.hsa_amd_ipc_memory_detach_fn = AMD::hsa_amd_ipc_memory_detach;
}
class Init {
@@ -611,4 +611,45 @@ hsa_status_t hsa_amd_pointer_info_set_userdata(void* ptr, void* userdata) {
return core::Runtime::runtime_singleton_->SetPtrInfoData(ptr, userdata);
}
hsa_status_t hsa_amd_ipc_memory_create(void* ptr, size_t len, hsa_amd_ipc_memory_t* handle) {
IS_OPEN();
IS_BAD_PTR(ptr);
IS_BAD_PTR(handle);
return core::Runtime::runtime_singleton_->IPCCreate(ptr, len, handle);
}
hsa_status_t hsa_amd_ipc_memory_attach(const hsa_amd_ipc_memory_t* ipc, size_t len,
uint32_t num_agents, const hsa_agent_t* mapping_agents,
void** mapped_ptr) {
static const int tinyArraySize = 8;
IS_OPEN();
IS_BAD_PTR(mapped_ptr);
if (num_agents != 0) IS_BAD_PTR(mapping_agents);
core::Agent** core_agents = nullptr;
if (num_agents > tinyArraySize)
core_agents = new core::Agent*[num_agents];
else
core_agents = (core::Agent**)alloca(sizeof(core::Agent*) * num_agents);
if (core_agents == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
MAKE_SCOPE_GUARD([&]() {
if (num_agents > tinyArraySize) delete[] core_agents;
});
for (int i = 0; i < num_agents; i++) {
core::Agent* device = core::Agent::Convert(mapping_agents[i]);
IS_VALID(device);
core_agents[i] = device;
}
return core::Runtime::runtime_singleton_->IPCAttach(ipc, len, num_agents, core_agents,
mapped_ptr);
}
hsa_status_t hsa_amd_ipc_memory_detach(void* mapped_ptr) {
IS_OPEN();
IS_BAD_PTR(mapped_ptr);
return core::Runtime::runtime_singleton_->IPCDetach(mapped_ptr);
}
} // end of AMD namespace
@@ -620,10 +620,11 @@ hsa_status_t Runtime::InteropMap(uint32_t num_agents, Agent** agents,
&altAddress, map_flags, num_agents,
nodes) != HSAKMT_STATUS_SUCCESS) {
map_flags.ui32.PageSize = HSA_PAGE_SIZE_4KB;
if (hsaKmtMapMemoryToGPUNodes(info.MemoryAddress, info.SizeInBytes,
&altAddress, map_flags, num_agents,
nodes) != HSAKMT_STATUS_SUCCESS)
if (hsaKmtMapMemoryToGPUNodes(info.MemoryAddress, info.SizeInBytes, &altAddress, map_flags,
num_agents, nodes) != HSAKMT_STATUS_SUCCESS) {
hsaKmtDeregisterMemory(info.MemoryAddress);
return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
}
}
if (metadata_size != NULL) *metadata_size = info.MetadataSizeInBytes;
@@ -715,6 +716,80 @@ hsa_status_t Runtime::SetPtrInfoData(void* ptr, void* userptr) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* handle) {
return HSA_STATUS_ERROR;
//static_assert(sizeof(hsa_amd_ipc_memory_t) == sizeof(HsaSharedMemoryHandle),
// "Thunk IPC mismatch.");
//if (hsaKmtShareMemory(ptr, len, (HsaSharedMemoryHandle*)handle) == HSAKMT_STATUS_SUCCESS)
// return HSA_STATUS_SUCCESS;
//else
// return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
hsa_status_t Runtime::IPCAttach(const hsa_amd_ipc_memory_t* handle, size_t len, uint32_t num_agents,
Agent** agents, void** mapped_ptr) {
return HSA_STATUS_ERROR;
//static const int tinyArraySize = 8;
//void* importAddress;
//HSAuint64 importSize;
//HSAuint64 altAddress;
//if (num_agents == 0) {
// if (hsaKmtRegisterSharedHandle(reinterpret_cast<const HsaSharedMemoryHandle*>(handle),
// &importAddress, &importSize) != HSAKMT_STATUS_SUCCESS)
// return HSA_STATUS_ERROR_INVALID_ARGUMENT;
// if (hsaKmtMapMemoryToGPU(importAddress, importSize, &altAddress) != HSAKMT_STATUS_SUCCESS) {
// hsaKmtDeregisterMemory(importAddress);
// return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
// }
// *mapped_ptr = importAddress;
// return HSA_STATUS_SUCCESS;
//}
//HSAuint32* nodes = nullptr;
//if (num_agents > tinyArraySize)
// nodes = new HSAuint32[num_agents];
//else
// nodes = (HSAuint32*)alloca(sizeof(HSAuint32) * num_agents);
//if (nodes == NULL) return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
//MAKE_SCOPE_GUARD([&]() {
// if (num_agents > tinyArraySize) delete[] nodes;
//});
//for (int i = 0; i < num_agents; i++)
// agents[i]->GetInfo((hsa_agent_info_t)HSA_AMD_AGENT_INFO_DRIVER_NODE_ID, &nodes[i]);
//if (hsaKmtRegisterSharedHandleToNodes(reinterpret_cast<const HsaSharedMemoryHandle*>(handle),
// &importAddress, &importSize, num_agents,
// nodes) != HSAKMT_STATUS_SUCCESS)
// return HSA_STATUS_ERROR_INVALID_ARGUMENT;
//HsaMemMapFlags map_flags;
//map_flags.Value = 0;
//map_flags.ui32.PageSize = HSA_PAGE_SIZE_64KB;
//if (hsaKmtMapMemoryToGPUNodes(importAddress, importSize, &altAddress, map_flags, num_agents,
// nodes) != HSAKMT_STATUS_SUCCESS) {
// map_flags.ui32.PageSize = HSA_PAGE_SIZE_4KB;
// if (hsaKmtMapMemoryToGPUNodes(importAddress, importSize, &altAddress, map_flags, num_agents,
// nodes) != HSAKMT_STATUS_SUCCESS) {
// hsaKmtDeregisterMemory(importAddress);
// return HSA_STATUS_ERROR_OUT_OF_RESOURCES;
// }
//}
//*mapped_ptr = importAddress;
//return HSA_STATUS_SUCCESS;
}
hsa_status_t Runtime::IPCDetach(void* ptr) {
return HSA_STATUS_ERROR;
//if (hsaKmtUnmapMemoryToGPU(ptr) != HSAKMT_STATUS_SUCCESS)
// return HSA_STATUS_ERROR_INVALID_ARGUMENT;
//if (hsaKmtDeregisterMemory(ptr) != HSAKMT_STATUS_SUCCESS)
// return HSA_STATUS_ERROR_INVALID_ARGUMENT;
//return HSA_STATUS_SUCCESS;
}
void Runtime::AsyncEventsLoop(void*) {
auto& async_events_control_ = runtime_singleton_->async_events_control_;
auto& async_events_ = runtime_singleton_->async_events_;