Skip to content

Commit 015c09f

Browse files
kurtmcmillanderobins
authored andcommitted
hipFile: Mirror kernel's MAX_RW_COUNT computation
Since PAGE_SIZE is not the same on all plaforms, mirror the kernel's computation of MAX_RW_COUNT so that hipFile doesn't use an incorrect value.
1 parent b04f41d commit 015c09f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/amd_detail/backend.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "io.h"
1212
#include "sys.h"
1313

14+
#include <climits>
1415
#include <cstddef>
1516
#include <exception>
1617
#include <memory>
@@ -19,9 +20,19 @@
1920

2021
namespace hipFile {
2122

23+
static const size_t PAGE_SIZE{[] {
24+
long v = sysconf(_SC_PAGE_SIZE);
25+
if (v == -1) {
26+
throw std::runtime_error("sysconf(_SC_PAGE_SIZE) failed");
27+
}
28+
return static_cast<size_t>(v);
29+
}()};
30+
31+
static const size_t PAGE_MASK{~(PAGE_SIZE - 1)};
32+
2233
// The maximum number of bytes that can be transferred in a single read() or
2334
// write() system call. Mirrors kernel's MAX_RW_COUNT
24-
static const size_t MAX_RW_COUNT = 0x7ffff000;
35+
static const size_t MAX_RW_COUNT = (INT_MAX & PAGE_MASK);
2536

2637
/// @brief Backend is not enabled
2738
struct BackendDisabled : public std::runtime_error {

0 commit comments

Comments
 (0)