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
134 lines
4.0 KiB
C++
134 lines
4.0 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/* Test Case Description:
|
|
1) This testcase verifies the basic scenario - supported on
|
|
all devices
|
|
*/
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip_test_kernels.hh>
|
|
#include <hip_test_checkers.hh>
|
|
#include <cstdio>
|
|
#include <cstdint>
|
|
#include <algorithm>
|
|
#include <thread>
|
|
#include <chrono>
|
|
#include <vector>
|
|
|
|
/*
|
|
This testcase verifies HIP Mem VMM API basic scenario - supported on all devices
|
|
*/
|
|
|
|
HIP_TEST_CASE(Unit_hipMemVmm_Basic) {
|
|
int vmm = 0;
|
|
HIP_CHECK(hipDeviceGetAttribute(&vmm, hipDeviceAttributeVirtualMemoryManagementSupported, 0));
|
|
INFO("hipDeviceAttributeVirtualMemoryManagementSupported: " << vmm);
|
|
|
|
if (vmm == 0) {
|
|
HIP_SKIP_TEST(HipTest::SkipReason::kVmmUnsupported);
|
|
}
|
|
|
|
size_t granularity = 0;
|
|
|
|
hipMemAllocationProp memAllocationProp{};
|
|
memAllocationProp.type = hipMemAllocationTypePinned;
|
|
memAllocationProp.location.id = 0;
|
|
memAllocationProp.location.type = hipMemLocationTypeDevice;
|
|
|
|
HIP_CHECK(hipMemGetAllocationGranularity(&granularity, &memAllocationProp,
|
|
hipMemAllocationGranularityRecommended));
|
|
|
|
size_t size = granularity * 4;
|
|
void* reservedAddress{nullptr};
|
|
HIP_CHECK(hipMemAddressReserve(&reservedAddress, size, 0, nullptr, 0));
|
|
|
|
hipMemGenericAllocationHandle_t gaHandle{nullptr};
|
|
HIP_CHECK(hipMemCreate(&gaHandle, size, &memAllocationProp, 0));
|
|
|
|
HIP_CHECK(hipMemMap(reservedAddress, size, 0, gaHandle, 0));
|
|
|
|
hipDevice_t device;
|
|
HIP_CHECK(hipDeviceGet(&device, 0));
|
|
hipMemAccessDesc desc;
|
|
desc.location.type = hipMemLocationTypeDevice;
|
|
desc.location.id = device;
|
|
desc.flags = hipMemAccessFlagsProtReadWrite;
|
|
std::vector<char> values(size);
|
|
const char value = 1;
|
|
|
|
HIP_CHECK(hipMemSetAccess(reservedAddress, size, &desc, 1));
|
|
HIP_CHECK(hipMemset(reservedAddress, value, size));
|
|
HIP_CHECK(hipMemcpy(&values[0], reservedAddress, size, hipMemcpyDeviceToHost));
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
REQUIRE(values[i] == value);
|
|
}
|
|
|
|
HIP_CHECK(hipMemUnmap(reservedAddress, size));
|
|
|
|
HIP_CHECK(hipMemRelease(gaHandle));
|
|
HIP_CHECK(hipMemAddressFree(reservedAddress, size));
|
|
}
|
|
|
|
/*
|
|
This testcase verifies HIP Mem VMM API basic scenario, but with Uncached memory -- supported
|
|
only on HIP
|
|
*/
|
|
|
|
#if HT_AMD
|
|
HIP_TEST_CASE(Unit_hipMemVmm_Uncached) {
|
|
int vmm = 0;
|
|
HIP_CHECK(hipDeviceGetAttribute(&vmm, hipDeviceAttributeVirtualMemoryManagementSupported, 0));
|
|
INFO("hipDeviceAttributeVirtualMemoryManagementSupported: " << vmm);
|
|
|
|
if (vmm == 0) {
|
|
HIP_SKIP_TEST(HipTest::SkipReason::kVmmUnsupported);
|
|
}
|
|
|
|
size_t granularity = 0;
|
|
|
|
hipMemAllocationProp memAllocationProp{};
|
|
memAllocationProp.type = hipMemAllocationTypeUncached;
|
|
memAllocationProp.location.id = 0;
|
|
memAllocationProp.location.type = hipMemLocationTypeDevice;
|
|
|
|
HIP_CHECK(hipMemGetAllocationGranularity(&granularity, &memAllocationProp,
|
|
hipMemAllocationGranularityRecommended));
|
|
|
|
size_t size = granularity;
|
|
void* reservedAddress{nullptr};
|
|
HIP_CHECK(hipMemAddressReserve(&reservedAddress, size, 0, nullptr, 0));
|
|
|
|
hipMemGenericAllocationHandle_t gaHandle{nullptr};
|
|
HIP_CHECK(hipMemCreate(&gaHandle, size, &memAllocationProp, 0));
|
|
|
|
HIP_CHECK(hipMemMap(reservedAddress, size, 0, gaHandle, 0));
|
|
|
|
hipDevice_t device;
|
|
HIP_CHECK(hipDeviceGet(&device, 0));
|
|
hipMemAccessDesc desc;
|
|
desc.location.type = hipMemLocationTypeDevice;
|
|
desc.location.id = device;
|
|
desc.flags = hipMemAccessFlagsProtReadWrite;
|
|
std::vector<char> values(size);
|
|
const int value = 1;
|
|
|
|
HIP_CHECK(hipMemSetAccess(reservedAddress, size, &desc, 1));
|
|
HIP_CHECK(hipMemset(reservedAddress, value, size));
|
|
HIP_CHECK(hipMemcpy(values.data(), reservedAddress, size, hipMemcpyDeviceToHost));
|
|
|
|
for (size_t i = 0; i < size; ++i) {
|
|
REQUIRE(values[i] == value);
|
|
}
|
|
|
|
HIP_CHECK(hipMemUnmap(reservedAddress, size));
|
|
|
|
HIP_CHECK(hipMemRelease(gaHandle));
|
|
HIP_CHECK(hipMemAddressFree(reservedAddress, size));
|
|
}
|
|
#endif
|