Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
53 changes: 49 additions & 4 deletions cpp/src/utilities/host_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#include <algorithm>
#include <atomic>
#include <cassert>
#include <cstdlib>
#include <memory>
#include <mutex>
#include <optional>
#include <shared_mutex>
Expand All @@ -27,6 +29,51 @@ namespace cudf {

namespace {

// Inlined from RMM internals after public MR definitions moved to source files:
// https://github.com/rapidsai/rmm/pull/2416
void* aligned_host_allocate(std::size_t bytes, std::size_t alignment)
{
assert(rmm::is_supported_alignment(alignment));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this assert needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// allocate memory for bytes, plus potential alignment correction,
// plus store of the correction offset
std::size_t padded_allocation_size{bytes + alignment + sizeof(std::ptrdiff_t)};
char* const original = static_cast<char*>(::operator new(padded_allocation_size));

// account for storage of offset immediately prior to the aligned pointer
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
void* aligned{original + sizeof(std::ptrdiff_t)};

// std::align modifies `aligned` to point to the first aligned location
std::align(alignment, bytes, aligned, padded_allocation_size);

// Compute the offset between the original and aligned pointers
std::ptrdiff_t const offset = static_cast<char*>(aligned) - original;

// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
*(static_cast<std::ptrdiff_t*>(aligned) - 1) = offset;

return aligned;
}

void aligned_host_deallocate(void* ptr,
[[maybe_unused]] std::size_t bytes,
[[maybe_unused]] std::size_t alignment) noexcept
{
assert(rmm::is_supported_alignment(alignment));

if (ptr != nullptr) {
// Get offset from the location immediately prior to the aligned pointer
// NOLINTNEXTLINE
std::ptrdiff_t const offset = *(reinterpret_cast<std::ptrdiff_t*>(ptr) - 1);

// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
void* const original = static_cast<char*>(ptr) - offset;

::operator delete(original);
}
}

class pinned_pool_with_fallback_memory_resource {
using upstream_mr = rmm::mr::pinned_host_memory_resource;
using host_pooled_mr = rmm::mr::pool_memory_resource;
Expand Down Expand Up @@ -219,8 +266,7 @@ class new_delete_memory_resource {
void* allocate_sync(std::size_t bytes, std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT)
{
try {
return rmm::detail::aligned_host_allocate(
bytes, alignment, [](std::size_t size) { return ::operator new(size); });
return aligned_host_allocate(bytes, alignment);
} catch (std::bad_alloc const& e) {
CUDF_FAIL("Failed to allocate memory: " + std::string{e.what()}, rmm::out_of_memory);
}
Expand All @@ -237,8 +283,7 @@ class new_delete_memory_resource {
std::size_t bytes,
std::size_t alignment = rmm::CUDA_ALLOCATION_ALIGNMENT) noexcept
{
rmm::detail::aligned_host_deallocate(
ptr, bytes, alignment, [](void* ptr) { ::operator delete(ptr); });
aligned_host_deallocate(ptr, bytes, alignment);
}

void deallocate([[maybe_unused]] cuda::stream_ref stream,
Expand Down
3 changes: 2 additions & 1 deletion python/cudf/cudf/pandas/scripts/run-pandas-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ if [ ! -d "pandas-tests" ]; then
# Vendored from pandas/pyproject.toml
cat > pandas-tests/pyproject.toml << \EOF
[tool.pytest.ini_options]
xfail_strict = true
# flaky xpasses tracked at https://github.com/rapidsai/cudf/issues/22681
xfail_strict = false
markers = [
"single_cpu: tests that should run on a single cpu only",
"slow: mark a test as slow",
Expand Down
3 changes: 1 addition & 2 deletions python/cudf_polars/cudf_polars/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ def all_gather_host_data(
allgather = AllGather(
comm=comm,
op_id=op_id,
br=br,
statistics=Statistics(enable=False),
br=br
)
# TODO: Make AllGather (bulk) a context manager so this becomes
# with AllGather(...) as ag:
Expand Down
Loading