2525#include < mutex> // for once_flag, call_once
2626#include < vector> // for vector
2727
28- #include " compressed_iterator.h" // for CompressedByteT
29- #include " cuda_context.cuh" // for CUDAContext
30- #include " cuda_dr_utils.h" // for GetGlobalCuDriverApi
31- #include " cuda_pinned_allocator.h" // for HostPinnedMemPool
28+ #include " compressed_iterator.h" // for CompressedByteT
29+ #include " cuda_context.cuh" // for CUDAContext
30+ #include " cuda_dr_utils.h" // for GetGlobalCuDriverApi
3231#include " device_compression.h"
3332#include " device_vector.cuh" // for DeviceUVector
3433#include " nvtx_utils.h" // for xgboost_NVTX_FN_RANGE
@@ -154,9 +153,11 @@ void SafeNvComp(nvcompStatus_t status) {
154153 return de;
155154}
156155
157- SnappyDecomprMgrImpl::SnappyDecomprMgrImpl (
158- dh::CUDAStreamView s, std::shared_ptr<common::cuda_impl::HostPinnedMemPool> pool,
159- CuMemParams params, common::Span<std::uint8_t const > in_compressed_data) {
156+ SnappyDecomprMgrImpl::SnappyDecomprMgrImpl (dh::CUDAStreamView s,
157+ std::shared_ptr<HostPinnedMemPool> pool,
158+ CuMemParams params,
159+ common::Span<std::uint8_t const > in_compressed_data)
160+ : n_dst_bytes{params.TotalDstBytes ()} {
160161 std::size_t n_chunks = params.size ();
161162 if (n_chunks == 0 ) {
162163 return ;
@@ -177,6 +178,7 @@ SnappyDecomprMgrImpl::SnappyDecomprMgrImpl(
177178 last_in += params[i].src_nbytes ;
178179 last_out += params[i].dst_nbytes ;
179180 }
181+ CHECK_EQ (this ->n_dst_bytes , last_out);
180182
181183 // copy to d
182184 dh::CopyTo (in_chunk_ptrs, &this ->d_in_chunk_ptrs , s);
@@ -210,6 +212,7 @@ SnappyDecomprMgrImpl::SnappyDecomprMgrImpl(
210212
211213common::Span<CUmemDecompressParams> SnappyDecomprMgrImpl::GetParams (
212214 common::Span<common::CompressedByteT> out) {
215+ xgboost_NVTX_FN_RANGE_C (3 , 252 , 198 );
213216 if (this ->de_params .empty ()) {
214217 return {};
215218 }
@@ -218,19 +221,34 @@ common::Span<CUmemDecompressParams> SnappyDecomprMgrImpl::GetParams(
218221 // Set the output buffers.
219222 std::size_t last_out = 0 ;
220223 for (std::size_t i = 0 ; i < n_chunks; ++i) {
224+ this ->de_params_copy [i] = this ->de_params [i];
221225 this ->de_params_copy [i].dst = out.subspan (last_out, de_params[i].dstNumBytes ).data ();
222226 last_out += de_params[i].dstNumBytes ;
223227 }
224228
225229 return this ->de_params_copy .ToSpan ();
226230}
227231
232+ [[nodiscard]] bool SnappyDecomprMgrImpl::Empty () const {
233+ #if defined(CUDA_HW_DECOM_AVAILABLE)
234+ return this ->de_params .empty ();
235+ #else
236+ return true ;
237+ #endif
238+ }
239+
228240SnappyDecomprMgr::SnappyDecomprMgr () : pimpl_{std::make_unique<SnappyDecomprMgrImpl>()} {}
229241SnappyDecomprMgr::SnappyDecomprMgr (SnappyDecomprMgr&& that) = default ;
230242SnappyDecomprMgr& SnappyDecomprMgr::operator =(SnappyDecomprMgr&& that) = default ;
231243
232244SnappyDecomprMgr::~SnappyDecomprMgr () = default ;
233245
246+ [[nodiscard]] bool SnappyDecomprMgr::Empty () const { return this ->Impl ()->Empty (); }
247+
248+ [[nodiscard]] std::size_t SnappyDecomprMgr::DecompressedBytes () const {
249+ return this ->Impl ()->n_dst_bytes ;
250+ }
251+
234252SnappyDecomprMgrImpl* SnappyDecomprMgr::Impl () const { return this ->pimpl_ .get (); }
235253
236254void DecompressSnappy (dh::CUDAStreamView stream, SnappyDecomprMgr const & mgr,
@@ -272,7 +290,7 @@ void DecompressSnappy(dh::CUDAStreamView stream, SnappyDecomprMgr const& mgr,
272290 dh::device_vector<void *> d_out_ptrs (n_chunks);
273291 dh::safe_cuda (cudaMemcpyAsync (d_out_ptrs.data ().get (), h_out_ptrs.data (),
274292 dh::ToSpan (d_out_ptrs).size_bytes (), cudaMemcpyDefault, stream));
275-
293+ CHECK ( curt::SupportsPageableMem () || curt::SupportsAts ());
276294 // Run nvcomp
277295 SafeNvComp (nvcompBatchedSnappyDecompressAsync (
278296 mgr_impl->d_in_chunk_ptrs .data ().get (), mgr_impl->d_in_chunk_sizes .data ().get (),
@@ -387,8 +405,9 @@ void DecompressSnappy(dh::CUDAStreamView stream, SnappyDecomprMgr const& mgr,
387405}
388406
389407[[nodiscard]] common::RefResourceView<std::uint8_t > CoalesceCompressedBuffersToHost (
390- dh::CUDAStreamView stream, CuMemParams const & in_params,
391- dh::DeviceUVector<std::uint8_t > const & in_buf, CuMemParams* p_out) {
408+ dh::CUDAStreamView stream, std::shared_ptr<HostPinnedMemPool> pool,
409+ CuMemParams const & in_params, dh::DeviceUVector<std::uint8_t > const & in_buf,
410+ CuMemParams* p_out) {
392411 std::size_t n_total_act_bytes = in_params.TotalSrcActBytes ();
393412 std::size_t n_total_bytes = in_params.TotalSrcBytes ();
394413 if (n_total_bytes == 0 ) {
@@ -399,8 +418,8 @@ void DecompressSnappy(dh::CUDAStreamView stream, SnappyDecomprMgr const& mgr,
399418 // copy from device buffer to the host cache.
400419 CHECK_EQ (n_total_bytes, in_buf.size ());
401420 auto c_page =
402- common::MakeFixedVecWithPinnedMalloc <std::remove_reference_t <decltype (in_buf)>::value_type>(
403- n_total_act_bytes);
421+ common::MakeFixedVecWithPinnedMemPool <std::remove_reference_t <decltype (in_buf)>::value_type>(
422+ pool, n_total_act_bytes, stream );
404423 std::vector<std::uint8_t const *> srcs (in_params.size ());
405424 std::vector<std::uint8_t *> dsts (in_params.size ());
406425 std::vector<std::size_t > sizes (in_params.size ());
@@ -450,6 +469,12 @@ SnappyDecomprMgr& SnappyDecomprMgr::operator=(SnappyDecomprMgr&& that) = default
450469SnappyDecomprMgr::~SnappyDecomprMgr () = default ;
451470SnappyDecomprMgrImpl* SnappyDecomprMgr::Impl () const { return nullptr ; }
452471
472+ [[nodiscard]] bool SnappyDecomprMgr::Empty () const { return true ; }
473+ [[nodiscard]] std::size_t SnappyDecomprMgr::DecompressedBytes () const {
474+ common::AssertNvCompSupport ();
475+ return 0 ;
476+ }
477+
453478// Round-trip compression
454479void DecompressSnappy (dh::CUDAStreamView, SnappyDecomprMgr const &,
455480 common::Span<common::CompressedByteT>, bool ) {
@@ -464,7 +489,8 @@ void DecompressSnappy(dh::CUDAStreamView, SnappyDecomprMgr const&,
464489}
465490
466491[[nodiscard]] common::RefResourceView<std::uint8_t > CoalesceCompressedBuffersToHost (
467- dh::CUDAStreamView, CuMemParams const &, dh::DeviceUVector<std::uint8_t > const &, CuMemParams*) {
492+ dh::CUDAStreamView, std::shared_ptr<HostPinnedMemPool>, CuMemParams const &,
493+ dh::DeviceUVector<std::uint8_t > const &, CuMemParams*) {
468494 common::AssertNvCompSupport ();
469495 return {};
470496}
0 commit comments