Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions rocfile/src/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <memory>
#include <syslog.h>

using namespace rocFile::async;
using rocFile::context::Context;
namespace rocFile {

AsyncMonitor::AsyncMonitor() : is_finished{false}
{
Expand Down Expand Up @@ -78,9 +77,9 @@ AsyncMonitor::completion_thread()
}
}

AsyncOp::AsyncOp(io::IoType _io_type, std::shared_ptr<file::IFile> _file,
std::shared_ptr<buffer::IBuffer> _buffer, std::shared_ptr<stream::IStream> _stream,
size_t *_size, off_t *_file_offset, off_t *_buffer_offset, ssize_t *_bytes_transferred)
AsyncOp::AsyncOp(IoType _io_type, std::shared_ptr<IFile> _file, std::shared_ptr<IBuffer> _buffer,
std::shared_ptr<IStream> _stream, size_t *_size, off_t *_file_offset, off_t *_buffer_offset,
ssize_t *_bytes_transferred)
: io_type{_io_type}, file{_file}, buffer{_buffer}, stream{_stream},

size{stream->fixedIOSize() ? std::variant<size_t, size_t *>{*_size}
Expand All @@ -96,3 +95,5 @@ AsyncOp::AsyncOp(io::IoType _io_type, std::shared_ptr<file::IFile> _file,
AsyncOp::~AsyncOp()
{
}

}
14 changes: 7 additions & 7 deletions rocfile/src/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#include <variant>
#include <vector>

namespace rocFile::async {
namespace rocFile {

class AsyncOp {
public:
const io::IoType io_type;
std::shared_ptr<file::IFile> file;
std::shared_ptr<buffer::IBuffer> buffer;
std::shared_ptr<stream::IStream> stream;
const IoType io_type;
std::shared_ptr<IFile> file;
std::shared_ptr<IBuffer> buffer;
std::shared_ptr<IStream> stream;
std::variant<size_t, size_t *> size;
std::variant<const off_t, off_t *> file_offset;
std::variant<const off_t, off_t *> buffer_offset;
Expand All @@ -37,8 +37,8 @@ class AsyncOp {
AsyncOp &&operator=(AsyncOp &&) = delete;
virtual ~AsyncOp();

AsyncOp(io::IoType ioType, std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer,
std::shared_ptr<stream::IStream> stream, size_t *size, off_t *file_offset, off_t *buffer_offset,
AsyncOp(IoType ioType, std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer,
std::shared_ptr<IStream> stream, size_t *size, off_t *file_offset, off_t *buffer_offset,
ssize_t *bytes_transferred);
};

Expand Down
9 changes: 4 additions & 5 deletions rocfile/src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <sys/types.h>
#include <unistd.h>

namespace rocFile::backend {
namespace rocFile {

// The maximum number of bytes that can be transferred in a single read() or
// write() system call. Mirrors kernel's MAX_RW_COUNT
Expand All @@ -39,7 +39,7 @@ struct Backend {
/// @param file_offset Offset from the start of the file
/// @param buffer_offset Offset from the start of the buffer
/// @return
virtual int score(std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer, size_t size,
virtual int score(std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset) const = 0;

/// @brief Perform a read or write operation
Expand All @@ -54,9 +54,8 @@ struct Backend {
/// @return Number of bytes transferred, negative on error
///
/// @throws Hip::RuntimeError Sys::RuntimeError
virtual ssize_t io(rocFile::io::IoType type, std::shared_ptr<file::IFile> file,
std::shared_ptr<buffer::IBuffer> buffer, size_t size, off_t file_offset,
off_t buffer_offset) = 0;
virtual ssize_t io(IoType type, std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset) = 0;
};

}
15 changes: 7 additions & 8 deletions rocfile/src/backend/asyncop-fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@
#include <syslog.h>
#include <memory>

using namespace rocFile::backend;
using rocFile::context::Context;
using namespace rocFile;

static void
hipHostDeleter(void *buffer)
{
try {
Context<rocFile::Hip>::get()->hipHostFree(buffer);
Context<Hip>::get()->hipHostFree(buffer);
}
catch (...) {
Context<rocFile::Sys>::get()->syslog(LOG_CRIT, "Error freeing pinned host memory.");
Context<Sys>::get()->syslog(LOG_CRIT, "Error freeing pinned host memory.");
}
}

AsyncOpFallback::AsyncOpFallback(io::IoType _io_type, std::shared_ptr<file::IFile> _file,
std::shared_ptr<buffer::IBuffer> _buffer,
std::shared_ptr<stream::IStream> _stream, size_t *_size, off_t *_file_offset,
off_t *_buffer_offset, ssize_t *_bytes_transferred)
AsyncOpFallback::AsyncOpFallback(IoType _io_type, std::shared_ptr<IFile> _file,
std::shared_ptr<IBuffer> _buffer, std::shared_ptr<IStream> _stream,
size_t *_size, off_t *_file_offset, off_t *_buffer_offset,
ssize_t *_bytes_transferred)
: AsyncOp{_io_type, _file, _buffer, _stream, _size, _file_offset, _buffer_offset, _bytes_transferred},
bytes_transferred_internal{0}, gpu_buffer{buffer->getBuffer()}, bounce_buffer_dev_ptr{nullptr},
bounce_buffer{nullptr, [](void *addr) { (void)addr; }}
Expand Down
10 changes: 5 additions & 5 deletions rocfile/src/backend/asyncop-fallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "async.h"

namespace rocFile::backend {
namespace rocFile {

struct AsyncOpFallback : async::AsyncOp {
struct AsyncOpFallback : AsyncOp {
ssize_t bytes_transferred_internal;
void *const gpu_buffer;
void *bounce_buffer_dev_ptr;
Expand All @@ -17,9 +17,9 @@ struct AsyncOpFallback : async::AsyncOp {
std::unique_ptr<void, void (*)(void *)> bounce_buffer;

public:
AsyncOpFallback(io::IoType ioType, std::shared_ptr<file::IFile> file,
std::shared_ptr<buffer::IBuffer> buffer, std::shared_ptr<stream::IStream> stream,
size_t *size, off_t *fileOffset, off_t *bufferOffset, ssize_t *bytesTransferred);
AsyncOpFallback(IoType ioType, std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer,
std::shared_ptr<IStream> stream, size_t *size, off_t *fileOffset, off_t *bufferOffset,
ssize_t *bytesTransferred);

void *bounceBufferHostPtr();
void *devPtr();
Expand Down
20 changes: 8 additions & 12 deletions rocfile/src/backend/fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@
#include <sys/mman.h>

using namespace rocFile;
using namespace rocFile::backend;

using rocFile::buffer::IBuffer;
using rocFile::context::Context;
using rocFile::file::IFile;
using std::min;
using std::shared_ptr;
using std::unique_ptr;

static const size_t DefaultChunkSize = 16 * 1024 * 1024;

int
Fallback::score(std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset) const
Fallback::score(std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size, off_t file_offset,
off_t buffer_offset) const
{
(void)buffer_offset;
(void)file;
Expand All @@ -34,17 +30,17 @@ Fallback::score(std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuff
}

ssize_t
Fallback::io(io::IoType type, std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer,
size_t size, off_t file_offset, off_t buffer_offset)
Fallback::io(IoType type, std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset)
{
return io(type, file, buffer, size, file_offset, buffer_offset, DefaultChunkSize);
}

ssize_t
Fallback::io(io::IoType io_type, shared_ptr<IFile> file, shared_ptr<IBuffer> buffer, size_t size,
Fallback::io(IoType io_type, shared_ptr<IFile> file, shared_ptr<IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset, size_t chunk_size)
{
size = min(size, rocFile::backend::MAX_RW_COUNT);
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)) {
Expand Down Expand Up @@ -74,14 +70,14 @@ Fallback::io(io::IoType io_type, shared_ptr<IFile> file, shared_ptr<IBuffer> buf
static_cast<size_t>(total_io_bytes));
try {
switch (io_type) {
case io::IoType::Read:
case IoType::Read:
io_bytes = Context<Sys>::get()->pread(file->getFd(), bounce_buffer.get(), count, offset);
if (io_bytes > 0) {
Context<Hip>::get()->hipMemcpy(device_buffer_position, bounce_buffer.get(),
static_cast<size_t>(io_bytes), hipMemcpyHostToDevice);
}
break;
case io::IoType::Write:
case IoType::Write:
Context<Hip>::get()->hipMemcpy(bounce_buffer.get(), device_buffer_position, count,
hipMemcpyDeviceToHost);
Context<Hip>::get()->hipStreamSynchronize(nullptr);
Expand Down
14 changes: 7 additions & 7 deletions rocfile/src/backend/fallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
#include "file.h"
#include "io.h"

namespace rocFile::backend {
namespace rocFile {

struct Fallback : public Backend {
virtual ~Fallback() override = default;

int score(std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset) const override;
int score(std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size, off_t file_offset,
off_t buffer_offset) const override;

ssize_t io(io::IoType type, std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer,
size_t size, off_t file_offset, off_t buffer_offset) override;
ssize_t io(IoType type, std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset) override;

// Once we can import gtest.h and make test suites or test friends everything
// below here should be made protected.
// protected:

ssize_t io(io::IoType type, std::shared_ptr<file::IFile> file, std::shared_ptr<buffer::IBuffer> buffer,
size_t size, off_t file_offset, off_t buffer_offset, size_t chunk_size);
ssize_t io(IoType type, std::shared_ptr<IFile> file, std::shared_ptr<IBuffer> buffer, size_t size,
off_t file_offset, off_t buffer_offset, size_t chunk_size);
};
}
10 changes: 5 additions & 5 deletions rocfile/src/batch/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include <unordered_map>
#include <vector>

namespace rocFile::batch {
namespace rocFile {

BatchOperation::BatchOperation(std::unique_ptr<const rocFileIOParams_t> params,
std::shared_ptr<buffer::IBuffer> _buffer, std::shared_ptr<file::IFile> _file)
std::shared_ptr<IBuffer> _buffer, std::shared_ptr<IFile> _file)
: io_params{std::move(params)}, buffer{_buffer}, file{_file}
{
// Cookie allows the user to track which operation caused the error.
Expand Down Expand Up @@ -120,7 +120,7 @@ BatchContext::submit_operations(const rocFileIOParams_t *params, unsigned num_pa
auto param_copy = std::make_unique<const rocFileIOParams_t>(params[i]);
// flags currently unused. Ambiguous if flags in rocFileBatchIOSubmit is for buffer or
// file flags.
auto [_file, _buffer] = context::Context<DriverState>::get()->getFileAndBuffer(
auto [_file, _buffer] = Context<DriverState>::get()->getFileAndBuffer(
param_copy->fh, param_copy->u.batch.devPtr_base, param_copy->u.batch.size, 0);
auto op = std::make_shared<BatchOperation>(std::move(param_copy), _buffer, _file);

Expand Down Expand Up @@ -159,7 +159,7 @@ BatchContextMap::destroyContext(rocFileBatchHandle_t handle)

auto context = active_contexts.find(handle);
if (context == active_contexts.end()) {
throw InvalidHandle();
throw InvalidBatchHandle();
}
// TODO: Check for outstanding operations.
// TODO: Attempt to cancel any outstanding operations.
Expand All @@ -177,7 +177,7 @@ BatchContextMap::get(rocFileBatchHandle_t handle)

auto context = active_contexts.find(handle);
if (context == active_contexts.end()) {
throw InvalidHandle();
throw InvalidBatchHandle();
}
return context->second;
}
Expand Down
14 changes: 7 additions & 7 deletions rocfile/src/batch/batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
#include <unordered_map>
#include <unordered_set>

namespace rocFile::batch {
namespace rocFile {

struct InvalidHandle : public std::invalid_argument {
InvalidHandle() : std::invalid_argument{"Invalid batch handle"}
struct InvalidBatchHandle : public std::invalid_argument {
InvalidBatchHandle() : std::invalid_argument{"Invalid batch handle"}
{
}
};
Expand All @@ -31,19 +31,19 @@ class BatchOperation {
/// @param [in] params IO parameters
/// @param [in] buffer Buffer corresponding to params->u.batch.devPtr_base
/// @param [in] file File corresponding params->fh
BatchOperation(std::unique_ptr<const rocFileIOParams_t> params, std::shared_ptr<buffer::IBuffer> buffer,
std::shared_ptr<file::IFile> file);
BatchOperation(std::unique_ptr<const rocFileIOParams_t> params, std::shared_ptr<IBuffer> buffer,
std::shared_ptr<IFile> file);

private:
/// @brief A copy of the params provided by the application.
/// @internal Keep this listed at the top of BatchOperation.
const std::unique_ptr<const rocFileIOParams_t> io_params;

/// @brief A reference to the specified Buffer.
const std::shared_ptr<const buffer::IBuffer> buffer;
const std::shared_ptr<const IBuffer> buffer;

/// @brief A reference to the specified registered File.
const std::shared_ptr<const file::IFile> file;
const std::shared_ptr<const IFile> file;
};

class IBatchContext {
Expand Down
16 changes: 7 additions & 9 deletions rocfile/src/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
#include <utility>
#include <vector>

using rocFile::Hip;
using rocFile::context::Context;
using std::shared_ptr;
using std::transform;
using std::vector;

namespace rocFile::buffer {
namespace rocFile {

static bool
isValidBufferRegion(void *ptr, size_t length)
Expand Down Expand Up @@ -57,11 +55,11 @@ Buffer::Buffer(const void *_buffer, size_t _length, int _flags)
}

if (type != hipMemoryTypeDevice) {
throw buffer::InvalidMemoryType();
throw InvalidMemoryType();
}

if (!isValidBufferRegion(buffer, length)) {
throw buffer::InvalidPointerRange();
throw InvalidPointerRange();
}
}

Expand Down Expand Up @@ -93,7 +91,7 @@ void
BufferMap::registerBuffer(const void *buf, size_t length, int flags)
{
if (from_ptr.end() != from_ptr.find(buf)) {
throw buffer::AlreadyRegistered();
throw BufferAlreadyRegistered();
}

auto buffer = std::shared_ptr<IBuffer>(new Buffer(buf, length, flags));
Expand All @@ -105,11 +103,11 @@ BufferMap::deregisterBuffer(const void *buf)
{
auto itr = from_ptr.find(buf);
if (from_ptr.end() == itr) {
throw buffer::NotRegistered();
throw BufferNotRegistered();
}

if (1 < itr->second.use_count()) {
throw buffer::OperationsOutstanding();
throw BufferOperationsOutstanding();
}

from_ptr.erase(buf);
Expand All @@ -120,7 +118,7 @@ BufferMap::getBuffer(const void *buf)
{
auto itr = from_ptr.find(buf);
if (from_ptr.end() == itr) {
throw buffer::NotRegistered();
throw BufferNotRegistered();
}

return itr->second;
Expand Down
Loading
Loading