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
177 lines
5.7 KiB
C++
177 lines
5.7 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/**
|
|
* @addtogroup hipMemAddressReserve hipMemAddressReserve
|
|
* @{
|
|
* @ingroup VirtualMemoryManagementTest
|
|
* `hipError_t hipMemAddressReserve (void** ptr,
|
|
* size_t size,
|
|
* size_t alignment,
|
|
* void* addr,
|
|
* unsigned long long flags)` -
|
|
* Reserves an address range.
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
|
|
#include "hip_vmm_common.hh"
|
|
|
|
#define DATA_SIZE (1 << 13)
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Verify if reserved address returned by hipMemAddressReserve
|
|
* for different alignment values are correctly aligned.
|
|
* ------------------------
|
|
* - unit/virtualMemoryManagement/hipMemAddressReserve.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 6.1
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipMemAddressReserve_AlignmentTest) {
|
|
size_t granularity = 0;
|
|
constexpr int N = DATA_SIZE;
|
|
size_t buffer_size = N * sizeof(int);
|
|
constexpr int initializer = 0;
|
|
int deviceId = 0;
|
|
hipDevice_t device;
|
|
CTX_CREATE();
|
|
HIP_CHECK(hipDeviceGet(&device, deviceId));
|
|
checkVMMSupported(device);
|
|
hipMemAllocationProp prop{};
|
|
prop.type = hipMemAllocationTypePinned;
|
|
prop.location.type = hipMemLocationTypeDevice;
|
|
prop.location.id = device; // Current Devices
|
|
HIP_CHECK(
|
|
hipMemGetAllocationGranularity(&granularity, &prop, hipMemAllocationGranularityMinimum));
|
|
REQUIRE(granularity > 0);
|
|
size_t size_mem = ((granularity + buffer_size - 1) / granularity) * granularity;
|
|
// Allocate virtual address range
|
|
void* ptrA;
|
|
size_t alignmnt = 1;
|
|
hipMemGenericAllocationHandle_t handle;
|
|
// Allocate physical memory
|
|
HIP_CHECK(hipMemCreate(&handle, size_mem, &prop, 0));
|
|
// Allocate host memory and intialize data
|
|
std::vector<int> A_h(N), B_h(N);
|
|
// Initialize with data
|
|
for (size_t idx = 0; idx < N; idx++) {
|
|
A_h[idx] = idx;
|
|
}
|
|
// check for address alignment fron 2 to 1024
|
|
for (int iter = 0; iter < 12; iter++) {
|
|
alignmnt = alignmnt * 2;
|
|
HIP_CHECK(hipMemAddressReserve(&ptrA, size_mem, alignmnt, 0, 0));
|
|
REQUIRE((reinterpret_cast<unsigned long long>(ptrA) % alignmnt) == 0);
|
|
std::fill(B_h.begin(), B_h.end(), initializer);
|
|
HIP_CHECK(hipMemMap(ptrA, size_mem, 0, handle, 0));
|
|
// Set access
|
|
hipMemAccessDesc accessDesc = {};
|
|
accessDesc.location.type = hipMemLocationTypeDevice;
|
|
accessDesc.location.id = device;
|
|
accessDesc.flags = hipMemAccessFlagsProtReadWrite;
|
|
// Make the address accessible to GPU 0
|
|
HIP_CHECK(hipMemSetAccess(ptrA, size_mem, &accessDesc, 1));
|
|
HIP_CHECK(hipMemcpyHtoD(reinterpret_cast<hipDeviceptr_t>(ptrA), A_h.data(), buffer_size));
|
|
HIP_CHECK(hipMemcpyDtoH(B_h.data(), reinterpret_cast<hipDeviceptr_t>(ptrA), buffer_size));
|
|
REQUIRE(true == std::equal(B_h.begin(), B_h.end(), A_h.data()));
|
|
HIP_CHECK(hipMemUnmap(ptrA, size_mem));
|
|
HIP_CHECK(hipMemAddressFree(ptrA, size_mem));
|
|
}
|
|
HIP_CHECK(hipMemRelease(handle));
|
|
CTX_DESTROY();
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Negative Tests
|
|
* ------------------------
|
|
* - unit/virtualMemoryManagement/hipMemAddressReserve.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 6.1
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipMemAddressReserve_Negative) {
|
|
size_t granularity = 0;
|
|
constexpr int N = DATA_SIZE;
|
|
size_t buffer_size = N * sizeof(int);
|
|
int deviceId = 0;
|
|
hipDevice_t device;
|
|
CTX_CREATE();
|
|
HIP_CHECK(hipDeviceGet(&device, deviceId));
|
|
checkVMMSupported(device);
|
|
hipMemAllocationProp prop{};
|
|
prop.type = hipMemAllocationTypePinned;
|
|
prop.location.type = hipMemLocationTypeDevice;
|
|
prop.location.id = device; // Current Devices
|
|
HIP_CHECK(
|
|
hipMemGetAllocationGranularity(&granularity, &prop, hipMemAllocationGranularityMinimum));
|
|
REQUIRE(granularity > 0);
|
|
size_t size_mem = ((granularity + buffer_size - 1) / granularity) * granularity;
|
|
// Allocate virtual address range
|
|
void* ptrA;
|
|
|
|
SECTION("Nullptr to ptr") {
|
|
REQUIRE(hipMemAddressReserve(nullptr, size_mem, 0, 0, 0) == hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("pass size as 0") {
|
|
REQUIRE(hipMemAddressReserve(&ptrA, 0, 0, 0, 0) == hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("pass non power of two for alignment") {
|
|
REQUIRE(hipMemAddressReserve(&ptrA, size_mem, 3, 0, 0) == hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("pass size as non multiple of host page size") {
|
|
REQUIRE(hipMemAddressReserve(&ptrA, (size_mem - 1), 0, 0, 0) == hipErrorInvalidValue);
|
|
}
|
|
|
|
CTX_DESTROY();
|
|
}
|
|
|
|
HIP_TEST_CASE(Unit_hipMemAddressReserve_Capture) {
|
|
hipMemGenericAllocationHandle_t allocation_handle;
|
|
size_t granularity = 0;
|
|
constexpr size_t kAlignment = 2;
|
|
constexpr int kDeviceId = 0;
|
|
hipDevice_t device = 0;
|
|
void* device_ptr = nullptr;
|
|
|
|
CTX_CREATE();
|
|
HIP_CHECK(hipDeviceGet(&device, kDeviceId));
|
|
|
|
hipMemAllocationProp allocation_prop{};
|
|
allocation_prop.type = hipMemAllocationTypePinned;
|
|
allocation_prop.location.type = hipMemLocationTypeDevice;
|
|
allocation_prop.location.id = device;
|
|
|
|
HIP_CHECK(hipMemGetAllocationGranularity(&granularity, &allocation_prop,
|
|
hipMemAllocationGranularityMinimum));
|
|
HIP_CHECK(hipMemCreate(&allocation_handle, granularity, &allocation_prop, 0));
|
|
|
|
hipStream_t stream = nullptr;
|
|
HIP_CHECK(hipStreamCreate(&stream));
|
|
|
|
GENERATE_CAPTURE();
|
|
BEGIN_CAPTURE(stream);
|
|
HIP_CHECK(hipMemAddressReserve(&device_ptr, granularity, kAlignment, nullptr, 0));
|
|
END_CAPTURE(stream);
|
|
|
|
HIP_CHECK(hipStreamDestroy(stream));
|
|
HIP_CHECK(hipMemAddressFree(device_ptr, granularity));
|
|
HIP_CHECK(hipMemRelease(allocation_handle));
|
|
CTX_DESTROY();
|
|
}
|
|
|
|
/**
|
|
* End doxygen group VirtualMemoryManagementTest.
|
|
* @}
|
|
*/
|