-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable hugepage for arrow host allocations #13914
Changes from 6 commits
bf367de
167e154
c75d6b6
b982ab4
d9ab05c
0599b45
52705a0
41298b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,40 @@ | |
|
||
#include <cudf/detail/interop.hpp> | ||
|
||
#include <memory> | ||
#include <sys/mman.h> | ||
#include <unistd.h> | ||
|
||
namespace cudf { | ||
namespace detail { | ||
|
||
/* | ||
Enable Transparent Huge Pages (THP) for large (>4MB) allocations. | ||
`buf` is returned untouched. | ||
Enabling THP can improve performance of device-host memory transfers | ||
significantly, see <https://github.com/rapidsai/cudf/pull/13914>. | ||
*/ | ||
template <typename T> | ||
T enable_hugepage(T&& buf) | ||
{ | ||
if (buf->size() < (1u << 22u)) { // Smaller than 4 MB | ||
return buf; | ||
} | ||
|
||
#ifdef MADV_HUGEPAGE | ||
const auto pagesize = sysconf(_SC_PAGESIZE); | ||
void* addr = const_cast<uint8_t*>(buf->data()); | ||
if (addr == nullptr) { return buf; } | ||
auto length{static_cast<std::size_t>(buf->size())}; | ||
if (std::align(pagesize, pagesize, addr, length)) { | ||
// Intentionally not checking for errors that may be returned by older kernel versions; | ||
// optimistically tries enabling huge pages. | ||
madvise(addr, length, MADV_HUGEPAGE); | ||
} | ||
#endif | ||
return buf; | ||
} | ||
|
||
std::unique_ptr<arrow::Buffer> allocate_arrow_buffer(int64_t const size, arrow::MemoryPool* ar_mr) | ||
{ | ||
/* | ||
|
@@ -28,9 +59,9 @@ std::unique_ptr<arrow::Buffer> allocate_arrow_buffer(int64_t const size, arrow:: | |
To work around this issue we compile an allocation shim in C++ and use | ||
that from our cuda sources | ||
*/ | ||
auto result = arrow::AllocateBuffer(size, ar_mr); | ||
arrow::Result<std::unique_ptr<arrow::Buffer>> result = arrow::AllocateBuffer(size, ar_mr); | ||
CUDF_EXPECTS(result.ok(), "Failed to allocate Arrow buffer"); | ||
return std::move(result).ValueOrDie(); | ||
return enable_hugepage(std::move(result).ValueOrDie()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for Generally There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice, we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I was assuming you just copied the std::move from the code that was there before, which just had There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The compiler does not allow |
||
} | ||
|
||
std::shared_ptr<arrow::Buffer> allocate_arrow_bitmap(int64_t const size, arrow::MemoryPool* ar_mr) | ||
|
@@ -42,9 +73,9 @@ std::shared_ptr<arrow::Buffer> allocate_arrow_bitmap(int64_t const size, arrow:: | |
To work around this issue we compile an allocation shim in C++ and use | ||
that from our cuda sources | ||
*/ | ||
auto result = arrow::AllocateBitmap(size, ar_mr); | ||
arrow::Result<std::shared_ptr<arrow::Buffer>> result = arrow::AllocateBitmap(size, ar_mr); | ||
vuule marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CUDF_EXPECTS(result.ok(), "Failed to allocate Arrow bitmap"); | ||
return std::move(result).ValueOrDie(); | ||
return enable_hugepage(std::move(result).ValueOrDie()); | ||
} | ||
|
||
} // namespace detail | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we have enable_hugepage just take a host_span? Do we really need to forward
std::unique_ptr<arrow::Buffer>
through the function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to but it means we can avoid an in-place function and have a simply return wrapper
return enable_hugepage(...)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't see the benefit, and I'm fine with that.