SWDEV-553375 - Allow hipMemAllocationTypeUncached in hipMemGetAllocationGranularity (#847)

이 커밋은 다음에 포함됨:
Jimbo
2025-09-05 10:31:20 -04:00
커밋한 사람 GitHub
부모 b2b44de1e7
커밋 3d9d35a1f8
2개의 변경된 파일63개의 추가작업 그리고 1개의 파일을 삭제
+2 -1
파일 보기
@@ -205,7 +205,8 @@ hipError_t hipMemGetAllocationGranularity(size_t* granularity, const hipMemAlloc
hipMemAllocationGranularity_flags option) {
HIP_INIT_API(hipMemGetAllocationGranularity, granularity, prop, option);
if (granularity == nullptr || prop == nullptr || prop->type != hipMemAllocationTypePinned ||
if (granularity == nullptr || prop == nullptr || (prop->type != hipMemAllocationTypePinned &&
prop->type != hipMemAllocationTypeUncached) ||
prop->location.type != hipMemLocationTypeDevice || prop->location.id >= g_devices.size() ||
(option != hipMemAllocationGranularityMinimum &&
option != hipMemAllocationGranularityRecommended)) {
+61
파일 보기
@@ -89,3 +89,64 @@ TEST_CASE("Unit_hipMemVmm_Basic") {
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
TEST_CASE("Unit_hipMemVmm_Uncached") {
int vmm = 0;
HIP_CHECK(hipDeviceGetAttribute(&vmm, hipDeviceAttributeVirtualMemoryManagementSupported, 0));
INFO("hipDeviceAttributeVirtualMemoryManagementSupported: " << vmm);
if (vmm == 0) {
SUCCEED(
"GPU 0 doesn't support hipDeviceAttributeVirtualMemoryManagement "
"attribute. Hence skipping the testing with Pass result.\n");
return;
}
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 = 4 * 1024;
void* reservedAddress{nullptr};
HIP_CHECK(hipMemAddressReserve(&reservedAddress, size, granularity, 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));
}
#endif