From 858112ea206581fb377335799d319bab803ae843 Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 20:53:22 +0000 Subject: [PATCH 01/12] hipFile/test: Ensure default values are setup properly for score tests - Ensure DEFAULT_MEM_ALIGN and DEFAULT_OFFSET_ALIGN are powers of 2 (> 1) - Ensure DEFAULT_BUFFER_ADDR is DEFAULT_MEM_ALIGN aligned - Ensure DEFAULT_BUFFER_OFFSET is DEFAULT_MEM_ALIGN aligned - Ensure DEFAULT_FILE_OFFSET is DEFAULT_OFFSET_ALIGN aligned - Ensure DEFAULT_IO_SIZE is DEFAULT_OFFSET_ALIGN aligned --- test/amd_detail/fastpath.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 3e4564b0..7d617ec9 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -54,8 +54,8 @@ operator==(const hipAmdFileHandle_t &lhs, const hipAmdFileHandle_t &rhs) // Provide default values for variables used in fastpath tests struct FastpathTestBase { const size_t DEFAULT_IO_SIZE{1024 * 1024}; - void *const DEFAULT_BUFFER_ADDR{reinterpret_cast(0x600DB10C)}; - const off_t DEFAULT_BUFFER_OFFSET{512}; + void *const DEFAULT_BUFFER_ADDR{reinterpret_cast(0xABAD'CAFE'0000'0000)}; + const off_t DEFAULT_BUFFER_OFFSET{DEFAULT_MEM_ALIGN}; const size_t DEFAULT_BUFFER_LENGTH{DEFAULT_IO_SIZE + static_cast(DEFAULT_BUFFER_OFFSET)}; const hipMemoryType DEFAULT_BUFFER_TYPE{hipMemoryTypeDevice}; const optional DEFAULT_UNBUFFERED_FD{7}; @@ -79,6 +79,18 @@ struct FastpathTestBase { struct FastpathTest : public FastpathTestBase, public Test {}; +TEST_F(FastpathTest, TestDefaults) +{ + ASSERT_FALSE((DEFAULT_MEM_ALIGN & (DEFAULT_MEM_ALIGN - 1))); + ASSERT_TRUE(DEFAULT_MEM_ALIGN > 1); + ASSERT_FALSE((DEFAULT_OFFSET_ALIGN & (DEFAULT_OFFSET_ALIGN - 1))); + ASSERT_TRUE(DEFAULT_OFFSET_ALIGN > 1); + ASSERT_FALSE((reinterpret_cast(DEFAULT_BUFFER_ADDR) & (DEFAULT_MEM_ALIGN - 1))); + ASSERT_FALSE((DEFAULT_BUFFER_OFFSET & (DEFAULT_MEM_ALIGN - 1))); + ASSERT_FALSE((DEFAULT_IO_SIZE & (DEFAULT_OFFSET_ALIGN - 1))); + ASSERT_FALSE((DEFAULT_FILE_OFFSET & (DEFAULT_OFFSET_ALIGN - 1))); +} + TEST_F(FastpathTest, UnbufferedFdAvailable) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); From c729861bb8bb82fc67ea993ff332ab77fdb78d5f Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:10:30 +0000 Subject: [PATCH 02/12] hipfile/test: Ensure fastpath test pass when STATX_DIOALIGN is not defined --- test/amd_detail/fastpath.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 7d617ec9..bc9b4523 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -95,7 +95,9 @@ TEST_F(FastpathTest, UnbufferedFdAvailable) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -105,7 +107,9 @@ TEST_F(FastpathTest, UnbufferedFdNotAvailable) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(nullopt)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -115,7 +119,9 @@ TEST_F(FastpathTest, ScoreRejectsNegativeAlignedFileOffset) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, -static_cast(DEFAULT_OFFSET_ALIGN), DEFAULT_BUFFER_OFFSET), @@ -126,7 +132,9 @@ TEST_F(FastpathTest, ScoreRejectsNegativeAlignedBufferOffset) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_BUFFER_OFFSET, -static_cast(DEFAULT_MEM_ALIGN)), @@ -139,7 +147,9 @@ TEST_P(FastpathSupportedHipMemoryParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(GetParam())); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -153,7 +163,9 @@ TEST_P(FastpathUnsupportedHipMemoryParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(GetParam())); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -168,7 +180,9 @@ TEST_P(FastpathAlignedIoSizesParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, GetParam(), DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -183,7 +197,9 @@ TEST_P(FastpathUnalignedIoSizesParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, GetParam(), DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -198,7 +214,9 @@ TEST_P(FastpathAlignedFileOffsetsParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, GetParam(), DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -213,7 +231,9 @@ TEST_P(FastpathUnalignedFileOffsetsParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, GetParam(), DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -228,7 +248,9 @@ TEST_P(FastpathAlignedBufferOffsetsParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_BUFFER_OFFSET, GetParam()), SCORE_ACCEPT); @@ -244,7 +266,9 @@ TEST_P(FastpathUnalignedBufferOffsetsParam, Score) { EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, GetParam()), SCORE_REJECT); From d936fbed638089ff9aa6e285259ef40995cdd837 Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:34:21 +0000 Subject: [PATCH 03/12] hipfile/test: Use valid param values for FastpathAlignedIoSizesParam FastpathAlignedIoSizesParam should only be instantiated with size_t values. -DEFAULT_OFFSET_ALIGN became 4294966784 in the test. --- test/amd_detail/fastpath.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index bc9b4523..d7fc51a1 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -189,7 +189,8 @@ TEST_P(FastpathAlignedIoSizesParam, Score) } INSTANTIATE_TEST_SUITE_P(FastpathTest, FastpathAlignedIoSizesParam, - Values(-DEFAULT_OFFSET_ALIGN, 0, DEFAULT_OFFSET_ALIGN)); + Values(0, DEFAULT_OFFSET_ALIGN, DEFAULT_OFFSET_ALIGN << 1, + DEFAULT_OFFSET_ALIGN << 2)); struct FastpathUnalignedIoSizesParam : public FastpathTestBase, public TestWithParam {}; From dcc49cca703d6c78b53e4d85e118fb8db9fe75cf Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:34:21 +0000 Subject: [PATCH 04/12] hipfile/test: Use valid param values for FastpathUnalignedIoSizesParam FastpathUnalignedIoSizesParam should only be instantiated with size_t values. (-DEFAULT_OFFSET_ALIGN + 1) became 4294966785 in the test. --- test/amd_detail/fastpath.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index d7fc51a1..37a01fb3 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -207,7 +207,8 @@ TEST_P(FastpathUnalignedIoSizesParam, Score) } INSTANTIATE_TEST_SUITE_P(FastpathTest, FastpathUnalignedIoSizesParam, - Values(-DEFAULT_OFFSET_ALIGN + 1, 1, DEFAULT_OFFSET_ALIGN - 1)); + Values(1, DEFAULT_OFFSET_ALIGN >> 1, DEFAULT_OFFSET_ALIGN - 1, + DEFAULT_OFFSET_ALIGN + 1)); struct FastpathAlignedFileOffsetsParam : public FastpathTestBase, public TestWithParam {}; From 180e01821a391fe48b8f1ca65df02e1df7c34b5a Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:34:21 +0000 Subject: [PATCH 05/12] hipfile/test: Use valid param values for FastpathAlignedFileOffsetsParam Cast DEFAULT_OFFSET_ALIGN to hoff_t before negating to ensure the test is instantiated with the expected value. -DEFAULT_OFFSET_ALIGN -> 4294966784 -static_cast(DEFAULT_OFFSET_ALIGN) -> -512 --- test/amd_detail/fastpath.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 37a01fb3..afcb090c 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -221,11 +221,14 @@ TEST_P(FastpathAlignedFileOffsetsParam, Score) #endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, GetParam(), DEFAULT_BUFFER_OFFSET), - SCORE_ACCEPT); + GetParam() >= 0 ? SCORE_ACCEPT : SCORE_REJECT); } INSTANTIATE_TEST_SUITE_P(FastpathTest, FastpathAlignedFileOffsetsParam, - Values(-DEFAULT_OFFSET_ALIGN, 0, DEFAULT_OFFSET_ALIGN)); + Values(-static_cast(DEFAULT_OFFSET_ALIGN << 2), + -static_cast(DEFAULT_OFFSET_ALIGN << 1), + -static_cast(DEFAULT_OFFSET_ALIGN), 0, DEFAULT_OFFSET_ALIGN, + DEFAULT_OFFSET_ALIGN << 1, DEFAULT_OFFSET_ALIGN << 2)); struct FastpathUnalignedFileOffsetsParam : public FastpathTestBase, public TestWithParam {}; From b12c3ab2433e076eedc5fed854e10e89f6b42df9 Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:34:21 +0000 Subject: [PATCH 06/12] hipfile/test: Use valid param values for FastpathUnalignedFileOffsetsParam Cast DEFAULT_OFFSET_ALIGN to hoff_t before negating to ensure the test is instantiated with the expected value. -DEFAULT_OFFSET_ALIGN -> 4294966784 -static_cast(DEFAULT_OFFSET_ALIGN) -> -512 --- test/amd_detail/fastpath.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index afcb090c..0f238937 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -245,7 +245,12 @@ TEST_P(FastpathUnalignedFileOffsetsParam, Score) } INSTANTIATE_TEST_SUITE_P(FastpathTest, FastpathUnalignedFileOffsetsParam, - Values(-DEFAULT_OFFSET_ALIGN + 1, 1, DEFAULT_OFFSET_ALIGN - 1)); + Values(-static_cast(DEFAULT_OFFSET_ALIGN << 2) - 1, + -static_cast(DEFAULT_OFFSET_ALIGN << 1) + 1, + -static_cast(DEFAULT_OFFSET_ALIGN) - 1, + -static_cast(DEFAULT_OFFSET_ALIGN >> 1), 1, DEFAULT_OFFSET_ALIGN >> 1, + DEFAULT_OFFSET_ALIGN - 1, (DEFAULT_OFFSET_ALIGN << 1) + 1, + (DEFAULT_OFFSET_ALIGN << 2) - 1)); struct FastpathAlignedBufferOffsetsParam : public FastpathTestBase, public TestWithParam {}; From deee9a97a5808ca830ef9d6138aff14ff407b3a3 Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 22:11:17 +0000 Subject: [PATCH 07/12] hipfile/test: Correct file_offset argument in FastpathAlignedBufferOffsetsParam We should be passing in a file offset value not a buffer offset value. --- test/amd_detail/fastpath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 0f238937..94620ddd 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -262,7 +262,7 @@ TEST_P(FastpathAlignedBufferOffsetsParam, Score) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif - ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_BUFFER_OFFSET, GetParam()), + ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, GetParam()), SCORE_ACCEPT); } From b2bdd3802b36d9d3a7179afd2fc999639808bd0f Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:34:21 +0000 Subject: [PATCH 08/12] hipfile/test: Use valid param values for FastpathAlignedBufferOffsetsParam Cast DEFAULT_OFFSET_ALIGN to hoff_t before negating to ensure the test is instantiated with the expected value. -DEFAULT_MEM_ALIGN -> 4294967292 -static_cast(DEFAULT_MEM_ALIGN) -> -4 --- test/amd_detail/fastpath.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 94620ddd..81673664 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -263,11 +263,14 @@ TEST_P(FastpathAlignedBufferOffsetsParam, Score) #endif ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, GetParam()), - SCORE_ACCEPT); + GetParam() >= 0 ? SCORE_ACCEPT : SCORE_REJECT); } INSTANTIATE_TEST_SUITE_P(FastpathTest, FastpathAlignedBufferOffsetsParam, - Values(-DEFAULT_MEM_ALIGN, 0, DEFAULT_MEM_ALIGN)); + Values(-static_cast(DEFAULT_MEM_ALIGN << 2), + -static_cast(DEFAULT_MEM_ALIGN << 1), + -static_cast(DEFAULT_MEM_ALIGN), 0, DEFAULT_MEM_ALIGN, + DEFAULT_MEM_ALIGN << 1, DEFAULT_MEM_ALIGN << 2)); /// @brief Tests negative and unaligned buffer offsets struct FastpathUnalignedBufferOffsetsParam : public FastpathTestBase, public TestWithParam {}; From 7d65b63cc031a0d99901a23d4176853f2af0520c Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 21:34:21 +0000 Subject: [PATCH 09/12] hipfile/test: Use valid param values for FastpathUnalignedBufferOffsetsParam Cast DEFAULT_OFFSET_ALIGN to hoff_t before negating to ensure the test is instantiated with the expected value. -DEFAULT_MEM_ALIGN -> 4294967292 -static_cast(DEFAULT_MEM_ALIGN) -> -4 --- test/amd_detail/fastpath.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 81673664..cfffd95b 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -288,7 +288,12 @@ TEST_P(FastpathUnalignedBufferOffsetsParam, Score) } INSTANTIATE_TEST_SUITE_P(FastpathTest, FastpathUnalignedBufferOffsetsParam, - Values(-DEFAULT_MEM_ALIGN + 1, 1, DEFAULT_MEM_ALIGN - 1)); + Values(-static_cast(DEFAULT_MEM_ALIGN << 2) - 1, + -static_cast(DEFAULT_MEM_ALIGN << 1) + 1, + -static_cast(DEFAULT_MEM_ALIGN) - 1, + -static_cast(DEFAULT_MEM_ALIGN >> 1), 1, DEFAULT_MEM_ALIGN >> 1, + DEFAULT_MEM_ALIGN - 1, (DEFAULT_MEM_ALIGN << 1) + 1, + (DEFAULT_MEM_ALIGN << 2) - 1)); struct FastpathIoParam : public FastpathTestBase, public TestWithParam { From 3715413b16fd3d9f0f344cf1014b47fef736cf90 Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Wed, 28 Jan 2026 18:31:39 +0000 Subject: [PATCH 10/12] hipfile/fastpath: Modify checks in Fastpath::score(...) Removes alignment check duplication. --- src/amd_detail/backend/fastpath.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/amd_detail/backend/fastpath.cpp b/src/amd_detail/backend/fastpath.cpp index 1238b778..c2510dc9 100644 --- a/src/amd_detail/backend/fastpath.cpp +++ b/src/amd_detail/backend/fastpath.cpp @@ -134,19 +134,21 @@ Fastpath::score(shared_ptr file, shared_ptr buffer, size_t size, accept_io &= 0 <= file_offset; accept_io &= 0 <= buffer_offset; + uint64_t mem_align_mask{4096 - 1}; + uint64_t offset_align_mask{4096 - 1}; + #if defined(STATX_DIOALIGN) const struct statx &stx{file->getStatx()}; accept_io &= !!(stx.stx_mask & STATX_DIOALIGN); accept_io &= stx.stx_dio_offset_align && stx.stx_dio_mem_align; - accept_io &= !(size & (stx.stx_dio_offset_align - 1)); - accept_io &= !(file_offset & (stx.stx_dio_offset_align - 1)); - accept_io &= !(buffer_offset & (stx.stx_dio_mem_align - 1)); -#else - accept_io &= !(size & 0xFFF); - accept_io &= !(file_offset & 0xFFF); - accept_io &= !(buffer_offset & 0xFFF); + mem_align_mask = stx.stx_dio_mem_align - 1; + offset_align_mask = stx.stx_dio_offset_align - 1; #endif + accept_io &= !(size & offset_align_mask); + accept_io &= !(file_offset & static_cast(offset_align_mask)); + accept_io &= !(buffer_offset & static_cast(mem_align_mask)); + return accept_io ? 100 : -1; } From 6bc8b1b0e146dca6133c2dee38094cf86ed312af Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Tue, 27 Jan 2026 23:03:19 +0000 Subject: [PATCH 11/12] hipfile/fastpath: Ensure (buffer_address + buffer_offset) is aligned --- src/amd_detail/backend/fastpath.cpp | 3 ++- test/amd_detail/fastpath.cpp | 30 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/amd_detail/backend/fastpath.cpp b/src/amd_detail/backend/fastpath.cpp index c2510dc9..adcd1f4b 100644 --- a/src/amd_detail/backend/fastpath.cpp +++ b/src/amd_detail/backend/fastpath.cpp @@ -147,7 +147,8 @@ Fastpath::score(shared_ptr file, shared_ptr buffer, size_t size, accept_io &= !(size & offset_align_mask); accept_io &= !(file_offset & static_cast(offset_align_mask)); - accept_io &= !(buffer_offset & static_cast(mem_align_mask)); + auto buffer_address{reinterpret_cast(buffer->getBuffer())}; + accept_io &= !((buffer_address + buffer_offset) & static_cast(mem_align_mask)); return accept_io ? 100 : -1; } diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index cfffd95b..0f8eac8d 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -98,6 +98,7 @@ TEST_F(FastpathTest, UnbufferedFdAvailable) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -110,6 +111,7 @@ TEST_F(FastpathTest, UnbufferedFdNotAvailable) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -122,6 +124,7 @@ TEST_F(FastpathTest, ScoreRejectsNegativeAlignedFileOffset) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, -static_cast(DEFAULT_OFFSET_ALIGN), DEFAULT_BUFFER_OFFSET), @@ -135,12 +138,31 @@ TEST_F(FastpathTest, ScoreRejectsNegativeAlignedBufferOffset) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_BUFFER_OFFSET, -static_cast(DEFAULT_MEM_ALIGN)), SCORE_REJECT); } +TEST_F(FastpathTest, ScoreRejectsBufferAddressPlusBufferOffsetIsUnaligned) +{ + EXPECT_CALL(*mfile, getUnbufferedFd).WillOnce(Return(DEFAULT_UNBUFFERED_FD)); + EXPECT_CALL(*mbuffer, getType).WillOnce(Return(DEFAULT_BUFFER_TYPE)); +#if defined(STATX_DIOALIGN) + EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); +#endif + // The DEFAULT_BUFFER_ADDR is DEFAULT_MEM_ALIGN aligned. Ensure that this + // test's buffer is not DEFAULT_MEM_ALIGN aligned. + EXPECT_CALL(*mbuffer, getBuffer) + .WillOnce(Return(reinterpret_cast(reinterpret_cast(DEFAULT_BUFFER_ADDR) + + (DEFAULT_MEM_ALIGN >> 1)))); + + ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, + -static_cast(DEFAULT_MEM_ALIGN)), + SCORE_REJECT); +} + struct FastpathSupportedHipMemoryParam : public FastpathTestBase, public TestWithParam {}; TEST_P(FastpathSupportedHipMemoryParam, Score) @@ -150,6 +172,7 @@ TEST_P(FastpathSupportedHipMemoryParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -166,6 +189,7 @@ TEST_P(FastpathUnsupportedHipMemoryParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -183,6 +207,7 @@ TEST_P(FastpathAlignedIoSizesParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, GetParam(), DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_ACCEPT); @@ -201,6 +226,7 @@ TEST_P(FastpathUnalignedIoSizesParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, GetParam(), DEFAULT_FILE_OFFSET, DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -219,6 +245,7 @@ TEST_P(FastpathAlignedFileOffsetsParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, GetParam(), DEFAULT_BUFFER_OFFSET), GetParam() >= 0 ? SCORE_ACCEPT : SCORE_REJECT); @@ -239,6 +266,7 @@ TEST_P(FastpathUnalignedFileOffsetsParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, GetParam(), DEFAULT_BUFFER_OFFSET), SCORE_REJECT); @@ -261,6 +289,7 @@ TEST_P(FastpathAlignedBufferOffsetsParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, GetParam()), GetParam() >= 0 ? SCORE_ACCEPT : SCORE_REJECT); @@ -282,6 +311,7 @@ TEST_P(FastpathUnalignedBufferOffsetsParam, Score) #if defined(STATX_DIOALIGN) EXPECT_CALL(*mfile, getStatx).WillOnce(ReturnRef(DEFAULT_STATX)); #endif + EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, GetParam()), SCORE_REJECT); From af88d424bba522b5fddbcb62ceb6b0533fb1321b Mon Sep 17 00:00:00 2001 From: Kurt McMillan Date: Wed, 28 Jan 2026 18:56:24 +0000 Subject: [PATCH 12/12] hipfile/test: Use correct argument in fastpath test --- test/amd_detail/fastpath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/amd_detail/fastpath.cpp b/test/amd_detail/fastpath.cpp index 0f8eac8d..e4c69079 100644 --- a/test/amd_detail/fastpath.cpp +++ b/test/amd_detail/fastpath.cpp @@ -140,7 +140,7 @@ TEST_F(FastpathTest, ScoreRejectsNegativeAlignedBufferOffset) #endif EXPECT_CALL(*mbuffer, getBuffer).WillOnce(Return(DEFAULT_BUFFER_ADDR)); - ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_BUFFER_OFFSET, + ASSERT_EQ(Fastpath().score(mfile, mbuffer, DEFAULT_IO_SIZE, DEFAULT_FILE_OFFSET, -static_cast(DEFAULT_MEM_ALIGN)), SCORE_REJECT); }