SWDEV-552141 - Fix handle/fd type passed from app to align with spec. (#759)
* SWDEV-552141 - Fix handle/fd type passed from app to align with spec. * SWDEV-552141 - Fix handle/fd type passed from app to align with spec.
This commit is contained in:
committato da
GitHub
parent
6bc1ea966f
commit
89070536c0
@@ -2434,7 +2434,7 @@ bool Device::ImportShareableHSAHandle(void* osHandle, uint64_t* hsa_handle_ptr)
|
||||
return false;
|
||||
}
|
||||
|
||||
int dmabuf_fd = *(reinterpret_cast<int*>(osHandle));
|
||||
int dmabuf_fd = static_cast<int>(reinterpret_cast<uintptr_t>(osHandle));
|
||||
if ((hsa_status = hsa_amd_vmem_import_shareable_handle(dmabuf_fd, &hsa_vmem_handle)) !=
|
||||
HSA_STATUS_SUCCESS) {
|
||||
LogPrintfError("Failed hsa_amd_vmem_import_shareable_handle with status: %d \n", hsa_status);
|
||||
|
||||
@@ -778,7 +778,6 @@ bool Buffer::create(bool alloc_local) {
|
||||
|
||||
if (memFlags & ROCCLR_MEM_PHYMEM) {
|
||||
if (memFlags & ROCCLR_MEM_INTERPROCESS) {
|
||||
int dmabuf_fd = *(reinterpret_cast<int*>(owner()->getSvmPtr()));
|
||||
// if interprocess flag is set, then the memory is importable.
|
||||
if (!dev().ImportShareableHSAHandle(owner()->getSvmPtr(),
|
||||
&owner()->getUserData().hsa_handle)) {
|
||||
|
||||
+16
-13
@@ -222,10 +222,11 @@ hipDeviceptr_t createVirtualMemoryAndFillData(int size, int* reservedAddrSize, i
|
||||
* Helper function to validate the handle from hipMemGetHandleForAddressRange
|
||||
* by extracting the data from the handle
|
||||
*/
|
||||
bool validateHandle(int* handle, int size, int device = 0) {
|
||||
bool validateHandle(int handle, int size, int device = 0) {
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, reinterpret_cast<void*>(handle),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(handle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
|
||||
size_t granularity = GetGranularity(device);
|
||||
if (granularity <= 0) {
|
||||
@@ -303,7 +304,7 @@ TEST_CASE("Unit_hipMemGetHandleForAddressRange_DeviceMemory") {
|
||||
constexpr int kDeviceId = 0;
|
||||
HIP_CHECK(hipDeviceGet(&device, kDeviceId));
|
||||
checkVMMSupported(device);
|
||||
REQUIRE(validateHandle(&handle, size) == true);
|
||||
REQUIRE(validateHandle(handle, size) == true);
|
||||
|
||||
HIP_CHECK(hipFree(srcDevMem));
|
||||
}
|
||||
@@ -341,7 +342,7 @@ TEST_CASE("Unit_hipMemGetHandleForAddressRange_VM") {
|
||||
hipMemGetHandleForAddressRange(&handle, ptrA, sizeBytes, hipMemRangeHandleTypeDmaBufFd, 0));
|
||||
REQUIRE(handle > 0);
|
||||
|
||||
REQUIRE(validateHandle(&handle, size) == true);
|
||||
REQUIRE(validateHandle(handle, size) == true);
|
||||
|
||||
HIP_CHECK(hipMemUnmap(ptrA, reservedAddrSize));
|
||||
HIP_CHECK(hipMemAddressFree(ptrA, reservedAddrSize));
|
||||
@@ -393,7 +394,7 @@ TEST_CASE("Unit_hipMemGetHandleForAddressRange_DeviceMemory_InAnotherDevice") {
|
||||
|
||||
HIP_CHECK(hipDeviceGet(&device, dstDeviceId));
|
||||
checkVMMSupported(device);
|
||||
REQUIRE(validateHandle(&handle, size, dstDeviceId) == true);
|
||||
REQUIRE(validateHandle(handle, size, dstDeviceId) == true);
|
||||
|
||||
HIP_CHECK(hipFree(srcDevMem));
|
||||
HIP_CHECK(hipDeviceReset())
|
||||
@@ -448,7 +449,7 @@ TEST_CASE("Unit_hipMemGetHandleForAddressRange_VM_InAnotherDevice") {
|
||||
HIP_CHECK(hipDeviceGet(&device, dstDeviceId));
|
||||
checkVMMSupported(device);
|
||||
|
||||
REQUIRE(validateHandle(&handle, size, dstDeviceId) == true);
|
||||
REQUIRE(validateHandle(handle, size, dstDeviceId) == true);
|
||||
|
||||
HIP_CHECK(hipMemUnmap(ptrA, reservedAddrSize));
|
||||
HIP_CHECK(hipMemAddressFree(ptrA, reservedAddrSize));
|
||||
@@ -498,15 +499,16 @@ TEST_CASE("Unit_hipMemGetHandleForAddressRange_MulProc_Socket_DeviceMem") {
|
||||
checkSysCallErrors(sockObj.recvShareableHdl(&shHandle));
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
// import the sareable handle
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, &shHandle,
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(shHandle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
|
||||
hipDevice_t device;
|
||||
HIP_CHECK(hipDeviceGet(&device, 0));
|
||||
checkVMMSupported(device);
|
||||
|
||||
// Validate the handle
|
||||
REQUIRE(validateHandle(&shHandle, size_mem / sizeof(int)));
|
||||
REQUIRE(validateHandle(shHandle, size_mem / sizeof(int)));
|
||||
|
||||
checkSysCallErrors(sockObj.closeThisSock());
|
||||
REQUIRE(close(fd[0]) == 0);
|
||||
@@ -591,14 +593,15 @@ TEST_CASE("Unit_hipMemGetHandleForAddressRange_MulProc_Socket_VM") {
|
||||
checkSysCallErrors(sockObj.recvShareableHdl(&shHandle));
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
// import the sareable handle
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, &shHandle,
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(shHandle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
hipDevice_t device;
|
||||
HIP_CHECK(hipDeviceGet(&device, 0));
|
||||
checkVMMSupported(device);
|
||||
|
||||
// Validate handle
|
||||
REQUIRE(validateHandle(&shHandle, size_mem / sizeof(int)));
|
||||
REQUIRE(validateHandle(shHandle, size_mem / sizeof(int)));
|
||||
|
||||
checkSysCallErrors(sockObj.closeThisSock());
|
||||
REQUIRE(close(fd[0]) == 0);
|
||||
|
||||
+12
-8
@@ -80,8 +80,9 @@ TEST_CASE("Unit_hipMemImportFromShareableHandle_Positive_Basic") {
|
||||
HIP_CHECK(hipMemExportToShareableHandle(&shareable_handle, handle,
|
||||
hipMemHandleTypePosixFileDescriptor, 0));
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, &shareable_handle,
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(shareable_handle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemRelease(handle));
|
||||
CTX_DESTROY();
|
||||
}
|
||||
@@ -179,8 +180,9 @@ TEST_CASE("Unit_hipMemImportFromShareableHandle_MulProc_ChldUseHdl") {
|
||||
checkSysCallErrors(sockObj.recvShareableHdl(&shHandle));
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
// import the sareable handle
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, &shHandle,
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(shHandle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
// Allocate virtual address range
|
||||
hipDeviceptr_t ptrA;
|
||||
HIP_CHECK(hipMemAddressReserve(&ptrA, size_mem, 0, 0, 0));
|
||||
@@ -311,8 +313,9 @@ TEST_CASE("Unit_hipMemImportFromShareableHandle_MulProc_ParntChldUseHdl") {
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
|
||||
// import the sareable handle
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, &shHandle,
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(shHandle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
// Allocate virtual address range
|
||||
hipDeviceptr_t ptrA;
|
||||
HIP_CHECK(hipMemAddressReserve(&ptrA, size_mem, 0, 0, 0));
|
||||
@@ -448,8 +451,9 @@ TEST_CASE("Unit_hipMemImportFromShareableHandle_MulProc_GrndChldUseHdl") {
|
||||
hipMemGenericAllocationHandle_t imported_handle;
|
||||
|
||||
// import the sareable handle
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle, &shHandle,
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
HIP_CHECK(hipMemImportFromShareableHandle(&imported_handle,
|
||||
reinterpret_cast<void*>(static_cast<uintptr_t>(shHandle)),
|
||||
hipMemHandleTypePosixFileDescriptor));
|
||||
// Allocate virtual address range
|
||||
hipDeviceptr_t ptrA;
|
||||
HIP_CHECK(hipMemAddressReserve(&ptrA, size_mem, 0, 0, 0));
|
||||
|
||||
Fai riferimento in un nuovo problema
Block a user