Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/device/hipIpcCloseMemHandle.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

117 lines
3.4 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip_test_common.hh>
#include <hip_test_process.hh>
/**
* @addtogroup hipIpcCloseMemHandle hipIpcCloseMemHandle
* @{
* @ingroup DeviceTest
* `hipIpcCloseMemHandle(void* devPtr)` -
* Close memory mapped with hipIpcOpenMemHandle.
* Unmaps memory returned by hipIpcOpenMemHandle.
* ________________________
* Test cases from other modules:
* - @ref Unit_hipIpcMemAccess_Semaphores
* - @ref Unit_hipIpcMemAccess_ParameterValidation
*/
#if HT_LINUX
/**
* Test Description
* ------------------------
* - Checks that memory stays mapped if reference count doesn't reach zero.
* - Checks that memory stays mapped if handle is closed in second process.
* Test source
* ------------------------
* - unit/device/hipIpcCloseMemHandle.cc
* Test requirements
* ------------------------
* - Host specific (LINUX)
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_hipIpcCloseMemHandle_Positive_Reference_Counting) {
int fd[2];
REQUIRE(pipe(fd) == 0);
// The fork must be performed before the runtime is initialized(so before any API that implicitly
// initializes it). The pipe in conjunction with wait is then used to impose total ordering
// between parent and child process. Because total ordering is imposed regular CATCH assertions
// should be safe to use
auto pid = fork();
REQUIRE(pid >= 0);
if (pid == 0) { // child
REQUIRE(close(fd[1]) == 0);
hipIpcMemHandle_t handle;
REQUIRE(read(fd[0], &handle, sizeof(handle)) >= 0);
REQUIRE(close(fd[0]) == 0);
void *child_ptr1, *child_ptr2;
HIP_CHECK(hipIpcOpenMemHandle(&child_ptr1, handle, hipIpcMemLazyEnablePeerAccess));
HIP_CHECK(hipIpcOpenMemHandle(&child_ptr2, handle, hipIpcMemLazyEnablePeerAccess));
REQUIRE(child_ptr1 == child_ptr2);
HIP_CHECK(hipIpcCloseMemHandle(child_ptr1));
hipPointerAttribute_t attributes;
HIP_CHECK(hipPointerGetAttributes(&attributes, child_ptr1));
HIP_CHECK(hipPointerGetAttributes(&attributes, child_ptr2));
HIP_CHECK(hipIpcCloseMemHandle(child_ptr2));
HIP_CHECK_ERROR(hipPointerGetAttributes(&attributes, child_ptr1), hipErrorInvalidValue);
HIP_CHECK_ERROR(hipPointerGetAttributes(&attributes, child_ptr2), hipErrorInvalidValue);
exit(0);
} else { // parent
REQUIRE(close(fd[0]) == 0);
void* ptr;
hipIpcMemHandle_t handle;
HIP_CHECK(hipMalloc(&ptr, 1024));
HIP_CHECK(hipIpcGetMemHandle(&handle, ptr));
REQUIRE(write(fd[1], &handle, sizeof(handle)) >= 0);
REQUIRE(close(fd[1]) == 0);
REQUIRE(wait(NULL) >= 0);
hipPointerAttribute_t attributes;
HIP_CHECK(hipPointerGetAttributes(&attributes, ptr));
HIP_CHECK(hipFree(ptr));
}
}
#endif
/**
* Test Description
* ------------------------
* - Closes the memory handle from the process that has created it.
* Test source
* ------------------------
* - unit/device/hipIpcCloseMemHandle.cc
* Test requirements
* ------------------------
* - Host specific
* - HIP_VERSION >= 5.2
*/
HIP_TEST_CASE(Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process) {
void* ptr;
hipIpcMemHandle_t handle;
HIP_CHECK(hipMalloc(&ptr, 1024));
HIP_CHECK(hipIpcGetMemHandle(&handle, ptr));
HIP_CHECK_ERROR(hipIpcCloseMemHandle(ptr), hipErrorInvalidValue);
HIP_CHECK(hipFree(ptr));
}
/**
* End doxygen group DeviceTest.
* @}
*/