diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index ad39635e..95110db3 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -289,6 +289,7 @@ ALIASES += buffer_base_param="Base address of the GPU buffer" ALIASES += batch_handle_param="Opaque handle for batch operations" ALIASES += hipstream_param="The stream used for async IO requests" ALIASES += hipstream_if_null="If NULL, this request will be synchronous" +ALIASES += max_io_size_note="@note The maximum IO size is determined by the Linux kernel and is currently 2^31 - PAGE_SIZE" # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources # only. Doxygen will then generate output that is more tailored for C. For diff --git a/include/hipfile.h b/include/hipfile.h index e6ffe649..ccf898b0 100644 --- a/include/hipfile.h +++ b/include/hipfile.h @@ -517,6 +517,8 @@ hipFileError_t hipFileBufDeregister(const void *buffer_base); * @param [in] file_offset Offset into the file that should be read from * @param [in] buffer_offset Offset of the GPU buffer that that the data should be written to * + * \max_io_size_note + * * @return if >= 0: Number of bytes read * @return if -1: System error (check `errno` for the specific error) * @return else: Negative value of the related hipFileOpError_t @@ -538,6 +540,8 @@ ssize_t hipFileRead(hipFileHandle_t fh, void *buffer_base, size_t size, hoff_t f * @param [in] file_offset Offset into the file that should be written to * @param [in] buffer_offset Offset of the GPU buffer that the data should be read from * + * \max_io_size_note + * * @return if >= 0: Number of bytes written * @return if -1: System error (check `errno` for the specific error) * @return else: Negative value of the related hipFileOpError_t @@ -838,6 +842,8 @@ void hipFileBatchIODestroy(hipFileBatchHandle_t batch_idp); * @param [out] bytes_read_p Number of bytes read * @param [in] stream \hipstream_param. \hipstream_if_null. * + * \max_io_size_note + * * @return \hipfile_error_return */ HIPFILE_API @@ -856,6 +862,8 @@ hipFileError_t hipFileReadAsync(hipFileHandle_t fh, void *buffer_base, size_t *s * @param [out] bytes_written_p Number of bytes written * @param [in] stream \hipstream_param. \hipstream_if_null. * + * \max_io_size_note + * * @return \hipfile_error_return */ HIPFILE_API diff --git a/src/amd_detail/backend.h b/src/amd_detail/backend.h index c2e040df..a2373d75 100644 --- a/src/amd_detail/backend.h +++ b/src/amd_detail/backend.h @@ -12,15 +12,26 @@ #include "sys.h" #include +#include #include #include #include namespace hipFile { +static const size_t PAGE_SIZE{[] { + long v = sysconf(_SC_PAGE_SIZE); + if (v == -1) { + throw std::runtime_error("sysconf(_SC_PAGE_SIZE) failed"); + } + return static_cast(v); +}()}; + +static const size_t PAGE_MASK{~(PAGE_SIZE - 1)}; + // The maximum number of bytes that can be transferred in a single read() or // write() system call. Mirrors kernel's MAX_RW_COUNT -static const size_t MAX_RW_COUNT = 0x7ffff000; +static const size_t MAX_RW_COUNT = (INT_MAX & PAGE_MASK); struct Backend { virtual ~Backend() = default;