From 9499bf6d1e8cc023af41eaca2bb41c41ac201c41 Mon Sep 17 00:00:00 2001 From: "Sang, Tao" Date: Tue, 1 Jul 2025 00:40:25 -0400 Subject: [PATCH] SWDEV-539145 - Add tests of hipHostMallocUncached, hipHostAllocUncached and hipHostRegisterUncached (#348) --- catch/unit/memory/hipHostAlloc.cc | 16 ++++++++++++---- catch/unit/memory/hipHostMalloc.cc | 20 ++++++++++++++++++-- catch/unit/memory/hipHostRegister.cc | 18 ++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/catch/unit/memory/hipHostAlloc.cc b/catch/unit/memory/hipHostAlloc.cc index a7d0a03828..7996efeb8a 100644 --- a/catch/unit/memory/hipHostAlloc.cc +++ b/catch/unit/memory/hipHostAlloc.cc @@ -202,11 +202,19 @@ TEST_CASE("Unit_hipHostAlloc_Basic") { float *A_h, *B_h, *C_h; float *A_d, *B_d, *C_d; HIP_CHECK(hipHostAlloc(reinterpret_cast(&A_h), SIZE, - hipHostMallocWriteCombined | hipHostMallocMapped)); - HIP_CHECK(hipHostAlloc(reinterpret_cast(&B_h), SIZE, - hipHostMallocDefault)); + hipHostAllocWriteCombined | hipHostAllocMapped)); + SECTION("hipHostAllocDefault") { + HIP_CHECK(hipHostAlloc(reinterpret_cast(&B_h), SIZE, + hipHostAllocDefault)); + } +#if (HT_AMD == 1) && (HT_LINUX == 1) + SECTION("hipHostAllocUncached") { + HIP_CHECK(hipHostAlloc(reinterpret_cast(&B_h), SIZE, + hipHostAllocUncached)); + } +#endif HIP_CHECK(hipHostAlloc(reinterpret_cast(&C_h), SIZE, - hipHostMallocMapped)); + hipHostAllocMapped)); HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast(&A_d), A_h, 0)); HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast(&C_d), C_h, 0)); diff --git a/catch/unit/memory/hipHostMalloc.cc b/catch/unit/memory/hipHostMalloc.cc index 6e4c06eb24..5b00f8d700 100644 --- a/catch/unit/memory/hipHostMalloc.cc +++ b/catch/unit/memory/hipHostMalloc.cc @@ -129,8 +129,24 @@ TEST_CASE("Unit_hipHostMalloc_Basic") { float *A_d, *B_d, *C_d; HIP_CHECK(hipHostMalloc(reinterpret_cast(&A_h), SIZE, hipHostMallocWriteCombined | hipHostMallocMapped)); - HIP_CHECK(hipHostMalloc(reinterpret_cast(&B_h), SIZE, - hipHostMallocDefault)); + SECTION("hipHostMallocDefault") { + HIP_CHECK(hipHostMalloc(reinterpret_cast(&B_h), SIZE, + hipHostMallocDefault)); + } +#if (HT_AMD == 1) && (HT_LINUX == 1) + SECTION("hipHostMallocUncached") { + HIP_CHECK(hipHostMalloc(reinterpret_cast(&B_h), SIZE, + hipHostMallocUncached)); + } + SECTION("hipHostMallocCoherent") { + HIP_CHECK(hipHostMalloc(reinterpret_cast(&B_h), SIZE, + hipHostMallocCoherent)); + } + SECTION("hipHostMallocNonCoherent") { + HIP_CHECK(hipHostMalloc(reinterpret_cast(&B_h), SIZE, + hipHostMallocNonCoherent)); + } +#endif HIP_CHECK(hipHostMalloc(reinterpret_cast(&C_h), SIZE, hipHostMallocMapped)); diff --git a/catch/unit/memory/hipHostRegister.cc b/catch/unit/memory/hipHostRegister.cc index 4e3f3b0fb8..393fc4e104 100644 --- a/catch/unit/memory/hipHostRegister.cc +++ b/catch/unit/memory/hipHostRegister.cc @@ -116,8 +116,18 @@ TEMPLATE_TEST_CASE("Unit_hipHostRegister_ReferenceFromKernelandhipMemset", "", \ HIP_CHECK(hipGetDeviceCount(&num_devices)); Ad = new TestType*[num_devices]; A = reinterpret_cast(malloc(sizeBytes)); - HIP_CHECK(hipHostRegister(A, sizeBytes, 0)); - + SECTION("hipHostRegisterDefault") { + HIP_CHECK(hipHostRegister(A, sizeBytes, hipHostRegisterDefault)); + } +#if (HT_AMD == 1) && (HT_LINUX == 1) + SECTION("hipExtHostRegisterUncached") { + HIP_CHECK(hipHostRegister(A, sizeBytes, hipExtHostRegisterUncached)); + } + SECTION("hipHostRegisterPortable | hipHostRegisterMapped | hipExtHostRegisterUncached") { + HIP_CHECK(hipHostRegister(A, sizeBytes, + hipHostRegisterPortable | hipHostRegisterMapped | hipExtHostRegisterUncached)); + } +#endif for (int i = 0; i < LEN; i++) { A[i] = static_cast(1); } @@ -926,6 +936,10 @@ TEMPLATE_TEST_CASE("Unit_hipHostRegister_Flags", "", int, float, double) { FlagType{0x08, true}, FlagType{hipHostRegisterPortable | hipHostRegisterMapped, true}, FlagType{hipHostRegisterPortable | hipHostRegisterMapped | 0x08, true}, +#if (HT_AMD == 1) && (HT_LINUX == 1) + FlagType{hipExtHostRegisterUncached, true}, + FlagType{hipHostRegisterPortable | hipHostRegisterMapped | hipExtHostRegisterUncached, true}, +#endif FlagType{0xF0, false}, FlagType{0xFFF2, false}, FlagType{0xFFFFFFFF, false});