Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5414a96
rocfile/test: Consolidate read/write hipPointerGetAttributes test
kurtmcmillan Nov 12, 2025
9199164
rocfile/test: Consolidate read/write unsupported hip memory type test
kurtmcmillan Nov 12, 2025
92b4582
rocfile/test: Consolidate read/write invalid buffer length test
kurtmcmillan Nov 12, 2025
a3e5609
rocfile/test: Consolidate read/write invalid file handle test
kurtmcmillan Nov 12, 2025
f49268b
rocfile: Allow backends to be injected into rocFileIo
kurtmcmillan Nov 20, 2025
1253688
rocfile/test: Use a mock backend in rocFileIo tests
kurtmcmillan Nov 20, 2025
3745f3b
rocfile/test: Consolidate read/write handles Sys::RuntimeError
kurtmcmillan Nov 20, 2025
42cd7c0
rocfile: Validate offsets and IO size in Fastpath::io
kurtmcmillan Nov 21, 2025
7b8ce2b
rocfile: Remove negative offset check from Fastpath::score
kurtmcmillan Nov 21, 2025
4fd091f
rocfile: Align Fallback::io's argument validation with Fastpath::io's
kurtmcmillan Nov 21, 2025
b229003
rocfile: Handle zero sized IOs in Fallback::io
kurtmcmillan Nov 21, 2025
9e05cfd
rocfile/test: Consolidate read/write invalid argument test
kurtmcmillan Nov 21, 2025
ba95130
rocfile/test: Consolidate read/write handles Hip::RuntimeError
kurtmcmillan Nov 20, 2025
ea3c611
rocfile: Move backend selection tests
kurtmcmillan Nov 21, 2025
e946565
rocfile/test: Move io.cpp to fallback.cpp
kurtmcmillan Nov 21, 2025
4073a1e
rocfile/test: Rename FallbackValidationTests to FallbackParam
kurtmcmillan Nov 21, 2025
675e77d
rocfile/test: Rename RocFileIO to FallbackIo
kurtmcmillan Nov 21, 2025
e59c1f3
rocfile/test: Rename RocFileWrite to FallbackWrite
kurtmcmillan Nov 21, 2025
7fd6057
rocfile/test: Rename RocFileRead to FallbackRead
kurtmcmillan Nov 21, 2025
ace606b
rocfile/test: Remove remaining rocFileRead call from Fallback tests
kurtmcmillan Nov 21, 2025
92daba0
rocfile/test: Remove remaining rocFileWrite call from fallback tests
kurtmcmillan Nov 21, 2025
22b8518
rocfile: IWYU fixes for PR
kurtmcmillan Nov 24, 2025
a5bc621
review: rocfile/test/rocfile.cpp: errno.h -> cerrno
kurtmcmillan Nov 25, 2025
8edf6e8
Merge branch 'develop' into z/kumcmill/move-rocfileio-tests
kurtmcmillan Nov 25, 2025
3075fe7
Merge branch 'develop' into z/kumcmill/move-rocfileio-tests
kurtmcmillan Nov 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions rocfile/src/backend/fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,24 @@ ssize_t
Fallback::io(IoType io_type, shared_ptr<IFile> file, shared_ptr<IBuffer> buffer, size_t size,
hoff_t file_offset, hoff_t buffer_offset, size_t chunk_size)
{
size_t buflen{buffer->getLength()};

size = min(size, rocFile::MAX_RW_COUNT);

if ((buffer_offset < 0) || (buffer->getLength() <= static_cast<size_t>(buffer_offset)) ||
(buffer->getLength() - static_cast<size_t>(buffer_offset) < size)) {
throw std::invalid_argument("bad buffer offset");
if (file_offset < 0) {
throw std::invalid_argument("Negative file offset");
}

if (file_offset < 0) {
throw std::invalid_argument("negative file offset");
if (buffer_offset < 0) {
throw std::invalid_argument("Negative buffer offset");
}

if (size == 0) {
return 0;
if (buflen <= static_cast<size_t>(buffer_offset)) {
throw std::invalid_argument("Buffer offset larger than buffer length");
}

if (buflen - static_cast<size_t>(buffer_offset) < size) {
throw std::invalid_argument("IO could overflow buffer");
}

auto ptr = Context<Sys>::get()->mmap(nullptr, chunk_size, PROT_READ | PROT_WRITE,
Expand All @@ -71,7 +76,7 @@ Fallback::io(IoType io_type, shared_ptr<IFile> file, shared_ptr<IBuffer> buffer,
unique_ptr<void, decltype(deleter)> bounce_buffer{ptr, deleter};

ssize_t total_io_bytes = 0;
while (static_cast<size_t>(total_io_bytes) < size) {
do {
auto count = min(chunk_size, size - static_cast<size_t>(total_io_bytes));
auto offset = file_offset + total_io_bytes;
ssize_t io_bytes = 0;
Expand Down Expand Up @@ -108,7 +113,7 @@ Fallback::io(IoType io_type, shared_ptr<IFile> file, shared_ptr<IBuffer> buffer,
if (io_bytes == 0) {
break;
}
}
} while (static_cast<size_t>(total_io_bytes) < size);

return total_io_bytes;
}
20 changes: 17 additions & 3 deletions rocfile/src/backend/fastpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ Fastpath::score(shared_ptr<IFile> file, shared_ptr<IBuffer> buffer, size_t size,

accept_io &= buffer->getType() == hipMemoryTypeDevice;

accept_io &= 0 <= file_offset;
accept_io &= 0 <= buffer_offset;

#if defined(STATX_DIOALIGN)
const struct statx &stx{file->getStatx()};
accept_io &= !!(stx.stx_mask & STATX_DIOALIGN);
Expand All @@ -156,9 +153,26 @@ Fastpath::io(IoType type, shared_ptr<IFile> file, shared_ptr<IBuffer> buffer, si
void *devptr{reinterpret_cast<void *>(reinterpret_cast<intptr_t>(buffer->getBuffer()) + buffer_offset)};
hipAmdFileHandle_t handle{};
size_t nbytes{};
size_t buflen{buffer->getLength()};

handle.fd = file->getFd();

if (file_offset < 0) {
throw std::invalid_argument("Negative file offset");
}

if (buffer_offset < 0) {
throw std::invalid_argument("Negative buffer offset");
}

if (buflen <= static_cast<size_t>(buffer_offset)) {
throw std::invalid_argument("Invalid buffer offset");
}

if (buflen - static_cast<size_t>(buffer_offset) < size) {
throw std::invalid_argument("IO could overflow buffer");
}

switch (type) {
case IoType::Read:
nbytes = Context<Hip>::get()->hipAmdFileRead(handle, devptr, size, file_offset);
Expand Down
6 changes: 5 additions & 1 deletion rocfile/src/rocfile-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
#include "hipfile-types.h"
#include "rocfile.h"

#include <memory>
#include <sys/types.h>
#include <vector>

namespace rocFile {
enum class IoType;
struct Backend;
}

// NOTE: This is an internal API that we don't document, even though it's
Expand All @@ -24,4 +27,5 @@ ROCFILE_API
void rocFileEnsureDriverInitPrivate();

ssize_t rocFileIo(rocFile::IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size,
hoff_t file_offset, hoff_t buffer_offset);
hoff_t file_offset, hoff_t buffer_offset,
const std::vector<std::shared_ptr<rocFile::Backend>> &backends);
19 changes: 13 additions & 6 deletions rocfile/src/rocfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <system_error>

using namespace rocFile;
using namespace std;

const char *
rocFileOpStatusError(rocFileOpError_t status)
Expand Down Expand Up @@ -224,14 +225,20 @@ catch (...) {
return handle_exception();
}

ssize_t
rocFileIo(IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset,
hoff_t buffer_offset)
try {
/// @brief Get the cached list of backends obtained from DriverState
static const vector<shared_ptr<Backend>> &
getCachedBackends()
{
HIPFILE_WARN_NO_EXIT_DTOR_OFF
static const auto backends{Context<DriverState>::get()->getBackends()};
HIPFILE_WARN_NO_EXIT_DTOR_ON
return backends;
}

ssize_t
rocFileIo(IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset,
hoff_t buffer_offset, const vector<shared_ptr<Backend>> &backends)
try {
auto [file, buffer] = Context<DriverState>::get()->getFileAndBuffer(fh, buffer_base, size, 0);
int score{-1};
std::shared_ptr<Backend> backend{};
Expand Down Expand Up @@ -288,14 +295,14 @@ catch (...) {
ssize_t
rocFileRead(rocFileHandle_t fh, void *buffer_base, size_t size, hoff_t file_offset, hoff_t buffer_offset)
{
return rocFileIo(IoType::Read, fh, buffer_base, size, file_offset, buffer_offset);
return rocFileIo(IoType::Read, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends());
}

ssize_t
rocFileWrite(rocFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset,
hoff_t buffer_offset)
{
return rocFileIo(IoType::Write, fh, buffer_base, size, file_offset, buffer_offset);
return rocFileIo(IoType::Write, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends());
}

rocFileError_t
Expand Down
2 changes: 1 addition & 1 deletion rocfile/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ set(TEST_SOURCE_FILES
driver.cpp
handle.cpp
hip.cpp
fallback.cpp
fastpath.cpp
io.cpp
misc.cpp
mountinfo.cpp
rocfile.cpp
Expand Down
Loading
Loading